Single Sourcing RAP and RCP - Desktop and web clients from a single code base
Upcoming SlideShare
Loading in...5

Single Sourcing RAP and RCP - Desktop and web clients from a single code base



Tutorial EclipseCon 2009 - Handout

Tutorial EclipseCon 2009 - Handout



Total Views
Views on SlideShare
Embed Views



5 Embeds 156 141 6 5 3 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Single Sourcing RAP and RCP - Desktop and web clients from a single code base Single Sourcing RAP and RCP - Desktop and web clients from a single code base Document Transcript

  • Tutorial “SingleSourcing RAP and RCP” EclipseCon 2009 Setup We provide a folder called RapTutorial2009. Copy this directory onto your computer. You should now have a directory structure like this: RapTutorial2009/ • ◦ projects/ • org.eclipse.rap.tutorial (the starting point) ◦ results/ (all projects in the final form) • ... ◦ workspaces/ • RAP/ (referred to as quot;RAP workspacequot;) • RCP/ (referred to as quot;RCP workspacequot;) ◦ ... Install RAP Tooling Start Eclipse and choose the RAP workspace • Install the latest RAP Tooling (version 1.2 M6) from this update site • RAPTutorial2009 folder also contains a local update site. Restart Eclipse after the installation is done • On the Welcome page, click quot;Rich Ajax Platform (RAP)quot; • On the next page, click “Install Target Platform” • The RAP Tooling contains the RAP runtime. It also comes with a “target installer” that extracts the RAP runtime and sets it as the target platform of the current workspace (i.e. the platform that all plug-in projects in the workspace are compiled against). Alternatively, the target can be switched by Window -> Preferences -> Plugin Development -> Target Platform Lab1 - Single Sourcing Import Project into Workspace We have prepared a simple project that basically contains the well-known mail template from RCP. Open the RCP workspace and import this project: Open the File → Import → Existing Projects into Workspace wizard and select the • org.eclipse.rap.tutorial project
  • Important: Do not copy the project into your workspace! Make sure the Application runs. Open the MANIFEST.MF and click on the link • “Launch an Eclipse Application”. Switch to RAP Workspace Select File → Switch workspace → Select “RAP” directory • Import the project org.eclipse.rap.tutorial into this workspace too, again • remember not to copy it into your workspace Resolve compile errors Fix bundle dependencies Open Problems view, there are > 100 compile errors. • Open the MANIFEST.MF and go to the “Dependencies” tab, section “Required Plug- • ins” Make the bundle-dependency to org.eclipse.ui optional (Select • org.eclipse.ui, click on the “Properties” button and check “Optional” Add org.eclipse.rap.ui and make it optional as well and save the changes • Note that the error count has reduced to two Create class AboutActionHelper Paste the two classes below into the source folder of your • org.eclipse.rap.tutorial project // AboutActionHelper package org.eclipse.rap.tutorial; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; public abstract class AboutActionHelper { private static final AboutActionHelper IMPL; static { Class clazz = AboutActionHelper.class; Object newInstance = ImplementationLoader.newInstance( clazz ); IMPL = ( AboutActionHelper )newInstance; } public static IWorkbenchAction create( IWorkbenchWindow window ) { return IMPL.createInternal( window ); } protected abstract IWorkbenchAction createInternal( IWorkbenchWindow window ); } // ImplementationLoader package org.eclipse.rap.tutorial; import java.text.MessageFormat;
  • public final class ImplementationLoader { public static Object newInstance( Class type ) { String name = type.getName(); Object result = null; ClassLoader loader = type.getClassLoader(); try { Class clazz = loader.loadClass( name + quot;Implquot; ); result = clazz.newInstance(); } catch( Throwable t ) { String txt = quot;Could not load implementation for {0}quot;; String msg = MessageFormat.format( txt, new Object[]{ name } ); throw new RuntimeException( msg, t ); } return result; } private ImplementationLoader() { } } In the class ApplicationActionBarAdvisor, go to line ~ 51 and change the • line aboutAction = ActionFactory.createAboutAction( window ); to aboutAction = AboutActionHelper.create( window ); Create Fragment Choose. New → Project → Fragment Project from the menu to create a fragment • named org.eclipse.rap.tutorial.rap Make sure to uncheck the “Use default location” option • Location: RapTutorial2009/projects/org.eclipse.rap.tutorial.rap • Note: Make sure that the project name is included! • Press Next and select the host plug-in org.eclipse.rap.tutorial • Create implementation class AboutActionHelperImpl Paste this code in the source folder of the org.eclipse.rap.tutorial.rap fragment. // AboutActionHelperImpl package org.eclipse.rap.tutorial; import org.eclipse.jface.action.Action; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; public class AboutActionHelperImpl extends AboutActionHelper { private static final class AboutAction extends Action implements IWorkbenchAction { private AboutAction() { setText( quot;Aboutquot; );
  • setId( quot;aboutActionquot; ); } public void run() { MessageDialog.openInformation( null, quot;Aboutquot;, quot;About the RAP tutorialquot; ); } public void dispose() { } } protected IWorkbenchAction createInternal( IWorkbenchWindow win ) { return new AboutAction(); } } “Resolve” the last problem For the sake of simplicity, comment out the org.eclipse.ui.bindings extension in the plugin.xml. To actually solve this problem, you would switch to the RCP workspace and move the bindings to the fragment.xml of org.eclipse.rap.tutorial.rcp. Create an entry point for RAP application. Open the MANIFEST.MF of the fragment org.eclipse.rap.tutorial.rap • and go to to the tab “Extensions” Add a new extension to the extension point org.eclipse.rap.ui.entrypoint. • You can leave the presets for the attributes “id” and “class” at their defaults. • Change the attribute “parameter” to tutorial • Click on the class link to have a skeleton of the class created • Implement the createUI method of the entry point like this: • public int createUI() { Display display = PlatformUI.createDisplay(); ApplicationWorkbenchAdvisor advisor = new ApplicationWorkbenchAdvisor(); PlatformUI.createAndRunWorkbench( display, advisor ); return 0; } You might need to press Ctrl+Shift+O to organize the imports Launch RAP application Create a new RAP launch configuration (Run → Run Configurations → RAP • Application) On tab “Main”, set the “Entry Point” to “tutorial” • On tab “Bundles”, make sure that your configuration is sane by pressing the • “Validate Bundles” button Launch the application with the “Run” button •
  • Lab 2 - Styling the Application Layout To have to workbench window fill the entire browser window, paste the method below into the ApplicationWorkbenchWindowAdvisor class. public void postWindowCreate() { super.postWindowCreate(); if ( SWT.getPlatform().startsWith( quot;rapquot; ) ) { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); Shell shell = configurer.getWindow().getShell(); shell.setMaximized( true ); } } And add the following lines to preWindowOpen if ( SWT.getPlatform().startsWith( quot;rapquot; ) ) { configurer.setShellStyle( SWT.NO_TRIM ); } Branding In the RAP workspace, open the fragment.xml of the RAP fragment. Switch to • the “Extensions” tab. Add an extension for the extension point org.eclipse.rap.ui.branding • Leave the default id as is • Set attribute “servletName” to “mail” • Set attribute “defaultEntrypointId” to “org.eclipse.rap.tutorial.rap.entrypoint1” As a • result, this entrypoint becomes the default entrypoint for this branding. Set attribute “title” to your chosen HTML title string, e.g. “RAP Tutorial Demo”. This • title will appear in the browser title bar In your launch configuration, change the servlet name to “mail” and restart the • application Instead of localhost:<port>/rap?startup=tutorial, you can now start the application with localhost:<port>/mail Theming Copy the directory RapTutorial2009/templates/theme/ into the RAP • fragment. Back in the fragment editor, add an extension for the extension point • org.eclipse.rap.ui.themes. Leave the default id as is • Set attribute “file” to “theme/theme.css”. • In the above created branding extension , set attribute “themeId” to the id of this • extension (org.eclipse.rap.tutorial.rap.theme1).
  • Now the theme is connected to the “mail” branding • Restart the application to see the changes • Open the fragment's and ensure that the theme folder is • checked in the Binary Build section. Presentation If you like to experiment with the new interaction design API, there is a default implementation available. Import the project from the • RapTutorial2009/projects folder into your workspace open your launch configuration and change the “Servlet Name” to business • Make sure that your launch configuration also includes the just imported plug-in and • set the servlet name Restart the application • The implementation is work in progress and will be available from the RAP CVS soon. Lab 3 - Deployment Ingredients In order to deploy your application you will need three more projects: org.eclipse.rap.demo.feature – serves as a template • org.eclipse.equinox.servletbrige • org.eclipse.equinox.http.servletbridge - provides a means to bridge • the servlet and OSGi runtimes Import these projects from the RapTutorial2009/projects folder into the workspace. Make sure that “Copy projects into workspace“ is unchecked. These projects are also located in the Eclipse CVS ( The org.eclipse.rap.demo.feature resides in the org.eclipse.rap/releng, the other projects can be found under org.eclipse.equinox/server-side/bundles. Adjust the template Open the feature.xml from the org.eclipse.rap.demo.feature project • and go to the Plug-ins page Add org.eclipse.rap.tutorial and org.eclipse.rap.tutorial.rap to • the list of plug-ins Open the config.ini in the templates/WEB-INF/eclipse/configuration • folder Add the bundle IDs org.eclipse.rap.tutorial and •
  • org.eclipse.rap.tutorial.rap to the osgi.bundles property like this: org.eclipse.rap.tutorial@start, org.eclipse.rap.tutorial.rap@start Run the build From the main menu choose Run → External Tools → External Tools Configuration • Run the webappBuilder launch configuration from the Ant Build category. • This launch configuration runs an Ant script and ensures that the script is executed within the same JRE as the workspace. See the script output in the console view and the PDE Export being started asynchronously Wait until the PDE Export has terminated as can be seen in the status line • Refresh the org.eclipse.rap.demo.feature project. You will see a build • folder. Open the “Archive File” export wizard under File → Export • Select the folder org.eclipse.rap.demo.feature/build/demo/WEB-INF/ • Enter demo.war as archive filename (the filename will usually become the name of • the deployed web application). Choose “Create only selected directories” from the options • Make sure that the WEB-INF folder is included in the war archive at the top level. • For troubleshooting, you can turn on the OSGi console by uncommenting the commandline init parameter “-console” in your web.xml. To have exceptions logged you can also add the commandline parameter “-consolelog”. Stress Testing You can use the RAPTutorial2009/templates/stress-testing.jmx as a starting point. Further information about this topic can be found here Don't forget to change to filename of the “Simple Data Writer” to something meaningful. Resources Frequently asked questions - • RAP home page - • RAP wiki - • Single Sourcing - •