| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| <html> |
| <head> |
| <meta name="copyright" content="Copyright (c) 2007 Innoopract Informationssysteme GmbH. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." > |
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <title>Hello World</title> |
| <link rel="stylesheet" href="../style.css" charset="ISO-8859-1" type="text/css"> |
| </head> |
| <body> |
| <h1>Hello World</h1> |
| <h2>How do I write a Hello World with RAP?</h2> |
| <ol> |
| |
| <li><p><strong>Create a new project</strong></p> |
| <p>Create a new Project by right-clicking in the package explorer and select |
| <strong>New > Project</strong>. In the upcoming "New Project"-wizard, |
| select <strong>Plug-in Project</strong> from the section |
| <strong>Plug-in Development</strong>.</p> |
| |
| <p>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 <strong>Plug-in Manifest Editor</strong> and go to the |
| <strong>Dependencies</strong> page.</p> |
| <p>Add the following plug-in to the list of <strong>Required Plug-ins</strong>. |
| <ul> |
| <li><code>org.eclipse.rap.ui</code></li> |
| </ul></p> |
| |
| <p>Add the following servlet packages to the list of <strong>Imported Packages</strong>. |
| <ul> |
| <li><code>javax.servlet</code></li> |
| <li><code>javax.servlet.http</code></li> |
| </ul></p> |
| <p>so that the <strong>Dependencies</strong> page looks like this:</p> |
| <img src="../../images/hello-world-dependencies.png"/> |
| </li> |
| |
| <li><p><strong>Create your package</strong></p> |
| <p>Before creating any files or classes you should create a package <code>org.eclipse.rap.helloworld</code> |
| (or another package name you like) to contain your source files.</p> |
| </li> |
| |
| <li><p><strong>Create a workbench advisor <code>HelloWorldWorkbenchAdvisor</code> |
| extending the <code>WorkbenchAdvisor</code> class</strong></p> |
| |
| <p>The WorkbenchAdvisor is necessary to provide the id of the perspective |
| to the workbench. Therefore you need to implement the only method |
| <code>getInitialWindowPerspectiveId()</code> to return the id of your |
| perspective.</p> |
| <p>Example code: |
| <pre><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"; |
| } |
| } |
| </code></pre> |
| </p> |
| <p>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.</p></li> |
| <li> <p><strong>Create the <code>HelloWorldWorkbench</code> class implementing |
| <code>IEntryPoint</code>.</strong></p> |
| <p>The HelloWorldWorkbench is the entry point of the application and responsible |
| for creating the UI. Therefore it must implement the interface |
| <code>IEntryPoint</code> with <code>createUI()</code> as the only method. |
| </p> |
| |
| <p>Example code: |
| <pre></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 Display createUI() { |
| Display result = PlatformUI.createDisplay(); |
| PlatformUI.createAndRunWorkbench( result, new HelloWorldWorkbenchAdvisor() ); |
| return result; |
| } |
| } |
| </code></pre> |
| </p> |
| </li> |
| |
| <li><p><strong>Create an entry point</strong></p> |
| <p>In the <strong>Plug-in Manifest Editor</strong>, switch to the |
| <strong>Extensions</strong> page.</p> |
| |
| <img src="../../images/hello-world-workbench.png"/> |
| |
| <p>Add an <code>entrypoint</code> extension for the |
| <code>org.eclipse.rap.ui.entrypoint</code> and enter these details: |
| <ul><li><strong>id:</strong> <code>org.eclipse.rap.helloworld.helloWorldWorkbench</code></li> |
| <li><strong>class:</strong> <code>org.eclipse.rap.helloworld.HelloWorldWorkbench</code></li> |
| <li><strong>parameter:</strong> <code>default</code></li> |
| </ul></p> |
| </li> |
| |
| <li><p><strong>Create the <code>HelloWorldView</code> view extending class |
| <code>ViewPart</code></strong></p> |
| |
| <p>The HelloWorldView is responsible for creating the view to display the output |
| of your application. The class needs to extend <code>ViewPart</code> and |
| provide an implementation for the method <code>createPartControl()</code>.</p> |
| |
| <p>Then <strong>implement the method <code>createPartControl</code> in that |
| HelloWorldView</strong></p> |
| <p>You then need to implement the method <code>createPartControl</code> to |
| create and add the components you want in your view.</p> |
| <p>Example code: |
| <pre></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 |
| } |
| } |
| </code></pre> |
| </p></li> |
| |
| <li> |
| <p><strong>Now you need to declare this <code>HelloWorldView</code> as an extension to |
| <code>org.eclipse.ui.views</code> with these parameters:</strong></p> |
| <p><img src="../../images/hello-world-view.png"/></p> |
| <ul> |
| <li><strong>id:</strong> <code>org.eclipse.rap.helloworld.helloWorldView</code></li> |
| <li><strong>name:</strong> <code>Hello World</code></li> |
| <li><strong>class:</strong> <code>org.eclipse.rap.helloworld.HelloWorldView</code></li> |
| <li><strong>icon:</strong> <em>some_icon.gif</em> |
| <p><strong>Important note:</strong> If the icon path does not exist, |
| an exception is thrown.</p> |
| |
| |
| </li> |
| </ul> |
| |
| |
| <li><p><strong>Create a <code>Perspective</code> implementing |
| <code>IPerspectiveFactory</code></strong></p> |
| |
| <p>The Perspective is responsible for defining the layout of your UI. Therefore |
| you need to implement <code>createInitialLayout()</code> 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 <strong>id</strong> of your view, |
| which needs to be distinguished from the <strong>class name</strong>.</p> |
| <p>Example code: |
| <pre><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" ); |
| } |
| } |
| |
| </code></pre></p></li> |
| |
| <li> |
| <p><strong>Then the <code>Perspective</code> needs to be declared as an extension to <code>org.eclipse.ui.perspectives</code>.</strong></p> |
| <img src="../../images/hello-world-perspective.png"/> |
| <p> |
| <ul> |
| <li><strong>id:</strong> <code>org.eclipse.rap.helloworld.perspective</code></li> |
| <li><strong>name:</strong> <code>Hello World Perspevtive</code></li> |
| <li><strong>class:</strong> <code>org.eclipse.rap.helloworld.Perspective</code></li> |
| </ul> |
| All other Attributes may remain empty.</p> |
| </li> |
| <li><strong> |
| Now the hello world application is complete.</strong> For information on how to |
| launch a RAP application please see the chapter |
| <a href="launcher.html">Launching RAP Applications</a>. |
| </li> |
| </ol> |
| </p> |
| |
| </body> |
| </html> |