Having Fun and PRODUCTIVITY with Acceleo


In the context of an RCP application for internal customers I have to parse some binary files and store the result in a relation Database (this is done with http://www.sqlite.org/). The binary file content is described in text specification document. To be short, this file contains different “events” belonging to a given “category”. The category of the event is defined in the header of the event and this category allow to decode the event’s content. There is roughly 200 categories.

200 ??? This mean I’ll have to code 200 “parser classes”, one for each of these categories inserting the right things in the database. Wait ….. Few weeks ago, a colleague working in an other internal RCP application,  presented to me this application based on many Modeling technologies and mainly on Acceleo to generate some code from graphical models.

My context is a little bit different, because I don’t want to provide the code generation to my end users but I want to have fun and to be more productive in my daily work.  After few days of work and thanks to help of my colleagues already using this technology and thanks to the reactive support of Obeo on the Eclipse Modeling Forums I have a first version of my tool using generated classes.

To achieve this I first created an ecore Model (or meta model but name ar not important) file (.ecore). This EMF file describe what is a category: it’s mainly a list of parameters having a given type and a given length. Then, using the magic EMF Reflexive Editor, I created an instance of my model (or meta model), an xmi file describing all the available categories and their content. Finally I created an Acceleo 3 project, which job is to take my xmi file has input and generate the associated 200 Parser classes (through the use of a template file coded in OCL).

To conclude, reading this post you are thinking “it seems really easy to bring together these technologies” !!! I confirm, it is !!

Advertisements

How Deliver RCP Patches and Updates ??


I have been working on an RCP application delivered to internal customers inside my (big) company during the last months. I already have a satisfying headless build for this application, generating a full package as a zip archive that is already delivered to the previously mentioned internal customers as release 0.9.6 (several releases have been done).

We plan now to deliver the 1st (1.0.0) “official” release for the beginning of the 2011. In this context we are thinking about the best strategy to handle updates and patches that will be done on top of this 1.0.0 release. To better understand the context here is the RCP product’s content:

  1. org.eclipse.rcp feature provided by the Eclipse Foundation
  2. my.company.generic feature provided by an other team in my company and delivered as P2 repository.
  3. my.company.product feature wrote by myself.

Our requirements regarding the updates/patches installation are the following ones:

  1. User must update the RCP application as a global action and doesn’t care which feature among the 3 features of the product is updated/patched
  2. Some users have access to our (through internal network) P2 update/patches repository and others don’t
  3. It’s not yet possible to add new optional “software” (features in Eclipse’s terminology) to the product

To handle the 1st requirement I decided to adopt the same policy to update OR to patch the product with increment of the product version. Each time the product feature (2) OR the product required feature (3) I’ll will upgrade the product version number, the product feature (2) number if this is the modified feature and I’ll perform a full rebuild of the product and update the p2 repository with the result of this build.

Regarding requirements number 2, I maintain an up to date p2 repository for users having access to it and provide a zipped version of the same repository each time it is updated for other. This solution will work but will enforce users without access to the repository to get a full zipped archive each time the product is updated even if for example only the required feature (2) is modified. Can you see a better solution to handle this situation ?

For the last requirement, I decided to not use the P2 UI and write my own update UI code as mentioned in this Eclipse wiki. It seems not so easy but feasible.

Feel free to tell us about your RCP’s experience regarding updating and patching by commenting this post,

Manuel

Simple Configurator AND Update Configurator


In the context of an RCP application and following this previous post, I am building my app using Features including the org.eclipse.rcp one. I recently decided to add the error log view to my product in order to inform users of what was wrong and to respect the following recommendation: “Don’t ignore that Error !!!“.

To do that I just added the error log view in my perspective and added a dependency on the org.eclipse.ui.views.log plugin in one of my plugin to have it included at build time. All is working fine but ….

When I first launch a freshly installed application I get several errors (but the tool behaves properly according to my test suites) such as:

“Could not install bundle plugins/org.eclipse.ui_3.5.2.M20100120-0800.jar   Bundle “org.eclipse.ui” version “3.5.2.M20100120-0800″ has already been installed from: reference:file:plugins/org.eclipse.ui_3.5.2.M20100120-0800.jar”

After long investigations and deep debugging of Eclipse, I concluded that both  org.eclipse.update.configurator and org.eclipse.equinox.simpleconfigurator where installed in my product. As a consequence they are both trying to install plugins, and for some plugins (I don’t know exactly when yet) they install the same plugins. Removing manually the Update Configurator plugin (it seems to be the old way to install bundles in Eclipse) from my product solves the issue. Unfortunately this plugin is included with the simple configurator plugin in the RCP feature on which I depend.

So for now I removed the dependency on RCP feature and “manually” manage the plugins required by my product. I am not satisfy on this solution and would be interested to get community thoughs on this topic. Any pointers on the subject are welcome.

Manu

 

Eclipse Can’t Refactor My Log Method ??!! What ???


Eclipse will not be able to re-factor the following method ???:

public void log(String Message);

into

public void log(String Message, String methodName);

with automatic replace of methodName parameter by the enclosing method name. For example the following call in the main method

log("my message");

will be replaced by

log("my message", "main");

I am sur I am missing something. Where ??

@#!!#Bundle-Localization!@#$%


One our spent to find why my plugin.properties file was not taken into account even if present in the build.properties file. The answer was the following missing line in my Manifest.MF

Bundle-Localization:  plugin

Next time I’ll not forget this line !!!

Eclipse, RCP, SWT and Opengl


I started recently to write (on my free time) a rubik’s cube RCP application.  The main goal for me is to get started with Opengl without loosing time into setting up all the required stuff before writing my first Opengl line. Thanks to my knowledge of the Eclipse platform and to the SWT’s people work I was able to run my first opengl application in few minutes.

After a little bit more of work I am now able to display my rubik’s cube and to rotate it. As you can see in the folowing screenshot, I still have a lot of things to learn before displaying the same cube as the one on Wikipedia’s page but I enjoy learning new things

Thanks SWT and Opengl  !!!!

Modify a file in response to IResourceChangeListener


Hi there,

In the context of an IResourceChangeListener I need to modify a given preference file in the workspace.  Because of “Note that during resource change event notification, further changes to resources may be disallowed.” the only solution to perform this change is to delay it on a future event (5 seconds later, on the next access to the file to be modified, on the next selection event, etc ..)

I would be interested to know how do you handle such situation ?

Plugin product VS Feature product


That is THE question ??? And it seems quite difficult to have a clear answer. Let’s recapitulate the information I gathered on this topic mainly related to build issues.  Please feel free to comment on this post in order to complete or to correct what I am saying:

Plugin Products:

  • No problem when building (Gui or headless) => all the required (the same than the required plugins computed in the launch configuration dialog when debugging the app) plugins are present
  • The RCP application disk footprint is optimized !! No useless plugins
  • No features are exported: as a result the features list tab of about dialog is empty !!!
  • It seems that plugin products are not recommended for RCP with self update (I didnd’t tested that yet) ???

Feature Products:

  • When exporting (headless), the only present plugins and features are the one listed in the .product file
  • Need to create a “dependencies” features including all the required plugins OR depend on all the features containing the required plugins => bring a lot of useless plugins
  • Features listed in the about dialog

In my case, I decided to use a Feature Product and then to “manually” create a feature including all the 90 plugins required by my RCP.

Because I am lazy and hate repetitive tasks, I wrote a simple Java main parsing a launch configuration file (.launch located in the workspace metadata folder) and generating from a template the feature with all the required dependencies. Is there any other existing way to do that ??

Hope this can help others, and if you need my simple Java feature dependency creator, just ask it.

Manu

Effective Java 2nd Edition – Builder Pattern in Eclipse


Hi there,

It’s been a long time since I didn’t post here and guess what … I am posting to ask some help !!!

I sometime use the Builder pattern as defined in Effective Java 2nd Edition item 2. Incidentally, I recommend this book to everybody writing Java code. Because I am a lazy man, I love JDT’s Java templates and will be really happy to have such a template for the builder pattern.

Let’s take the following example of Builder in order to illustrate this post (I just pasted 3 of the many parameters of the circle renderer class for readability):

public class XYPointCircleRenderer extends AbstractPointRenderer {

	/**
	 * Builder class for {@link XYPointCircleRenderer}.
	 */
	public static class Builder {

		private boolean bordered = false;

		private final int radius;

		private boolean tooltipable = true;

		/**
		 * Construct a new Builder with the given radius.
		 *
		 * @param radius
		 *            the radius of the circle. Must be > 0.
		 * @throws IllegalArgumentException
		 *             if radius <= 0
		 */
		public Builder(int radius) {
			if (radius <= 0) {
				throw new IllegalArgumentException(
						"radius must be greater than 0");
			}
			this.radius = radius;
		}

		/**
		 * Set the bordered value of this builder.
		 *
		 * @param val
		 *            the bordered value
		 * @return this for convenience
		 */
		public Builder bordered(boolean val) {
			bordered = val;
			return this;
		}

		/**
		 * Return a new {@link XYPointCircleRenderer}.
		 *
		 * @return a new {@link XYPointCircleRenderer}
		 */
		public XYPointCircleRenderer build() {
			return new XYPointCircleRenderer(this);
		}

		/**
		 * Sets the tooltipable value of this builder.
		 *
		 * @param val
		 *            the tooltipable value
		 * @return this for convenience
		 */
		public Builder tooltipable(boolean val) {
			tooltipable = val;
			return this;
		}
	}

	/**
	 * The circle's diameter.
	 */
	private final int diam;

	/**
	 * The circle's radius.
	 */
	private final int radius;

	/**
	 * Private constructor use by Builder.
	 *
	 * @param builder
	 *            the builder to use to set this attributes.
	 */
	private XYPointCircleRenderer(Builder builder) {
		super(builder.bordered, builder.tooltipable);
		radius = builder.radius;
		diam = 2 * radius;
	}

    @Override
	public ChartElement paintPoint(int x, int y, GC gc) {
		gc.fillOval(x-radius, y-radius, diameter, diam);
		if (bordered) {
			gc.drawOval(x-radius, y-radius, diam, diam);
		}
		if (tooltipable) {
            rect = new Rectangle(x-radius,y-radius,diam,diam);
			return new RectChartEleme(null, rect);
		} else {
			return null;
		}
	}
}

I would like to create a builder template “asking for questions to the user”. I.e the builder template should ask the end user what are the required fields of the enclosing class, and what are the default values of non required fields. Is it possible to do that ? If yes, where can I get information to start ?

Note: I often use eclipse “equals and hashcode” generator, and I guess it’s implemented by Java code. Thus the only solution to my problem is may be to implement my Builder generator the same way ….

Manu