The Basic RCP ApplicationAn overview of the code that makes up the skeleton of a basic RCPapplication. This includes the b...
Creating an Eclipse RCP ApplicationUse the “Plug-in Project” wizard!Project Page:     Specify the plug-in name:      com....
Creating an Eclipse RCP ApplicationContent Page     Change information as appropriate     Activator generated     We co...
Creating an Eclipse RCP ApplicationTemplates Page:     Use “Hello RCP” template4                                      L00...
Launch the ApplicationThe launch configuration for the application canbe created in several ways     E.g. use the “Launch...
Update the Launch configurationThe arguments of the launch configuration for the application should beupdated with the fol...
Eclipse Workbench Start-Up SequenceThe Eclipse workbench is started in the following stepsFrom the user code the important...
Eclipse Workbench Start-Up Sequence     ActionBarAdvisor:                  In 3.2: Created all actions (if hard-coded) -...
The Application (IApplication) Object (3.3 and later edition)Identified via the extension point org.eclipse.core.runtime.a...
The WorkbenchAdvisor Object     Specified by the Application object     Identifies the initial perspective to be used in t...
The WorkbenchWindowAdvisor Object    Specified by the WorkbenchAdvisor object    Specifies the ActionBarAdvisor to usepubl...
The WorkbenchWindowAdvisor Object    Configures the basic window properties       Name       Size       Presence of bas...
The ActionBarAdvisor Object Specified by the WorkbenchWindowAdvisor object In 3.2: Created all actions (if hard-coded) - f...
The Perspective Object Specified by the WorkbenchAdvisor object Creates the initial perspective in terms of      Views   ...
Lab Exercise Create the application. If you have not used the Eclipse debugger before, then introduce an error – e.g. divi...
Adding a View A new view can easily be added using the extensions page for the plugin.xml file      Add a new extension w...
Adding a View, cont’ Click on the “class” link to create the new View class automatically Two methods must be implemented ...
Adding a View, cont’ Adding the view to the perspective      No editor is used      Views are positioned relatively to o...
Re-Launch the Application Now the application includes the new view Note that      The are no editor area      The view ...
Adding a File→Exit Command (3.3 and later edition) Added in the plugin.xml file        <extension point="org.eclipse.ui.me...
Re-Launch the Application Now the application includes the new exit action21                                             L...
Lab Exercise Create 4 views altogether Add the views to the perspective      The way to position views in a perspective h...
More Information “Eclipse Rich Client Platform: Designing, Coding, and Packaging Java(TM) Applications” by Jeff McAffer an...
Upcoming SlideShare
Loading in...5
×

L0020 - The Basic RCP Application

1,050

Published on

