blob: f6029dd5d6321c7c9d9e047e6cdb9f88fb74a1c5 [file] [log] [blame]
<!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 &gt; 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>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.entrypoint.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 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>
<p><strong>Now 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.swt.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 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>
<img src="../../images/hello-world-view.png"/>
<p>Now you need to declared this <code>HelloWorldView</code> as an extension to
<code>org.eclipse.ui.views</code> with these parameters:</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>
<p><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>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>
<p>Then the <code>Perspective</code> needs to be declared as an extension to <code>org.eclipse.ui.perspectives</code>.</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>
</ol>
<h2>Now it's time to start the HelloWorld application</h2>
<p>To start your HelloWorld application, select <strong>Run...</strong> from
the <strong>Run</strong> menu. You need to create a <strong>New Launch
configuration</strong> as an <strong>Equinox OSGi Framework</strong> and
ensure that the following plug-ins are activated
<ul>
<li>javax.servlet</li>
<li>org.apache.commons.logging</li>
<li>org.eclipse.core.commands</li>
<li>org.eclipse.core.contenttype</li>
<li>org.eclipse.core.expressions</li>
<li>org.eclipse.core.jobs</li>
<li>org.eclipse.core.runtime</li>
<li>org.eclipse.core.runtime.compatibility.registry</li>
<li>org.eclipse.equinox.app (when using Eclipse 3.3)</li>
<li>org.eclipse.equinox.common</li>
<li>org.eclipse.equinox.http.jetty</li>
<li>org.eclipse.equinox.http.registry</li>
<li>org.eclipse.equinox.http.servlet</li>
<li>org.eclipse.equinox.preferences</li>
<li>org.eclipse.equinox.registry</li>
<li>org.eclipse.osgi</li>
<li>org.eclipse.osgi.services</li>
<li>org.eclipse.rap.demo</li>
<li>org.eclipse.rap.jface</li>
<li>org.eclipse.rap.rwt</li>
<li>org.eclipse.rap.ui</li>
<li>org.eclipse.rap.ui.workbench</li>
<li>org.mortbay.jetty</li>
</ul>
Click <strong>Run</strong> to start the application. For further information
on how to launch a RAP application and trouble-shooting please also see the
<a href="demo-app.html">Demo Application</a> chapter.
</p>
<p>To see your RAP HelloWorld in action, please start your browser and enter
the URL <strong>http://localhost/rap</strong>.</p>
</body>
</html>