In Eclipse IDE, you can see the window title in the format: perspective - editPart name - Eclipse SDK - workspace. But in an RCP app, the title is usually the Product Name defined in the *.product file. This tip explains how to change it dynamically like IM clients - where the window title should be product name - user name.
Window title is *not* set on the IWorkbenchWindow. You need to do it on the IWorkbenchWindowConfigurer.
Whenever the user performs a login/logout, you need to set the window title. The details are sketchy, as its left to you whether to pass the instance of the windowConfigurer to the Login/LogoutAction or implement some sort of event listener for login/logout and do the title change there. But in general:
IWorkbenchWindowConfigurer windowConfigurer = ...;
String title = Platform.getProduct().getName();
if(loggedIn)
title = title + " - " + userName;
windowConfigurer.setTitle(title);
In case you were wondering where to get the instance of the windowConfigurer, it will be passed to your application thru the WorkbenchAdvisor.createWorkbenchWindowAdvisor() method.
Apr 23, 2008
Window Title in an RCP app
Posted by
Prakash G.R.
at
10:40 AM
0
comments
Labels: guidelines, RCP
Apr 1, 2008
Content type Specific File icons
Eclipse 3.4 M6 is out. It has lots of wonderful features like p2 and the installer. But one small change that is going to save a lot of developers time is the content type specific file icons. Earlier if I had to contribute an icon for a specific file, I've to write my own label decorator. Now Eclipse comes with a label decorator that does the same.
All you have to do is to define the content type and associate an editor with that content type. If you were wondering writing an editor is not a trivial task, don't worry, you can reuse the existing ones.
Assume that in my app, I have some files with extension 'config'. They are nothing but normal properties files. I would like to invoke the Properties editor on this extension and give a different icon. Here is how I create a new content type for the extension associated the Properties editor for that.
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type base-type="org.eclipse.core.runtime.properties"
file-extensions="config"
id="in.cypal.eclipse.myConfig"
name="My Config File"
priority="normal">
</content-type>
</extension>
<extension point="org.eclipse.ui.editors">
<editor class="org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileEditor"
default="false"
extensions="config"
icon="icons/sample.gif"
id="in.cypal.eclipse.editors.myConfigEditor"
name="My Config Editor">
<contentTypeBinding contentTypeId="in.cypal.eclipse.myConfig">
</contentTypeBinding>
</editor>
</extension>
Content types are not just based on file names/extensions. If you have an xml file, you can use the XMLContentDescriber to find the content type based on the root element; create an editor extension; specify the Text Editor/XML Editor class; associate the content id and add the icon to the editor. You are done. All of this without writing a single line of code!
Mar 15, 2008
Wizard as a Dialog
In an RCP application, I had these requirements for a Dialog box:
- OK button should not be enabled until all the mandatory fields are filled
- Hints for probably incorrect data (The email id grprakash+eclipse@gmail.com "looks" like a wrong one) These should not stop the user from pressing OK
- Progress bar should be shown for long running operations (clicking OK, "check for user id availability", etc)
I was thinking on how to handle all these in a Dialog and something flashed in my mind - JFace Wizards. All the above requirements can be easily done if I use a Wizard. The Finish button is disabled when we call setPageComplete(false), we can show warnings and still allow the user to finish and by calling setNeedsProgressMonitor() & getContainer().run() we can show the progress bar in the UI as well. But there are two small issues to be handled when we use the wizard.
- The first one is to get rid of the Back and Next buttons. We are lucky here because JFace will not show those buttons if there is only one page in the wizard
- The "Finish" looks odd and should be renamed to "OK" or "Submit. This can be done by subclassing the WizardDialog:
@Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
Button finishButton = getButton(IDialogConstants.FINISH_ID);
finishButton.setText(IDialogConstants.OK_LABEL);
}
};
Now with the util method, I can enable/disable the "OK" button, reflecting the status of the UI items.
Related:
Util method for Wizard Pages
JFace Wizard Guidelines
Posted by
Prakash G.R.
at
11:57 AM
0
comments
Labels: eclipse, guidelines, jface, RCP, wizards
Feb 19, 2008
EMF Packing changes in 2.4
EMF has changed the packaging in 2.4. You need to download an additional jar for docs and source for EMF and XSD. While this might be a good news for those who are bundling EMF in RCP apps, not for the early adopters of WTP. If you are an early adopter, then probably you may want to do vote for the all-in-one package for the milestone builds.
Related:
How does EMF finds the right parser?
Converting EMF Resource to Platform Resource (IFile)
EMF Packing changes in 2.4
Using EMF with XML Catalog
Feb 14, 2008
FullScreen mode in SWT/RCP Application
If you didn't know the Eclipse Summer of Code gave us a nice addition - Full Screen mode for SWT (From Eclipse 3.4 only. Won't work with 3.3 or earlier). No tricky API, just a getter/setter. Shell.setFullScreen(true) Go play!
Related:
How to add TrayItem in Eclipse RCP application?
How to add a status bar in an RCP app?
Posted by
Prakash G.R.
at
9:11 PM
0
comments
Feb 8, 2008
Eclipse icons
Explaining an action or describing an object with fewer words is tough. Showing them as 16x16 icons is even more tougher. Eclipse has a wonderful collection of icons. The best part of it - the whole set is consistent in sizing, coloring and styling. (I personally feel that icons like the filter
, jar library
, plugins
are brilliantly done). You can reuse them in many places in your own plugins/RCP Application as well. AFAIK, these icons are under Eclipse Public License and so you should not be falling into any legal trap for using these (don't take my word, I'm not a lawyer :-).
Many common images (undo, redo, file, folder, cut, copy) are available thru the org.eclipse.ui.ISharedImages interface. You can get them with IWorkbench:
Image folderImg = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
For other common items (refresh, filter, collapse all, expand all), finding the images inside the plugins jars will be a tough task. So here are some images that you can reuse in your plugins:
Add, Delete :

