Eclipse Equinox as a Windows Service

In the Eclipse SCADA project we finally wanted to create a setup of the server components for the Windows platform. Ideally all the server tasks should be integrated into the Windows service framework, so that you can stop and start services “the Windows way”.

While there seems to be a commercial solution (64bit) from Tanuki Software, we wanted (needed) to go the open source way. Which actually brings one to Apache Commons Daemon. Since we are already using “jsvc” (the Unix way) of the library, is made sense to use “prunsrv.exe” for the Windows side.

The idea is pretty simple, you specify a class that has two static methods (start and stop) which perform the task of starting and stopping your service. The service wrapper “prunsrv.exe” will take care of loading the JVM. “start” and “stop” will be executed in the same JVM instance, so if you have a global instance variable you have no issues here. Luckily Eclipse/Equinox already has an appropriate class: EclipseStarter.

Continue reading

Creating Mac OS X Icons (icns) on Linux

Time again for some new icons for an Eclipse RCP launcher. While The Gimp can easily create XPM and Windows ICO files, when it comes to Mac OS “icns” format, you won’t have any built in support.

There are some fine tools out there for Mac OS, but if you are running Linux and don’t want to buy a Mac just for creating some icon files, png2icns comes to the rescue. It is a small command line tool which simply creates an “icns” files from some “png” files.

Create your icon files as “png” in multiple resolutions. If you are creating an Eclipse RCP launcher, you will, most likely, have them anyway for creating your Windows “ico” file. Place them in any folder you like:

-rwxr-xr-x 0 jens jens 1427 Feb 24 10:49 icon_16px.png
-rwxr-xr-x 0 jens jens 2003 Feb 24 10:49 icon_32px.png
-rwxr-xr-x 0 jens jens 2560 Feb 24 10:48 icon_48px.png
-rwxr-xr-x 0 jens jens 5304 Feb 24 10:48 icon_128px.png
-rwxr-xr-x 0 jens jens 9883 Feb 24 10:47 icon_256px.png

Ensure that you have the “png2icns” application installed. On Ubuntu it comes with the package “icnsutils”, which can simply be installed by executing:

sudo apt-get install icnsutils

Now call “png2icns”. As the man page suggest you need to provide all PNG files, that you want to be part of the icon, as argument. The first argument is the output filename. Also you can let the shell find the correct PNG file by using the wildcard (*):

png2icns icon.icns icon_*px.png

Easy! ;-)

PS: If anything goes wrong, “png2icns” will complain at the command line (e.g. due to some wrong resolution).

Registering EMF models in plain java

Using Eclipse EMF/Ecore models inside the Eclipse Platform is quite easy. Loading an XML/XMI serialized model file is only a matter of some lines of code. The most interesting thing about this is that the whole Eclipse platform can handle the registration of models and model factories for you. So instead of knowing what model type you are loading, it will be detected and the right model factory will be used for loading and creating your model instance. Even better is the fact that also derived model objects can be loaded that way.

Just image you are writing a model A and extend object in the model B. So you can create a model instance which contains objects from model A and B and just serialize it to XML. Loading it back will of course give you model objects of type A and B. Although initially only model A existed and B was an extension using derivation. For this to work the resource mechanism of EMF must need to know which namespace is handled by which resource package and factory. If you are running inside an Eclipse Platform this is easily done using the extension mechanism. And the “genmodel” file and generator will automatically create the correct code and “plugin.xml” for this setup.

The problems start when you are outside the Eclipse Platform and running in a plain Java application. The default way to go is by registering all EMF models somewhere before loading the serialized models:

public void setup () {
  MyModelPackage.eINSTANCE.eClass();
}

Continue reading

Fixing the theming issue with Eclipse RCP applications in E4

It seems that migrating from Eclipse RCP 3.x to E4 (Eclipse 4.x) is not a quick win. If you already have an RCP based application the switch to E4 turns out to be a real problem. As is the E4 way if you want some sort of “custom” application that features some IDE components (like a perspective switcher or about dialog). It seems a bit strange that the migration from 3 to 4 is such a bumpy ride. Although there a are lots of tutorials, they mostly only scratch the surface of the task to convert a full blown RCP application. But this should be a rant on E4, I hope that the next releases improve that situation a lot.

When I migrated our RCP Application (OSTC from openSCADA) to E4 using the RCP bundle of E4. This seems not to be a real E4 application, but allows one to run a legacy, 3.x, application inside the new E4 environment. A quick it-just-works migration, still you miss all the E4 fun. But at the first start the user interface looked up bit garbled up. Some black line drawing artifacts. The tabs where a bit “dull” compared to the facy new tabs in E4.

The solution was pretty simple, the final RCP application was missing the bundle “org.eclipse.platform” which contained the themes and the necessary resources.

Fixing the Mint-X theme for Eclipse/SWT

If you are running Mint, Eclipse and you like the Mint-X theme, you might be a bit frustrated every time you open up Eclipse. Especially with Eclipse 4.2 the design of the toolbars is pretty messed up. See the launchpad bug entry: https://bugs.launchpad.net/linuxmint/+bug/1168281

eclipse1

Gladly this is only a minor glitch which can be fixed easily. Hopefully the change of the github pull request will find its way into Mint.

Issues with Eclipse Acceleo and sub-packages in the meta model

