Skip to main content

JFace's IAction and SWT's Button Mapping

Has it ever occurred to you that, you use the IAction/Action as a model for the swt's button widget.

Well there is very simple way of doing it, following steps help you achieve just that:
  1. Create and IAction object 
  2. Create the Wrapper around IAction object of ActionContributionItem
  3. Call the fill method (there are 3 overridden fill method are present choose as per your requirement) of the class ActionContributionItem passing the parent composite on which you want your button widget to be created
  4. That's it your button widget is ready with Action model on the backend :)
Following are the benefits of keeping the model and UI separate:
  1. You don't have to bother about the state change and propagation of events  
  2. You can work on Action object on the back-end which is easier and simpler than working on UI objects
  3. Your UI layer can be automated without worrying about sync problems

Comments

Popular posts from this blog

Interview at Progress Software

I have given a lot of interviews before however, this one was special. Let me start from the beginning. I got a call from Progress Software and was scheduled for the first telephonic discussion. Next day, I got a call from HR and she asked me questions on Java and a few basic puzzles.  After clearing the previous round, I got scheduled for the second telephonic interview. This interview covered Java, design-related problems and algorithms. After a week, I got a call from the HR for the onsite interviews in Hyderabad. This is the first time I googled about Progress Software. I said yes for the onsite interviews. Journey to onsite started not as planned after my flight got delayed. Because of fog-related delay in Delhi, I reached the PSI (Progress Software India) office couple of hours late.  HR introduced me to the first interviewer. The interviewer explained the first round. It was a coding round (I am not a big fan of coding rounds), the problem was well expl

java.net.SocketException: Connection reset

I am able to fix the problem via setting the following params on the HTTPClient class... client.getParams().setParameter("http.socket.timeout", new Integer(0)); client.getParams().setParameter("http.connection.stalecheck", new Boolean(true)); java.net.SocketException: Connection reset at java.net.SocketInputStream.read(Unknown Source) at java.io.BufferedInputStream.fill(Unknown Source) at java.io.BufferedInputStream.read(Unknown Source) at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:77) at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:105) at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1115) at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1832) at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590) at org.apache.commons.httpclient.HttpMethodBase.execute(

New in Dolphin - Java 7

With Dolphin java introduced cool new features like: 1. Strings in “switch” block      switch(s) {           case “Apple”:           // do something;           case “Orange”:           // do something;           default :      }      2. <> (Diamond) operator – Type inference for generic instance creation E.g List > list = new ArrayList>(); vis-à-vis List > list = new ArrayList <> (); Empty diamond braces is required and it's not a typo :).      3. Single Catch for multiple Exceptions with "|" operator           try {           // Reflective operations calling Class.forName,           // Class.newInstance, Class.getMethod, Method.invoke, etc.      } catch (final ClassNotFoundException |      InstantiationException | NoSuchMethodException |      InvocationTargetException e) {           log(e)           throw e;      }      4. Also in Java 7, this will work      public void rethrowException(String exceptionName) throw