An overview of the code that makes up the skeleton of a basic RCP application. This includes the basics for advisors and perspectives. This module also describes the basics of how to launch and debug an RCP application.

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,050
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
32
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • Creating a new Eclipse RCP is quite easy: just use the supplied wizard. \n
  • Enabling the API Analysis does not matter in this case. It is used to test for incompatible changes between releases of a plug-in.\n
  • Don&amp;#x2019;t use any of thee other templates &amp;#x2013; that would be cheating!\n
  • A launch configuration can be saved in the files system making it easy to share the configuration. Simply click the Shared option on the &amp;#x201C;Common&amp;#x201D; tab of the launch configuration and specify the name of the launch file. The shared launch configurations are automatically picked up by Eclipse IDE.\n
  • \n
  • The different advisors are described in details in the module &amp;#x201C;L0038 - The Workbench Configuration&amp;#x201D;.\n
  • The different advisors are described in details in the module &amp;#x201C;L0038 - The Workbench Configuration&amp;#x201D;.\n
  • \n
  • The changes made to way the application is started (and stopped), is primary due to better support servers. In server multiple applications can be running in the same process space and the start and stop methods are therefore important. \n
  • The generated code above is not really optional when scaling up the application. The PERSPECTIVE_ID should be moved to the Perspective class as ID.\n
  • \n
  • \n
  • The fact that the ActionBarAdvisor is specified by the WorkbenchWindowAdvisor means that each window will have its own set of actions, menus, etc. In most cases, this is overkill and could be avoided by some careful programming. Note though that if the windows are placed on different monitors (with different properties such as size, resolution and color-depth) then it is necessary to have different font and image resources for the different windows&amp;#x2026;\nThe configurer is used to retrieve the different managers for the menu, tool bar, status line, etc. It is also used to register global actions if needed.\n
  • \n
  • Now it&amp;#x2019;s time for the lab.\n
  • \n
  • \n
  • The exact possibilities when positioning views is covered in the module &amp;#x201C;L0011 - Contributing to the Eclipse User Interface&amp;#x201D;.\n
  • The tab can easily be avoided by using addStandaloneView(&amp;#x2026;) instead of addView(&amp;#x2026;). This is useful when certain view may never be moved or closed.\n
  • This is basically the same as on the previous slide &amp;#x2013; just declared instead of programmed&amp;#x2026;\n
  • \n
  • Now it&amp;#x2019;s time for the lab.\n
  • \n
  • L0020 - The Basic RCP Application

    1. 1. The Basic RCP ApplicationAn overview of the code that makes up the skeleton of a basic RCPapplication. This includes the basics for advisors and perspectives. Thismodule also describes the basics of how to launch and debug an RCPapplication.Redistribution and other use of this material requires written permission from The RCP Company.L0001 - 2010-11-27
    2. 2. Creating an Eclipse RCP ApplicationUse the “Plug-in Project” wizard!Project Page:  Specify the plug-in name: com.rcpcompany.cex (or whatever)2 L0001 - 2010-11-27
    3. 3. Creating an Eclipse RCP ApplicationContent Page  Change information as appropriate  Activator generated  We contribute to the UI  It is an RCP Application!3 L0001 - 2010-11-27
    4. 4. Creating an Eclipse RCP ApplicationTemplates Page:  Use “Hello RCP” template4 L0001 - 2010-11-27
    5. 5. Launch the ApplicationThe launch configuration for the application canbe created in several ways  E.g. use the “Launch an RCP Application” in the Overview page of the plugin.xml editorChange the name of the application if needed  Use “Run” → “Open Run Dialog…”5 L0001 - 2010-11-27
    6. 6. Update the Launch configurationThe arguments of the launch configuration for the application should beupdated with the following extra arguments:  -clean – cleans all internal caches  -console – starts the OSGi console  -consoleLog – prints all log messages on standard output6 L0001 - 2010-11-27
    7. 7. Eclipse Workbench Start-Up SequenceThe Eclipse workbench is started in the following stepsFrom the user code the important classes are  Application (IApplication):  Handles the initialization of the display  Any login dialog  Creates and runs the workbench using the workbench advisor  WorkbenchAdvisor:  Names the initial perspective  Specifies the window advisor to use  Provides call-outs that is invoked during the life cycle of the workbench – e.g. postStartup and preShutdown  WorkbenchWindowAdvisor:  Specifies the action bar advisor to use  Provides call-outs that is invoked during the life cycle of the workbench window – e.g. postWindowCreate7 L0001 - 2010-11-27
    8. 8. Eclipse Workbench Start-Up Sequence  ActionBarAdvisor:  In 3.2: Created all actions (if hard-coded) - filled in the actions in the menu, tool bar, and status line as needed  In 3.3: Registers all built-in implementations for standard commands  In 3.4 and later: Empty!8 L0001 - 2010-11-27
    9. 9. The Application (IApplication) Object (3.3 and later edition)Identified via the extension point org.eclipse.core.runtime.applicationsSimply creates a new SWT display and launches the application codeThe place to handle login dialogs and similarEclipse 3.3 has added a stop() method to gracefully stop an application public class Application implements IApplication { public Object start(IApplicationContext context) throws Exception { Display display = PlatformUI.createDisplay(); try { int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); if (returnCode == PlatformUI.RETURN_RESTART) return IApplication.EXIT_RESTART; else return IApplication.EXIT_OK; } finally { display.dispose(); } } public void stop() { … } }9 L0001 - 2010-11-27
    10. 10. The WorkbenchAdvisor Object Specified by the Application object Identifies the initial perspective to be used in the application – can be overridden by saved state Specifies the WorkbenchWindowAdvisor to be used when SWT windows are createdpublic class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { private static final String PERSPECTIVE_ID = "com.rcpcompany.cex.perspective"; public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { return new ApplicationWorkbenchWindowAdvisor(configurer); } public String getInitialWindowPerspectiveId() { return PERSPECTIVE_ID; }} 10 L0001 - 2010-11-27
    11. 11. The WorkbenchWindowAdvisor Object Specified by the WorkbenchAdvisor object Specifies the ActionBarAdvisor to usepublic class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { super(configurer); } @Override public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) { return new ApplicationActionBarAdvisor(configurer); } ....}11 L0001 - 2010-11-27
    12. 12. The WorkbenchWindowAdvisor Object Configures the basic window properties  Name  Size  Presence of basic UI elements  Menu bar, toolbar, status Line, fast views, and perspective switcher  Progress indicatorspublic class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { .... @Override public void preWindowOpen() { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); configurer.setInitialSize(new Point(800, 600)); configurer.setShowCoolBar(false); configurer.setShowMenuBar(true); configurer.setShowStatusLine(false); configurer.setTitle("Hello Contact Manager"); }}12 L0001 - 2010-11-27
    13. 13. The ActionBarAdvisor Object Specified by the WorkbenchWindowAdvisor object In 3.2: Created all actions (if hard-coded) - filled in the actions in the menu, tool bar, and status line as needed In 3.3: Registers all built-in implementations for standard commands In 3.4 and later: Empty! public class ApplicationActionBarAdvisor extends ActionBarAdvisor { public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { super(configurer); } protected void makeActions(IWorkbenchWindow window) { } protected void fillMenuBar(IMenuManager menuBar) { } }13 L0001 - 2010-11-27
    14. 14. The Perspective Object Specified by the WorkbenchAdvisor object Creates the initial perspective in terms of  Views  Global actions  Shortcuts on relevant menus public class Perspective implements IPerspectiveFactory { public void createInitialLayout(IPageLayout layout) { } }14 L0001 - 2010-11-27
    15. 15. Lab Exercise Create the application. If you have not used the Eclipse debugger before, then introduce an error – e.g. divide-by-zero – and find the error in the debugger15 L0001 - 2010-11-27
    16. 16. Adding a View A new view can easily be added using the extensions page for the plugin.xml file  Add a new extension with the name “org.eclipse.ui.views”  Select the new line and add a “New”→”view” using the context menu  Specify id, name and class as shown here16 L0001 - 2010-11-27
    17. 17. Adding a View, cont’ Click on the “class” link to create the new View class automatically Two methods must be implemented  createPartControl(Composite): Creates the visual content of the view  setFocus(): Sets the initial focus of the view public class FirstView extends ViewPart { @Override public void createPartControl(Composite parent) { } @Override public void setFocus() { } }17 L0001 - 2010-11-27
    18. 18. Adding a View, cont’ Adding the view to the perspective  No editor is used  Views are positioned relatively to other views (or the editor)  The new view is placed to the left of the (non-existing) editor and will take all of the room public class Perspective implements IPerspectiveFactory { public void createInitialLayout(IPageLayout layout) { final String area = layout.getEditorArea(); layout.setEditorAreaVisible(false); layout.addView(”com.rcpcompany.ex.views.FirstView”, IPageLayout.LEFT, 1.0f, area); } }18 L0001 - 2010-11-27
    19. 19. Re-Launch the Application Now the application includes the new view Note that  The are no editor area  The view tab is present  The view can be closed  The view can be minimized19 L0001 - 2010-11-27
    20. 20. Adding a File→Exit Command (3.3 and later edition) Added in the plugin.xml file <extension point="org.eclipse.ui.menus"> <menuContribution locationURI="menu:org.eclipse.ui.main.menu"> <menu label="File” id=”file” mnemonic="F"> <command commandId="org.eclipse.ui.file.exit" /> </menu> </menuContribution> </extension> And to the ActionBarAdvisor object (3.3 edition only)  Uses predefined exit action public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { super(configurer); } protected void makeActions(IWorkbenchWindow window) { register(ActionFactory.QUIT.create(window)); } protected void fillMenuBar(IMenuManager menuBar) { }  This is not needed for Eclipse 3.4 or later, where the behavior is defined via the handlers extension point20 L0001 - 2010-11-27
    21. 21. Re-Launch the Application Now the application includes the new exit action21 L0001 - 2010-11-27
    22. 22. Lab Exercise Create 4 views altogether Add the views to the perspective  The way to position views in a perspective have not be discussed in details, but… Create the actions  Help→About  Hint: the ID is org.eclipse.ui.help.aboutAction Extras:  Add the “Show View” command22 L0001 - 2010-11-27
    23. 23. More Information “Eclipse Rich Client Platform: Designing, Coding, and Packaging Java(TM) Applications” by Jeff McAffer and Jean-Michel Lemieux (ISBN 978-0321334619)  The essential bible for everybody involved in Eclipse RCP. Includes numerous examples with best practices for RCP applications23 L0001 - 2010-11-27
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×