Eclipse Yoxos Services Downloads Blogs About
Home > Blogs >

Posts Tagged ‘swt’

on Jul 6th, 2009Integrating BIRT into RAP applications

Finally I had some time to write down some of my experiences with integrating the Business Intelligence Reporting Tools (BIRT) into a Rich Ajax Platform (RAP) application. I wrote it all down in a small tutorial that shows how you can integrate charts and reports seamlessly in your RAP application. Topics covered in the tutorial include how to setup the environment to let BIRT and RAP play well together.

Birt rap chart demo Integrating BIRT into RAP applications

Many thanks to BIRT committer, Virgil Dodson, to help with this tutorial- it was really great to get Eclipse committers from different projects working together!

on May 8th, 2009UI.toString() in a snippet

Ever wanted to get a print out of all components that make up a piece of UI?

This little recursive snippet does that for you.

private void printChildren(Composite composite, int count) {
  StringBuilder spaces = new StringBuilder(count * 2);
  for (int i = 0; i < count * 2; i++) {
    spaces.append(' ');
  }
  for (Control c : composite.getChildren()) {
    System.out.println(String.format("%s%s (%s)", spaces.toString(), c.toString(), c.getLayoutData()));
    if (c instanceof Composite) {
      printChildren((Composite) c, count + 1);
    }
  }
}

Here’s an example of the output:

ui to string UI.toString() in a snippet

Composite {} (null)
  Composite {} (null)
    Composite {} (null)
      Composite {} (GridData {horizontalAlignment=Undefined 256 grabExcessHorizontalSpace=true verticalAlignment=GridData.CENTER})
        Label {Subject:} (GridData {horizontalAlignment=SWT.BEGINNING verticalAlignment=GridData.CENTER})
        Label {This is a message about the cool Eclipse RCP!} (GridData {horizontalAlignment=SWT.BEGINNING verticalAlignment=GridData.CENTER})
        Label {From:} (GridData {horizontalAlignment=SWT.BEGINNING verticalAlignment=GridData.CENTER})
        Link {<a>nicole@mail.org</a>} (GridData {horizontalAlignment=SWT.BEGINNING verticalAlignment=GridData.CENTER})
        Label {Date:} (GridData {horizontalAlignment=SWT.BEGINNING verticalAlignment=GridData.CENTER})
        Label {10:34 am} (GridData {horizontalAlignment=SWT.BEGINNING verticalAlignment=GridData.CENTER})
      Text {} (GridData {horizontalAlignment=SWT.FILL grabExcessHorizontalSpace=true verticalAlignment=SWT.FILL grabExcessVerticalSpace=true})

on Apr 17th, 2009Finding SWT Leaks with Sleak

In SWT, the mantra is “if you created it, you dispose it.”

The problem is, people forget to dispose which makes leaks a reality.

For example, ever come across this dreaded exception from SWT?

...
org.eclipse.swt.SWTError: No more handles
at org.eclipse.swt.SWT.error(SWT.java:2966)
at org.eclipse.swt.SWT.error(SWT.java:2863)
at org.eclipse.swt.SWT.error(SWT.java:2834)
at org.eclipse.swt.widgets.Widget.error(Widget.java:395)
at org.eclipse.swt.widgets.Control.createHandle(Control.java:482)
at org.eclipse.swt.widgets.Composite.createHandle(Composite.java:229)
at org.eclipse.swt.widgets.Control.createWidget(Control.java:497)
at org.eclipse.swt.widgets.Scrollable.createWidget(Scrollable.java:131)
at org.eclipse.swt.widgets.Control. (Control.java:97)
at org.eclipse.swt.widgets.Scrollable. (Scrollable.java:72)
at org.eclipse.swt.widgets.Composite. (Composite.java:87)
...

One of the most common causes of this type of exception is a resource leak. In SWT, you’re allocating operating system resources for widgets, images, fonts, and other graphical objects. Since there is a platform-specific limit on the amount of resources you can allocate, you must be careful to free any objects that you allocate. To see what resources your application has allocated, the SWT team has a tool called Sleak. To get an idea of how Sleak works, let’s modify the famous RCP Mail example. The first step will be to add the Sleak view to the RCP Mail perspective (Perspective.java):

layout.addStandaloneView(NavigationView.ID,  false, IPageLayout.LEFT, 0.25f, editorArea);
IFolderLayout folder = layout.createFolder("messages", IPageLayout.TOP, 0.5f, editorArea);
folder.addPlaceholder(View.ID + ":*");
folder.addView(View.ID);
folder.addView("org.eclipse.swt.sleak.views.SleakView"); // add sleak here!

The next step is to simulate a leak so we can show the benefit of using Sleak. We can simulate a resource leak by creating a bold font and never disposing of it in the RCP Mail view (View.java):

...
// setup bold font
// comment out the safe way of getting a bold font via the jface registry
// Font boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
FontData[] fontData = JFaceResources.getDialogFont().getFontData();
for (int i = 0; i < fontData.length; i++) {
	FontData data = fontData[i];
	data.setStyle(SWT.BOLD);
}
boldFont = new Font(parent.getDisplay(), fontData); // this should be disposed in dispose()
...

