Eclipse Yoxos Services Downloads Blogs About
Home > Blogs >

Posts Tagged ‘rcp’

on Dec 18th, 2008Extended Presentation API

If you want to make a custom look&feel for an RCP or RAP application you have no choice other than to write a new Presentation. But if you’ve already worked with the Presentation API, I would bet that you’re not too happy with it. The only option the API gives you is to make StackPresentations, but what about other components like the ToolBar or MenuBar?
There is an internal Interface called IActionBarPresentationFactory. You can implement it and you’ll have the opportunity to change the look&feel of the ToolBar, the View ToolBar, the CoolBar and the ToolBar’s Contribution items. Great. This is a lot more but it’s an internal – use it at your own risk.

Now that we have the PresentationFactory and the IActionBarPresentationFactory, we have a lot we can customize. But, there are still some components missing like the MenuBar and the view’s menu. You have no other choice except to hack these, but this isn’t really a choice, is it? icon wink Extended Presentation API

If you want to customize a RAP application you need to do more than customize these components. You probably want to position these in different places and introduce additional components like a header and a footer. You can do this right now using the WorkbenchWindowAdvisor#createWindowContents(Shell shell) method. But this is not the Eclipse way. If you use the WorkbenchWindowAdvisor to change the look&feel of your application you’ll get a fixed coupling between the application code and the presentation code. So wouldn’t it be great to have these separated, ie. in different bundles?

Another issue that comes with RAP applications is the branding. You can define different servlets, which are coupled with a theme and an entrypoint. But there is no opportunity to couple a servlet with Presentation.

So, I wrote an extended Presentation API for RAP, which covers the things mentioned above. The API is still in prototype, but I hope we can release it in RAP 1.2. (Maybe this is interesting for RCP, too?)

I also implemented a demo using the new API which you can see in the screenshot below. I’m the first to admit that it doesn’t look really nice yet but it does show you the possibilities for the new API. The whole presentation is implemented in a separate bundle and just coupled with the application using the servlet.

newpresentationapi Extended Presentation API

If you have comments or ideas for additional components , please email me or feel free to comment on this post.

on Oct 3rd, 2008Tip: Spellchecking in Eclipse

Ever wanted to add spelling checking to a dialog, form or some editor in your Eclipse-based application?

spell1 300x300 Tip: Spellchecking in Eclipse

Well, I needed to do this recently for a project and thought I would share with people how it can be done (also, I had people emailing me to write more tips ;p). The spell checking infrastructure in Eclipse is handled by the text editor framework. Speficially, there’s an extension point where you can add your own spellchecking engines if you so desire:

spell2 300x224 Tip: Spellchecking in Eclipse

The Java Development Tools (JDT) provides an engine by default that gets activated for things like java source files, properties files and ‘text’ files. To take advantage of this functionality, we need to hook into the text editing framework inside of Eclipse. I’ve provided a simple example to show you how you can do it, but here are the basics:

