1
edit
Changes
→Create a RCP Application
=== Create a RCP Application ===
'''This tutorial uses the [http://www.vogella.de/articles/EclipseJFaceTable/article.html#jfaceviewers Jface Tutorial] as reference.''' <br/>
In this tutorial we are going to demonstrate how to build a simple RCP application to maintain student's information. We keep the data in a List object and will not preserve data. <br/>
To begin with, we create a simple RCP from the "Hello World" RCP template. The will add our Model classes. Eventually we use perspective, view, Jface viewe and Commands, to display, edit, Add and Delete students' records.<br/>
==== Start The Application ====
Create an a new plug-in project from File menu (File>New>Project>Plug-in Development> Plug-in project).<br/>
[[Image: createRCPApp1.jpg | 400px]]<br/>
<br/>
The "RCP" project is created with some classes already in it. We will modify this project to create our RCP application for the purpose if this tutorial.<br/>
[[Image: createRCPApp6.jpg | 700px]]<br/>
<br/>
In the "ApplicationWorkbenchWindowAdvisor" class, modify the preWindoOpen() method to set the title of the window ar "Simple RCP Application".<br/>
<code>ApplicationWorkbenchWindowAdvisor.java </code> to <code> true</code>
<source lang=java>
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(400, 300));
configurer.setShowCoolBar(false);
configurer.setShowStatusLine(false);
configurer.setTitle("Simple RCP Application"); //$NON-NLS-1$
configurer.setShowStatusLine(true);
configurer.setShowPerspectiveBar(true);
}
</source>
==== Run The Application ====
To run the application, right click on the project and select :Run As> Eclipse Application. Alternatively, you can click on the "Run an Eclipse Application" In the "Testing section of the project Overview window.<br/>
[[Image: RCPRun1.jpg | 700px]]<br/>
<br/>
At this point, the application starts and looks like this:<br/>
[[Image: RCPRun2.jpg | 350px]]<br/>
<br/>
'''Run Configuration'''<br/>
You can also set the run configuration if required, for example if there is a separate project for a view and you want to add that view to the perspective of the current project you need to make sure that both projects are running, so you need to set that in the run configuration, and you can reach it by right clicking on the project in Project explorer view and select Run As> Run configuration, and double clicking on the '''Eclipse Application''' to create a new Run configuration for the application. However, for this project we do not need any new run configuration. <br/>
=== Add Model ===
In order to have a data model for Student, we need to create a "Student Class" which keeps an student's data and "ModelProvider" Class that creates and keeps a list of Student class objects.<br/>
==== Create Model Package ====
==== Add Model Provider ====
"ModelProvider" class creates and maintains an ArrayList of Student objects and helps us find an student by it's id from the list of students.<br/>
<code>ModelProvider.java </code>
<source lang=java>
package cs.ecl.rcp.simplercp.model;
import java.util.ArrayList;
import java.util.List;
public enum ModelProvider {
INSTANCE;
private List<Student> students;
private ModelProvider() {
students = new ArrayList<Student>();
// Data could be retrieved here from database
students.add(new Student("01234567","Ladan", "Zahiroleslam", "CPA"));
students.add(new Student("09876543", "Anastasia", "Semionova", "CPA"));
students.add(new Student("01122334", "Minoo", "Ziaei", "CPA"));
students.add(new Student("02233445", "Sergiu", "Ecob", "CPA"));
}
public Student getPersonById(String id) {
for (Student student : students) {
if (student.getId() == id) {
return student;
}
}
return null;
}
public List<Student> getStudents() {
return students;
}
}
</source>
<br/>
[[Teams_Winter_2011/team1| Index Page]] [[Teams_Winter_2011/team1/RCP/Define_and_use_commands| Next>>]]