Collapse All/Expand All: 
Navigation:

Window operations: 


Run & Debug:

Import & Export:

Date & Time:

Editor Operations:

Vertical & Horizontal:

Flat & Hierarchical: 

Misc: Eclipse
, Config
&
, Console
, Font
Help
, Lock
, Stop
, Properties
, Search
&
, Tip/Quick Fix
, Sort
, Task
&
, Sync
&
, Pulldown Menu
, Binary
, Bookmark
, Category 
Let me know if I've missed any commonly used icon. I'll add it to this list. The complete set of above icons can be downloaded from here.
Related:
Eclipse Icons - follow up post
Searching for Eclipse - source, blogs, images ...
Accessing CVS of Eclipse.org
Feb 6, 2008
Feature based configuration of an RCP application
For a RCP application, I started with plugins based product configuration. When I reached a point where I need to provide software updates thru an update site, I needed a feature based product configuration. I thought should be as simple as selecting the features check box and adding the feature. But I spent around two whole days googling and debugging to bring it up and running. I think everyone would have gone thru the phase. I thought I'll write a blog entry on the issues, but I was lazy to draft such a long post. Yesterday Jan Kohnert sent a nice mail on his experience to the news group. Instead of copy-pasting the whole thing here, I present the information with little modifications. Thanks Jan.
- In the Configuration tab, click "New Feature...", and create the new feature:

- In the newly created feature, go to the included features tab and add "org.eclipse.rcp" feature:

- Go to the plugins tab and add your product's plugins
- RCP feature has most of the plugins that you would require. However if you use anything other plugins (core.resources, ui.forms, etc), you need to add those plugins to the feature:

Ideally, even for software updates, this should work fine. However, if you try to create an update site and try running software update, you will be hitting the java.lang.SecurityException: "Invalid signature file digest for Manifest main attributes". To get rid of that, remove the RCP feature from the included features list of your feature and add the plugins in RCP feature to your feature. Thanks to PDE team, copy-pasting works in the plugins tab of Feature Editor :-)

