Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Eclipse RAP Development Guide
Previous Page Home Next Page

Hello World

How do I write a Hello World with RAP?

  1. Create a new project

    Create a new Project by right-clicking in the package explorer and select New > Project. In the upcoming "New Project"-wizard, select Plug-in Project from the section Plug-in Development.

    Your newly created plug-in project depends on a number of plug-ins that You need to enter as required plug-ins. To do so, open the project's MANIFEST.MF with the Plug-in Manifest Editor and go to the Dependencies page.

    Add the following plug-in to the list of Required Plug-ins.

    • org.eclipse.rap.ui

    Add the following servlet packages to the list of Imported Packages.

    • javax.servlet
    • javax.servlet.http

    so that the Dependencies page looks like this:

  2. Create your package

    Before creating any files or classes you should create a package org.eclipse.rap.helloworld (or another package name you like) to contain your source files.

  3. Create a workbench advisor HelloWorldWorkbenchAdvisor extending the WorkbenchAdvisor class

    The WorkbenchAdvisor is necessary to provide the id of the perspective to the workbench. Therefore you need to implement the only method getInitialWindowPerspectiveId() to return the id of your perspective.

    Example code:

    
    package org.eclipse.rap.helloworld;
    
    import org.eclipse.ui.application.WorkbenchAdvisor;
    
    public class HelloWorldWorkbenchAdvisor extends WorkbenchAdvisor {
    
      public String getInitialWindowPerspectiveId() {
        return "org.eclipse.rap.helloworld.perspective";
      }
    }
    
    

    For now we ignore the fact that the perspective id does not yet exist but keep in mind to label the perspective extension with the same id that we used here.

  4. Create the HelloWorldWorkbench class implementing IEntryPoint.

    The HelloWorldWorkbench is the entry point of the application and responsible for creating the UI. Therefore it must implement the interface IEntryPoint with createUI() as the only method.

    Example code:

    
    package org.eclipse.rap.helloworld;
      
    import org.eclipse.rwt.lifecycle.IEntryPoint;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.ui.PlatformUI;
    
    public class HelloWorldWorkbench implements IEntryPoint {
      
      public int createUI() {
        Display display = PlatformUI.createDisplay();
        WorkbenchAdvisor advisor = new HelloWorldWorkbenchAdvisor();
        int result = PlatformUI.createAndRunWorkbench( display, advisor );
        return result;
      }
    }
    
    

  5. Create an entry point

    In the Plug-in Manifest Editor, switch to the Extensions page.

    Add an entrypoint extension for the org.eclipse.rap.ui.entrypoint and enter these details:

    • id: org.eclipse.rap.helloworld.helloWorldWorkbench
    • class: org.eclipse.rap.helloworld.HelloWorldWorkbench
    • parameter: default

  6. Create the HelloWorldView view extending class ViewPart

    The HelloWorldView is responsible for creating the view to display the output of your application. The class needs to extend ViewPart and provide an implementation for the method createPartControl().

    Then implement the method createPartControl in that HelloWorldView

    You then need to implement the method createPartControl to create and add the components you want in your view.

    Example code:

    
    package org.eclipse.rap.helloworld;
    
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.ui.part.ViewPart;
    
    public class HelloWorldView extends ViewPart {
    
      public void createPartControl( Composite parent ) {
        Label label = new Label ( parent, SWT.NONE );
        label.setText( "Hello RAP World" );
        label.setSize( 80, 20 );
      }
    
      public void setFocus() {
        // do nothing
      }
    }
    
    

  7. Now you need to declare this HelloWorldView as an extension to org.eclipse.ui.views with these parameters:

    • id: org.eclipse.rap.helloworld.helloWorldView
    • name: Hello World
    • class: org.eclipse.rap.helloworld.HelloWorldView
    • icon: some_icon.gif

      Important note: If the icon path does not exist, an exception is thrown.

  8. Create a Perspective implementing IPerspectiveFactory

    The Perspective is responsible for defining the layout of your UI. Therefore you need to implement createInitialLayout() to set up the layout of your UI and add the views (only one view in the HelloWorld application). Please note that you need to specify the id of your view, which needs to be distinguished from the class name.

    Example code:

    
    package org.eclipse.rap.helloworld;
    
    import org.eclipse.ui.IFolderLayout;
    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 );
        IFolderLayout left = layout.createFolder( "left",
                                                  IPageLayout.LEFT,
                                                  0.25f,
                                                  editorArea );
        left.addView( "org.eclipse.rap.helloworld.helloWorldView" );
      }
    }
    
    
    

  9. Then the Perspective needs to be declared as an extension to org.eclipse.ui.perspectives.

    • id: org.eclipse.rap.helloworld.perspective
    • name: Hello World Perspevtive
    • class: org.eclipse.rap.helloworld.Perspective
    All other Attributes may remain empty.

  10. Now the hello world application is complete. For information on how to launch a RAP application please see the chapter Launching RAP Applications.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire