<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>richclientgui.com</title>
	<atom:link href="http://blog.richclientgui.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.richclientgui.com</link>
	<description>RichClientGUI Blog</description>
	<lastBuildDate>Thu, 12 Aug 2010 10:36:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Some excellent Java Courses scheduled in South Africa</title>
		<link>http://blog.richclientgui.com/?p=74</link>
		<comments>http://blog.richclientgui.com/?p=74#comments</comments>
		<pubDate>Thu, 12 Aug 2010 10:36:26 +0000</pubDate>
		<dc:creator>herman</dc:creator>
				<category><![CDATA[Training]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java courses]]></category>
		<category><![CDATA[java courses south africa]]></category>
		<category><![CDATA[java training]]></category>
		<category><![CDATA[java training in south africa]]></category>

		<guid isPermaLink="false">http://blog.richclientgui.com/?p=74</guid>
		<description><![CDATA[Polymorph Systems has scheduled their two flagship Java courses for October and November this year.
The Java Intermediate course will be presented in their new training facilities in Worcester, South Africa, from 18 to 21 October.
There is an early-bird special on this course: if you register before 15 September 2010, you will get a huge 20% discount on the course fees.
The very exclusive JavaSpecialists.EU Java Master course will run from 22 to 25 November 2010, also in Worcester, South Africa.
]]></description>
			<content:encoded><![CDATA[<p>Polymorph Systems has scheduled their two flagship Java courses for October and November this year.</p>
<p>The<a title="Java Intermediate" rel="self" href="http://www.jtraining.co.za/java/java/intermediate.html"> Java Intermediate course</a> will be presented in their new training facilities in Worcester, South Africa, from <strong>18 to 21 October.</strong></p>
<p><span style="color: #ff9900;">There is an </span><strong><span style="color: #ff9900;">early-bird special </span></strong><span style="color: #ff9900;">on this course: if you register</span><strong><span style="color: #ff9900;"> before 15 September</span></strong><span style="color: #ff9900;"> 2010, you will get a huge </span><strong><span style="color: #ff9900;">20% discount </span></strong><span style="color: #ff9900;">on the course fees.<br />
</span><br />
The very exclusive <a title="Java Master Course" rel="self" href="http://www.jtraining.co.za/java/java/master.html">Java Master course</a> will run from<strong> 22 to 25 November 2010</strong>, also in Worcester.</p>
<p><em>And for those interested in the overview of the courses, read this:</em></p>
<p><strong>Java Intermediate Course</strong><br />
Our Java Intermediate course is aimed at developers who feel they got a basic understanding of Java and OO, and would like to learn more about topics like multi-threading, generics, annotations, a design pattern or two, network and database programming, and a bit of reflection to round it off.<br />
This course is extremely practical oriented, and also discuss the use of unit-testing (JUnit) and basics of logging.</p>
<p>This course is based on <span style="text-decoration: underline;"><a href="http://www.javaspecialists.eu/courses/j2se.jsp">The JavaSpecialist Java SE</a></span> course material. We added a lot more programming exercises and some more advanced topics.</p>
<p><strong>Java Master Course</strong><strong><img src="http://www.jtraining.co.za/blog/files/javaspecialists-training_small.png" alt="javaspecialists-training_small" width="193" height="45" /></strong><br />
This is easily the best Java course in existence. It is meant for intermediate to advanced Java programmers, and tackle very interesting topics on multi-threading and concurrent programming, performance tuning and optimization, data structures, the NIO library and lots more.<br />
The trainer (<span style="text-decoration: underline;"><a href="http://www.jtraining.co.za/about/about/trainers.html">Herman Lintvelt</a></span>) has been hand-trained by Dr Heinz Kabutz (the author of the course) in Crete, Greece, and is one of only a select few in the world that is qualified to present this course, and the only one in Africa.<br />
This is a very intense and challenging course, and the amount you will learn is extremely valuable &#8211; to your company and your own career.<br />
<span style="text-decoration: underline;"><a href="http://www.jtraining.co.za/java/java/master.html">Read here why you should consider this course, and what the prerequisites are.</a></span><br />
Students who successfully complete the course will get a certificate from The JavaSpecialists, issued by Heinz Kabutz.</p>
<p>Please <span style="text-decoration: underline;"><a href="http://www.jtraining.co.za/about/contact/contact.php">contact us</a></span> if you have enquiries about the course.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richclientgui.com/?feed=rss2&amp;p=74</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add Logging without changing code</title>
		<link>http://blog.richclientgui.com/?p=62</link>
		<comments>http://blog.richclientgui.com/?p=62#comments</comments>
		<pubDate>Mon, 14 Jun 2010 19:16:55 +0000</pubDate>
		<dc:creator>herman</dc:creator>
				<category><![CDATA[Eclipse RCP]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[adjt]]></category>
		<category><![CDATA[AOP]]></category>
		<category><![CDATA[aspect oriented]]></category>
		<category><![CDATA[aspectj]]></category>
		<category><![CDATA[aspects]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[eclipse rcp]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[proxy]]></category>

		<guid isPermaLink="false">http://blog.richclientgui.com/?p=62</guid>
		<description><![CDATA[I recently got a request from my one client: “Please add logging of the time it takes to do remote service calls, with minimal impact on the existing code.” Now I immediately thought of the Proxy design pattern. The existing code had quite a large number of business interfaces defined, with an implementation for each [...]]]></description>
			<content:encoded><![CDATA[<p>I recently got a request from my one client: “Please add logging of the time it takes to do remote service calls, with minimal impact on the existing code.”</p>
<p>Now I immediately thought of the <a href="http://en.wikipedia.org/wiki/Proxy_pattern">Proxy design pattern</a>. </p>
<p>The existing code had quite a large number of business interfaces defined, with an implementation for each one that made use of RMI to call the remote objects. I’ll spare you the unnecessary details (JAAS, etc). It boiled down to basically every public method in each business interface implementation making use of an anonymous inner class with a simple public Object run() method to make the actual call to the remote object. A lot of code to change by hand, if logging and measurement of the time it took for remote calls were to be added.</p>
<p>A drastically reduced business interface might look like:</p>
<pre class="brush: java;">
package com.richclientgui.blog.delegate;

public interface SoccerScoreService {
    public int getTeamScore(String teamName);
}
</pre>
<p>In order to re-enact the work of the JAAS Subject.doAs(&#8230;) code that is involved with the actual code, I created a MockSubject class for this example, which just calls the run() method of whatever Runnable gets passed to it:</p>
<pre class="brush: java;">
import java.util.concurrent.Callable;

public class MockSubject {
    public static &lt;T&gt; T doAs(Callable&lt;T&gt; action) throws Exception {
        return action.call();
    }
}
</pre>
<p>We add a very basic mock implementation (no real remote calls happening here&#8230;):</p>
<pre class="brush: java;">
import java.util.concurrent.Callable;

public class MockSoccerScoreServiceImpl implements SoccerScoreService {

    @Override
    public int getTeamScore(String teamName) {
        try {
        &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;    Integer result = MockSubject.doAs(
                                    new Callable&lt;Integer&gt;() {
                public Integer call() throws Exception {
                    System.out.print(&quot;Doing some work...&quot;);
                    try {
                         Thread.sleep(1000);
                    } catch (InterruptedException e) {
                         e.printStackTrace();
                    }
                    System.out.println(&quot;completed.&quot;);
                    return new Integer(50);
                }
             });
             return result.intValue();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
        } catch (Exception e) {
             //for this blog, I don't care about the
             //exception handling...
             e.printStackTrace();
             return -1;
        }
    }
}
</pre>
<p>Now we can just create a simple class with a main method that calls getTeamScore(&#8230;) on an instance of <span style="font-size: 11pt">MockSoccerScoreServiceImpl</span>. </p>
<p><em>Now to add the logging&#8230;</em></p>
<p><strong>Approach A: Use a Proxy</strong><br />
We can create a Proxy for the Callable, since all our calls to the server are done using Callable instances. This proxy class measures the time it takes to perform the call() method of the real Callable, and logs it to sysout.</p>
<pre class="brush: java;">
import java.util.concurrent.Callable;

public class LoggingCallableProxy &lt;T&gt; implements Callable&lt;T&gt; {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;private final Callable&lt;T&gt; realCallable;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;public LoggingCallableProxy(Callable&lt;T&gt; realCallable){
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;this.realCallable = realCallable;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;@Override
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;public T call() throws Exception {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;long time = System.currentTimeMillis();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;T result = realCallable.call();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;time = System.currentTimeMillis()-time;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;//find calling method, using call level of 3
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;//for this example
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;final StackTraceElement stackTrace
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;= Thread.currentThread().getStackTrace()[3];
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;//using sysout for example, but of course
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;//use proper logging in real life
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;System.out.println(
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;stackTrace.getClassName()+&quot;.&quot;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;+stackTrace.getMethodName()
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;+&quot; took &quot;+time+&quot;ms to execute.&quot;);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return result;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
}
</pre>
<p>Now comes the <strong>disadvantage</strong> of using a Proxy: we now have to change all the existing code to now create the instance of <span style="font-size: 11pt">LoggingCallableProxy</span> where the Callable was used up to now. This is not so bad if you have the source code, it is just a simple find&amp;replace, so we can be pragmatic and live with it (I’ve always wanted to use the word “pragmatic” in a blog). Our <span style="font-size: 11pt">MockSoccerScoreServiceImpl</span> class changes to look like:</p>
<pre class="brush: java;">
import java.util.concurrent.Callable;
import com.richclientgui.blog.proxy.LoggingCallableProxy;

public class MockSoccerScoreServiceImpl implements SoccerScoreService {

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;@Override
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;public int getTeamScore(String teamName) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;try {
        &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;    Integer result = MockSubject.doAs(
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;           new LoggingCallableProxy&lt;Integer&gt;(
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;               new Callable&lt;Integer&gt;() {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;         public Integer call() throws Exception {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;             System.out.print(&quot;Doing some work...&quot;);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;             try {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;                     Thread.sleep(1000);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;             } catch (InterruptedException e) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;                     e.printStackTrace();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;             }
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;             System.out.println(&quot;completed.&quot;);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;                     return new Integer(50);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;         }
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;     }));
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;     return result.intValue();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} catch (Exception e) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;     //for this blog, I don't care about the
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;     //exception handling...
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;     e.printStackTrace();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;     return -1;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
}
</pre>
<p>Now we have logging of the time measurements, with minimal code impact. </p>
<p><em>However, that simple yet far-reaching find&amp;replace operation one potentially hundreds of methods in a huge number of classes still worries me&#8230;</em></p>
<p><strong>Approach B: use Aspects</strong></p>
<p>Aspect-oriented programming (AOP) has been around for a while, and it allows us to weave in functionality without changing existing java classes. That is an extremely brief and potentially inaccurate summary, but it will suffice for this blog. Go <a href="http://www.eclipse.org/aspectj/">read more about aspects and AspectJ</a>.</p>
<p><strong>First</strong>, we need to enable aspects on our project. Do this, you must:</p>
<ol>
<li>Download the <a href="http://www.eclipse.org/ajdt/">AspectJ Development Tools (AJDT)</a> if you are using the Eclipse IDE (AspectJ also integrates with other IDEs).</li>
<li>Convert the project to an AspectJ project: Right-click on project, choose <strong>Configure -&gt; Convert to AspectJ </strong>project</li>
<li>Now you are ready to start implementing aspects.</li>
</ol>
<p><strong>Second</strong>: change back the <span style="font-size: 11pt">MockSoccerScoreServiceImpl</span> class to now make use of the LoggingCallableProxy anymore.</p>
<p>Then we can implement our aspect:</p>
<pre class="brush: java;">
import com.richclientgui.blog.delegate.MockSubject;

/**
 * This aspect will find all occurrences of the MockSubject.doAs(...)
 * method being called, and wrap that in code to log the time
 * measurements.
 */
public aspect TimeLoggerAspect  {

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;// the pointcut defines what method calls to intercept
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;// All calls to the MockSubject.doAs(...) method
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;// (wildcards for return and param types)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;pointcut doingRemoteCalls() :
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;call(* MockSubject.doAs(..));

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;/* around() defines an advise that will be executed whenever
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; * the doingRemoteCalls() pointcut is matched.
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; * It measures the time that it takes to execute the actual
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; * doAs(...)method at that point, and prints out the time,
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; * class and method calling the MockSubject.doAs(..) method
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; */
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Object around() : doingRemoteCalls() {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;long time = System.currentTimeMillis();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Object result = proceed();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;time = System.currentTimeMillis()-time;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;//find calling method
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;final StackTraceElement stackTrace
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;= Thread.currentThread().getStackTrace()[2];
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;System.out.println(
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;stackTrace.getClassName()+&quot;.&quot;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;+stackTrace.getMethodName()+&quot; took &quot;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;+time+&quot;ms to execute.&quot;);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return result;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
}
</pre>
<p>Now you can run your main/test class as an AspectJ application, by using the <strong>Run As -&gt; AspectJ/Java Application</strong> menu option in Eclipse.<br />
(Visit the AspectJ website to see how to run it from commandline or other IDEs.)</p>
<p>We added logging to the remote calls, without changing any existing code, by just adding one simple aspect. This is only the tip of the iceberg of what you can do with AOP.</p>
<p><strong>Eclipse RCP tip:</strong><br />
For Eclipse RCP applications, you will need to add a dependency to the <strong>org.aspectj.runtime </strong>plug-in to your plug-in project in order to use AspectJ.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richclientgui.com/?feed=rss2&amp;p=62</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Workshop on Fast-tracking Java GUI Development</title>
		<link>http://blog.richclientgui.com/?p=57</link>
		<comments>http://blog.richclientgui.com/?p=57#comments</comments>
		<pubDate>Thu, 10 Jun 2010 19:37:07 +0000</pubDate>
		<dc:creator>herman</dc:creator>
				<category><![CDATA[Eclipse RCP]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[gui development]]></category>
		<category><![CDATA[java south africa]]></category>
		<category><![CDATA[java training south africa]]></category>
		<category><![CDATA[south africa]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[ui dsl]]></category>
		<category><![CDATA[xtext]]></category>

		<guid isPermaLink="false">http://blog.richclientgui.com/?p=57</guid>
		<description><![CDATA[I recently blogged (on my blogger site) about my quest to find a more effective way of coding Java GUI applications. This resulted in the creation of a one-day workshop that I am very excited about. The details from the JTraining website are: Fast-tracking Java GUI Development This is a great one-day workshop that discusses [...]]]></description>
			<content:encoded><![CDATA[<p>I recently blogged (on my <a title="blogger" href="http://hermanlintvelt.blogspot.com" target="_blank">blogger</a> site) about my quest to find a more effective way of coding Java GUI applications. This resulted in the creation of a one-day workshop that I am very excited about.</p>
<p>The details from the <a title="JTraining" href="http://jtraining.co.za" target="_blank">JTraining</a> website are:</p>
<p><strong>Fast-tracking Java GUI Development</strong><br />
This is a great one-day workshop that discusses a number of concerns with developing Graphical User Interfaces applications with Java, and explore various ways to improve the speed and efficiency of development.</p>
<ul style="list-style-type: disc;">
<li><em>Do you sometimes think that coding in Java is perhaps not the best way of constructing GUIs?</em></li>
<li><em>Do you feel that your team should be able to develop GUI applications much faster?</em></li>
<li><em>Are you frustrated with the amount of “donkey code” you are writing to implement some basic GUI features?</em></li>
<li><em>Are the new team members struggling with the high learning curve of the Java GUI framework you are using?</em></li>
<li><em>Are you spending more time on coding GUI behaviour than you spend on coding domain behaviour?</em></li>
<li><em>Do your team find it difficult to add or modify existing features of a GUI application?</em></li>
</ul>
<p>The above questions highlight some of the issues typically found when doing GUI application development. We have been specialising in Java GUI development for more than a decade, and in this time we have investigated and used a wide range of frameworks, tools and techniques to help us build GUI applications more effectively. This workshop explores a number of these options, in a highly interactive and hands-on way.</p>
<p><strong>Visual</strong> GUI builder <strong>tools</strong>, <strong>code generators</strong>, <strong>UI DSL</strong>s: these are some of the topics we will investigate.</p>
<p>However, none of these have any meaning if a good foundation of UI development principles and practices is not embraced in a project. The workshop also aims to instil a number of important <strong>principles and practices</strong> that is a must for any good GUI development team.</p>
<p>I’m also giving away more detail here (I still have to finalize the content and outline, will add that to our website later):<br />
<strong>A</strong>) discussion of frustrations &amp; issues with &#8220;traditional&#8221; approach to GUI development using something like RCP/Swing<br />
<em>[interactive discussion]</em><br />
<strong>B</strong>) exploration of alternatives:<br />
* Tools (e.g. SWT Designer, Eclipse e4, etc)<br />
* UI DSLs (e.g. Glimmer, Gryphon, XScalaWT)<br />
* Code Generation (e.g. XText, ANTler)<br />
<em>[I want to demo some of the options, and allow for practical hands-on use of at least one. My current idea is that we divide in groups, and each develop a UI DSL, using something like XText, or a more dynamic language like Scala]</em><br />
<strong>C</strong>) Discussion of Practices and Principles when doing GUI development, including:<br />
- UI Design<br />
- UI Testing<br />
- Tool (in)dependency<br />
- Domain Driven UIs<br />
<em>[This discussion will also involve a whiteboard/interactive design session (also done in groups).]</em></p>
<p><em> </em></p>
<p>And all this will be taking place on 1 July 2010 at my new training and agile office venue in Worcester (or if the group gets to big, we’ll move to an extremely nice country lodge nearby).</p>
<p><a href="http://jtraining.co.za/ui/uicourses.html">Please see our training website for more details.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richclientgui.com/?feed=rss2&amp;p=57</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exciting new Java Courses in South Africa</title>
		<link>http://blog.richclientgui.com/?p=56</link>
		<comments>http://blog.richclientgui.com/?p=56#comments</comments>
		<pubDate>Thu, 27 May 2010 11:36:34 +0000</pubDate>
		<dc:creator>herman</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[annotations]]></category>
		<category><![CDATA[cape town]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[java beginner]]></category>
		<category><![CDATA[java course south africa]]></category>
		<category><![CDATA[java courses]]></category>
		<category><![CDATA[java learning]]></category>
		<category><![CDATA[java training]]></category>
		<category><![CDATA[java training south africa]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[oo]]></category>
		<category><![CDATA[south africa]]></category>
		<category><![CDATA[worcester]]></category>
		<category><![CDATA[world cup]]></category>

		<guid isPermaLink="false">http://blog.richclientgui.com/?p=56</guid>
		<description><![CDATA[I have been doing a lot of work around renewing my Java courses, talking to Heinz Kabutz in Crete, creating a new website. Why? Because I realized I have a passion for teaching others how to become great programmers. So am starting to concentrate more on training (while still doing enough real development work to [...]]]></description>
			<content:encoded><![CDATA[<p>I have been doing a lot of work around renewing my Java courses, talking to Heinz Kabutz in Crete, creating a new website.<br />
Why?<br />
Because I realized I have a passion for teaching others how to become great programmers. So am starting to concentrate more on training (while still doing enough real development work to keep the balance).</p>
<p>I am very excited to announce three new open Java courses that are going to be presented in June/July in South Africa by me.</p>
<p>First we have the <a href="http://www.jtraining.co.za/java/javacourses.html#foundation">Java and OO Foundation course</a>, from <strong>14-15 and 17-18 June 2010 </strong>(16th is Youth Day), happening in Worcester, South Africa, at our new training facility there. I can recommend this course to anyone starting out with OO and Java. Most of the content comes from my friend Heinz Kabutz’s <a href="http://www.javaspecialists.eu">JavaSpecialist</a> Java Foundation course. </p>
<p>Then we have our first presentation of the <a href="http://www.jtraining.co.za/java/javacourses.html#intermediate">Java Intermediate Course</a> happening from <strong>5 to 8 July</strong>, also in Worcester. I can recommend this course to developers who are comfortable with the basics of the Java language and OO, and who wants to learn more about real life Java topics like using JUnit, concurrency, generics and annotations. </p>
<p>Finally we have another big <strong>first for Africa</strong>: the first presentation of the now famous <a href="http://www.jtraining.co.za/java/javacourses.html#master">Java Specialist Master Course</a>, from <strong>13 to 16 July 2010</strong>. All those <em>Soccer World Cup </em>fans out there: stay a week longer in South Africa and come attend this brilliant course, authored by Heinz Kabutz. </p>
<p>I am extremely excited about our <a href="http://www.jtraining.co.za/packages/packages/worcester.html">new training facilities</a> in Worcester, which we call “The Loft @ PolymorphHQ”. Worcester is only about 100km away from Cape Town, a very scenic drive over the mountains. I am planning to combine all courses presented in Worcester with a bit of wine-tasting or even game-drive experiences. We are also investigating providing special packages that include accommodation. And we will definitely work in a nice steak and some good red wine with great Java discussions one of the evenings of the course.</p>
<p>I also want to announce our The Loft opening special: if you <a href="http://www.jtraining.co.za/packages/courses/register.html">register</a> for both the Java and OO Foundation (14 June 2010) and the Java Intermediate (5 July 2010) courses, you save R7,000. </p>
<p>I hope to have a lot of great Java developers coming out of Worcester these next few years <img src='http://blog.richclientgui.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richclientgui.com/?feed=rss2&amp;p=56</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flexible Java Developers for Agile Opportunity in Worcester, South Africa</title>
		<link>http://blog.richclientgui.com/?p=53</link>
		<comments>http://blog.richclientgui.com/?p=53#comments</comments>
		<pubDate>Thu, 14 Jan 2010 11:29:47 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[job]]></category>
		<category><![CDATA[oo]]></category>
		<category><![CDATA[rap]]></category>
		<category><![CDATA[rcp]]></category>
		<category><![CDATA[south africa]]></category>
		<category><![CDATA[worcester]]></category>

		<guid isPermaLink="false">http://blog.richclientgui.com/?p=53</guid>
		<description><![CDATA[If you: are a fast and willing learner are passionate about developing quality software are self-disciplined and self-motivating tired of the typical city and office life need more flexibility in your working day have experience in Object-oriented development have experience in Java (acronyms optional) are willing to either move to Worcester or work remotely with [...]]]></description>
			<content:encoded><![CDATA[<p>If you:</p>
<ul>
<li>are a fast and willing learner</li>
<li>are passionate about developing quality software</li>
<li>are self-disciplined and self-motivating</li>
<li>tired of the typical city and office life</li>
<li>need more flexibility in your working day</li>
<li>have experience in Object-oriented development</li>
<li>have experience in Java (acronyms optional)</li>
<li>are willing to either move to Worcester or work remotely with regular visits to Worcester</li>
</ul>
<p>Then we:</p>
<ul>
<li>want to talk to you about contracting or permanent employee options</li>
<li>want to provide training and mentoring</li>
<li>want to make you part of a newly founded team that has the goal of becoming the leading Southern Africa Eclipse RCP/RAP and OSGi development team</li>
<li>want to expose you not only to exciting new software projects, prototyping, and technology research, but also to interesting consultation opportunities, and unfortunately a bit of less interesting maintenance work</li>
</ul>
<p>Email us at: jobs@richclientgui.com</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richclientgui.com/?feed=rss2&amp;p=53</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse RCP Commands Part 3: visibleWhen and Core Expressions</title>
		<link>http://blog.richclientgui.com/?p=50</link>
		<comments>http://blog.richclientgui.com/?p=50#comments</comments>
		<pubDate>Wed, 03 Jun 2009 15:16:59 +0000</pubDate>
		<dc:creator>herman</dc:creator>
				<category><![CDATA[Eclipse RCP]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Eclipse RCP Commands Actions Java expressions visibleWhen property testers]]></category>

		<guid isPermaLink="false">http://blog.richclientgui.com/?p=50</guid>
		<description><![CDATA[This is the third part of my blog series on the Eclipse Commands framework. Please see Part One for an outline of topics covered in the various blogs. Limiting visibility of Commands A powerful feature of the Commands framework is that you can declare in the plugin.xml when a Command should be visible (or rather [...]]]></description>
			<content:encoded><![CDATA[<p>This is the third part of my blog series on the Eclipse Commands framework. Please see <a href="http://hermanlintvelt.blogspot.com/2009/05/eclipse-rcp-commands-api-part-one.html" title="Java, Mac, Software and other kaos: Eclipse RCP Commands API Part One">Part One</a> for an outline of topics covered in the various blogs.</p>
<h2>Limiting visibility of Commands</h2>
<p>A powerful feature of the Commands framework is that you can declare in the <em>plugin.xml</em> when a Command should be visible (or rather when specific menu contributions should be visible) and when it should be enabled. This is done by using what is called <a href="http://wiki.eclipse.org/Command_Core_Expressions" title="Command Core Expressions - Eclipsepedia">core expressions</a>.</p>
<p><a name="simple"></a><br />
<h3>Simple <em>visibleWhen</em> definition</h3>
<p>Let us take a simple example first: we want to limit the <em>Annotate eBook</em> command (from the example in <a href="http://hermanlintvelt.blogspot.com/2009/06/eclipse-rcp-commands-api-review-of-part.html">Part Two: Quick Review</a>) to only show in the context menu if one item is selected in the view. If no item is selected, or more than one, it must not appear in the menu.</p>
<li>First select the <strong>popup:org.eclipse.ui.popup.any?after=additions</strong> menu contribution extension element
<li>Now select the <em>Annotate</em> command element, right-click and choose <strong>New -&gt; visibleWhen</strong>
<li>Set the <strong>checkEnabled</strong> value to <em>false</em> (setting to <em>true</em> will use the enabled state of the command to determine the visibility)
<li>Right-click on the <strong>visibleWhen</strong> element, and choose <strong>New -&gt; with</strong>
<li>Set the <strong>variable</strong> attribute to &#8220;<em>activeMenuSelection</em>&#8220;. &#8220;<em>activeMenuSelection</em>&#8221; is a known expressions variable that will get resolved when the platform must populate the context menu. Se <a href="#vars">the list</a> of other known expression variables.
<li>Right-click on the <strong>activeMenuSelection(with)</strong> element and choose <strong>New -&gt; count</strong>
<li>Set the <strong>value</strong> attribute for <em>count</em> to &#8220;<strong>1</strong>&#8220;.
<p>
We have now set up the context-menu contribution to only show the <em>Annotate</em> command when one and only one item in the view is selected. That was not so difficult, was it? I remember spending hours on creating nice selection behaviour helper classes for IActionDelegate-based frameworks, and still not getting the initial visibility or enabling of the actions in the menus right, due to constraints with that approach.
</p>
<p><a name="simpleexample"></a>The menu contributions extension in the <em>plugin.xml</em> now looks like:</p>
<div align="left" class="java">
<table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
<tr>
  <!-- start source code --></p>
<td nowrap="nowrap" valign="top" align="left">
    <code><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;extension</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">point=</font><font color="#2a00ff">&#34;org.eclipse.ui.menus&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;menuContribution</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">locationURI=</font><font color="#2a00ff">&#34;menu:file?before=quit&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;command</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">commandId=</font><font color="#2a00ff">&#34;com.richclientgui.myreader.commands.OpenEBook&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">mnemonic=</font><font color="#2a00ff">&#34;O&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">style=</font><font color="#2a00ff">&#34;push&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/command&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;command</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">commandId=</font><font color="#2a00ff">&#34;com.richclientgui.myreader.commands.AnnotateEBook&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">mnemonic=</font><font color="#2a00ff">&#34;A&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">style=</font><font color="#2a00ff">&#34;push&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/command&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/menuContribution&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;menuContribution</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">locationURI=</font><font color="#2a00ff">&#34;popup:org.eclipse.ui.popup.any?after=additions&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;command</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">commandId=</font><font color="#2a00ff">&#34;com.richclientgui.myreader.commands.AnnotateEBook&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">label=</font><font color="#2a00ff">&#34;Annotate&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">mnemonic=</font><font color="#2a00ff">&#34;A&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">style=</font><font color="#2a00ff">&#34;push&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;visibleWhen</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">checkEnabled=</font><font color="#2a00ff">&#34;false&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;with</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">variable=</font><font color="#2a00ff">&#34;activeMenuSelection&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;count</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">value=</font><font color="#2a00ff">&#34;1&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/count&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/with&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/visibleWhen&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/command&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/menuContribution&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/extension&gt;</font></code></p>
</td>
<p>  <!-- end source code --><br />
   </tr>
</table>
</div>
<p><!-- =       END of automatically generated HTML code       = --><br />
<!-- ======================================================== --></p>
<p><a name="expressiondef"></a><br />
<h3>Expression Definitions</h3>
<p>Before I delve more deeply into even more interesting <em>visibleWhen</em> capabilities, first a very nifty tip on core expressions: it is possible to declare a specific expression definition, and then just refer to that definition from your <em>visibleWhen, activeWhen</em>, etc elements. </p>
<p>We do this with the <strong>org.eclipse.core.expressions.definitions</strong> extension. To define an expression that checks that only one item is selected:</p>
<li>Add the <strong>org.eclipse.core.expressions.definitions</strong> extension (click <strong>Add&#8230;</strong> on Extensions tab of plugin manifest editor, you might need to uncheck the &#8220;<em>Show only extension points from the required plug-ins</em>&#8221; checkbox)
<li>Give a proper <strong>id</strong> to your definition, e.g. <em>expression.onlyOneItemSelected</em>
<li>Right-click on the <em>expression.onlyOneItemSelected</em> element and choose <strong>New -&gt; with</strong>
<li>Set the <strong>variable</strong> attribute to &#8220;<em>activeMenuSelection</em>&#8220;.
<li>Right-click on the <strong>activeMenuSelection(with)</strong> element and choose <strong>New -&gt; count</strong>
<li>Set the <strong>value</strong> attribute for <em>count</em> to &#8220;<strong>1</strong>&#8220;.
</p>
<p>You might have noticed it is the same steps as those followed for a <a href="#simple">simple visibleWhen definition</a> above.<br />
For those who rather do it directly in the<em> plugin.xml</em>, here is the <strong>org.eclipse.core.expressions.definitions</strong> extension declaration:<br />
<!-- ======================================================== --><br />
<!-- = Java Sourcecode to HTML automatically converted code = --><br />
<!-- =   Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard  markus@jave.de   = --><br />
<!-- =     Further information: http://www.java2html.de     = --></p>
<div align="left" class="java">
<table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
<tr>
  <!-- start source code --></p>
<td nowrap="nowrap" valign="top" align="left">
    <code><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;extension</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">point=</font><font color="#2a00ff">&#34;org.eclipse.core.expressions.definitions&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;definition</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">id=</font><font color="#2a00ff">&#34;expression.onlyOneItemSelected&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;with</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">variable=</font><font color="#2a00ff">&#34;activeMenuSelection&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;count</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">value=</font><font color="#2a00ff">&#34;1&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/count&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/with&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/definition&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/extension&gt;</font></code></p>
</td>
<p>  <!-- end source code --><br />
   </tr>
</table>
</div>
<p><!-- =       END of automatically generated HTML code       = --><br />
<!-- ======================================================== --></p>
<h4>How do I use the expression definition?</h4>
<p>What do you gain with first defining an expression? Well, you can reuse this definition in multiple places in your <em>plugin.xml</em> if you need the same expression, whether it is for a<em> visibleWhen, activeWhen </em>or <em>enabledWhen</em> declaration.</p>
<p>To replace our expression for our context menu contribution with the definition, you simply do the following:</p>
<li>Select the <em>activeMenuSelection(when)</em> element under the <em>popup:org.eclipse.ui.popup.any?after=additions</em> menu contribution&#8217;s <em>visibleWhen</em> element, right-click and select <strong>Delete</strong>
<li>Right-click again on the <em>visibleWhen</em> element and choose <strong>New -&gt; reference</strong>
<li>Set the <strong>definitionId</strong> attribute to <em>expression.onlyOneItemSelected</em> (i.e. the <strong>id</strong> of the expression definition you want to use to evaluate whether the menu contribution must be visible or not)
<p>
If you run the application now, it should still behave the same as before we used our own definition, but now we are ready for a much more complex playing field. Underneath is a screenshot of how the extension declarations should look in the Plugin Editor.
</p>
<p><img src="http://blog.richclientgui.com/wp-content/uploads/2009/06/extensions-commands-4.png" alt="Extensions Commands 4" height="311" width="479"></p>
<p><a name="expressions"></a><br />
<h2>To infinity and beyond: the power of expressions</h2>
<p>We have seen a very basic expression up to now. You should have seen a number of other possible items to choose from when you selected <strong>New -&gt; with</strong> in the steps above. I list them below. These can all be used to build up complex expressions that gets evaluated at runtime to determine whether a specific menu contribution should be visible or not, if used in conjunction with a visibleWhen element.<br />
<img src="http://blog.richclientgui.com/wp-content/uploads/2009/06/possible-expression-elements.png" alt="Possible Expression Elements" height="307" width="452"></p>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<th>Element</th>
<th>Description</th>
</tr>
<tr>
<td><strong>adapt</strong></td>
<td>Use to adapt the object in focus (i.e. the object passed to the expression) to the specified <strong>type</strong>. See <a href="#adapt">Using adapt</a> for more information.</td>
</tr>
<tr>
<td><strong>and</strong></td>
<td>AND the results from evaluating the sub-elements</td>
</tr>
<tr>
<td><strong>count</strong></td>
<td>Use to count the number of elements in a collection. The <strong>value</strong> attribute be an integer or a supported wildcard. See <a href="#count">Using count</a> for more information.</td>
</tr>
<tr>
<td><strong>equals</strong></td>
<td>Use to check equality of the focussed object with the specified <strong>value</strong> attribute</td>
</tr>
<tr>
<td><strong>instanceof</strong></td>
<td>Use to perform an instanceof check on the object in focus. See <a href="#instanceof">Using instanceof</a> for more information.</td>
</tr>
<tr>
<td><strong>iterate</strong></td>
<td>Use to iterate over a collection, if the focussed object is of type <em>java.util.Collection</em>. See <a href="#iterate">Using iterate</a> for more information.</td>
</tr>
<tr>
<td><strong>not</strong></td>
<td>NOT the results from evaluating the sub-elements</td>
</tr>
<tr>
<td><strong>or</strong></td>
<td>OR the results from evaluating the sub-elements</td>
</tr>
<tr>
<td><strong>reference</strong></td>
<td>This is the element we use to refer to an expression defined under <strong>org.eclipse.core.expressions.definitions</strong>. The <strong>definitionId</strong> is the unique id of the expression definition to use for the evaluation.</td>
</tr>
<tr>
<td><strong>systemTest</strong></td>
<td>Use to test a system property, where <strong>property</strong> is the name of the property to get via System.getProperty, and <strong>value</strong> is the expected value to test against (as <em>String</em> value).</td>
</tr>
<tr>
<td><strong>test</strong></td>
<td>Use this element to test the <strong>value</strong> of a specific <strong>property</strong> on the focussed object. See <a href="#test">Using test</a> for more information.</td>
</tr>
<tr>
<td><strong>with</strong></td>
<td>Use to change the object to inspect or focus on to the object referenced by the <strong>variable</strong> attribute. See <a href="#vars">the list of available expression variables</a>.</td>
</tr>
<tr>
<td><strong>resolve</strong></td>
<td>Resolve does almost the same as <strong>with</strong>, but it allows the use of a custom <em>IVariableResolver</em>, and passing the specified <strong>args</strong> as arguments to the variable resolver. More detail might be topic of a future blog post. I must admit, I have never used this one.</td>
</tr>
</table>
<p><h4>Note on String values</h4>
<p>The <strong>value</strong> attribute for the above elements gets specified as some string. Here follows the extract from the Eclipse online help on how that String value might get converted:
</p>
<p>
<em>When specifying a value to be tested against any of these expressions, the value is assumed to be a string except for when the following conversions are successful:</p>
<li>the string &#8220;true&#8221; is converted into Boolean.TRUE
<li>the string &#8220;false&#8221; is converted into Boolean.FALSE
<li>if the string contains a dot, the interpreter tries to convert the value into a Float object
<li>if the string only consists of numbers, the interpreter converts the value into an Integer object<br />
the conversion into a Boolean, Float, or Integer can be suppressed by surrounding the string with single quotes.<br />
</em>
</p>
<p>
<a name="adapt"></a><br />
<h4>Using adapt</h4>
<p><strong>Adapt</strong> is used to adapt the object in focus (you can see this as the object provided or specified by the parent element) to the type specified its the <strong>type</strong> attribute. Any sub-elements of the adapt element will be evaluated against the adapted object. Read up about <em>IAdapterFactory</em> and <em>IAdaptable</em> interfaces for more information about adaption.<br />
If the object can be adapted, the adapt evaluate to <strong>true</strong>. E.g. we can define an expression for evaluating if something adapts to the <em>ICountable</em> interface.<br />
<!-- ======================================================== --><br />
<!-- = Java Sourcecode to HTML automatically converted code = --><br />
<!-- =   Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard  markus@jave.de   = --><br />
<!-- =     Further information: http://www.java2html.de     = --></p>
<div align="left" class="java">
<table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
<tr>
  <!-- start source code --></p>
<td nowrap="nowrap" valign="top" align="left">
    <code><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;extension</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">point=</font><font color="#2a00ff">&#34;org.eclipse.core.expressions.definitions&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;definition</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">id=</font><font color="#2a00ff">&#34;isCountable&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;adapt</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">type=</font><font color="#2a00ff">&#34;org.eclipse.core.expressions.ICountable&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/adapt&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/definition&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/extension&gt;</font></code></p>
</td>
<p>  <!-- end source code --><br />
   </tr>
</table>
</div>
<p><!-- =       END of automatically generated HTML code       = --><br />
<!-- ======================================================== -->
</p>
<p>
<a name="instanceof"></a><br />
<h4>Using instanceof</h4>
<p>This is used to perform an instanceof check on the object in focus. We can for example enhance our <em>Annotate eBook</em> menu contribution in the <em>File</em> menu to only display if at least on of the selected items is an instance of <em>java.lang.String</em> (iterate gets discussed <a href="#iterate">here</a>):<br />
<!-- ======================================================== --><br />
<!-- = Java Sourcecode to HTML automatically converted code = --><br />
<!-- =   Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard  markus@jave.de   = --><br />
<!-- =     Further information: http://www.java2html.de     = --></p>
<div align="left" class="java">
<table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
<tr>
  <!-- start source code --></p>
<td nowrap="nowrap" valign="top" align="left">
    <code><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;extension</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">point=</font><font color="#2a00ff">&#34;org.eclipse.ui.menus&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;menuContribution</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">locationURI=</font><font color="#2a00ff">&#34;menu:file?before=quit&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;command</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">commandId=</font><font color="#2a00ff">&#34;com.richclientgui.myreader.commands.OpenEBook&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">mnemonic=</font><font color="#2a00ff">&#34;O&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">style=</font><font color="#2a00ff">&#34;push&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/command&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;command</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">commandId=</font><font color="#2a00ff">&#34;com.richclientgui.myreader.commands.AnnotateEBook&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">mnemonic=</font><font color="#2a00ff">&#34;A&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">style=</font><font color="#2a00ff">&#34;push&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;visibleWhen</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">checkEnabled=</font><font color="#2a00ff">&#34;false&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;with</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">variable=</font><font color="#2a00ff">&#34;selection&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;iterate</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">ifEmpty=</font><font color="#2a00ff">&#34;false&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">operator=</font><font color="#2a00ff">&#34;or&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;</font><font color="#7f0055"><b>instanceof</b></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">value=</font><font color="#2a00ff">&#34;java.lang.String&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/</font><font color="#7f0055"><b>instanceof</b></font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/iterate&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/with&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/visibleWhen&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/command&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/menuContribution&gt;</font></code></p>
</td>
<p>  <!-- end source code --><br />
   </tr>
</table>
</div>
<p><!-- =       END of automatically generated HTML code       = --><br />
<!-- ======================================================== -->
</p>
<p>
<a name="iterate"></a><br />
<h4>Using iterate</h4>
<p>Iterate can be used if the object in focus is a <em>java.util.Collection</em> (e.g. when <strong>with</strong> is used in the parent element and the <strong>variable</strong> attribute is set to &#8220;<em>selection</em>&#8220;). It iterates through the collection, and evaluate the sub-elements against each item in the collection.
</p>
<p>
The <strong>operator</strong> attribute can be set to <em>and</em> or <em>or</em>. For <em>and</em>, every item must cause the sub-elements of the expression to evaluate to <strong>true</strong>, and for <em>or</em>, at least one must evaluate to true.
</p>
<p>
The <strong>ifEmpty</strong> attribute can be set to <em>true</em> or <em>false</em>. If <em>true</em>, then the iterate expression will evaluate to <strong>true</strong> for empty collections, else to <strong>false</strong>.
</p>
<p>
See the example under the <a href="#instanceof">instanceof</a> section.
</p>
<p>
<a name="count"></a><br />
<h4>Using count</h4>
<p>The count element&#8217;s <strong>value</strong> attribute can take an integer value as parameter if the collection needs to contain the exact number of items. However, the following wildcards are also allowed:</p>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td>*</td>
<td>Any number of items</td>
</tr>
<tr>
<td>?</td>
<td>Zero or one item</td>
</tr>
<tr>
<td>+</td>
<td>One ore more items</td>
</tr>
<tr>
<td>!</td>
<td>No items</td>
</tr>
</table>
<p>
See our <a href="#simpleexample">first simple visibleWhen example</a> for usage.
</p>
<p>
<a name="test"></a><br />
<h4>Using test</h4>
<p>Test can be used to evaluate the state (i.e. value) of a specific property of the focussed object. The test expression can evaluate to <strong>true</strong>, <strong>false</strong> or <strong>not-loaded</strong> if the property tester (implemented by a Java class) is not loaded.</p>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td><strong>property</strong></td>
<td>specifies the name of the property of the object to test</td>
</tr>
<tr>
<td><strong>args</strong></td>
<td>specifies additional arguments to pass to the property tester</td>
</tr>
<tr>
<td><strong>value</strong></td>
<td>the value we expect the property to be</td>
</tr>
<tr>
<td><strong>forcePluginActivation</strong></td>
<td>if this is set to <strong>true</strong>, the plugin that contributes the property tester class will be loaded to enable the evaluation, if it is not loaded yet. However, this loading will only happen if the evaluation context used allows plugin activation. What does this mean: do not depend that when you set this flag to true, the plugin containing the property tester code will actually be loaded.</td>
</tr>
</table>
<p>
	In a future blog I will discuss how to implement your own property testers; quite a powerful feature. For now, let me just point you to some property testers available for your enjoyment. You can follow the links for the detailed code level information, or else have a look at the Propery Testers section in the <a href="http://wiki.eclipse.org/Command_Core_Expressions" title="Command Core Expressions - Eclipsepedia">Command Core Expressions</a> wiki page for a summary.</p>
<li><a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/propertytester/PlatformPropertyTester.java?view=co" title="">PlatformPropertyTester</a>
<li><a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.core.resources/src/org/eclipse/core/internal/propertytester/ResourcePropertyTester.java?view=co" title="">ResourcePropertyTester</a>
<li><a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.core.resources/src/org/eclipse/core/internal/propertytester/FilePropertyTester.java?view=co" title="">FilePropertyTester</a>
<li><a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.core.resources/src/org/eclipse/core/internal/propertytester/ProjectPropertyTester.java?view=co" title="">ProjectPropertyTester</a>
<li><a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.core.resources/src/org/eclipse/core/internal/propertytester/ResourceMappingPropertyTester.java?view=co" title="">ResourceMappingPropertyTester</a>
<li><a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.workbench/Eclipse%20UI/org/eclipse/ui/internal/activities/ActivityPropertyTester.java?view=co" title="">ActivityPropertyTester</a>
<li><a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.workbench/Eclipse%20UI/org/eclipse/ui/internal/OpenPerspectivePropertyTester.java?view=co" title="">OpenPerspectivePropertyTester</a>
</p>
<p>
<a name="vars"></a><br />
<h3>Core Expression Variables</h3>
<p>I was planning to list the most common variables available for core expressions here and discuss some of them, but time caught up with me. For now I will point you to:</p>
<li>The Variables and the Command Framework section in the <a href="http://wiki.eclipse.org/Command_Core_Expressions" title="Command Core Expressions - Eclipsepedia">Command Core Expressions</a> wiki page.
<li>The <a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.workbench/Eclipse%20UI/org/eclipse/ui/ISources.java?view=co" title="">ISources.java</a> file that list these variables.
</p>
<p>
<strong>Note:</strong> if you use the <em>selection</em> variable, you need to make sure the View that you are expecting a selection from is a SelectionProvider for the platform by registering it as a selection provider, e.g. by calling <em>getSite().setSelectionProvider(viewer)</em>.
</p>
<h2>Coming soon&#8230;</h2>
<li>What about enabling and disabling Commands? (enabledWhen, activeWhen)
<li>More on using object properties to determine visibility and enablement of Commands (propertyTesters)
<li>If you don&#8217;t like XML: how to tune your Commands from the Java side of things (the programmatic approach)
<p><h2>References</h2>
<li><a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=223445">Eclipse.org Commands Framework Article in bugzilla</a>
<li><a href="http://svn2.assembla.com/svn/eclipsecommands/trunk/EclipseCommands/contents/article.html" title="The Eclipse RCP Command Framework">Article on Eclipse Commands Framework</a>, by Marc R. Hoffmann
<li><a href="http://svn2.assembla.com/svn/eclipsecommands/trunk/EclipseCommands/contents/article.html" title="The Eclipse RCP Command Framework">Eclipse.org Wiki on Command Framework</a>
<li><a href="http://www.vogella.de/articles/EclipseCommands/article.html" title="Using Eclipse Commands with Eclipse Ganymede (3.4) - Tutorial">Eclipse Commands Tutorial</a>, by Lars Vogel
<li><a href="http://wiki.eclipse.org/Command_Core_Expressions" title="Command Core Expressions - Eclipsepedia">Eclipse.org Wiki on Core Expressions</a>
<li><a href="http://wiki.eclipse.org/Menu_Contributions" title="Menu Contributions - Eclipsepedia">Eclipse.org Wiki on Menu Contributions</a>
<li><a href="http://wiki.eclipse.org/Menus_Extension_Mapping" title="Menus Extension Mapping - Eclipsepedia">Eclipse.org Wiki on mapping from old to new menu contribution extension points</a>
</p>
<p>Enough said.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richclientgui.com/?feed=rss2&amp;p=50</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Archeology of Java</title>
		<link>http://blog.richclientgui.com/?p=18</link>
		<comments>http://blog.richclientgui.com/?p=18#comments</comments>
		<pubDate>Mon, 01 Jun 2009 21:21:37 +0000</pubDate>
		<dc:creator>herman</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[archeology]]></category>
		<category><![CDATA[ejb]]></category>
		<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[servlets]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[struts]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://blog.richclientgui.com/?p=18</guid>
		<description><![CDATA[On the archeology of big Java systems...]]></description>
			<content:encoded><![CDATA[<p>When faced with a bulky problem&#8230;<br />
<a rel="attachment wp-att-19" href="http://blog.richclientgui.com/?attachment_id=19"><img class="size-full wp-image-19" src="http://blog.richclientgui.com/wp-content/uploads/2009/06/archeology.png" alt="When faced with a bulky problem..." width="600" height="264" /></a></p>
<p>you have to start digging.<br />
<a rel="attachment wp-att-20" href="http://blog.richclientgui.com/?attachment_id=20"><img class="size-full wp-image-20" src="http://blog.richclientgui.com/wp-content/uploads/2009/06/archeology2.png" alt="you have to start digging" width="600" height="264" /></a></p>
<p>Thanks to <a href="http://aslamkhan.net/">Aslam Khan</a> for planting the term &#8220;archeology of Java&#8221; in a discussion.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richclientgui.com/?feed=rss2&amp;p=18</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse RCP Commands Part Two: Review</title>
		<link>http://blog.richclientgui.com/?p=15</link>
		<comments>http://blog.richclientgui.com/?p=15#comments</comments>
		<pubDate>Mon, 01 Jun 2009 09:52:02 +0000</pubDate>
		<dc:creator>herman</dc:creator>
				<category><![CDATA[Eclipse RCP]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Eclipse RCP Commands Actions Java]]></category>

		<guid isPermaLink="false">http://blog.richclientgui.com/?p=15</guid>
		<description><![CDATA[Quick Review: Defining a Command In this blog I just want review the basic definition of a command by adding an additional Command to the example application using the steps defined in Part Two of the series on Eclipse RCP Commands. We already have an Open eBook command that we made visible in the File [...]]]></description>
			<content:encoded><![CDATA[<h2>Quick Review: Defining a Command</h2>
<p>In this blog I just want review the basic definition of a command by adding an additional Command to the example application using the steps defined in <a title="Java, Mac, Software and other kaos: Eclipse RCP Commands API Part Two" href="http://hermanlintvelt.blogspot.com/2009/05/eclipse-rcp-commands-api-part-two.html">Part Two</a> of the series on Eclipse RCP Commands.</p>
<p>We already have an <em>Open eBook</em> command that we made visible in the <em>File</em> menu of the <a href="http://hermanlintvelt.blogspot.com/2009/05/eclipse-rcp-commands-api-part-two.html#example">MyReader</a> application. Now we want to another item to the <em>File</em> menu, as well as to a context menu, to allow the user to annotate an eBook. Let us call this the <em>Annotate eBook</em> command. So let us follow the same eight steps we did for the <em>Open eBook</em> command.</p>
<h3>Step 1: Create RCP application</h3>
<p>Done already (I assume you are working from the example in  <a title="Java, Mac, Software and other kaos: Eclipse RCP Commands API Part Two" href="http://hermanlintvelt.blogspot.com/2009/05/eclipse-rcp-commands-api-part-two.html">Part Two</a>.)</p>
<h3>Step 2: Add <em>org.eclipse.ui.commands</em> extension to <em>plugin.xml</em>.</h3>
<p>Done already. (see <a href="http://hermanlintvelt.blogspot.com/2009/05/eclipse-rcp-commands-api-part-two.html#step2">step 2</a> of previous blog)</p>
<p><a name="step3"></a></p>
<h3>Step 3: Declare <em>Annotate eBook</em> command.</h3>
<li>right-click the <em>org.eclipse.ui.commands</em> extension, and select <strong>New -&gt; Command</strong> from the context menu.</li>
<li>change the <strong>id</strong> to something like &#8220;<em>com.richclientgui.myreader.commands.AnnotateEBook</em>&#8220;</li>
<li>change the <strong>name</strong> to &#8220;<em>Annotate eBook</em>&#8220;</li>
<li>change <strong>description</strong> to &#8220;<em>Annotates the current eBook</em>&#8221;
<p>Our plugin.xml now contains the following entry for the <em>org.eclipse.ui.commands</em> extension:</p>
<p><!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--></p>
<p><!-- ======================================================== --><br />
<!-- = Java Sourcecode to HTML automatically converted code = --><br />
<!-- =   Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard  markus@jave.de   = --><br />
<!-- =     Further information: http://www.java2html.de     = --></p>
<div class="java">
<p><!-- end source code --></p>
<table border="0" cellspacing="0" cellpadding="3" bgcolor="#ffffff">
<tbody>
<tr><!-- start source code --></p>
<td align="left" valign="top"><code><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;extension</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">point=</span><span style="color: #2a00ff;">"org.eclipse.ui.commands"</span><span style="color: #000000;">&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;command</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">defaultHandler=</span><span style="color: #2a00ff;">"com.richclientgui.myreader.handlers.DefaultOpenEBookHandler"</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">description=</span><span style="color: #2a00ff;">"Open an eBook file for reading"</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">id=</span><span style="color: #2a00ff;">"com.richclientgui.myreader.commands.OpenEBook"</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">name=</span><span style="color: #2a00ff;">"Open eBook"</span><span style="color: #000000;">&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;/command&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;command</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">description=</span><span style="color: #2a00ff;">"Annotates the current eBook"</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">id=</span><span style="color: #2a00ff;">"com.richclientgui.myreader.commands.AnnotateEBook"</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">name=</span><span style="color: #2a00ff;">"Annotate eBook"</span><span style="color: #000000;">&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;/command&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;/extension&gt;</span></code></td>
</tr>
</tbody>
</table>
</div>
<p><!-- =       END of automatically generated HTML code       = --><br />
<!-- ======================================================== --></p>
<h3>Step 4: Add the <em>org.eclipse.ui.menus</em> extension to <em>plugin.xml</em>.</h3>
<p>Done. (see <a href="http://hermanlintvelt.blogspot.com/2009/05/eclipse-rcp-commands-api-part-two.html#step4">step 4</a> of previous blog)</p>
<h3>Step 5: Add the <em>menuContribution</em> element</h3>
<p>We want to make our <em>Annotate eBook</em> command accessible both in the <em>File</em> menu, and in the context menu of the view. We already declared a <em>menuContribution</em> for the File menu (see <a href="http://hermanlintvelt.blogspot.com/2009/05/eclipse-rcp-commands-api-part-two.html#step5">step 5</a> of previous blog).<br />
In order to make the command accessible in any context menu, we add a new <em>menuContribution</em>:</li>
<li> Right-click the org.eclipse.ui.menus extension, and select <strong>New -&gt; menuContribution</strong> from the context menu</li>
<li> Change the <strong>locationURI</strong> to <strong>popup:org.eclipse.ui.popup.any?after=additions</strong><br />
<h3>Step 6: Add the <em>Annotate eBook</em> command to the menuContributions.</h3>
</li>
<li> Right-click on the <em>menuContribution</em> created in step 5, and select <strong>New -&gt; command</strong> from the context menu.</li>
<li> Change <strong>commandId</strong> to the <strong>id</strong> you provided to your Command definition in <a href="#step3">step 3</a>.</li>
<li> Change mnemonic to &#8220;A&#8221; to underline the first letter of &#8220;Annotate&#8221; as your shortcut mnemonic for your command in the menu.</li>
<li> Repeat the above for the <strong>menu:file?before=quit</strong> menuContribution element.But now we have an interesting problem: the client wants the menu item in the <em>File</em> menu to read &#8220;<em>Annotate eBook</em>&#8220;, but the context menu&#8217;s item must read only &#8220;<em>Annotate</em>&#8220;. If we change the <strong>name</strong> attribute of the command definition, then it will change in both places. Luckily, the Commands API can help us out here. It is possible to change the presentation of commands for specific menu contributions by &#8220;overriding&#8221; the text to be used for labels and tooltips. To do this we:</li>
<li>Select the command contribution element under the <strong>popup:org.eclipse.ui.popup.any?after=additions</strong> menu contribution elment,</li>
<li>and change the value of the <strong>label</strong> attribute to &#8220;Annotate&#8221;.<br />
Our <em>org.eclipse.ui.menus</em> extension definition in the <em>plugin.xml</em> now looks like:</p>
<p><!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--></p>
<p><!-- ======================================================== --><br />
<!-- = Java Sourcecode to HTML automatically converted code = --><br />
<!-- =   Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard  markus@jave.de   = --><br />
<!-- =     Further information: http://www.java2html.de     = --></p>
<div class="java">
<p><!-- end source code --></p>
<table border="0" cellspacing="0" cellpadding="3" bgcolor="#ffffff">
<tbody>
<tr><!-- start source code --></p>
<td align="left" valign="top"><code><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;extension</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">point=</span><span style="color: #2a00ff;">"org.eclipse.ui.menus"</span><span style="color: #000000;">&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;menuContribution</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">locationURI=</span><span style="color: #2a00ff;">"menu:file?before=quit"</span><span style="color: #000000;">&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;command</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">commandId=</span><span style="color: #2a00ff;">"com.richclientgui.myreader.commands.OpenEBook"</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">mnemonic=</span><span style="color: #2a00ff;">"O"</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">style=</span><span style="color: #2a00ff;">"push"</span><span style="color: #000000;">&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;/command&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;command</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">commandId=</span><span style="color: #2a00ff;">"com.richclientgui.myreader.commands.AnnotateEBook"</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">mnemonic=</span><span style="color: #2a00ff;">"A"</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">style=</span><span style="color: #2a00ff;">"push"</span><span style="color: #000000;">&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;/command&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;/menuContribution&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;menuContribution</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">locationURI=</span><span style="color: #2a00ff;">"popup:org.eclipse.ui.popup.any?after=additions"</span><span style="color: #000000;">&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;command</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">commandId=</span><span style="color: #2a00ff;">"com.richclientgui.myreader.commands.AnnotateEBook"</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">label=</span><span style="color: #2a00ff;">"Annotate"</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">mnemonic=</span><span style="color: #2a00ff;">"A"</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">style=</span><span style="color: #2a00ff;">"push"</span><span style="color: #000000;">&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;/command&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;/menuContribution&gt;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">&lt;/extension&gt;</span></code></td>
</tr>
</tbody>
</table>
</div>
<p><!-- =       END of automatically generated HTML code       = --><br />
<!-- ======================================================== --></p>
<h3>Step 7: Change command menu-item placement.</h3>
<p>Let&#8217;s assume we are happy with the current placement.</p>
<h3>Step 8: Implement a default Handler</h3>
<p>Let us be lazy again and implement a very basic handler that just opens a message dialog. I will go into more detail about <strong>org.eclipse.core.commands.Handler</strong> and a future blog.</li>
<li> Implement a class called <strong>DefaultAnnotateEBookHandler</strong> that extends <strong>AbstractHandler</strong>, and only override the<strong> execute(&#8230;)</strong> method to call the JFace <em>MessageDialog</em> class to show some information.</li>
<li> Select the <strong>AnnotateEBookCommand</strong> definition from <a href="#step3">step 3</a> and select the <strong>DefaultAnnotateEBookHandler</strong> class as the <strong>defaultHandler</strong>&#8216;s value.<br />
The code for <strong>DefaultAnnotateEBookHandler</strong> looks something like this:</p>
<p><!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--></p>
<p><!-- ======================================================== --><br />
<!-- = Java Sourcecode to HTML automatically converted code = --><br />
<!-- =   Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard  markus@jave.de   = --><br />
<!-- =     Further information: http://www.java2html.de     = --></p>
<div class="java">
<p><!-- end source code --></p>
<table border="0" cellspacing="0" cellpadding="3" bgcolor="#ffffff">
<tbody>
<tr><!-- start source code --></p>
<td align="left" valign="top"><code><br />
<span style="color: #7f0055;"><strong>import </strong></span><span style="color: #000000;">org.eclipse.core.commands.AbstractHandler;</span><br />
<span style="color: #7f0055;"><strong>import </strong></span><span style="color: #000000;">org.eclipse.core.commands.ExecutionEvent;</span><br />
<span style="color: #7f0055;"><strong>import </strong></span><span style="color: #000000;">org.eclipse.core.commands.ExecutionException;</span><br />
<span style="color: #7f0055;"><strong>import </strong></span><span style="color: #000000;">org.eclipse.jface.dialogs.MessageDialog;</span><br />
<span style="color: #7f0055;"><strong>import </strong></span><span style="color: #000000;">org.eclipse.swt.widgets.Display;</span></p>
<p><span style="color: #7f0055;"><strong>public class </strong></span><span style="color: #000000;">DefaultAnnotateEBookHandler </span><span style="color: #7f0055;"><strong>extends </strong></span><span style="color: #000000;">AbstractHandler </span><span style="color: #000000;">{</span></p>
<p><span style="color: #ffffff;"> </span><span style="color: #7f0055;"><strong>public </strong></span><span style="color: #000000;">Object execute</span><span style="color: #000000;">(</span><span style="color: #000000;">ExecutionEvent event</span><span style="color: #000000;">) </span><span style="color: #7f0055;"><strong>throws </strong></span><span style="color: #000000;">ExecutionException </span><span style="color: #000000;">{</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">MessageDialog.openInformation</span><span style="color: #000000;">(</span><span style="color: #000000;">Display.getDefault</span><span style="color: #000000;">()</span><span style="color: #000000;">.getActiveShell</span><span style="color: #000000;">()</span><span style="color: #000000;">,</span><br />
<span style="color: #ffffff;"> </span><span style="color: #2a00ff;">"Annotate"</span><span style="color: #000000;">, </span><span style="color: #2a00ff;">"For now: write in the margins of the real book."</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #7f0055;"><strong>return null</strong></span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">}</span></p>
<p><span style="color: #000000;">}</span></code></td>
</tr>
</tbody>
</table>
</div>
<p><!-- =       END of automatically generated HTML code       = --><br />
<!-- ======================================================== --></p>
<h3>Where&#8217;s that context menu?</h3>
<p>Those of you who have actually been entering the example code, would have found out by now that there is no context showing when running the example. Why not? Well, we have not created a context menu yet for our View. Do that, open the <strong>View</strong> class created by the <em>New Plug-in Project Wizard</em> in <a href="http://hermanlintvelt.blogspot.com/2009/05/eclipse-rcp-commands-api-part-two.html#step1">step 1</a> of my previous blog.<br />
Change the code to look like this (basically adding the <strong>createContextMenu()</strong> method):</p>
<p><!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--></p>
<p><!-- ======================================================== --><br />
<!-- = Java Sourcecode to HTML automatically converted code = --><br />
<!-- =   Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard  markus@jave.de   = --><br />
<!-- =     Further information: http://www.java2html.de     = --></p>
<div class="java">
<p><!-- end source code --></p>
<table border="0" cellspacing="0" cellpadding="3" bgcolor="#ffffff">
<tbody>
<tr><!-- start source code --></p>
<td align="left" valign="top"><code><br />
<span style="color: #7f0055;"><strong>public class </strong></span><span style="color: #000000;">View </span><span style="color: #7f0055;"><strong>extends </strong></span><span style="color: #000000;">ViewPart </span><span style="color: #000000;">{</span><br />
<span style="color: #ffffff;"> </span><span style="color: #7f0055;"><strong>public static final </strong></span><span style="color: #000000;">String ID = </span><span style="color: #2a00ff;">"MyReader.view"</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #7f0055;"><strong>private </strong></span><span style="color: #000000;">TableViewer viewer;</span></p>
<p><span style="color: #ffffff;"> </span><span style="color: #3f7f5f;">//other code not shown...</span><br />
<span style="color: #ffffff;"> </span><br />
<span style="color: #ffffff;"> </span><span style="color: #7f0055;"><strong>public </strong></span><span style="color: #7f0055;"><strong>void </strong></span><span style="color: #000000;">createPartControl</span><span style="color: #000000;">(</span><span style="color: #000000;">Composite parent</span><span style="color: #000000;">) {</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">viewer = </span><span style="color: #7f0055;"><strong>new </strong></span><span style="color: #000000;">TableViewer</span><span style="color: #000000;">(</span><span style="color: #000000;">parent, SWT.MULTI | SWT.H_SCROLL</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">| SWT.V_SCROLL</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">viewer.setContentProvider</span><span style="color: #000000;">(</span><span style="color: #7f0055;"><strong>new </strong></span><span style="color: #000000;">ViewContentProvider</span><span style="color: #000000;">())</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">viewer.setLabelProvider</span><span style="color: #000000;">(</span><span style="color: #7f0055;"><strong>new </strong></span><span style="color: #000000;">ViewLabelProvider</span><span style="color: #000000;">())</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">viewer.setInput</span><span style="color: #000000;">(</span><span style="color: #000000;">getViewSite</span><span style="color: #000000;">())</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">createContextMenu</span><span style="color: #000000;">()</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">}</span><br />
<span style="color: #ffffff;"> </span><br />
<span style="color: #ffffff;"> </span><span style="color: #7f0055;"><strong>private </strong></span><span style="color: #7f0055;"><strong>void </strong></span><span style="color: #000000;">createContextMenu</span><span style="color: #000000;">(){</span><br />
<span style="color: #ffffff;"> </span><span style="color: #7f0055;"><strong>final </strong></span><span style="color: #000000;">MenuManager mm = </span><span style="color: #7f0055;"><strong>new </strong></span><span style="color: #000000;">MenuManager</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"view.popupmenu"</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">mm.setRemoveAllWhenShown</span><span style="color: #000000;">(</span><span style="color: #7f0055;"><strong>true</strong></span><span style="color: #000000;">)</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">mm.addMenuListener</span><span style="color: #000000;">(</span><span style="color: #7f0055;"><strong>new </strong></span><span style="color: #000000;">IMenuListener</span><span style="color: #000000;">(){</span><br />
<span style="color: #ffffff;"> </span><span style="color: #7f0055;"><strong>public </strong></span><span style="color: #7f0055;"><strong>void </strong></span><span style="color: #000000;">menuAboutToShow</span><span style="color: #000000;">(</span><span style="color: #000000;">IMenuManager manager</span><span style="color: #000000;">) {</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">mm.add</span><span style="color: #000000;">(</span><span style="color: #7f0055;"><strong>new </strong></span><span style="color: #000000;">Separator</span><span style="color: #000000;">(</span><span style="color: #000000;">IWorkbenchActionConstants.MB_ADDITIONS</span><span style="color: #000000;">))</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">}</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">})</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #7f0055;"><strong>final </strong></span><span style="color: #000000;">Menu menu = mm.createContextMenu</span><span style="color: #000000;">(</span><span style="color: #000000;">viewer.getTable</span><span style="color: #000000;">())</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">viewer.getTable</span><span style="color: #000000;">()</span><span style="color: #000000;">.setMenu</span><span style="color: #000000;">(</span><span style="color: #000000;">menu</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">getSite</span><span style="color: #000000;">()</span><span style="color: #000000;">.registerContextMenu</span><span style="color: #000000;">(</span><span style="color: #000000;">mm, viewer</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span><br />
<span style="color: #ffffff;"> </span><span style="color: #000000;">}</span></code></td>
</tr>
</tbody>
</table>
</div>
<p><!-- =       END of automatically generated HTML code       = --><br />
<!-- ======================================================== --></p>
<p>If you run the <em>MyReader</em> application now, you should get the context menu when right-clicking in the view, proudly showing your &#8220;<em>Annotate</em>&#8221; item.</p>
<p>Feel free to <a href="http://www.richclientgui.com/blogs/eclipsecommands/myreader_sample02.zip">download the source code</a> for this blog&#8217;s example.</p>
<h2>Next up</h2>
</li>
<li>Showing commands only when you want to&#8230;<br />
<h2>References</h2>
</li>
<li><a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=223445">Eclipse.org Commands Framework Article in bugzilla</a></li>
<li><a title="The Eclipse RCP Command Framework" href="http://svn2.assembla.com/svn/eclipsecommands/trunk/EclipseCommands/contents/article.html">Article on Eclipse Commands Framework</a>, by Marc R. Hoffmann</li>
<li><a title="The Eclipse RCP Command Framework" href="http://svn2.assembla.com/svn/eclipsecommands/trunk/EclipseCommands/contents/article.html">Eclipse.org Wiki on Command Framework</a></li>
<li><a title="Using Eclipse Commands with Eclipse Ganymede (3.4) - Tutorial" href="http://www.vogella.de/articles/EclipseCommands/article.html">Eclipse Commands Tutorial</a>, by Lars Vogel
<p>Enough said.</li>
]]></content:encoded>
			<wfw:commentRss>http://blog.richclientgui.com/?feed=rss2&amp;p=15</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XCode Useful Shortcut keys</title>
		<link>http://blog.richclientgui.com/?p=8</link>
		<comments>http://blog.richclientgui.com/?p=8#comments</comments>
		<pubDate>Fri, 29 May 2009 15:24:33 +0000</pubDate>
		<dc:creator>herman</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[xcode shortcut keys]]></category>

		<guid isPermaLink="false">http://blog.richclientgui.com/?p=8</guid>
		<description><![CDATA[Some XCode shortcut keys I found very useful: Editor keys Key Description Tab Accept the current completion and jump to after it Escape, Control-comma, F5 Shows a pop-up list from which you can select from all the available code sense completions Control-period to insert the most likely completion Control-Slash / Shift-Control-Slash move between place holder [...]]]></description>
			<content:encoded><![CDATA[<p>Some XCode shortcut keys I found very useful:
</p>
<p>
<h3>Editor keys</h3>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<th>Key</th>
<th>Description</th>
</tr>
<tr>
<td><strong>Tab</strong></td>
<td>Accept the current completion and jump to after it</td>
</tr>
<tr>
<td><strong>Escape, Control-comma, F5</strong></td>
<td>Shows a pop-up list from which you can select from all the available code sense completions</td>
</tr>
<tr>
<td><strong>Control-period</strong></td>
<td>to insert the most likely completion</td>
</tr>
<tr>
<td><strong>Control-Slash / Shift-Control-Slash</strong></td>
<td>move between place holder tokens</td>
</tr>
<tr>
<td><strong>Cmd-/</strong></td>
<td>insert comment line</td>
</tr>
<tr>
<td><strong>Ctrl+Left/Right Arrow</strong></td>
<td>Jump to previous/next word</td>
</tr>
<tr>
<td><strong>Command-[ and Command-]</strong></td>
<td>indent and unindent selected text</td>
</tr>
<tr>
<td><strong>Control-Command Left/Right</strong></td>
<td>fold and unfold the function</td>
</tr>
<tr>
<td><strong>Command-Shift-E</strong></td>
<td>expand the editor view to full height of the window</td>
</tr>
</table>
<p>
<h3>Navigation keys</h3>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<th>Key</th>
<th>Description</th>
</tr>
<tr>
<td><strong>Alt-Command-Up</strong></td>
<td>Switch between .m and .h file</td>
</tr>
<tr>
<td><strong>Alt-Command-Left / Alt-Command-Right</strong></td>
<td>Navigate among open files back and forth.</td>
</tr>
<tr>
<td><strong>Command-Shift-D</strong></td>
<td>Show the &#8220;Open Quickly&#8221; dialog for navigating to defined type or function in your project</td>
</tr>
<tr>
<td><strong>Control-Option-1</strong></td>
<td>Show list of all project files</td>
</tr>
<tr>
<td><strong>Control-Option-2</strong></td>
<td>Show list of members of current file</td>
</tr>
<tr>
<td><strong>Control-Option-3</strong></td>
<td>Show list of include files</td>
</tr>
<tr>
<td><strong>Control-Option-4</strong></td>
<td>Show list of bookmarks</td>
</tr>
<tr>
<td><strong>Control-Option-5</strong></td>
<td>Show list of breakpoints</td>
</tr>
<tr>
<td><strong>Control-Shift-R</strong></td>
<td>Show the Console</td>
</tr>
<tr>
<td><strong>Control-Alt-Command-R</strong></td>
<td>clear the log</td>
</tr>
<tr>
<td><strong>Shift-Command-C</strong></td>
<td>Show the Class browser</td>
</tr>
<tr>
<td><strong>Command-=</strong></td>
<td>Jump to the next error in the list of build errors</td>
</tr>
<tr>
<td><strong> Command-Shift-F</strong></td>
<td>Display the multiple Find panel</td>
</tr>
<tr>
<td><strong>Command-O</strong></td>
<td>Jump to the Project tab</td>
</tr>
<tr>
<td><strong> Command-Shift-B</strong></td>
<td>Jump to the Build tab</td>
</tr>
<tr>
<td><strong> Command-Shift-Y</strong></td>
<td>Jump to the Debug tab</td>
</tr>
</table>
<p>
<h3>Mouse tips</h3>
<li><strong>Double-click</strong> on the square <strong>brackets</strong> or parentheses to select everything between opening and closing brackets
<li><strong>Command-double click</strong> on a symbol to see the definition of a symbol
<li><strong>Option-double click</strong> on a symbol to see the documentation for that symbol
</p>
<p>Thanks to Adeem Basraa for his <a href="http://adeem.me/blog/2009/04/14/list-of-xcode-shortcut-keys-or-tips/" title="Xcode Tips and Shortcut, List of shortcut for xcode, xcode IDE | iPhone Diary | Xcode">shortcuts list</a> that helped me find my way around XCode and was a reference for this quick blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richclientgui.com/?feed=rss2&amp;p=8</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse RCP Commands</title>
		<link>http://blog.richclientgui.com/?p=3</link>
		<comments>http://blog.richclientgui.com/?p=3#comments</comments>
		<pubDate>Wed, 27 May 2009 09:39:15 +0000</pubDate>
		<dc:creator>herman</dc:creator>
				<category><![CDATA[Eclipse RCP]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[actions]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[rcp]]></category>

		<guid isPermaLink="false">http://blog.richclientgui.com/?p=3</guid>
		<description><![CDATA[This is my second blog about the Eclipse Commands framework, but actually the first one containing useful (I hope) information. I&#8217;m going to focus on the topic from a practical &#8220;using it in development&#8221; point of view, trying to keep the examples as simple as possible and the theory limited. For an updated outline please [...]]]></description>
			<content:encoded><![CDATA[<p>
	This is my second blog about the Eclipse Commands framework, but actually the first one containing useful (I hope) information. I&#8217;m going to focus on the topic from a practical &#8220;using it in development&#8221; point of view, trying to keep the examples as simple as possible and the theory limited. For an updated outline please refer to the first blog in the series: <a href="http://hermanlintvelt.blogspot.com/2009/05/eclipse-rcp-commands-api-part-one.html" title="Java, Mac, Software and other kaos: Eclipse RCP Commands API Part One">Eclipse RCP Commands Part One</a>.
</p>
<p>
	<em>Short history</em>: the Commands framework has been around partially since Eclipse 3.0, maturing over the versions until it became quite useful in Eclipse 3.3. Some refinements in Eclipse 3.4 makes it even more appealing. I must admit, before Eclipse 3.3 I saw no reason for using Commands, and I stuck to using <a href="http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/jface/action/IAction.html" title="IAction (Eclipse Platform API Specification)">IActions</a> and <a href="http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/IActionDelegate.html" title="IActionDelegate (Eclipse Platform API Specification)">IActionDelegates</a>, trying to work around their issues as much as possible (and falling into the rythm of the copy-and-paste anti-pattern in order to contribute an IActionDelegate to multiple places in a UI). No I&#8217;m trying to convince all my clients to &#8220;renew&#8221; their code to use Commands&#8230;
</p>
<h2><a name="intro">What are Commands</a></h2>
<p>
	&#8220;<i>A command is neither the presentation nor a particular behavior implementation; it is an abstract representation of some semantical behavior.</i>&#8221; &#8211; Marc R. Hoffmann (see <a href="http://svn2.assembla.com/svn/eclipsecommands/trunk/EclipseCommands/contents/article.html" title="The Eclipse RCP Command Framework">Article on Eclipse Commands Framework</a>)
</p>
<p>
	That&#8217;s the best quote I could find as to what a Command is. What does it boil down to? I assume (hope?) you are all familiar with the <a href="http://en.wikipedia.org/wiki/Model_view_controller" title="Model–view–controller - Wikipedia, the free encyclopedia">Model-View-Controller</a> pattern, used especially when developing UI applications. By abstracting a particular piece of functionality into separate Model, View and Controller objects, the code is must less coupled, allowing more (and easier) reuse, flexibility and extensibility.
</p>
<p>
	Well, the Command design is not exactly MVC, but it has the same goals in mind. It abstracts the actual business or application semantics (i.e. what is actually meant to happen from business or application functionality perspective) into this thing called a Command. Worries about how it should appear in the UI (menu contributions), or what exactly must happen on a code implementation level to execute the command (handlers) is left for later. In this way we get the same decoupling of presentation and implementation as with MVC, and thus the gain in reusability of Commands and their handlers, and increase in the flexibility and extensibility of the code, thus leading overall to code that is much easier to maintain.
</p>
<p>
	Add to the above paragraph that code that is easier to maintain leads to huge development cost savings, and you&#8217;ll have a convincing argument to offer to your boss for allowing you to refactor away all the old IActionDelegates.
</p>
<h4>Ok, but what to we do with Commands?</h4>
<p>Plain and simple: we use it to implement functions that our application can perform and make it available as menu or toolbar items so the user can invoke it.</p>
<h2>On a more practical level</h2>
<p>That is about enough theory for one day. Let&#8217;s get down to the bits and the bytes. </p>
<h4><a name="example">The Example</a></h4>
<p>Firstly, I want to introduce my patent-pending idea for an application. Image this: you have this cross-platform application (obviously implemented using Eclipse RCP) that can actually read electronic versions of books, that we can call &#8220;e-books&#8221;. &#8220;Wow!&#8221; you say. &#8220;Amazing&#8221;. &#8220;What a novel idea&#8221;.
</p>
<p>Let us call our bleeding edge application <em>MyReader</em>. You can <a href="http://www.richclientgui.com/blogs/eclipsecommands/myreader_sample01.zip">download</a> the source code for this blog&#8217;s version of the example.
</p>
<p><a name="step1"></a><strong>Step 1</strong>: Create a RCP application using Eclipse 3.4 (I&#8217;m using 3.4.1) and the <em>New Plug-in Project</em> wizard. </p>
<li> Name the project <em>MyReader</em>
<li> On the next wizard page fill in the details you want, but make sure &#8220;<em>Would you like to create a rich client application</em>&#8221; is set to &#8220;<em>Yes</em>&#8220;.
<li> On the third wizard page, select the &#8220;<em>RCP application with a view</em>&#8221; as the template to use.
<li> Run the resulting RCP application to make sure it runs, so you don&#8217;t blame my examples later for messing up your pristine code.
</p>
<p>Now we have the example application that we are going to enable with Commands. Exciting, isn&#8217;t it?</p>
<h2>How to define a Command</h2>
<p>To have a command that is actually accessible in the UI, and able to do something, we need 3 &#8220;components&#8221;:</p>
<li>The Intent: the Command declaration
<li>The Presentation: the menu contribution declaration(s)
<li>The Behaviour: the Handler that implements the behaviour of the Command
</p>
<h3><a name="definecommand">Declaring the Command (Intent)</a></h3>
<p>We declare the Command using the <a href="http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_commands.html" title="Commands">org.eclipse.ui.commands</a> extension point. I&#8217;m sure you remember this command we declare indicates the meaning or intent of the functionality we want to add to our application or plugin.
</p>
<p>Let us explore this Command declaration in our example, and then I&#8217;ll discuss what is going on.<br />
	We need to open an ebook file with our application, so we will define a command to do this.
</p>
<p>
	<strong><a name="step2"></a>Step 2</strong>: Add the <em>org.eclipse.ui.commands</em> extension to our <em>plugin.xml</em></p>
<li> Open the PDE-Editor (Plugin Editor), if it is not open already, and select the <strong>Extensions</strong> tab. (You double-click the plugin.xml or MANIFEST.MF files in the project. However, if you did not know that, you must maybe first implement a &#8220;Hello RCP World&#8221; application before jumping to Commands&#8230;)
<li> If, due to random bit-changes caused by unexplained solar activity, you already have the <em>org.eclipse.ui.commands</em> extension in your list of extensions, then do not follow the rest of this step.
<li> Click on the &#8220;<strong>Add&#8230;</strong>&#8221; button.
<li> Start typing in &#8220;<strong>org.eclipse.ui.commands</strong>&#8220;, and select it from the filtered list when you see it. If it is not available uncheck the &#8220;<em>Show only extension points from required plug-ins</em>&#8221; option.
<li> Select the <strong>Finish</strong> button. This will add the <em>org.eclipse.ui.commands</em> entry to your <em>plugin.xml</em> file.
</p>
<p><strong><a name="step3"></a>Step 3</strong>: Declare the Open File command</p>
<li>right-click the <em>org.eclipse.ui.commands</em> extension, and select <strong>New -&gt; Command</strong> from the context menu.
<li>change the <strong>id</strong> to something like &#8220;<em>mydomain.myreader.commands.OpenEBook</em>&#8221;
<li>change the <strong>name</strong> to &#8220;<em>Open eBook</em>&#8221;
<li>change <strong>description</strong> to &#8220;<em>Opens an eBook file for reading</em>&#8221;
<li>for now, ignore the rest
</p>
<p>Steps 2 and 3 updates the <em>plugin.xml</em> file of the plugin project by adding the necessary extension point and declaring a basic command. The plugin.xml file now contains:</p>
<p>    <!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--></p>
<p><!-- ======================================================== --><br />
<!-- = Java Sourcecode to HTML automatically converted code = --><br />
<!-- =   Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard  markus@jave.de   = --><br />
<!-- =     Further information: http://www.java2html.de     = --></p>
<div align="left" class="java">
<table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
<tr>
  <!-- start source code --></p>
<td nowrap="nowrap" valign="top" align="left">
    <code><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;extension</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">point=</font><font color="#2a00ff">&#34;org.eclipse.ui.commands&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;command</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">description=</font><font color="#2a00ff">&#34;Open&nbsp;an&nbsp;eBook&nbsp;file&nbsp;for&nbsp;reading&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">id=</font><font color="#2a00ff">&#34;com.richclientgui.myreader.commands.OpenEBook&#34;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">name=</font><font color="#2a00ff">&#34;Open&nbsp;eBook&#34;</font><font color="#000000">&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/command&gt;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/extension&gt;</font></code></p>
</td>
<p>  <!-- end source code --><br />
   </tr>
</table>
</div>
<p><!-- =       END of automatically generated HTML code       = --><br />
<!-- ======================================================== --></p>
<p>Congratulations! Your first command. </p>
<p>&#8220;But if I run my app, I don&#8217;t see this command. What&#8217;s wrong?&#8221; Nothing. We still need to define how this command will be visible in the UI, and what the behavior should be when this command is invoked. As mentioned earlier, these are decoupled from the Command declaration.
</p>
<p>However, let us first examine the declaration in the plugin.xml. The org.eclipse.ui.commands extension allows us to declare, among other things, a Command. The Command definition needs the following attributes:</p>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td><strong>id</strong></td>
<td>a unique id that will be used for referring to this command when declaring the UI contributions and Handlers</td>
</tr>
<tr>
<td><strong>name</strong></td>
<td>a user-readable name that will be used for the label in the menu contribution(s), if the menu contribution does not define its own label</td>
</tr>
<tr>
<td><strong>description</strong></td>
<td>a user-readable name that will be used for the tooltip in the menu contribution(s), if the contribution does not define its own description</td>
</tr>
</table>
<p>We are still going to have a look at some of the other attributes available. If you can&#8217;t wait, go and see <a href="http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_commands.html" title="Commands">org.eclipse.ui.commands</a> for more detailed information about the extension point definition. Go on, don&#8217;t mind me.
</p>
<p><em><strong>Note</strong>: here we had a look at how to declare commands using the extension point in the plugin.xml file. In a later blog I plan to discuss how to do it programmatically. I will update this section with a link to that blog as soon as it is available.</em></p>
<h3><a name="menucontribution">Basic menu contribution (Presentation)</a></h3>
<p>It is time to get his command to be presented in the UI of the application. I assume you have already done some nice UI design work sessions with your potential end-users and you are ready to build the ultimate user friendly intuitive graphical user interface for your application. For our example we are just going to use the UI-design-by-coincidence approach and just add our stuff and see how it looks.
</p>
<p>In order to contribute an item that will invoke a Command to the UI, we need to add the <a href="http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_menus.html" title="Help - Eclipse SDK">org.eclipse.ui.menus</a> extension to our <em>plugin.xml</em>, and declare a <em>MenuContribution</em> element followed by a <em>Command</em> element.
</p>
<p>We first declare where (i.e. the main menubar or toolbar, or a view or editor specific menu and/or toolbar, or a context menu) the command should be added via the <em>MenuContribution</em>. Then we declare the visual representation of our Command using the MenuContribution&#8217;s <em>Command</em> element.
</p>
<p><a name="step4"></a><strong>Step 4</strong>:Add the <em>org.eclipse.ui.menus</em> extension to <em>plugin.xml</em></p>
<li> Click on the <strong>Add&#8230;</strong> button in the Plugin Editor.
<li> Select the org.eclipse.ui.menus extension from the list of available extensions. If it is not available uncheck the &#8220;<em>Show only extension points from required plug-ins</em>&#8221; option.
<li> Select the Finish button. This will add the <em>org.eclipse.ui.menus</em> extension to the <em>plugin.xml</em> file.
</p>
<p><a name="step5"></a><strong>Step 5</strong>: Add the <em>MenuContribution</em> element</p>
<li> Right-click the org.eclipse.ui.menus extension, and select <strong>New -&gt; menuContribution</strong> from the context menu
<li> Change the <strong>locationURI</strong> to <strong>menu:file?after=additions</strong> (don&#8217;t worry, we&#8217;ll discuss it just now)
</p>
<p><a name="step6"></a><strong>Step 6</strong>: Add the <em>Command</em> to the MenuContribution</p>
<li> Right-click on the <em>menuContribution</em> created in step 5, and select <strong>New -&gt; command</strong> from the context menu.
<li> Change <strong>commandId</strong> to the <strong>id</strong> you provided to your Command definition in <a href="#step3">step 3</a>.
<li> Change mnemonic to &#8220;O&#8221; to underline the first letter of the &#8220;Open&#8221; as your shortcut mnemonic for your command in the menu.
</p>
<p>I&#8217;m sure you are eager to run your MyReader app now. Go ahead, please. Do you see it? A grayed-out <em>Open eBook</em> menu-item just underneath <em>Exit</em> in the <em>File</em> menu.<br />
<img src="http://www.richclientgui.com/blogs/eclipsecommands/firstmenucontribution.png" alt="First Menu Contribution with grayed-out Open eBook Command" />
</p>
<p>That is not quite what we intended. We&#8217;ll get there, though. First a discussion on what we actually did.
</p>
<p>We first needed to add the <em>org.eclipse.ui.menus</em> extension to our plugin, and then we declared that we want to contribute an item to a menu via the <em>MenuContribution</em> element. We only had to specify one attribute: the <em>locationURI</em>. More on that in the next <a href="#location">section</a>.
</p>
<p>We then declared that we are actually contributing a <em>Command</em> item as part of our MenuContribution. This is not the actual definition of a Command, but just an element indicating that we wish to represent the command with the identifier specified in <strong>commandId</strong> as an item in the menu or toolbar that we are declaring this MenuContribution for. Thus by specifying the locationURI &#8220;<em>menu:file?after=additions</em>&#8221; and the commandId &#8220;<em>com.richclientgui.myreader.commands.OpenEBook</em>&#8221; we are saying that we want the <em>OpenEBook</em> command to display in the standard <em>File</em> menu after the <em>additions</em> placeholder.
</p>
<p>The <strong>mnemonic</strong> attribute indicates what character should be underlined and act as a shortcut key for selecting the menu item, if that menu is currently open. Other additional attributes can be specified to manage the presentation of the Command in the menu, e.g. the icon, label (overriding the value set in the Command&#8217;s <strong>name</strong> attribute), tooltip (overriding the value set in the Command&#8217;s <strong>description</strong> attribute), etc. This gives us the flexibility to present the same Command slightly different depending on where it gets contributed, something that is not possible with IActions and IActionDelegates.
</p>
<h4><a name="location">LocationURI</a></h4>
<p>The locationURI is an interesting attribute: it allows the developer to use a URI string to specify where a specific contribution (whether it is a command item, a submenu or some other widget that can be contributed) must be added. It is of the form:<br />
<strong>[scheme]:[id]?[placement arguments]</strong>
</p>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td><strong>scheme</strong></td>
<td>The scheme indicates the type of the target component of the contribution, and can be one of: </p>
<li> <em>menu</em> : either main menu or view menu
<li> <em>toolbar</em> : either main toolbar or view toolbar
<li> <em>popup</em> : context menu
		</td>
</tr>
<tr>
<td><strong>id</strong></td>
<td>The unique identifier of the menu, toolbar or context (popup) menu where the contribution must be added. See the <a href="#standardids">list</a> below for standard platform identifiers that can be used.</td>
</tr>
<tr>
<td><strong>placement</strong></td>
<td>The arguments helps to define the placement of the contribution items in relation to another item or placeholder (i.e. GroupMarker) in the target menu. It consists of either the word &#8220;<em>before</em>&#8221; or &#8220;<em>after</em>&#8221; followed by an equal sign (<em>=</em>) and then the identifier of a menu contribution item. The word &#8220;<em>additions</em>&#8221; can also be used in place of an identifier. Contributions added to &#8220;<em>additions</em>&#8221; will typically be placed last in a menu. </td>
</tr>
</table>
<p></p>
<p>Talking in detail about the locationURI and menu contribution placement can be a long blog entry on its own, so I want to come to this subject in more detail later in the series.
</p>
<p><em><strong>Note</strong>: I usually declare my view&#8217;s identifier as the same as the fully qualified Java class name of the ViewPart implementation class, and then use the convention <strong>viewID.menu</strong>, <strong>viewID.toolbar</strong> and <strong>viewID.popup</strong> as identifiers for its various menus. E.g. a View implemented in the class <strong>com.richclientgui.myreader.BookView</strong> will have the Id <strong>com.richclientgui.myreader.BookView</strong> and the menu IDs <strong>com.richclientgui.myreader.BookView.menu</strong>, <strong>com.richclientgui.myreader.BookView.toolbar</strong> and <strong>com.richclientgui.myreader.BookView.popup</strong>.</em>
</p>
<h4><a name="standardids">Platform Menu IDs</a></h4>
<p>Some standard identifiers are available for commonly used menus and toolbars:</p>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<th>ID</th>
<th>Description</th>
</tr>
<tr>
<td>org.eclipse.ui.main.menu</td>
<td>the main Eclipse application menubar</td>
</tr>
<tr>
<td>org.eclipse.ui.main.toolbar</td>
<td>the main Eclipse application toolbar</td>
</tr>
<tr>
<td>org.eclipse.ui.popup.any</td>
<td>contributions using this identifier will be visible in all context menus of the application (well, that&#8217;s not the full truth, but that is a topic for another blog)</td>
</tr>
<tr>
<td>menu:file</td>
<td>three guesses what menu this one point to&#8230;</td>
</tr>
<tr>
<td>menu:help</td>
<td>I&#8217;m not even going to say its a menu, and you only get one guess</td>
</tr>
<tr>
<td>menu:window</td>
<td>Ok, you start to get the picture</td>
</tr>
<tr>
<td>helpEnd</td>
<td>name of group-marker at end of <em>Help</em> menu</td>
</tr>
<tr>
<td>quit</td>
<td>id of <em>Exit</em> action</td>
</tr>
</table>
<p>See <a href="http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_menus.html" title="Help - Eclipse SDK">IIDEActionConstants</a> and <a href="http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/IWorkbenchActionConstants.html" title="Help - Eclipse SDK">IWorkbenchActionConstants</a> for more useful identifiers.
</p>
<p>I can&#8217;t wait to move that <em>Open eBook</em> item to the top of the menu&#8230;</p>
<p><strong><a name="step7"></a>Step 7</strong>: Change Command menu-item placement</p>
<li> Select the <em>menuContribution</em> element we specified in <a href="#step6">step 6</a>.
<li> Change the <strong>locationURI</strong> to be <strong>menu:file?before=quit</strong>
</p>
<p>Running our latest version gives us a still grayed-out item, but at least where we want it.<br /> <br />
<img src="http://www.richclientgui.com/blogs/eclipsecommands/intherightplace.png" alt="Open eBook Command in right place" />
</p>
<p>And our plugin.xml has grown a bit:</p>
<p>	    <!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--></p>
<p>	<!-- ======================================================== --><br />
	<!-- = Java Sourcecode to HTML automatically converted code = --><br />
	<!-- =   Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard  markus@jave.de   = --><br />
	<!-- =     Further information: http://www.java2html.de     = --></p>
<div align="left" class="java">
<table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
<tr>
	  <!-- start source code --></p>
<td nowrap="nowrap" valign="top" align="left">
	    <code><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;extension</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">point=</font><font color="#2a00ff">&#34;org.eclipse.ui.commands&#34;</font><font color="#000000">&gt;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;command</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">description=</font><font color="#2a00ff">&#34;Open&nbsp;an&nbsp;eBook&nbsp;file&nbsp;for&nbsp;reading&#34;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">id=</font><font color="#2a00ff">&#34;com.richclientgui.myreader.commands.OpenEBook&#34;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">name=</font><font color="#2a00ff">&#34;Open&nbsp;eBook&#34;</font><font color="#000000">&gt;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/command&gt;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/extension&gt;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;extension</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">point=</font><font color="#2a00ff">&#34;org.eclipse.ui.menus&#34;</font><font color="#000000">&gt;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;menuContribution</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">locationURI=</font><font color="#2a00ff">&#34;menu:file?before=quit&#34;</font><font color="#000000">&gt;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;command</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">commandId=</font><font color="#2a00ff">&#34;com.richclientgui.myreader.commands.OpenEBook&#34;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">mnemonic=</font><font color="#2a00ff">&#34;O&#34;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">style=</font><font color="#2a00ff">&#34;push&#34;</font><font color="#000000">&gt;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/command&gt;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/menuContribution&gt;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;</font><font color="#000000">&lt;/extension&gt;</font></code></p>
</td>
<p>	  <!-- end source code --><br />
	   </tr>
</table></div>
<p>	<!-- =       END of automatically generated HTML code       = --><br />
	<!-- ======================================================== -->
</p>
<p>Now to implement the behaviour.
</p>
<h3><a name="definehandler">Simple Handler (Behaviour)</a></h3>
<p>After all this build-up, it is quite simple to actually add behaviour to a Command. You need to</p>
<li> implement a class that extends <strong>org.eclipse.core.commands.AbstractHandler</strong>,
<li> and update your Command&#8217;s <strong>defaultHandler</strong> attribute that you left empty in <a href="#step3">step 3</a>.
</p>
<p><a name="step8"></a><strong>Step 8</strong>: Implement a default Handler</p>
<li> Implement a class called <strong>DefaultOpenEBookHandler</strong> that extends <strong>AbstractHandler</strong>, and only override the<strong> execute(&#8230;)</strong> method. I just added a call to the JFace <em>MessageDialog</em> class to show some information. I will discuss these Handler classes more in a future blog in the series.
<li> Select the <strong>OpenEBookCommand</strong> definition from <a href="#step3">step 3</a> and select the <strong>DefaultOpenEBookHandler</strong> class as the <strong>defaultHandler</strong>&#8216;s value.
</p>
<p>
	Here is my <strong>DefaultOpenEBookHandler</strong> class:</p>
<p>	    <!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--></p>
<p>	<!-- ======================================================== --><br />
	<!-- = Java Sourcecode to HTML automatically converted code = --><br />
	<!-- =   Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard  markus@jave.de   = --><br />
	<!-- =     Further information: http://www.java2html.de     = --></p>
<div align="left" class="java">
<table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
<tr>
	  <!-- start source code --></p>
<td nowrap="nowrap" valign="top" align="left">
	    <code><br />
	<font color="#7f0055"><b>package&nbsp;</b></font><font color="#000000">com.richclientgui.myreader.handlers;</font><br />
	<font color="#ffffff"></font><br />
	<font color="#7f0055"><b>import&nbsp;</b></font><font color="#000000">org.eclipse.core.commands.AbstractHandler;</font><br />
	<font color="#7f0055"><b>import&nbsp;</b></font><font color="#000000">org.eclipse.core.commands.ExecutionEvent;</font><br />
	<font color="#7f0055"><b>import&nbsp;</b></font><font color="#000000">org.eclipse.core.commands.ExecutionException;</font><br />
	<font color="#7f0055"><b>import&nbsp;</b></font><font color="#000000">org.eclipse.jface.dialogs.MessageDialog;</font><br />
	<font color="#7f0055"><b>import&nbsp;</b></font><font color="#000000">org.eclipse.swt.widgets.Display;</font><br />
	<font color="#ffffff"></font><br />
	<font color="#7f0055"><b>public&nbsp;class&nbsp;</b></font><font color="#000000">DefaultOpenEBookHandler&nbsp;</font><font color="#7f0055"><b>extends&nbsp;</b></font><font color="#000000">AbstractHandler&nbsp;</font><font color="#000000">{</font><br />
	<font color="#ffffff"></font><br />
	<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><b>public&nbsp;</b></font><font color="#000000">Object&nbsp;execute</font><font color="#000000">(</font><font color="#000000">ExecutionEvent&nbsp;event</font><font color="#000000">)&nbsp;</font><font color="#7f0055"><b>throws&nbsp;</b></font><font color="#000000">ExecutionException&nbsp;</font><font color="#000000">{</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">MessageDialog.openInformation</font><font color="#000000">(</font><font color="#000000">Display.getDefault</font><font color="#000000">()</font><font color="#000000">.getActiveShell</font><font color="#000000">()</font><font color="#000000">,</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#2a00ff">&#34;O&nbsp;no!&#34;</font><font color="#000000">,&nbsp;</font><font color="#2a00ff">&#34;I'm&nbsp;not&nbsp;ready&nbsp;yet.&nbsp;Go&nbsp;read&nbsp;the&nbsp;hardcopy&nbsp;book.&#34;</font><font color="#000000">)</font><font color="#000000">;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><b>return&nbsp;null</b></font><font color="#000000">;</font><br />
	<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
	<font color="#ffffff"></font><br />
	<font color="#000000">}</font></code></p>
</td>
<p>	  <!-- end source code --><br />
	   </tr>
</table></div>
<p>	<!-- =       END of automatically generated HTML code       = --><br />
	<!-- ======================================================== -->
</p>
<p>If you run the application now, you will actually see that the command item in the menu is enabled, and you should see a dialog with a message if you select the item.<br />
<img src="http://www.richclientgui.com/blogs/eclipsecommands/dialog.png" alt="Open eBook Command shows dialog" />
</p>
<h3><a name="sum">The Sum of the Parts</a></h3>
<p>We saw a basic introduction of how to:</p>
<li> declare a Command
<li> contribute that command to the main menu-bar
<li> define a class that encapsulated the behaviour of the Command
</p>
<p>Each of these components on their own does not add value to an application, but together it forms a powerful yet flexible and very maintainable Commands framework, far superior to using IActions and IActionDelegates because of the separation between the intent, presentation and behaviour.
</p>
<h4>Summary of Steps</h4>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td><a href="#step1">Step 1</a></td>
<td>Create sample RCP application</td>
</tr>
<tr>
<td><a href="#step2">Step 2</a></td>
<td>Add the org.eclipse.ui.commands extension to our plugin.xml</td>
</tr>
<tr>
<td><a href="#step3">Step 3</a></td>
<td>Declare the Open File command</td>
</tr>
<tr>
<td><a href="#step4">Step 4</a></td>
<td>Add the org.eclipse.ui.menus extension to plugin.xml</td>
</tr>
<tr>
<td><a href="#step5">Step 5</a></td>
<td>Add the MenuContribution element</td>
</tr>
<tr>
<td><a href="#step6">Step 6</a></td>
<td>Add the Command to the MenuContribution</td>
</tr>
<tr>
<td><a href="#step7">Step 7</a></td>
<td>Change Command menu-item placement</td>
</tr>
<tr>
<td><a href="#step8">Step 8</a></td>
<td>Implement a default Handler</td>
</tr>
</table>
<p>	You can <a href="http://www.richclientgui.com/blogs/eclipsecommands/myreader_sample01.zip">download</a> the source code for this blog&#8217;s version of the example.<br />
</p>
<h2>Next Episode</h2>
<p>Do not miss out on the next exciting episode on Eclipse RCP Commands. There I&#8217;ll be tackling mind-blowing topics, like</p>
<li> how to show commands only when you want to
<li> how to disable commands
<li> dynamic menu contributions
<li> handling the Handlers<br />
(Time and weather permitting.)
</p>
<h2>References</h2>
<li><a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=223445">Eclipse.org Commands Framework Article in bugzilla</a>
<li><a href="http://svn2.assembla.com/svn/eclipsecommands/trunk/EclipseCommands/contents/article.html" title="The Eclipse RCP Command Framework">Article on Eclipse Commands Framework</a>, by Marc R. Hoffmann
<li><a href="http://svn2.assembla.com/svn/eclipsecommands/trunk/EclipseCommands/contents/article.html" title="The Eclipse RCP Command Framework">Eclipse.org Wiki on Command Framework</a>
<li><a href="http://www.vogella.de/articles/EclipseCommands/article.html" title="Using Eclipse Commands with Eclipse Ganymede (3.4) - Tutorial">Eclipse Commands Tutorial</a>, by Lars Vogel
</p>
<p>Enough said for now.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richclientgui.com/?feed=rss2&amp;p=3</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