While going thru the update stuff, I realized that the update will not function as expected if we launch it from the IDE (Not sure of why). So I have to export the product and run from the disk, which means I can't debug and step thru the code :-( To know what happens during the update, I start the application with -debug options and add these lines in the .options file:
org.eclipse.update.core/debug=true
org.eclipse.update.core/debug/warning=true
org.eclipse.update.core/debug/parsing=true
org.eclipse.update.core/debug/install=true
org.eclipse.update.core/debug/configuration=true
org.eclipse.update.core/debug/type=true
org.eclipse.update.core/debug/web=true
org.eclipse.update.core/debug/installhandler=true
org.eclipse.update.core/debug/reconciler=true
Click here for more info on the .options
Feb 5, 2008
How to prevent multiple instances of an RCP Application?
The Eclipse IDE does this by obtaining lock on a file in the workspace. However, this method allows you to run multiple instances of the same IDE, each of them in a separate workspace.
In an RCP Application, if you follow the file lock mechanism, you need to get a lock on a well known file (like C:\Program Files\My App\instance.lock). Alternatively you can also prevent multiple instances by creating a server socket on some port (this method might alert Virus scanners/Firewalls)
There is no technique that is specific to RCP application, that is used to achieve this. You can use any Java application technique. You can Google around for more Java solutions and apply them in your RCP applicaiton.
Posted by
Prakash G.R.
at
12:59 PM
0
comments
Labels: RCP
Feb 4, 2008
How to automatically update my RCP Application?
Updating a RCP application might be different from updating Eclipse IDE. In Eclipse IDE, the update *usually* triggered by the user and he is allowed to select the updates he wants to install and cancel it at any time. But in RCP application, the situation might be different. You might have a requirement that you should be always running the latest version. In this case, the application update need not be triggered by the user, rather it can be triggered automatically during startup (like Gchat) and/or periodically by a job.
To enable such updates, you need to specify the update site in your feature:
In your Application's startup code, add this:
ProgressMonitorDialog dialog = new ProgressMonitorDialog(new Shell(display, SWT.NONE));
dialog.run(false, false, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
UpdateCommand command = new UpdateCommand("in.cypal.studio.wsdlEditor", "false");
command.run(monitor);
}
});
The comman.run() method returns a boolean value indicating whether an update happened or not. Depending on that you can decide whether to proceed normally or to force a restart by returning IApplication.EXIT_RESTART from the start method of your Application.
Posted by
Prakash G.R.
at
10:02 PM
0
comments
Jan 27, 2008
How to add TrayItem in Eclipse RCP application?
In an application like Yahoo Messenger or Skype, you don't want to quit the application when the main window is closed. Most of these applications will move themselves to System Tray when the main window is closed and clicking on the Tray icon would bring back the window. Lets try to see how to do it in an Eclipse RCP Application.
When the window is closed, the WorkbenchWindowAdvisor.preWindowShellClose() method is called. If this returns false, then the close request will not be honored. So all we need to do is to override this method; create a TrayItem; hide the window and return false.
trayItem = new TrayItem(Display.getDefault().getSystemTray(), SWT.NONE);
trayItem.setText("My RCP App");
trayItem.setImage(getAppIcon());
trayItem.addSelectionListener(getSelectionListener());
getWindowConfigurer().getWindow().getShell().setVisible(false);
return false;
In the SelectionListener, we can add code to bring up the window:
Shell workbenchWindowShell = getWindowConfigurer().getWindow().getShell();
workbenchWindowShell.setVisible(true);
workbenchWindowShell.setActive();
workbenchWindowShell.setFocus();
workbenchWindowShell.setMinimized(false);
trayItem.dispose();
Simple :-)
Jan 18, 2008
How to add a status bar in an RCP app?
If you are writing an RCP application, you may want to add a status message in the status bar. Adding it is very simple.
By all chance, you already have a class extending org.eclipse.ui.application.ActionBarAdvisor in your RCP app (If not, Google around to find out how to add one to your RCP app). Just override the fillStatusLine method.
private StatusLineContributionItem statusItem;
@Override
protected void fillStatusLine(IStatusLineManager statusLine) {
statusItem = new StatusLineContributionItem("LoggedInStatus");
statusItem.setText("Logged in");
statusLine.add(statusItem);
}
Thats it :-)
Note 1: You can add any number of status items
Note 2: In Eclipse 3.3, the class StatusLineContributionItem is in org.eclipse.ui.internal.util package. This has been moved to org.eclipse.jface.action package in Eclipse 3.4
Posted by
Prakash G.R.
at
10:45 PM
0
comments
Jan 10, 2008
Deploying RCP along with JRE
When you distribute your RCP application you never know whether the end user will have a JVM installed in his machine or not. Even if he has a JVM, there are a good number of possibilities that it will be an older version. A simple solution to this problem is to bundle and ship a JRE along with your product and make the product to use that JRE. Eclipse provides a easier way to do it. In the Launching tab of your product editor, select the JRE you want to bundle. Save the file and export the product.
You are done :-)
Its good to have an installer without the JRE as well, because for those who have the required JRE, it will help in the download size
Posted by
Prakash G.R.
at
4:45 PM
0
comments

