blob: cb6208e8d8fb8936bc085dbf4ea952968176f365 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="copyright" content="Copyright (c) 2007, 2013 EclipseSource. 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=UTF-8"/>
<title>Writing a Hello World with RAP</title>
<link rel="stylesheet" href="../../../PRODUCT_PLUGIN/book.css" type="text/css"/>
</head>
<body>
<h1>Creating a Hello World with RAP</h1>
<p>
This document describes how to quickly create and launch a first user interface with RAP.
A complete application includes a few more components, depending on your
<a href = "application-setup.html">application setup</a>.
</p>
<h2>Preconditions</h2>
<ul>
<li><a href="setup-ide.html">the RAP Tools are installed</a></li>
<li><a href="target-install.html">a RAP target platform is installed and active</a></li>
</ul>
<h2>Create a new project</h2>
<p>
First we need to create a project for your application.
It is recommended to use a <em>Plug-in Project</em>,
unless you want to write an <a href = "rwt-standalone">RAP applications
without OSGi</a>. In the latter case, you can also create a plain <em>Java Project</em> here.
(If you do so, the project setup will differ slightly from this tutorial. Most notably, you
will have to add <em>org.eclipse.rap.rwt</em> to the java build path/
<em class="UILabel">Required Projects</em> in the next step.)
</p><p>
From the menu, select <em class="UILabel">File &gt; New &gt; Plug-in Project</em>.
Let's call the plug-in <code>org.example.rap.helloworld</code>.
In the <em class="UILabel">Target Platform</em> box, choose
<em class="UILabel">Eclipse version</em> and <em class="UILabel">3.5 or greater</em> to create a
bundle that is compatible with Eclipse.
</p>
<img src="../images/hello-world/NewProject-1.png" alt="New Project Wizard"/>
<p>
On the second page of the wizard, disable the option
<em class="UILabel">Generate an activator</em>.
(This option would create a bundle activator, but we don't need that now.)
Ensure that no <em class="UILabel">Rich Client Application</em> will be created.
</p>
<img src="../images/hello-world/NewProject-2.png" alt="New Project Wizard"/>
<p>
On the next page select the <em class="UILabel">RAP Hello World</em> template.
</p>
<img src="../images/hello-world/NewProject-3.png" alt="New Project Wizard"/>
<p>
Set the <em class="UILabel">Application window title</em> and
<em class="UILabel">Package name</em> and click "Finish".
</p>
<img src="../images/hello-world/NewProject-4.png" alt="New Project Wizard"/>
<p>
The wizard will create all needed classes for your RAP application.
</p>
<h2 id="entrypoint">Create the application UI</h2>
<p>
Every RAP application needs an entry point class that creates the initial UI of the application.
</p>
<p>
The wizard automatically creates a class named <em>BasicEntryPoint</em> that extends
<em><a href="../reference/api/org/eclipse/rap/rwt/application/AbstractEntryPoint.html">AbstractEntryPoint</a></em>
in the speified package. In the method
<em><a href="../reference/api/org/eclipse/rap/rwt/application/AbstractEntryPoint.html#createContents(org.eclipse.swt.widgets.Composite)">createContents</a></em>,
we already have some SWT code with two buttons.
</p>
<pre class="lang-java">
public class BasicEntryPoint extends AbstractEntryPoint {
@Override
protected void createContents(Composite parent) {
parent.setLayout(new GridLayout(2, false));
Button checkbox = new Button(parent, SWT.CHECK);
checkbox.setText("Hello");
Button button = new Button(parent, SWT.PUSH);
button.setText("World");
}
} </pre>
<h2>Launch the application</h2>
<p>
Now we can launch this application using the generated launch configuration
<em>org.examples.rap.helloworld.launch</em> in the project root.
Select <em class="UILabel">Run As &gt; org.examples.rap.helloworld</em> from the context menu
of the launch configuration file.
A browser view should open up soon afterwards and show your running application.
More information on launching RAP applications can be found in the chapter
<a href="./launcher.html">Launching RAP Applications</a>.
</p>
</body>
</html>