Ok, now that we have the code modifications out of the way, we need to launch our application. Note, in order to have Sleak function properly, you have to enable some options:

org.eclipse.ui/debug=true
org.eclipse.ui/trace/graphics=true

The easiest way to do this is in your Eclipse application launch configuration. There is a ‘Tracing’ tab that allows you to tweak options:
tracing 300x209 Finding SWT Leaks with Sleak

Once that is done, we can launch our application and find the ‘Sleak’ view:

sleak1 300x191 Finding SWT Leaks with Sleak

If you press the ‘Snap’ button in Sleak, it will take a snapshot of the current allocated resources. To demonstrate the leak, we need to open two more messages in the mail application, close both of them, and then go back to the Sleak view to press the ‘Diff’ button:

sleak3 300x155 Finding SWT Leaks with Sleak

Sleak now informs us that there are two more fonts allocated than before, we have found our leak! If you click the ‘Stack’ option, you can even get a stracktrace that tells you where the resource was allocated. A fix for this problem goes back to the SWT mantra of “if you created it, you dispose it.” In our view, we simply need to dispose of the bold font when we’re done using it (or use the font registry like before):

...
public void dispose() {
     super.dispose();
     boldFont.dispose(); // we need to dispose that font to prevent a leak!
}
...

Here’s a zip of mail example with the leak if you want to toy with Sleak.

Hope this helps!

on Mar 6th, 2009New Nebula SWT Widgets

Did you know about the Nebula project at Eclipse? If not, you should… Nebula is a source for custom SWT widgets and other UI components:

nebula 281x300 New Nebula SWT Widgets

Nebula also acts as an incubator for the SWT project at Eclipse. Here’s the list of widgets in Nebula so far:

But wait, there’s more! Tom Schindl, the new Nebula project co-lead, sent out an email detailing some new Nebula contributions on the horizon:

  • Office Ribbon from Emil Crumhorn (Provides a Microsoft Office like Ribbon)
  • Rich-Texteditor from Pavel Petrochenko (Provides HTML-Editing-Facilities)
  • RadioGroup/RadioItem from Matthew Hall (Provides a List-like Group-Widget)
  • XViewer from OSEE (Provides a fancy framework around SWT-Table/Tree)

If you have any widgets you have developed personally and would like to see them used elsewhere, why not consider donating them to the Nebula project?

on Mar 5th, 2009I *heart* SWT Cocoa

A good portion of the EclipseSource technical team use MacBook Pro’s for their development machines. We are doing our best helping the SWT team in testing the Cocoa port. As the Eclipse 3.5M6 milestone gets closer, the SWT team is converging on finishing the Cocoa port which just has me thrilled! It should have you thrilled too, because you can finally do things like use Java 1.6 in your projects! If you have any projects or products that run on the Mac, you should consider testing out the Cocoa port now so the SWT team has time to react. In particular, Kevin Barnes has been helpful in testing out some of the popular RCP applications (i.e., XMind, RSSOwl) on Cocoa to see how they perform. Feel free to catch him on Twitter, he’s really responsive to SWT Cocoa related questions (especially when you bring stacktraces)!

iamkevb 253x300 I *heart* SWT Cocoa

On a funny side note, Jeff McAffer recently got a new shiny MacBook Pro. As someone who was used to the first painful week of using a Mac, here are some quotes I’d like to share describing the conversion process:

“!@#$%^& mouse acceleration, how do I turn it off!”
“!@#$, where’s the print screen key?”
“seriously? four !@#$%^& modifier keys?”
“!@#$, does delete mean backspace or !@#$”

Anyone else have some good quotes from their first experience with a Mac ;) ?

on Feb 10th, 2009The first e4 milestone

Wow, I just saw the new and noteworthy posted for the first e4 milestone. There’s a lot of stuff there! I’m amazed that the e4 team was able to get this milestone out given that a lot of them were also working on the Eclipse 3.5M5 release.

Anyways, here are some of my favorite noteworthy items:

CSS Support for SWT

css swt editor 300x285 The first e4 milestone

RCP Mail CSS Example

css rcp example 300x282 The first e4 milestone

SWT Browser Edition

controlexample 273x300 The first e4 milestone

Heck, there’s even a basic ActionScript development environment… cross-compilation debugger magic!

If you like what you see, why not get involved with the e4 project to help shape the future of Eclipse!

on Feb 2nd, 2009Very basic dependencies

We recently moved our continuous integration builds to a new server. The builds are set up self-contained or have only little dependencies to files outside their workspace. So it shouldn’t be a big deal: Just set up the new projects in your CI server and copy over the settings from the old projects, right?

And if you then get an error that even Google knows only 2 pages of useless results about, you start scratching your head. At least I did after I got this one:

java.lang.UnsatisfiedLinkError: no swt-pi-gtk-3346 or swt-pi-gtk in swt.library.path, java.library.path or the jar file

It gets a bit more mysterious when you start looking for the swt-pi-gtk libraries, locate them in one of the SWT fragments, and you make sure that all your “-os” “-ws” and “-arch” options are set correctly.

To make the long story short, the solution was to install GTK on the new server…

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
© EclipseSource 2008 - 2010