Eclipse Commands: Cut, Copy and Paste

Posted on July 1st, 2009 in Eclipse by Stefan

I came around the requirement to enable the default cut, copy and paste function as menu entries within the main menubar. When adding the commands org.eclipse.ui.edit.cut, org.eclipse.ui.edit.copy and org.eclipse.ui.edit.paste to my menubar using the org.eclipse.ui.menus extension point. Unfortunately, these menu entries where disabled all the time. This was pretty comprehensible, as there was no active handler available. So I did register an appropriate handler (working like the Eclipse WidgetMethodHandler) using the IHandlerService. It takes the currently focussed element and checks whether this Control has the necessary cut(), copy() or paste() method to invoke and calls the required method on execution. So far, so good, my menu entries were now enabled - at least sometimes?!? The reason for that was the isHandled() method of my handler which returns true only if the method is available on the currently focussed element.

/** {@inheritDoc} */
@Override
public boolean isHandled() {
return isTargetMethodAvailable(Display.getCurrent().getFocusControl()) != null;
}

As the isHandled() is called only on the context part’s (IWorkbenchPart) activation, the state of the handler is only requested once for the default focus Control of the part. So the state of the commands stays the same for the whole part activation. Additionally, a ‘no active handler available’ exception is thrown, if the menu entry is selected with a focussed Control not supporting the method. Bad luck.

So, what to do now? I ended up registering a focus Listener for all elements of the part to keep the command state in sync with the handler state.


// create a listener for tracking the focus
final Listener listener = new Listener() {
/** {@inheritDoc} */
@Override
public void handleEvent(Event event) {
ICommandService commandService = (ICommandService)workbenchPart.getSite().getService(ICommandService.class);
commandService.refreshElements(commandId, null);
}
};

The refreshElements() method calls the updateElement() method of active handlers for the given command ID implementing the IElementUpdater interface. So I let my handler implement that interface, the interface method simply fired an HandlerEvent stating that the enabled state changed.

/** {@inheritDoc} */
@Override
public void updateElement(UIElement element, Map parameters) {
fireHandlerChanged(new HandlerEvent(this, true, false));
}

The only thing left to do was to implement the isEnabled() method which is used to determine the commands enablement state.

/** {@inheritDoc} */
@Override
public boolean isEnabled() {
return isTargetMethodAvailable(Display.getCurrent().getFocusControl()) != null;
}

There you are, it works!

Back again…

Posted on June 9th, 2009 in General, Personal by Stefan

Sorry for the long time away. I have been quite busy finishing my personal ’small’ project. If you like, take a look at amazon here. It took quite a long while to get it done, but now only the last corrections are left to finish. Hope you like it.

Model View Presenter, Passive View & DI

Posted on November 7th, 2008 in Eclipse by Stefan

After three days of interesting conversations I’m off to my November holidays. This is a very calm and silent time which leaves a lot time for interesting thoughts.

Denmark

Denmark

I heard a talk about testing RCP Applications on Wednesday shortly before I left Munich which was pretty interesting. Ralf Ebert outlined a way of designing GUIs to ease testing by applying the Model View Presenter pattern in combination with the Passiv View pattern. Basicly it introduces a presenter which mediates between the ‘Model’ and the ‘View’. The model includes all data and logic, e.g. adding two numbers. The view simply displays everything. The presenter connects input and widgets and delegates calls from the UI to the model’s logic. This allows mocking the view’s behaviour and simply test the logic within the model.

The testing aspect sounds interesting, but something else comes a long with that design. In distributed systems, the view usually calls some logic from serverside services. That means, the view has to somehow access a service instance by using some context holding component. Now, what about making the view part of this service structure and provide the service via DI. Usually (in Spring terms ;) ) this means hooking the view into the service container, which is pretty bad (if even possible) as they are controlled by the platform. But using a so called view model (at least I tend to call it like that) solves that. The model (and even the presenter) may be hooked easily to the container, which makes interaction quite easy.

Nice idea, what do you think?

Greetings from the W-JAX

Posted on November 4th, 2008 in Eclipse by Stefan

I had my Eclipse RCP Workshop here in Munich yesterday together with Benjamin and Matthias. It was quite a nice little event with about 20 participants. As usual, we had a little introduction held by Matthias, which outlines the RCP / OSGi basics. Then we went on with the hands-on part of the Workshop. Ben introduced Views and JFace Viewers and I concluded by showing Extension and Extension Points. I hope everyone had fun, at least we three had.