...
final SourceViewer sourceViewer = new SourceViewer(
     composite, null, null, true, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
// grab the text widget from the source viewer
StyledText fTextField = sourceViewer.getTextWidget();
// this is where the magic happens for spellchecking
// see TextSourceViewerConfiguration#getReconciler
Document document = new Document(text);
SourceViewerConfiguration config =
     new TextSourceViewerConfiguration(EditorsUI.getPreferenceStore());
sourceViewer.configure(config);
sourceViewer.setDocument(document, annotationModel);
...

If you ever have written an editor within Eclipse, this code should look familiar to you. If not, well, welcome to text editing framework within Eclipse. You’ll notice that by default, everything is spellchecked. This is because of how the TextSourceViewerConfiguration sets up reconciliation by default (see getReconciler):

...
SpellingService spellingService= EditorsUI.getSpellingService();
IReconcilingStrategy strategy= new SpellingReconcileStrategy(sourceViewer, spellingService);
MonoReconciler reconciler= new MonoReconciler(strategy, false);
...

If you need to only spellcheck certain areas of a document, like say comment headers, you need to provide your own reconciler and partitions. Than you need to setup your partitions that you want to have a spellchecking strategy (SpellingReconcileStrategy) associated with.

I hope this helps and here is the code used in this tip if you’re interested.

on Jul 23rd, 2008Tip: Internationalization and RCP

I had to help someone internationalize their RCP application today and I didn’t really have a straight forward simple example to point them to so I figure I’d share something here for everyone’s benefit. I’ll use the famous RCP mail example to get things started. The first step in internalization is making sure our strings are externalized so translators can actually do something with them. For Eclipse plug-ins, there will be two places you need to externalize strings:

  • Java artifacts (ie., .java)
  • Plug-in related artifacts (MANIFEST.MF and plugin.xml)

Within Java files, the wonderful JDT tooling provides an Externalize Strings wizard (Source->Externalize Strings…):

picture 4 300x222 Tip: Internationalization and RCP

Within plug-in artifacts, PDE also provides an Externalize Strings wizard (PDE Tools->Externalize Strings or click the hyperlink on the Overview page):

picture 5 300x212 Tip: Internationalization and RCP

Once we have all our strings externalized, we need to create a fragment (e.g., org.eclipse.mail.nl1) to store our translations (File->New->Fragment Project):

picture 3 Tip: Internationalization and RCP

From the screenshot above, you should see that the translated properties files are co-located in the same respective location of the original file. The translated properties files also have a naming convention of name_locale.properties (e.g., messages_es.properties).

So now that we have some translated properties file, how do we test our translations? PDE provides an easy way to set the locale you’re developing against… similar to the way you define a target platform. In the target platform preference page, head over to the Environment tab and choose the language you’re interested in:

picture 11 300x247 Tip: Internationalization and RCP

Once you do that, simply launch like you normally would to test out the fancy translations:

picture 21 300x152 Tip: Internationalization and RCP

That’s it! Also, if you need translations for Eclipse.org plug-ins… check out the Babel project!

Here is the code used in this tip if you need to take a test drive at home. Hope this helps.

on Jul 18th, 2008Tip: Suppressing Keybindings

I was helping a colleague today with a key binding issue that I think is fairly common. To illustrate the problem, let’s look at what happens when you press CMD+N in the RCP mail sample:

picture 1 Tip: Suppressing Keybindings

What!? New Project Wizard? That’s not what I wanted! In this case, I actually wanted a ‘New Message’ to pop up instead of that new wizard. I don’t want any of my end-users ever seeing this dialog! What’s the problem here? Well, in simple terms, Eclipse is using its own default key configuration scheme if you don’t set one. So by default, you may get strange results like above or even conflicts with existing key bindings.

What’s the solution?

Well, there are a few ways to go about this but I think the simplest one for most people is to simply create your own key configuration scheme and instruct Eclipse to use it. To do this, you first need to create your own scheme:

<extension point="org.eclipse.ui.bindings">
<scheme
id="mail.scheme"
name="My Mail Scheme">
</scheme>
</extension>

After that, make sure your bindings are instructed to use this scheme:

<extension
point="org.eclipse.ui.bindings">
<key
commandId="mail.open"
schemeId="mail.scheme"
sequence="M1+N">
</key>
<key
commandId="mail.openMessage"
schemeId="mail.scheme"
sequence="M1+3">
</key>
<key
commandId="org.eclipse.ui.file.exit"
schemeId="mail.scheme"
sequence="M1+X">
</key>
</extension>

Finally, you need to create a plugin_customization.ini if you don’t have one already for your application and put this in there:

org.eclipse.ui/KEY_CONFIGURATION_ID=mail.scheme

That’s it. Once you do that, you should have key binding bliss:

picture 2 Tip: Suppressing Keybindings

Thanks for listening and let me know if this helps. Here is the sample project for reference.

© EclipseSource 2008 - 2011