Today I stumbled over an issue that was unsolved in my workspace for some days now. Finally I got the time to fix it. I have a ECore meta-model which consists of three sub-packages and has no class in the main package. Generating model, edit and editor for this I had a nice start for my task. Then I wanted to generate code from this meta model and ran into a strange problem. On the console I simply got the following message when I tried to launch the Acceleo UI generator action:

The type of the first parameter of the main template named 'generateElement' is a proxy.

Due to some strange behaviour Acceleo was not able to read the meta-model definition when loading its templates, although the model itself was loaded fine. Trying to re-produce the issue with a new meta-model, everything seemed to work fine until I noticed the difference between my test model and the real model. The test model did have a class in the main package of the meta-model, while the real model did not. So the real model was like:

model
   -> sub1
       -> class1
       -> class2
    -> sub2
       -> class1
       -> class2

while the test model was:

model
   -> class1
   -> sub1
      -> class1

Adding a dummy class to my main package and re-generating all files (including new plugin.xml files) solved the issue with Acceleo. Although I am still not sure where the problem actually lies. It is not in the Eclipse Bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=401075

Build your own SIP trunk with Asterisk and mISDN

The mission: “save some bucks by using a free PBX using a cheap isdn card”. Don’t try! Buy something working in the first place. But if you have to, here is one example how it can be done. There are, for sure, many others!

The idea was to replace trixbox using an AVM Fritz!PCI card with something more up to date and not that buggy. FreePBX Distro kicked itself out because of the issues with mISDN. Elastix brought in mISDN support but still failed in configuring it. Since the setup was for only 3 users for now and the idea was to later buy something more professional (I really hope it comes to this point), I used Starface free. It has 4 users and 10 extensions for free. Yet the free version only allows using SIP providers. Also it was not possible to buy a Patton SmartNode 4120 at the moment, which I still hope to get somewhere in the future. So I needed to build our own SIP trunk since the provider used (M-NET) does not provide SIP trunks as a product.

Continue reading

Eclipse Draw2D Border Magic

While using Eclipse Draw2D I stumbled over some quite interesting behaviour on win32 using rectangles and scaling.

We have a scalable layer and added a rectangle. When the layer was actually scaling (so not 1.0) strange artifacts appeared on win32 platforms. Finally it turned out that it was a negative line size with the outline flag set to true. Which renders on Linux as if outline would be set to false. Yet interesting was that setting the lineSize to 0.0 (zero) while keeping the outline flag true causes a hairline to be drawn. So a line which is 1 pixel, independent of the scale factor.

SettingsScreenshot
figure.setOutline ( false );
figure.setOutline ( true );

Which is the same as:

figure.setOutline ( true );
figure.setLineWidthFloat ( 1.0f );
figure.setOutline ( true );
figure.setLineWidthFloat ( 0.0f );

This is the actual hairline variant.

figure.setOutline ( true );
figure.setLineWidthFloat ( 2.0f );
figure.setOutline ( true );
figure.setLineWidthFloat ( -1.0f );

Note the small artefacts at on the sides. These are invisible if run under Linux.

The full code to create the canvas was:

ScalableLayeredPane pane = new ScalableLayeredPane();

Layer layer = new Layer();
layer.setLayoutManager(new StackLayout());

pane.add ( layer );

Figure figure = new Figure ();
figure.setLayoutManager(new XYLayout());
figure.setBackgroundColor(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY));
figure.setOpaque(true);

RectangleFigure r = new RectangleFigure();
r.setBackgroundColor(Display.getDefault().getSystemColor(SWT.COLOR_YELLOW));
figure.add(r, new Rectangle(10,10,20,20));
layer.add ( figure );

pane.setScale(4.0);
r.setLineWidthFloat(0.0f);
r.setOutline(true);


Setting the page size and orientation with ODFDOM for tables aka spreadsheets

Most tasks that seem to be quite easy tend to turn out as a desaster. Setting the page size and orientation with ODFDOM was such a thing. While styling with ODFDOM is powerfull and a horror at the same time. You actually never know where the attribute have to be placed or which attributes to use.

After I finished an export to “ods” (aka spreadsheet) it simply wanted to set the format to “A4 landscape”. Here is how to do that:

First create your spreadsheet and sheet ( you might already have done that):

OdfSpreadsheetDocument output = OdfSpreadsheetDocument.newSpreadsheetDocument ();
final OdfTable sheet = OdfTable.newTable ( output );

Now change the styles to “A4 landscape”:

First we need to get the “master page” named “Default”:

StyleMasterPageElement defaultPage = output.getOfficeMasterStyles ().getMasterPage ( "Default" );

The master page tells us the name of the page style:

String pageLayoutName = defaultPage.getStylePageLayoutNameAttribute ();

Which gives us the page layout object:

OdfStylePageLayout pageLayout = defaultPage.getAutomaticStyles ().getPageLayout ( pageLayoutName );

Finally we can set “A4 landscape”:

pageLayout.setProperty ( OdfPageLayoutProperties.PrintOrientation, "landscape" );
pageLayout.setProperty ( OdfPageLayoutProperties.PageHeight, "210.01mm" );
pageLayout.setProperty ( OdfPageLayoutProperties.PageWidth, "297mm" );
pageLayout.setProperty ( OdfPageLayoutProperties.NumFormat, "1" );

All four properties seem to be required. Also the width and height have to be rotatate according to “landscape”.