own rich client applications based on the Eclipse Rich. Client Platform (RCP) ...
RCP infrastructure that are available as building blocks for your own applications
...
102 – Developing Applications With the Eclipse Rich Client Platform (RCP) John Arthorne & Chris Laffra IBM Rational http://eclipsefaq.org/{john,chris} Tuesday, Aug. 30, 9:15 a.m. – 10:45 a.m.
© 2005 IBM
Session Abstract
When many people think of Eclipse, they see a Javacentric development environment. But there's more to Eclipse than Java—you now have several languages and protocols from which to choose. The Eclipse versioned plug-in architecture lets developers easily add new components, including language support for C++, PHP, Fortran, Web services and others. In this session, we will show how easy it is to write your own rich client applications based on the Eclipse Rich Client Platform (RCP). We will guide you through the various parts of the Eclipse RCP infrastructure that are available as building blocks for your own applications
© 2005 IBM
Roadmap Introduction Rich Client Programming The Eclipse RCP Project Examples of RCP applications Quick tour of RCP APIs Building your own Eclipse RCP application
Conclusions
© 2005 IBM
Source of Materials Material sources: My head RCP tutorials at eclipse.org RCP samples from eclipse.org Feedback from Eclipse committers The Official Eclipse 3.0 FAQs
© 2005 IBM
Format Question and answer format We will introduce Some background; what is a Rich Client? The Eclipse project and RCP Quick tour of Eclipse RCP plugins with sample code
After this presentation, you should be able to develop your own Eclipse RCP application.
© 2005 IBM
What is a Rich Client? Google dictionary: “A computer program that can download files for manipulation, run applications, or request application-based services from a file server.” Need some form of ‘installation’. Not a Thin Client (like a Web site). A ‘client’ with rich UI and interaction
© 2005 IBM
Rich Client Examples
Java Applets in a browser JavaScript applications (e.g., Bindows) J2ME MIDP Midlets on a phone/PDA Macromedia Flash MX Microsoft Foundation Class (MFC) apps Eclipse Rich Clients
© 2005 IBM
Rich Client Criterias
Support for various platforms Ease of installation Look-and-Feel The ‘Richness’ of the solution Interoperability with other solutions Tooling support Performance Mind-share (following the current trend) © 2005 IBM
The Eclipse RCP in a nutshell The Eclipse Rich Client Platform is a subset of the Eclipse platform designed for developing Rich Clients written in Java, using the Eclipse plug-in model for defining individual components using XML manifests. Open Source, free. Uses SWT for close-to-native feeling
© 2005 IBM
Eclipse RCP sample 1 Maestro – NASA Space Mission Management Shown at EclipseCon 2005
© 2005 IBM
Eclipse RCP sample 2 IBM Workplace Client Technology, Client Administrator Shown at EclipseCon 2005
© 2005 IBM
Eclipse RCP sample 3 Schoolclipse – Greek school management software
© 2005 IBM
Eclipse RCP Motivation Modular approach, using plug-ins written in XML and Java. Connections between plug-ins are loose. Lots of open source plug-ins easily added to your application Eclipse behaves like a native application (due to SWT). Eclipse is a framework. Lots of lessons learned and decisions have been made for you, leaving you more time to focus on your value add. The learning curve will pay off. Upgradeability. Use plug-ins to upload content handlers, and provide users with a given set of abilities and plugins based on their credentials. Versioning. Plug-ins are versioned, platform manages them. © 2005 IBM
What is Eclipse? An open IDE platform for anything, and for nothing in particular. Open: allows for easy extension by third parties. IDE: tooling to manage workspaces; to build, launch and debug applications; team sharing; easy customization of the programming experience. Platform: not a finished application Anything: Java, Web-services, games, etc. Nothing in particular: Java focus is historical. © 2005 IBM
Where did Eclipse RCP come from? Core of OTI/IBM products since late 90’s VisualAge Micro Edition (written in Java, first use of SWT) VAME framework generalized into Eclipse Eclipse open source project, Fall 2001 Community began tearing it apart to build things other than language tools Eclipse RCP released in June 2004 (part of Eclipse 3.0) © 2005 IBM
What articles are there? More than 60 at http://eclipse.org/articles Printable format is over 500 pages Covers wide range of Eclipse topics; from SWT to preferences to RCP to Wizards to style guides to internationalization to editor support to using CVS branching. IBM DeveloperWorks also hosts a few dozen articles on Eclipse and products
© 2005 IBM
What books are available? More than 28 were counted in July 2005 Many are introductory with wide coverage Others focus on vertical domain (SWT, EMF) Eclipse RCP Book: October 2005, Jeff McAffer and JeanMichel Lemieux © 2005 IBM
Where to download Eclipse? Eclipse.org/downloads:
Latest Release tested, may be 6 months old Stable/milestone build, 6 weeks apart Integration build, each week Nightly build, mileage varies directly from CVS, not for the faint of heart
Builds are tested and results are posted
© 2005 IBM
Eclipse Supported Platforms
Microsoft Windows 2000/XP Red Hat Enterprise Linux SuSE Linux 8.2 Sun Solaris 8 SPARC Motif HP HP−UX 11i hp9000 IBM AIX 5L PowerPC Motif Apple Mac OS X 10.3 SWT also on QNX Photon and Win CE © 2005 IBM
How to upgrade Eclipse? Use the included Update Manager works for Eclipse IDE and RCP upgrade existing plug-ins to later versions install new plug-ins from third party locations
Allows you to build a rich client and have extensions added later (like content handlers or additional business logic)
© 2005 IBM
Where to get Help? Included in your plug-ins/application: Help > Help Contents… F1, context-sensitive help Can be added to an RCP application
During development: http://eclipse.org (articles, newsgroups, etc) Books, tutorials, portals “Use the source, Luke!”
© 2005 IBM
What is a plug-in? An encapsulation of behavior that cooperates with other plug-ins to construct a program Plug-ins typically consists of: Manifest, described in plugin.xml Icons and resource bundles Java code in one or more jars
In Eclipse, everything is a plug-in
© 2005 IBM
What is the plugin.xml file? Here is an example: Preference pages and three Eclipse articles on Preference pages © 2005 IBM
Using an ImageRegistry
Images are OS resources that need to be managed carefully to avoid waste & leaks Here is an example:
public class ExamplesPlugin extends AbstractUIPlugin { public static final String PLUGIN_ID = "org.eclipse.faq.examples"; public static final String IMAGE_ID = "sample.image"; ... protected void initializeImageRegistry(ImageRegistry registry) { Bundle bundle = Platform.getBundle(PLUGIN_ID); IPath path = new Path("icons/sample.gif"); URL url = Platform.find(bundle, path); ImageDescriptor desc = ImageDescriptor.createFromURL(url); registry.put(IMAGE_ID, desc); } }
© 2005 IBM
Creating new Perspectives Extension point: org.eclipse.ui.perspectives Defines initial layout relative to editor area and contents of menus and toolbar API allows for whatever you can do in Window > Customize Perspective See Help for a good explanation in the PDE section to create new perspectives
© 2005 IBM
Views and Editors Workbench contains Views and Editors. Create one using the PDE plug-in template wizard.
© 2005 IBM
Views and Editors Compared Views
Editors
E.g., Outline/Navigator E.g., Java Editor/PDE Arbitrary contents
Arbitrary contents
Arbitrary layout
Arbitrary layout
One per page
Multiple per page
Anywhere on page
At fixed page location
Nothing to save
Can be “dirty”
Have a local toolbar
Use global toolbar
© 2005 IBM
A Minimal Editor Step one: declare extension point, specify what file extensions to handle, and class name of editor.
© 2005 IBM
A Minimal Editor Step two: Implementation. public class MinimalEditor extends EditorPart { private Label contents; public void createPartControl(Composite parent) { contents = new Label(parent, SWT.NONE); contents.setText("Minimal Editor"); } public void init(IEditorSite site, IEditorInput input) { setSite(site); setInput(input); } public void setFocus() { contents.setFocus(); } } © 2005 IBM
More Elaborate Editors For form-based editors, such as the PDE plugin.xml editor, use the org.eclipse.ui.forms extension point For graphical editors, see the Eclipse Graphical Editor Framework (GEF) project at http://eclipse.org/gef For nested editors, see the PDE wizard that creates a multi-page editor, using the MultiPageEditorPart. For text editors, see Chapter 15 and 19 of the Eclipse FAQ book © 2005 IBM
Buttons and Menus Menus and toolbars use ‘Actions’ to define content:
See the PDE wizard for the ‘Hello World’ plug-in
© 2005 IBM
Commands An abstraction of Actions Do not physically appear in the UI, and they have no code associated with them Must be associated with an action that performs the work Key bindings are associated with commands Example: The ‘Cut’ command is mapped to Ctrl+C. When an editor gets focus, it associates a particular text cut action with that command © 2005 IBM
What is an Eclipse Application? Could be “headless” with no UI Could use just runtime (extension registry) Just SWT and JFace But Eclipse has a particular technical use of the word “application”. Only one per Eclipse instance; the equivalent of ‘main’
© 2005 IBM
What is an Eclipse Application? Sample of plugin.xml for a simple headless application:
© 2005 IBM
What is an Eclipse Application? Here is the Java part for this sample: public class HelloWorld implements IPlatformRunnable { public Object run(Object args) { System.out.println("Hello"); return EXIT_OK; } }
© 2005 IBM
What is an Eclipse Application? Here is how the sample is executed: eclipse −application acme.hello The fully qualified ID is the plugin ID + application ID (i.e., “acme” + “.” + “hello”). Application get to fully control contents of menu, toolbar, views, etc. Much more control than plugins hosted by the Eclipse IDE. Eclipse Application can have UI or be headless See also IDEApplication in org.eclipse.ui.ide.
© 2005 IBM
What is an RCP app? RCP apps have more control over UI Workbench is still in charge, but takes “advice” from the RCP application WorkbenchAdvisor: main advisor; responsible for event loop, application lifecycle, creating other advisors WorkbenchWindowAdvisor: responsible for lifecycle of a window ActionBarAdvisor: responsible for filling the menus, tool bars, and status bar © 2005 IBM
Minimal Eclipse RCP App? Simple workbench advisor that is also the application: public class MinimalRCPApp extends WorkbenchAdvisor implements IPlatformRunnable { createWorkbenchWindowAdvisor(...) {...} getInitialWindowPerspectiveId() {...} run(...) {...} }
© 2005 IBM
Minimal Eclipse RCP App? First, tell the configurer what perspective to use: public String getInitialWindowPerspectiveId() { return "org.eclipse.faq.minimalperspective"; }
© 2005 IBM
Minimal Eclipse RCP App? Define a workbench window advisor: public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor( IWorkbenchWindowConfigurer configurer) { return new MinimalWindowAdvisor(configurer); } class MinimalWindowAdvisor extends WorkbenchWindowAdvisor { public void preWindowOpen() {…} }
© 2005 IBM
Minimal Eclipse RCP App? Then, window advisor defines what to show: public void preWindowOpen() { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); configurer.setShowCoolBar(false); configurer.setShowFastViewBars(false); configurer.setShowMenuBar(false); configurer.setShowPerspectiveBar(false); configurer.setShowProgressIndicator(false); configurer.setShowStatusLine(false); }
© 2005 IBM
Minimal Eclipse RCP App? Finally, get an SWT display, and launch the platform on it, using your workbench advisor: public Object run(Object args) throws Exception { Display d = PlatformUI.createDisplay(); int ret = PlatformUI.createAndRunWorkbench(d, this); if (ret == PlatformUI.RETURN_RESTART) return EXIT_RESTART; return EXIT_OK; }
© 2005 IBM
Minimal Eclipse RCP App? The result: no menu bar, no toolbar, no status bar, no views, no editors:
© 2005 IBM
Customizing the RCP menus Method implemented by ActionBarAdvisor: public void fillMenuBar(IMenuManager mainMenu) { MenuManager windowMenu = new MenuManager("&Window", IWorkbenchActionConstants.M_WINDOW); mainMenu.add(windowMenu); windowMenu.add(ActionFactory.MAXIMIZE.create(window)); MenuManager helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP); mainMenu.add(helpMenu); helpMenu.add(new AboutAction()); }
© 2005 IBM
Enabling action key bindings Key bindings are made for free when you use the actionSet extension point in your plugin.xml When you create actions on the fly, make sure your action has a command ID, and then use: ActionBarAdvisor advisor = ...; IAction action = ...; advisor.register(action);
© 2005 IBM
Just use SWT and JFace? FAQ 247 discusses how simple that is Complete source is offered at http://eclipsefaq.org
© 2005 IBM
Storing Application Data
Data is stored in the ‘workspace’ Simplest way is to rely on the –data argument See Platform.getInstanceLocation(); Make sure to lock the workspace location You can choose your own location See IDEApplication for all the subtleties
© 2005 IBM
Application vs. Product Application has program logic written in Java Product is entirely declarative and specifies: Icons, text, splash screen, etc
One product, can have multiple applications Example: Eclipse IDE is one product, but has multiple applications, such as the workbench and custom Ant runners
© 2005 IBM
Product Distribution
Zip it up, add a JRE, use an installer Use features and an Update for upgrades Add multiple languages (lots of support here) Use install handlers to do post-installation fixes Add your own splash screen and workbench icon Write your own platform launcher (eclipse.exe) Use art from http://eclipse.org/artwork/main.html
© 2005 IBM
Customizing RCP Apps See the plugin_customization.ini file Example to use curved view header tabs: org.eclipse.ui/SHOW_TRADITIONAL_STYLE_ TABS=false See Help > Help Contents > Platform Plug-in Developers Guide > Programmer’s Guide > Packaging and Delivering Eclipse-based Products > What is a Product? > Customizing a Product
© 2005 IBM
How do I create a plug-in? Plug-in Development Environment (PDE) has special wizards to get you going quickly Use code templates to create a plug-in with: A toolbar button and a menu option An editor A view (with a tree or a table) A property page A new perspective
Help > Cheat Sheet… © 2005 IBM
Plugin-Development Tip: Use the PDE wizards and editors
© 2005 IBM
Creating an RCP Application
© 2005 IBM
Running an RCP Application 1. Launch from the project’s context menu:
2. Or simply from the PDE editor:
© 2005 IBM
Branding an RCP Application Creating an Eclipse Product is also easy See File > New > Other... > Product Configuration
© 2005 IBM
How do I edit a plug-in? Plug-in Manifest editor provides a graphical view on the plug-in XML file. F1 can be used to get Help.
© 2005 IBM
Extension point creation Plug-ins can publish extension points Create them ala “Monkey see, Monkey do” Alternatively, use PDE manifest editor: Extension Points > Add… Choose an ID and a name Choose a name for your schema Add one or more elements and save
Generated code ends up in plugin.xml file Click F1 to get Help © 2005 IBM
How do I create a feature? A special PDE wizard can create a feature: File > New > Other... > Plug−in Development > Feature Project
Just add the plug-ins you want to add Features are the next step up from plug-ins A product is shipped as a collection of features, each containing one/more plug-ins
© 2005 IBM
What is the update manager? Help > Software Updates… Allows you to find new features on your workstation, network, or the Internet Manages configurations, allowing installation and deactivation of features Needs “update sites” to download features
© 2005 IBM
How to create an update site? A special PDE wizard: File > New > Other... > Plug−in Development > Update Site Project
Just add the features you want to add Generates site.xml Editor has a special “Build All” button
© 2005 IBM
Plug-in, Feature, Update Site Update site has one or more features Features have one or more plug-ins Plug-ins provide icons, plugin.xml and Java implementation Supports versioning
© 2005 IBM
References
http://eclipse.org http://dev.eclipse.org/viewcvs/index.cgi/~che ui-home/rcp http://eclipsefaq.org http://eclipse.techforge.com
© 2005 IBM