Changes

Jump to: navigation, search

Teams Winter 2011/team1/RCP/Define and use commands

2,370 bytes added, 13:31, 9 March 2011
Run your app with view(s)
=== Define Views in The Application ===
In this part of the tutorial we are going to add a view to our application. We have to create a view and add it to the perspective and make it visible.<br/>
 
==== Create Views====
Click on the Extensions tab in the plugin.xml window in the project and add a new Extension Point as "org.eclipse.ui.views".
<br/>
[[Image: RCPView3.jpg | 400px]]<br/>
<br/>
Right click on the newly added Extension Point and choose: New > View.<br/>
Then in the details section give the view a Name("StudentView"), id ("cs.ecl.rcp.simpleRCP.StudentView")and a class ("cs.ecl.rcp.simplercp.StudentView").<br/>
[[Image: RCPView4.jpg | 700px]]<br/>
<br/>
Double click on the class link and the New Java Class window will open. Notice that the StudentView class is a subclass of "org.eclipse.ui.part.ViewPart" class.<br/>
 
[[Image: RCPView1.jpg | 400px]]<br/>
<br/>
Go to the project in project explorer and find the StudentView in the "cs.ecl.rcp.simplercp" package in the src folder. Here is how it looks like ( we added a text to this view).
<br/>
[[Image: RCPView2.jpg | 700px]]<br/>
 
==== Add view(s) to perspective via code ====
Now we have to add our view to the perspective.We could do this in Extensions window, but here we want to show you how to do it programmatically.<br/>
Find the "Perspective" class in src folder of your project in the "cs.ecl.rco.simplercp" package.Here is how it looks like:<br/>
[[Image: RCPView5.jpg | 700px]]<br/>
<br/>
Add the following code to add view to the perspective. we also are making the view non-closeable, so that user cannot close it.
<code>Perspective.java</code>
<source lang="java">
package cs.ecl.rcp.simplercp;
 
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
 
 
public class Perspective implements IPerspectiveFactory {
 
public void createInitialLayout(IPageLayout layout) {
layout.setEditorAreaVisible(true);
layout.addView(StudentsView.ID, IPageLayout.LEFT, 1.0f, layout.getEditorArea());
//make the view fixed
layout.setFixed(true);
//make the view non-closeable
layout.getViewLayout(StudentsView.ID).setCloseable(false);
}
}
</source>
 
==== Run your app with view(s)====
Run the project now. Here is what you will see:
<br/>
[[Image: RCPView7.jpg | 400px]]<br/>
 
<br/>
[[Teams_Winter_2011/team1| Index Page]] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [[Teams_Winter_2011/team1/RCP/Define_and_use_editors| Next>>]]
1
edit

Navigation menu