Exploring Eclipse RCP

A "Rich" Alternative for System i GUI Development

January 10, 2007

Continuing to modify Eclipse RC Tutorial (part 1) into a System i client

The last blog entry explained how to modify the application created in Rich Client Tutorial Part 1 , Hello RCP, to connect to a System i. To demonstrate that the application was connected the modification fudged output to the console -- a cheezy cluge. This was needed because users interact with an Eclipse RCP application through views and editors. Hello RPC has neither, the template generated an empty perspective.

This blog entry extends the RCP application created in the last blog entry into a System i rich client application by explaining how to
- add SampleView, a view generated by a PDE template, and
- modify this view to display information from a System i.

1. Add SampleView, a view using a template provided by Eclipse IDE

A view is added by contributing a view extension to the org.eclipse.ui.views extension point. Open the your_domain.eclipsercp.tutorial.mod1 project's plugin.xml and go to the Extensions page. Click Add... and create an extension of type org.eclipse.ui.views. Type "org.." into the extension point filter and select this extension point.

At the bottom of the dialog you will see "SampleView" under "Available templaces for views:". Select this and click "Next".

The next dialog is titled "Main View Settings". Accept all the defaults and click "Next".

The "View Features" dialog is displayed. These features are the common ways this kind of view, a list, can interact with the application and user. Accept all the defaults and click "Finish".

A new package is created, your_domain.eclipsercp.tutorial.mod1.views. This was one of the default values in the "Main View Settings" dialog.

2. Add a constant for the view id

Go back to the Extensions page. The extension "org.eclipse.ui.views" is now listed. Open it then open "Sample View (view)". On the right is "Extension Element Details". The first property is "id*". This value has to be added to SampleView.java as a constant.

Copy the value into the clipboard. On my project this value is "info.billblalock.eclipsercp.tutorial.mod1.views.SampleView". Your view id should substitute "your_domain" for "info.billblalock", whatever you used when you created the project.

Open SampleView.java. Add a constant for the view id at the top of the class.


// view id constant
public static final String ID =
"info.billblalock.eclipsercp.tutorial.mod1.views.SampleView";
private TableViewer viewer; // original code generated by template

Remember, the value of ID must be the view id of the extension you created for your project. You can't cut and paste this snippet from the blog entry unless your project has the same name that mine does.

3. Add SampleView to the Perspective

Open Perspective.java. The overriden method createInitialLayout() is empty. Add two method calls to the IPageLayout which is passed to this method.


public void createInitialLayout(IPageLayout layout) {
layout.setEditorAreaVisible(false);
layout.addStandaloneView(SampleView.ID, false, IPageLayout.LEFT,
1.0f, layout.getEditorArea());
}

This code causes the SampleView to be executed when the Perspective, application window, is initally layed out by starting the RCP application. The view id (SampleView.ID) tells the plugin manager how the find the view to execute. The view id was added in step 2 and is used in this step.

4. Test the application

Run the application in the Eclipse IDE as you did previously. You will be prompted for the System i connection information and see the console output. This time you should have a table with rows "One" "Three" "Two". Right clicking any show two actions to select from, a demonstartion of actions. The table is sorted alphabetically.

5. Remove preStartup() and preShutdown() methods from ApplicationWorkbenchAdvisor.java

These methods were overriden simply to get the RCP Application to do something to prove it was connected to the System i. Remove the methods so the application doesn't required a console, so it can be run outside the Eclipse IDE.

6. Replace the String[] displayed in the table with an array of Strings from the System i

The SampleView.getElements() method returns an Object[] for the Jface table viewer to display. In the generated view, SampleView, this list of objects is a String[], {"One" "Two" "Three"}.

Modify the method getElements() of SampleView.java to return a String array from the System i. Many classes in the as400.access package of jt400 return String[] or Object[]. You can choose one that interests you! I chose to get a list of files from a folder of the IFS. To do this modify SampleView.getElements() this way:


