Post on 09-May-2015
description
transcript
RCP by Example
by
Subramanian Thiruppathi
Agenda
Talk about RCP RCP Features Real Time Examples Discuss about Important Classes in
RCP Recommended Reading
End User Expectation …
High Quality end-user experience High-Speed local processing Rich native UI
drag-and-drop Clipboard Navigation Customization
Developer Expectation …
Good Development Environment Easy Deployment Easy update latest code in Client
side And lot more ….
What is RCP
An application that uses the windowing and GUI features of the operating system
RCP Features Components Middleware and infrastructure Native user experience
Look and Feel Portability
Even support Mobile Application (J2ME) Intelligent install and update
Java web start Disconnected operation
Local processing Development tooling support
RCP IDE
Real time Examples for RCP
IBM Workplace Client Technology Maestro - NASA Space Mission
Management And lot more ….
Important Classes
Application
Application class
Must Implement IPlatformRunnable
Note: We can use any name as Class but here we are following RCP Standard naming convention.
Application class
Must Implement IPlatformRunnable Implement run method
Application class
Implement IPlatformRunnable Implement run method Run method is Main method
Application class
Implement IPlatformRunnable Implement run method Run method is Main method Starting point of your application and
Ending of your application
Application class
package com.rcp.example;
import org.eclipse.core.runtime.IPlatformRunnable;import org.eclipse.swt.widgets.Display;import org.eclipse.ui.PlatformUI;
/** * This class controls all aspects of the application's execution */public class Application implements IPlatformRunnable {
public Object run(Object args) throws Exception {Display display = PlatformUI.createDisplay();
try {int returnCode = PlatformUI.createAndRunWorkbench(display,new ApplicationWorkbenchAdvisor()); if (returnCode == PlatformUI.RETURN_RESTART) { return IPlatformRunnable.EXIT_RESTART; }
return IPlatformRunnable.EXIT_OK;} finally {
display.dispose();}
}
}
Important Classes
Application ApplicationWorkbenchAdivsor
ApplicationWorkbenchAdivsor class
Extend WorkbenchAdvisor
ApplicationWorkbenchAdivsor class
Must extend WorkbenchAdvisor Application Level advice
ApplicationWorkbenchAdivsor class
Must extend WorkbenchAdvisor Application Level advice Participates in the start up and shut
down of the workbench
ApplicationWorkbenchAdivsor class
Must extend WorkbenchAdvisor Application Level advice Participates in the start up and shut
down of the workbench One running Workbench per running
Eclipse application
ApplicationWorkbenchAdivsor class
package com.rcp.example;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;import org.eclipse.ui.application.WorkbenchAdvisor;import org.eclipse.ui.application.WorkbenchWindowAdvisor;
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
private static final String PERSPECTIVE_ID = "RCPView.perspective";
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {return new ApplicationWorkbenchWindowAdvisor(configurer);
}
public String getInitialWindowPerspectiveId() {return PERSPECTIVE_ID;
}
}
Important Classes
Application ApplicationWorkbenchAdivsor ApplicationWorkbenchWindowAdiv
sor
ApplicationWorkbenchWindowAdivsor class
Must Extend WorkbenchWindowAdvisor
ApplicationWorkbenchWindowAdivsor class
Must Extend WorkbenchWindowAdvisor
Window-level advice
ApplicationWorkbenchWindowAdivsor class
Must Extend WorkbenchWindowAdvisor
Window-level advice Helps to show or hide the menu, cool
bar etc.,
ApplicationWorkbenchWindowAdivsor class
Must Extend WorkbenchWindowAdvisor
Window-level advice Helps to show or hide the menu, cool
bar etc., Only one instance for each window
ApplicationWorkbenchWindowAdivsor class
package com.rcp.example;
import org.eclipse.swt.graphics.Point;import org.eclipse.ui.application.ActionBarAdvisor;import org.eclipse.ui.application.IActionBarConfigurer;import org.eclipse.ui.application.IWorkbenchWindowConfigurer;import org.eclipse.ui.application.WorkbenchWindowAdvisor;
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {super(configurer);
}
public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
return new ApplicationActionBarAdvisor(configurer);}
public void preWindowOpen() {IWorkbenchWindowConfigurer configurer = getWindowConfigurer();configurer.setInitialSize(new Point(400, 300));configurer.setShowCoolBar(false);configurer.setShowStatusLine(false);configurer.setTitle("RCP Application");
}}
Important Classes
Application ApplicationWorkbenchAdivsor ApplicationWorkbenchWindowAdiv
sor ActionBarAdvisor
ActionBarAdvisor class
Must extend ActionBarAdvisor Important methods are
makeActions fillMenuBar
Important Classes
Application ApplicationWorkbenchAdivsor ApplicationWorkbenchWindowAdiv
sor ActionBarAdvisor Perspective
Perspective class
Must implement IPerspectiveFactory Implement createInitialLayout method
Perspective class
package com.rcp.example;
import org.eclipse.ui.IPageLayout;import org.eclipse.ui.IPerspectiveFactory;
public class Perspective implements IPerspectiveFactory {
public void createInitialLayout(IPageLayout layout) {String editorArea = layout.getEditorArea();layout.setEditorAreaVisible(false);layout.setFixed(true);layout.addStandaloneView(View.ID, false, IPageLayout.LEFT, 1.0f, editorArea);
}
}
Perspective class
Must implement IPerspectiveFactory Implement createInitialLayout method
Generates the initial page layout
Important Classes
Application ApplicationWorkbenchAdivsor ApplicationWorkbenchWindowAdiv
sor ActionBarAdvisor Perspective View
View class
Must extend ViewPart
View class
Must extend ViewPart Page design (Forms,Showing Buttons,
etc)
View class
package com.rcp.example;import org.eclipse.jface.viewers.TableViewer;import org.eclipse.swt.SWT;import org.eclipse.swt.widgets.Composite;import org.eclipse.ui.part.ViewPart;public class View extends ViewPart {public static final String ID = "RCPView.view";private TableViewer viewer;/** This is a callback that will allow us to create the viewer and initialize it */public void createPartControl(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL| SWT.V_SCROLL);viewer.setContentProvider(new ViewContentProvider());viewer.setLabelProvider(new ViewLabelProvider());viewer.setInput(getViewSite());
}/** Passing the focus request to the viewer's control. */public void setFocus() {
viewer.getControl().setFocus();} }
Flow
Plugin.xml<?xml version="1.0" encoding="UTF-8"?><?eclipse version="3.2"?><plugin>
<extension id="application" point="org.eclipse.core.runtime.applications"> <application> <run class="com.rcp.example.Application"> </run> </application> </extension> <extension point="org.eclipse.ui.perspectives"> <perspective name="Perspective" class="com.rcp.example.Perspective" id="RCPView.perspective"> </perspective> </extension> <extension point="org.eclipse.ui.views"> <view name="View" class="com.rcp.example.View" id="RCPView.view"> </view> </extension>
</plugin>
Run the Application
Recommended Reading Eclipse Rich Client Platform
By Jeff McAffer and Jean-Michel Lemieux Addison-Wesley Professional ISBN: 0321334612
SWT : The Standard Widget Toolkit, Volume 1 By Steve Northover, Mike Wilson Addison-Wesley Professional ISBN: 0321256638
Contributing to Eclipse: Principles, Patterns, and Plugins By Erich Gamma, Kent Beck Addison-Wesley Professional ISBN: 0321205758
Prerequisites
Eclipse RCP Target download used is eclipse-RCP-SDK-3.1.2-win32.zip
j2sdk 1.4.2 or higher
Thanks for your time