Eclipse RCP Workshop

Eclipse RCP Workshop

I you did not attend the W-JAX this year, do it next year. It is a great location and a lot of interesting talks.  So, see you next year :) !

AM Grand PokerSeason 2008 - 8th Session

Posted on July 26th, 2008 in Personal by Stefan

On friday, the 8th session of our Grand Poker Season took place. Again, we played at Andreas’ place, thanks again for hosting us on your birthday! Unfortunatly his winning streak ended, he came in 4th. Here are the results:

  1. Stefan
  2. Stephan
  3. Torsten
  4. Andreas
  5. Michael

The Executiove board took the lead and is now head of the table. Again we are all looking forward to the next session again at Andreas place.

See you at the tables!

PS: I missed out posting the results of the 7th session:

  1. Andreas
  2. Stefan
  3. Stephan
  4. Michael

Sorry for that!

Eclipse RCP & Logging

Posted on June 28th, 2008 in Eclipse by Stefan

Logging within an Eclipse RCP application is pretty easy, every Activator provides an ILog using it’s getLog() method. Though it’s a little annoying wrapping the log statements with an IStatus, using some convenience methods solves that. But what about using another logging framework, e.g. Log4J?

Nearly everybody who tried to use Log4J accross Eclipse bundles faced the context classloader problem. Usually, the Log4J binaries should be placed within a library bundle. The configuration, the log4j.properties file, though is supposed to be somewhere else within a project specific bundle. Creating a Logger instance then runs into a problem: the configuration is not visible from the library bundle. So what to do now?

A pretty elegant solution is to use a fragment containing the configuration tied to the library bundle. So the project specific configuration is seperated from the framework and can be managed individually.

Eclipse DemoCamps 2008 - Ganymede Edition/Hamburg

Posted on June 17th, 2008 in Eclipse by Stefan

Yesterday, the Eclipse DemoCamp 2008 Ganymede_Edition/Hamburg was on schedule in Hamburg’s Former Coffee Exchange. Round about 40 Eclipse enthusiasts took part which is a pretty nice crowd of people. Thanks to Peter and Martin Hamburg now provides two regular events for the Eclipse community around here which is really nice (assuming and hoping that the DemoCamp and the Stammtisch will now occur regularly :). We had very interesting talks about Eclipse, especially Reginald’s talk about automated GUI Testing was pretty wicked. Unfortunatly I missed out taking photos, but trust me, if you didn’t attend, do it next time!

Remote offline checkin? Create a patch!

Posted on June 13th, 2008 in Personal by Stefan

Today a collegue of mine asked me to check in some change to our SVN repository. This was a little tricky as I had a home office day today and no access to our repository. Fortunatly there is this handy ‘create patch’ function in my Eclipse contextmenu. So I simply created a patch as a text file and sent it to him by Google Talk. A remote offline checkin - wicked eyh?

AM Grand PokerSeason 2008 - 6th Session

Posted on June 3rd, 2008 in Personal by Stefan

On friday, the 6th session of our Grand Poker Season took place. Dirk “The Shaker”, our host came in 3rd, Andreas winning again is about to follow Hani as this years ‘Altmeister’. Here are the results:

  1. Andreas
  2. Stefan
  3. Dirk
  4. Lars
  5. Heike
  6. Stephan
  7. Matthias

Dirk is still head of the table followed by myself and Stephan. Again we are all looking forward to the next session again at Andreas place.

See you at the tables!

Why Java Web Development basicly sucks

Posted on May 17th, 2008 in Software Architecture by Stefan

Developing Java web application really is a pain in the butt. Simple things like autocompletion, an editable table or client and server side validation seam to be so damn tricky. Sure, you get all these JSF frameworks from Sun or Apache, Rich Faces, Ajax 4 JSF and so on. All these promise to make things SOOOO easy. But tying these together busts the whole thing as they do not work together properly. You really have to bend everything to the max to get it at least running. Why is everybody so fancy about Web Applications anyway? Actually, the Web initially was made for a specific reason which is to display content. Abusing it to develop applications that more or less look and behave like a ‘real’ application brings me to the question, why we do that anyway. Is distribution that important that we need use a hammer to get in the screw?

Next Page »