public Object[] getElements(Object parent) {
// return new String[] { "One", "Two", "Three" }; -- comment out
// IFS path to get list of files and folders
String path = "/home";
try {
// use IFSFile class of jt400 to get list of files in path
String[] fileList = new IFSFile(Activator.getAs400(), path).list();
// null returned if the path does not exits, give user some output
if( fileList == null )
return new String[] {"Unable to list path: " + path};
return fileList;
}
catch(IOException ioe) {
// give user information about error returned
return new String[] {"IOException from IFSFile.list() for " + path,
ioe.getMessage() };
}
catch(Exception e) {
// give user information about error returned
return new String[] {"Unexpected Exception from IFSFILE.list() for " +
path, e.getMessage() };
}
}

Comment out the original String[] returned by the method.

Set the IFS path to list in "path". To list the root set "path" to "/".

Use the IFSFile.list() method to get a String[] of the files in the path of the IFS. See how the AS400 object created in the Activator is used?

IFSFile.list() returns null if the path is invalid or empty. If a null is returned then have getElements() return a String[] with something informative in it.

IFSFile can throw an IOException or an Exception. If this happens then have getElements() return something informative.

7. Test the application

The rich System i client you are developing should now display files and folders in the IFS "/home" folder of the System i. If there is no "/home" folder, or it is empty, the table will have two rows explaining the error. If there is a problem getting the folder, perhaps the ID does not have security rights, then two rows explaining the error will be displayed in the table.

8. Make a product and run the rich client System i client outside Eclipse

So far this modified version of the part 1 tutorial has been run from the Eclipse IDE. We stopped following the tutorial after "Taking it for a Spin", that is testing it from the IDE. See http://www.eclipse.org/articles/Article-RCP-1/tutorial1.html This was necessary because the output which showed the System i connection was sent to the console.

The console output has been removed. Now follow the remaining steps of making this RCP application into a product and running it outside of Eclipse. This gives you a stand alone a rich client for a System i.

Comments

This demo project can easily be modied to display a list of anything that a class in ibm.com.as400.access returns as a String[] or Object[]. It is not much use but fun. This project demostrates using Eclipse RCP to build a rich System i client application.

Source code

The source code is on the CVSDude repository under the project "info.billblalock.eclipsercp.tutorial.mod1ver2". You may view it as web pages or check it out through Eclipse.

In this entry explain how to modify the application developed in the prior entry, the project which you created following the previous blog entry. So as not to overwrite the source for the previous blog I copied that project, changed the plug in id, and continued the development for this blog entry.

My e-mail address is b_blalock@comcast.net.

How to add a CVS repository to Eclipse for Exploring Eclipse RCP blog

1. First open up the CVS perspective. Click on "Window" -> "Open perspective" -> "Other" -> "CVS Repository Explorer"
2. Create a new Repository Location. Right click on the left window -> "New" -> "Repository Location".
3. Fill out the form


  • Host: cvsdude.org

  • Repository path: /cvs/billblalock

  • User: systeminetworkblog

  • Password: eclipsercp

  • Connection type: pserver

  • Select "Use default port" radio button

  • Check "Save password"

4. Open the repository
5. Open HEAD
6. The projects will be listed. They can be explored through the CVS perspective or checked out.

Web access

The link for web access to the CVS repository for Exploring Eclipse RCP blog is http://cvsdude.com/vcvs/billblalock


  • User: systeminetworkblog

  • Password: eclipsercp

Eclipse projects will have a "src" folder. That is where the Java source will be found.


Thanks to CVSDude for hosting the materials for this blog at CVSDude : CVS, Subversion, Trac source control and project management hosting

Posted by Bill Blalock at January 10, 2007 5:08 PM

Comments

Post a comment




Remember Me?


Bill Blalock
October 2008
Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Blog Policy

We welcome your comments and opinions and encourage lively debate on the issues. However, Penton Media reserves the right to delete or move any content that it may determine, in its sole discretion, violates or may violate its Terms of Use or is otherwise unacceptable. For more information, see Penton Media's Terms of Use.

ProVIP Sponsors