<?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/" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:icbm="http://postneo.com/icbm" xmlns:geourl="http://geourl.org/rss/module/" xmlns:media="http://search.yahoo.com/mrss/" ><channel> <title>XPOMUL - The ruler of chaos</title> <atom:link href="http://xpomul.bloggles.info/feed/" rel="self" type="application/rss+xml"/> <link>http://xpomul.bloggles.info</link> <description>Eclipse, Java, Research and other things</description> <lastBuildDate>Wed, 05 Nov 2008 09:45:29 +0000</lastBuildDate> <generator>http://blogates.com/?v=3.0</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <image> <title>XPOMUL - The ruler of chaos</title> <url>http://1.gravatar.com/avatar/9409d1d28b5c6abea0f194a89a33e2de?s=96&amp;d=http%3A%2F%2Fs.bloggles.info%2Ffavicon.ico</url> <link>http://xpomul.bloggles.info/</link> </image> <atom:link rel='hub' href='http://xpomul.bloggles.info/?pushpress=hub'/> <item> <title>Java2Uml &#8211; generating UML2 class diagrams from existing code</title> <link>http://xpomul.bloggles.info/2008/11/05/java2uml-generating-uml2-class-diagrams-from-existing-code/</link> <comments>http://xpomul.bloggles.info/2008/11/05/java2uml-generating-uml2-class-diagrams-from-existing-code/#comments</comments> <pubDate>Wed, 05 Nov 2008 09:43:18 +0000</pubDate> <dc:creator>xpomul</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Eclipse]]></category> <category><![CDATA[eclipse]]></category> <category><![CDATA[EMF]]></category> <category><![CDATA[UML]]></category> <guid isPermaLink="false">http://xpomul.bloggles.info/?p=30</guid> <description><![CDATA[The Eclipse UML2 project provides models and diagram editors for creating and editing UML models in Eclipse. The problem is that these models are not tied to code in any way, and in particular, if you want to visualize existing Java code in class diagrams, you have no option but to create the class diagram [...]]]></description> <content:encoded><![CDATA[<!-- google_ad_section_start --><p>The <a href="http://wiki.eclipse.org/MDT-UML2Tools">Eclipse UML2</a> project provides models and diagram editors for creating and editing UML models in Eclipse. The problem is that these models are not tied to code in any way, and in particular, if you want to visualize existing Java code in class diagrams, you have no option but to create the class diagram manually.<span id="more-30"></span></p><p>A former alternative, the <a href="http://wiki.eclipse.org/MDT-UML2Tools">Omondo EclipseUML Free Edition</a> is not available for Eclipse 3.4 and other free tools (I have tried a lot) don&#8217;t work well, or not at alll, either.</p><p>Well, with the exception of the <a title="TOPCASED Java2UML Plugin" href="http://gforge.enseeiht.fr/frs/?group_id=24" target="_blank">TOPCASED Java2UML Plugin</a>, which is not easy to find and has not been updated for over 2 years now. However, I tried it with Eclipse Ganymede and it still works quite well in the current version as it is able to generate a UML2 model from Java code from which then a class diagram can be initialized and edited.</p><p>To install it, simply download the <em>org.topcased.java.reverse_0.2.0.jar</em> plugin and put it into your favourite dropin location (e.g. ${ECLIPSE_HOME}/eclipse/dropins/plugins). Then start Eclipse and make sure that all UML2 components are installed. Right-click on a Java Package in the Package Explorer and you should see the menu item <em>UML from Java</em> just above the <em>Run as/Debug as </em>submenu items. When selected, a wizard opens which lets you specify the target .uml file, which will be generated.</p><p>After the generation process you can simply choose <em>Initialze Class Diagram</em> from the .uml file&#8217;s context menu to visualize you classes. Note that you have to hide a lot of external classes and other information you don&#8217;t need, but doing this is much more efficient than creating the whole diagram by hand.</p><p><map name='google_ad_map_30_cc04eee439b4d157'><area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/30?pos=0' coords='1,2,367,28'/><area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map><img usemap='#google_ad_map_30_cc04eee439b4d157' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=30&amp;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F11%2F05%2Fjava2uml-generating-uml2-class-diagrams-from-existing-code%2F'/></p>]]></content:encoded> <wfw:commentRss>http://xpomul.bloggles.info/2008/11/05/java2uml-generating-uml2-class-diagrams-from-existing-code/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <media:content url="http://1.gravatar.com/avatar/9409d1d28b5c6abea0f194a89a33e2de?s=96&#38;d=http%3A%2F%2Fs.bloggles.info%2Ffavicon.ico" medium="image"> <media:title type="html">xpomul</media:title> </media:content> <media:thumbnail url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=30&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F11%2F05%2Fjava2uml-generating-uml2-class-diagrams-from-existing-code%2F"/> <media:content url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=30&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F11%2F05%2Fjava2uml-generating-uml2-class-diagrams-from-existing-code%2F" medium="image"/> </item> <item> <title>Advanced features in Eclipse popup menus &#8211; Take 2: The new API</title> <link>http://xpomul.bloggles.info/2008/08/12/advanced-features-in-eclipse-popup-menus-take-2-the-new-api/</link> <comments>http://xpomul.bloggles.info/2008/08/12/advanced-features-in-eclipse-popup-menus-take-2-the-new-api/#comments</comments> <pubDate>Tue, 12 Aug 2008 14:14:10 +0000</pubDate> <dc:creator>xpomul</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Eclipse]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[action]]></category> <category><![CDATA[commands]]></category> <category><![CDATA[eclipse]]></category> <category><![CDATA[java]]></category> <guid isPermaLink="false">http://xpomul.bloggles.info/?p=22</guid> <description><![CDATA[Following Robin&#8217;s comment on my earlier post I found the new API (Extension point description of org.eclipse.ui.menus) which unifies all command contributions to Eclipse menus, views, objects, toolbars etc.With this example it requires a lot less code to add an action (well, the new API uses commands) which is visible or enabled dynamically based on [...]]]></description> <content:encoded><![CDATA[<!-- google_ad_section_start --><p>Following Robin&#8217;s comment on my <a title="Earlier post" href="http://xpomul.bloggles.info/2008/07/24/using-advanced-features-in-eclipse-popup-menus/#comments" target="_blank">earlier post</a> I found the new API (<a title="Eclipse Help" href="http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/workbench_cmd_menus.htm" target="_blank">Extension point description</a> of <strong>org.eclipse.ui.menus</strong>) which unifies all command contributions to Eclipse menus, views, objects, toolbars etc.<span id="more-22"></span></p><p>With this example it requires a lot less code to add an action (well, the new API uses commands) which is visible or enabled dynamically based on an object property. However, at the same time, we have to do quite a bit more extension configurations:</p><p>Instead of a single declaration of an <strong>org.eclipse.ui.popupMenus</strong> extension, we need all this:</p><ul><li>A command (which only declares the abstract concept of the semantic behavior):</li><pre>&lt;extension point="org.eclipse.ui.commands"&gt;
  &lt;command
        description="Do something with a model element"
        id="my.command.id"
        name="Do Something"&gt;
  &lt;/command&gt;
&lt;/extension&gt;</pre><li>A handler (which implements the behavior &#8211; the equivalent to what used to be the <code>ActionDelegate</code>):</li><pre>&lt;extension point="org.eclipse.ui.handlers"&gt;
  &lt;handler
        class="my.contribution.MyCommandHandler"
        commandId="my.command.id"&gt;
  &lt;/handler&gt;
&lt;/extension&gt;</pre><li>A contribution (which connects the command to a menu or action bar):</li><pre>&lt;extension point="org.eclipse.ui.menus"&gt;
  &lt;menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions"&gt;
     &lt;command
           commandId="my.command.id"
           style="push"&gt;
        &lt;visibleWhen&gt;
            &lt;with variable="activeMenuSelection"&gt;
               &lt;iterate&gt;
                  &lt;instanceof
                     value="my.model.MyObject"&gt;
                  &lt;/instanceof&gt;
               &lt;/iterate&gt;
           &lt;/with&gt;
        &lt;/visibleWhen&gt;
     &lt;/command&gt;
  &lt;/menuContribution&gt;
&lt;/extension&gt;</pre></ul><p>Note that the <strong>locationURI </strong>offers a lot of options &#8211; the case above simulates the objectContribution behavior, as the command is added to any popup menu and the visibility is determined by the selected objects&#8217; types.</p><p>Instead of behaving like an objectContribution, we can simply change the <strong>locationURI </strong>to <code>menu:&lt;view-or-menu-id&gt;</code> or to <code>toolbar:&lt;view-or-toolbar-id&gt;</code> in order to contribute the command to a view&#8217;s menu or toolbar, respectively. Naturally, in these cases, we don&#8217;t need the <strong>visibleWhen</strong> constraint.</p><p>The command handler implemtation is a lot simpler than the action delegate handler, as the abstract class <code>org.eclipse.core.commands.AbstractHandler</code> does all the extra work (listener implementation etc.) for us.</p><p>The only method, we have to implement ourselves is <code>execute()</code>:</p><pre>package my.contribution;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

public class MyCommandHandler extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {

		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
		MyObject object = (MyObject) selection.getFirstElement();

		// do something with MyObject
	}

}</pre><p>Again, until here, we only implemented a command which is enabled always. Now, if we want to enable the command only, if the selected model element fulfills a certain constraint, in the old API we needed an adapter.</p><p>In the new API, the adapter is made implicit using the concept of a <strong>PropertyTester</strong>. A <strong>PropertyTester</strong> can be used to add custom testable properties to arbitrary classes. For our example, the declaration and looks like this:</p><pre>&lt;extension point="org.eclipse.core.expressions.propertyTesters"&gt;
      &lt;propertyTester
            class="my.package.MyObjectPropertyTester"
            id="my.proptester.id"
            namespace="my.property.namespace"
            properties="type"
            type="my.model.MyObject"&gt;
      &lt;/propertyTester&gt;
&lt;/extension&gt;</pre><p>and the implementation is as follows:</p><pre>package de.feuh.st.requipse.project;

import org.eclipse.core.expressions.PropertyTester;

public class ArtifactPropertyTester extends PropertyTester {

	@Override
	public boolean test(Object receiver, String property, Object[] args,
			Object expectedValue) {

		MyObject obj = (MyObject)receiver;
		if(property.equals("type")) {
			return expectedValue.equals(obj.getType());
		}
		else {
			return false;
		}
	}
}</pre><p>This way, we have defined a property called <strong>type</strong> in the namespace <strong>my.property.namespace</strong> which applies to objects which are instance of <strong>my.model.MyObject</strong>. The implementation then compares the value of the object&#8217;s <code>getType()</code> method to a given expected value and returns the result.</p><p>As a final step, we have to use the PropertyTester in our handler declaration. We enhance the handler as follows:</p><pre>&lt;extension point="org.eclipse.ui.handlers"&gt;
  &lt;handler
        class="my.contribution.MyCommandHandler"
        commandId="my.command.id"&gt;
     &lt;enabledWhen&gt;
        &lt;with variable="selection"&gt;
           &lt;iterate
                 ifEmpty="false"
                 operator="and"&gt;
              &lt;test
                    property="my.property.namespace.type"
                    value="FOO"&gt;
              &lt;/test&gt;
           &lt;/iterate&gt;
        &lt;/with&gt;
     &lt;/enabledWhen&gt;
  &lt;/handler&gt;
&lt;/extension&gt;</pre><p>This enables the command only if all of the selected objects return &#8220;FOO&#8221; for <code>getType()</code>.</p><p>Further Reading:</p><ul><li><a href="http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/workbench_cmd_menus.htm" target="_self">Eclipse Platform Guide for Workbench Commands</a></li><li><a href="http://pa-blogger.blogspot.com/2008/07/orgeclipseuimenus.html">Blog Entry describing the migration from the old to the new API</a></li><li><a href="http://www.eclipsecon.org/2008/sub/attachments/Using_Commands_and_Menu_Contributions.ppt" target="_self">Using Commands and Menu Contributions (Slides from EclipseCon 2008)</a></li></ul><p><map name='google_ad_map_22_cc04eee439b4d157'><area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/22?pos=0' coords='1,2,367,28'/><area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map><img usemap='#google_ad_map_22_cc04eee439b4d157' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=22&amp;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F08%2F12%2Fadvanced-features-in-eclipse-popup-menus-take-2-the-new-api%2F'/></p>]]></content:encoded> <wfw:commentRss>http://xpomul.bloggles.info/2008/08/12/advanced-features-in-eclipse-popup-menus-take-2-the-new-api/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <media:content url="http://1.gravatar.com/avatar/9409d1d28b5c6abea0f194a89a33e2de?s=96&#38;d=http%3A%2F%2Fs.bloggles.info%2Ffavicon.ico" medium="image"> <media:title type="html">xpomul</media:title> </media:content> <media:thumbnail url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=22&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F08%2F12%2Fadvanced-features-in-eclipse-popup-menus-take-2-the-new-api%2F"/> <media:content url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=22&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F08%2F12%2Fadvanced-features-in-eclipse-popup-menus-take-2-the-new-api%2F" medium="image"/> </item> <item> <title>Adding EOperation body to model</title> <link>http://xpomul.bloggles.info/2008/08/08/adding-eoperation-body-to-model/</link> <comments>http://xpomul.bloggles.info/2008/08/08/adding-eoperation-body-to-model/#comments</comments> <pubDate>Fri, 08 Aug 2008 11:19:06 +0000</pubDate> <dc:creator>xpomul</dc:creator> <category><![CDATA[Eclipse]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[eclipse]]></category> <category><![CDATA[EMF]]></category> <category><![CDATA[java]]></category> <guid isPermaLink="false">http://xpomul.bloggles.info/?p=18</guid> <description><![CDATA[This is just a short notice for an EMF code generator feature which is mostly unknown and not really documented (well, it will be in the EMF 2nd Edition book, but this won&#8217;t be out until December or later).To add a custom body (replacing the usual throw new UnsupportedOperationException body generated by default), follow this [...]]]></description> <content:encoded><![CDATA[<!-- google_ad_section_start --><p>This is just a short notice for an EMF code generator feature which is mostly unknown and not really documented (well, it will be in the <a title="EMF book 2nd edition" href="http://safari.informit.com/9780321331885" target="_blank">EMF 2nd Edition book</a>, but this won&#8217;t be out until December or later).</p><p>To add a custom body (replacing the usual throw new UnsupportedOperationException body generated by default), follow <a title="Step by step tutorial" href="http://blog.cypal-solutions.com/2008/05/adding-util-methods-to-generated-emf.html" target="_self">this step-by-step howto</a>.</p><p><map name='google_ad_map_18_cc04eee439b4d157'><area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/18?pos=0' coords='1,2,367,28'/><area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map><img usemap='#google_ad_map_18_cc04eee439b4d157' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=18&amp;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F08%2F08%2Fadding-eoperation-body-to-model%2F'/></p>]]></content:encoded> <wfw:commentRss>http://xpomul.bloggles.info/2008/08/08/adding-eoperation-body-to-model/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <media:content url="http://1.gravatar.com/avatar/9409d1d28b5c6abea0f194a89a33e2de?s=96&#38;d=http%3A%2F%2Fs.bloggles.info%2Ffavicon.ico" medium="image"> <media:title type="html">xpomul</media:title> </media:content> <media:thumbnail url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=18&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F08%2F08%2Fadding-eoperation-body-to-model%2F"/> <media:content url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=18&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F08%2F08%2Fadding-eoperation-body-to-model%2F" medium="image"/> </item> <item> <title>Using advanced features in Eclipse popup menus</title> <link>http://xpomul.bloggles.info/2008/07/24/using-advanced-features-in-eclipse-popup-menus/</link> <comments>http://xpomul.bloggles.info/2008/07/24/using-advanced-features-in-eclipse-popup-menus/#comments</comments> <pubDate>Thu, 24 Jul 2008 12:57:29 +0000</pubDate> <dc:creator>xpomul</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Eclipse]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[action]]></category> <category><![CDATA[adaption]]></category> <category><![CDATA[eclipse]]></category> <category><![CDATA[EMF]]></category> <category><![CDATA[java]]></category> <guid isPermaLink="false">http://xpomul.bloggles.info/?p=15</guid> <description><![CDATA[One of the first Hello World examples when dealing with contributions to Eclipse extension points is adding an objectContribution or a viewerContribution to a popup menu. However, if one wants to add a more flexible contribution which is hided or disabled in certain circumstances, documentation gets rare.This article describes how to implement these advanced featues [...]]]></description> <content:encoded><![CDATA[<!-- google_ad_section_start --><p>One of the first Hello World examples when dealing with contributions to Eclipse extension points is adding an <strong>objectContribution</strong> or a <strong>viewerContribution</strong> to a popup menu. However, if one wants to add a more flexible contribution which is hided or disabled in certain circumstances, documentation gets rare.</p><p>This article describes how to implement these advanced featues by example. Let&#8217;s assume we have an EMF model of objects <code>MyObject</code> which implement a property called <code>type</code>. EMF can generate item and label providers for tree editors. Let&#8217;s assume we have implemented such an editor and we want to contribute an action which is only visible for a particular type value.</p><p><strong>Update: </strong><em>This article uses the old API of contributing actions to views&#8217; and objects&#8217; popup menus. There is a new API which is described <a href="http://xpomul.bloggles.info/2008/08/12/advanced-features-in-eclipse-popup-menus-take-2-the-new-api/" target="_self">in another post</a>.</em><strong><br/></strong></p><p><span id="more-15"></span>As a first step we implement the corresponding <code>ActionDelegate</code> and register it as an object contribution: This</p><pre>&lt;extension point="org.eclipse.ui.popupMenus"&gt;
   &lt;objectContribution
            adaptable="false"
            id="my.contribution.id"
            objectClass="my.model.MyObject"&gt;
         &lt;action
               class="my.contribution.MyActionDelegate"
               enablesFor="1"
               id="my.contribution.action.id"
               label="Do something only with type FOO"
               menubarPath="additions"&gt;
         &lt;/action&gt;
  &lt;/objectContribution&gt;
&lt;/extension&gt;</pre><p>This way, however, the contribution is visible and enabled always. We want to hide (or disable) it, if <code>selectedObject.getType()</code> is not equal to <code>"FOO"</code>. The <strong>popupMenus</strong> extension point lets us specify <strong>visibility</strong> and <strong>enablement</strong> constraints and we can use the <strong>objectState</strong> element to query the object&#8217;s state. However, this is not as simple as it sounds, because <strong>objectState</strong> can only query objects which implement the <code>IActionFilter</code> interface and since <code>MyObject</code> is a EMF generated class, we cannot simply implement the interface.</p><p>But what we can do, is adapt. So we write an adapter and its factory:</p><pre>public class MyObjectToActionFilterAdapter implements IActionFilter {

	private static final Object MYOBJECT_TYPE = "objectType";

	private static ArtifactToActionFilterAdapter INSTANCE = new ArtifactToActionFilterAdapter();

	private ArtifactToActionFilterAdapter() {}

	@Override
	public boolean testAttribute(Object target, String name, String value) {
		if (target instanceof MyObject) {
			MyObject obj = (MyObject) target;

			if(MYOBJECT_TYPE.equals(name)) {
				return value.equals(obj.getType());
			}
		}

		return false;
	}

	public static ArtifactToActionFilterAdapter getInstance() {
		return INSTANCE;
	}
}

public class MyActionFilterAdapterFactory implements IAdapterFactory {

	@SuppressWarnings("unchecked")
	@Override
	public Object getAdapter(Object adaptableObject, Class adapterType) {
		if(adapterType == IActionFilter.class)
			return MyObjectToActionFilterAdapter.getInstance();
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Class[] getAdapterList() {
		return new Class[] {IActionFilter.class};
	}
}</pre><p>Note that the adapter can be implemented as a singleton because the <code>testAttribute</code> implementation is called with the object to be tested.</p><p>Now we have to register our adapter factory using:</p><pre>&lt;extension point="org.eclipse.core.runtime.adapters"&gt;
      &lt;factory
            adaptableType="my.model.MyObject"
            class="my.contribution.MyActionFilterAdapterFactory"&gt;
         &lt;adapter
               type="org.eclipse.ui.IActionFilter"&gt;
         &lt;/adapter&gt;
      &lt;/factory&gt;
&lt;/extension&gt;</pre><p>and after that we are ready to declare our constraints:</p><pre>&lt;extension point="org.eclipse.ui.popupMenus"&gt;
   &lt;objectContribution
            adaptable="false"
            id="my.contribution.id"
            objectClass="my.model.MyObject"&gt;
         &lt;action
               class="my.contribution.MyActionDelegate"
               enablesFor="1"
               id="my.contribution.action.id"
               label="Do something only with type FOO"
               menubarPath="additions"&gt;
         &lt;/action&gt;
         &lt;visibility&gt;
               &lt;objectState
                     name="objectType"
                     value="FOO"&gt;
               &lt;/objectState&gt;
         &lt;/visibility&gt;
  &lt;/objectContribution&gt;
&lt;/extension&gt;</pre><p>This causes the action to appear only if the property type of <code>MyObject</code> has the value <code>FOO</code>.</p><p>Instead of hiding the action, we can also disable it using the element <strong>&lt;enablement&gt;</strong> istead of <strong>&lt;visibility&gt;</strong>. In this case, however, the <strong>&lt;enablement&gt;</strong> constraint has to be a child of the <strong>&lt;action&gt;</strong> element instead of a sibling.</p><p><map name='google_ad_map_15_cc04eee439b4d157'><area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/15?pos=0' coords='1,2,367,28'/><area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map><img usemap='#google_ad_map_15_cc04eee439b4d157' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=15&amp;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F07%2F24%2Fusing-advanced-features-in-eclipse-popup-menus%2F'/></p>]]></content:encoded> <wfw:commentRss>http://xpomul.bloggles.info/2008/07/24/using-advanced-features-in-eclipse-popup-menus/feed/</wfw:commentRss> <slash:comments>3</slash:comments> <media:content url="http://1.gravatar.com/avatar/9409d1d28b5c6abea0f194a89a33e2de?s=96&#38;d=http%3A%2F%2Fs.bloggles.info%2Ffavicon.ico" medium="image"> <media:title type="html">xpomul</media:title> </media:content> <media:thumbnail url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=15&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F07%2F24%2Fusing-advanced-features-in-eclipse-popup-menus%2F"/> <media:content url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=15&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F07%2F24%2Fusing-advanced-features-in-eclipse-popup-menus%2F" medium="image"/> </item> <item> <title>How to make an Eclipse Plugin Scriptable with Groovy</title> <link>http://xpomul.bloggles.info/2008/07/02/how-to-make-an-eclipse-plugin-scriptable-with-groovy/</link> <comments>http://xpomul.bloggles.info/2008/07/02/how-to-make-an-eclipse-plugin-scriptable-with-groovy/#comments</comments> <pubDate>Wed, 02 Jul 2008 09:26:27 +0000</pubDate> <dc:creator>xpomul</dc:creator> <category><![CDATA[Eclipse]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[eclipse]]></category> <category><![CDATA[groovy]]></category> <category><![CDATA[java]]></category> <guid isPermaLink="false">http://xpomul.bloggles.info/?p=9</guid> <description><![CDATA[Say, you want to implement a quick and flexible automation enhancement to one of your eclipse RCP plugins &#8211; for example, because you are writing some sort of business application in which you always have to create a few standard structures manually in order to play with it and test it.Here&#8217;s how you can do [...]]]></description> <content:encoded><![CDATA[<!-- google_ad_section_start --><p>Say, you want to implement a quick and flexible automation enhancement to one of your eclipse RCP plugins &#8211; for example, because you are writing some sort of business application in which you always have to create a few standard structures manually in order to play with it and test it.</p><p>Here&#8217;s how you can do it the groovy way:</p><ul><li>create a new plugin project that depends on all plug-ins you want the automation script to be able to access.</li><li>download <code>groovy-all-x.y.z.jar</code> from the Groovy homepage and put it into your plug-in&#8217;s runtime classpath.</li><li>create an objectContribution like this:</li><pre>      &lt;objectContribution
            adaptable="false"
            id="myproject.groovyRunner"
            nameFilter="*.groovy"
            objectClass="org.eclipse.core.resources.IFile"&gt;
         &lt;action
               class="myproject.automate.RunGroovyAction"
               enablesFor="1"
               id="myproject.groovyRunnerAction"
               label="Execute as Automation Script"
               menubarPath="additions"&gt;
         &lt;/action&gt;
      &lt;/objectContribution&gt;</pre><li>implement the action like this</li><pre>package myproject.automate;

import java.io.PrintWriter;
import java.io.StringWriter;

import groovy.lang.GroovyClassLoader;

import org.codehaus.groovy.control.ErrorCollector;
import org.codehaus.groovy.control.MultipleCompilationErrorsException;
import org.codehaus.groovy.control.messages.Message;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

import myproject.MyPlugin;

public class RunGroovyAction implements IObjectActionDelegate {

	/** store the parent shell */
	private Shell shell = null;

	/** store the selected file */
	private IFile file;

	@Override
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		shell = targetPart.getSite().getShell();
	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		file = (IFile) ((IStructuredSelection)selection).getFirstElement();
	}

	@Override
	public void run(IAction action) {
		Assert.isNotNull(shell);
		Assert.isNotNull(file);

		try {
			/* initialize the GroovyClassLoader with the Eclipse class loader */
			GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader());

			/* parse the groovy file */
			Class&lt;?&gt; parsed = loader.parseClass(file.getContents());

			/* cast it to runnable (or whatever you like to implement */
			Class&lt;? extends Runnable&gt; clazz = parsed.asSubclass(Runnable.class);

			/* instantiate and rum */
			Runnable r = clazz.newInstance();
			r.run();
		}
		catch(MultipleCompilationErrorsException e) {
			/* report compilation errors in an error dialog */

			StringWriter messages = new StringWriter();
			PrintWriter printWriter = new PrintWriter(messages);

			ErrorCollector ec = e.getErrorCollector();
			if(ec.hasErrors()) {
				for(Object o : ec.getErrors()) {
					((Message) o).write(printWriter);
					printWriter.append('\n');
				}
			}

			Status status = new Status(IStatus.ERROR, MyPlugin.PLUGIN_ID,
					messages.toString(), e);

			ErrorDialog.openError(shell, "Compilation errors", messages.toString(), status);
		} catch(Exception e) {
			/* report all other errors here */

			Status status = new Status(IStatus.ERROR, MyPlugin.PLUGIN_ID,
					"Execution error", e.getCause() == null ? e : e
							.getCause());

			ErrorDialog.openError(shell, "Error", "Execution error", status);
		}
	}
}</pre></ul><p>Now you can run your Eclipse application, create a .groovy class (implementing Runnable in the case above) in a file and run it from within your runtime workspace.</p><p>Happy scripting &#8230;</p><p><map name='google_ad_map_9_cc04eee439b4d157'><area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/9?pos=0' coords='1,2,367,28'/><area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map><img usemap='#google_ad_map_9_cc04eee439b4d157' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=9&amp;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F07%2F02%2Fhow-to-make-an-eclipse-plugin-scriptable-with-groovy%2F'/></p>]]></content:encoded> <wfw:commentRss>http://xpomul.bloggles.info/2008/07/02/how-to-make-an-eclipse-plugin-scriptable-with-groovy/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <media:content url="http://1.gravatar.com/avatar/9409d1d28b5c6abea0f194a89a33e2de?s=96&#38;d=http%3A%2F%2Fs.bloggles.info%2Ffavicon.ico" medium="image"> <media:title type="html">xpomul</media:title> </media:content> <media:thumbnail url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=9&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F07%2F02%2Fhow-to-make-an-eclipse-plugin-scriptable-with-groovy%2F"/> <media:content url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=9&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F07%2F02%2Fhow-to-make-an-eclipse-plugin-scriptable-with-groovy%2F" medium="image"/> </item> <item> <title>Extract BibTeX-Entries used in LaTeX source</title> <link>http://xpomul.bloggles.info/2008/05/09/extract-bibtex-entries-used-in-latex-source/</link> <comments>http://xpomul.bloggles.info/2008/05/09/extract-bibtex-entries-used-in-latex-source/#comments</comments> <pubDate>Fri, 09 May 2008 14:22:22 +0000</pubDate> <dc:creator>xpomul</dc:creator> <category><![CDATA[LaTeX]]></category> <category><![CDATA[bibtex]]></category> <guid isPermaLink="false">http://xpomul.bloggles.info/?p=8</guid> <description><![CDATA[I manage all of my references in a single big BibTeX database (BTW, I do this using JabRef &#8211; a really nice Java tool to manage BibTeX files). Now if I am writing a paper, I first use the big file just because it is easy and I have everything in one place.But when the [...]]]></description> <content:encoded><![CDATA[<!-- google_ad_section_start --><p>I manage all of my references in a single big BibTeX database (BTW, I do this using <a title="JabRef reference manager" href="http://jabref.sourceforge.net/" target="_blank">JabRef</a> &#8211; a really nice Java tool to manage BibTeX files). Now if I am writing a paper, I first use the big file just because it is easy and I have everything in one place.</p><p>But when the paper is finished, I want to throw away all unused references, to optimize the bibtex file and to edit all of the references used in one place (like abbreviating booktitles, because my paper is too long &#8230;). So how to extract all entries needed and throwing away the rest?</p><p>To do this, I found <a href="http://blog.mikezhang.com/2007/07/04/bibtex-entry-extractorsubsetter/" target="_blank">this perl script</a> from Michael Zhang which does exactly what I need. Thanks Mike! Nice work!</p><p><map name='google_ad_map_8_cc04eee439b4d157'><area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/8?pos=0' coords='1,2,367,28'/><area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map><img usemap='#google_ad_map_8_cc04eee439b4d157' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=8&amp;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F05%2F09%2Fextract-bibtex-entries-used-in-latex-source%2F'/></p>]]></content:encoded> <wfw:commentRss>http://xpomul.bloggles.info/2008/05/09/extract-bibtex-entries-used-in-latex-source/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <media:content url="http://1.gravatar.com/avatar/9409d1d28b5c6abea0f194a89a33e2de?s=96&#38;d=http%3A%2F%2Fs.bloggles.info%2Ffavicon.ico" medium="image"> <media:title type="html">xpomul</media:title> </media:content> <media:thumbnail url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=8&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F05%2F09%2Fextract-bibtex-entries-used-in-latex-source%2F"/> <media:content url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=8&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F05%2F09%2Fextract-bibtex-entries-used-in-latex-source%2F" medium="image"/> </item> <item> <title>Eclipse ClassLoading Hell</title> <link>http://xpomul.bloggles.info/2008/04/30/eclipse-classloading-hell/</link> <comments>http://xpomul.bloggles.info/2008/04/30/eclipse-classloading-hell/#comments</comments> <pubDate>Wed, 30 Apr 2008 13:21:27 +0000</pubDate> <dc:creator>xpomul</dc:creator> <category><![CDATA[Eclipse]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[debugging]]></category> <category><![CDATA[eclipse]]></category> <category><![CDATA[java]]></category> <guid isPermaLink="false">http://xpomul.bloggles.info/?p=5</guid> <description><![CDATA[I like Eclipse. It is a really useful tool. It does a lot of magic behind the scenes and after a bit of getting familiar with its API you are able to write quite powerful plug-ins.The bad thing is, that if something bad happens deep inside that magical box, it is quite challenging to analyze [...]]]></description> <content:encoded><![CDATA[<!-- google_ad_section_start --><p>I like Eclipse. It is a really useful tool. It does a lot of magic behind the scenes and after a bit of getting familiar with its API you are able to write quite powerful plug-ins.</p><p>The bad thing is, that if something bad happens deep inside that magical box, it is quite challenging to analyze and understand what exactly is going on.</p><p>My problem had to do with such a case. I am using the Eclipse Modeling Framework (EMF) and my plan is to persist my models using the CDO-Teneo-Hibernate-MySQL bridge. CDO and Teneo are a bit experimental, but they are well supported in the <a title="eclipse.technology.emft" href="http://www.eclipse.org/newsportal/thread.php?group=eclipse.technology.emft" target="_blank">eclipse.technology.emft Newsgroup.</a></p><p>The database persistence uses an approach of mapping arbitrary EMF models to database tables automatically including the dynamic creation of proxies. But as you might guess, all of this requires two sets of plug-ins (CDO and Teneo) as well as the hibernate library (which has further dependencies, e.g. the CGLib to dynamically create proxies) and the database driver library.</p><p>So, last week I ran into massive class loading problems, because the different plugins in the CDO and Teneo projects make use of the Hibernate libraries and manage access to them through a rather heterogeneous collection of exporting and importing packages and making use of the <code>Eclipse-BuddyPolicy</code> tag. Using this tag, for example, a user-contributed plugin can contribute the database driver class to the classpath of an existing plug-in.</p><p>However, one of the problems was caused by the fact, that the CGLib Java Bytecode generator was going to build a proxy for a class defined in another bundle (let&#8217;s say A) but at the same time also needed to incorporate the HibernateProxy interface (which was in the hibernate library in bundle B). And there is no dependency between A and B, because hibernate is a strategy add-on to CDO. Consequently, the class generation went awfully wrong because CGLib would take the classloader associated with its input class (so classloader of bundle A) which of course did not find the HibernateProxy interface from bundle B.</p><p>Back then I did not know all that. I only got an exception with a stack trace like this:</p><pre>net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException--&gt;null
   at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
   at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
   at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
   at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:127)
   at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
   at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
   at org.hibernate.tuple.entity.AbstractEntityTuplizer.(AbstractEntityTuplizer.java:135)
   at org.hibernate.tuple.entity.PojoEntityTuplizer.(PojoEntityTuplizer.java:55)
   at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.(EntityEntityModeToTuplizerMapping.java:56)
   at org.hibernate.tuple.entity.EntityMetamodel.(EntityMetamodel.java:302)
   at org.hibernate.persister.entity.AbstractEntityPersister.(AbstractEntityPersister.java:434)
   at org.hibernate.persister.entity.JoinedSubclassEntityPersister.(JoinedSubclassEntityPersister.java:91)
   at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:58)
   at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:226)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
   at org.eclipse.emf.cdo.server.internal.hibernate.HibernatePackageHandler.getSessionFactory(HibernatePackageHandler.java:273)
   ... some more
Caused by: java.lang.reflect.InvocationTargetException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
   at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
   ... 74 more
Caused by: java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(Unknown Source)
   ... 80 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.proxy.HibernateProxy
   at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:481)
   at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:397)
   at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:385)
   at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClassInternal(Unknown Source)
   ... 82 more
</pre><p><em>What &#8230;?</em> I thought. CDO calls Hibernate calls CGLib and CGLib can not locate a Hibernate class? So I went digging through the internet tried to understand class loading in Eclipse I found a good <a title="Eclipse VMs and ClassLoaders" href="http://www.eclipsezone.com/articles/eclipse-vms/" target="_blank">article</a> and this <a title="EclipsePedia" href="http://wiki.eclipse.org/index.php/Context_Class_Loader_Enhancements" target="_blank">Eclipsepedia Entry</a> which provide some insight.</p><p>However, this did not really help. If you are stuck somewhere with a ClassNotFoundException, because you don&#8217;t know, which class loader was being used to load the class (and failed), you have a problem. Both setting an exception breakpoint and stepping through the execution using the debugger is a bad idea, because there are so many class loads &#8211; and also many failing class loads &#8211; in Eclipse, that both methods are cumbersome.</p><p>A better way to gain information is enabling tracing and activating the class loader trace in org.eclipse.osgi:</p><p><img src="http://xpomul.bloggles.info/files/2008/04/2.png" alt="Enabling OSGi ClassLoader tracing"/></p><p>This leads to output like this:</p><pre>BundleClassLoader[org.eclipse.emf.teneo_0.8.0.qualifier].loadClass(org.eclipse.emf.teneo.annotations.pannotation.DiscriminatorValue)
BundleLoader[org.eclipse.emf.teneo_0.8.0.qualifier].loadBundleClass(org.eclipse.emf.teneo.annotations.pannotation.DiscriminatorValue)
BundleLoader[org.eclipse.emf.teneo.annotations_0.8.0.qualifier].findLocalClass(org.eclipse.emf.teneo.annotations.pannotation.DiscriminatorValue)
BundleLoader[org.eclipse.emf.teneo.annotations_0.8.0.qualifier] found local class org.eclipse.emf.teneo.annotations.pannotation.DiscriminatorValue
</pre><p>So you can see in which bundle (in sqare brackets) the classloader looks for your class. This helped me find out, what was going on (described above). To solve my problem, I had to patch the two of the CDO manifests to make the classloader find the additional classes.</p><p>One way or another, all that classpath magic is hard to see through, when it comes to dynamic code generation and third party libraries in eclipse.</p><p>As a final note: I came over <a title="Classloading in Eclipse" href="http://www.martinlippert.com/publications/JS-Classloading-in-Eclipse-final-web.pdf" target="_blank">another article (in German)</a>, which does not directly address my issues, but could be helpful when you have several plug-ins which have to load different classes from different bundles.</p><p><map name='google_ad_map_5_cc04eee439b4d157'><area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/5?pos=0' coords='1,2,367,28'/><area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map><img usemap='#google_ad_map_5_cc04eee439b4d157' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=5&amp;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F04%2F30%2Feclipse-classloading-hell%2F'/></p>]]></content:encoded> <wfw:commentRss>http://xpomul.bloggles.info/2008/04/30/eclipse-classloading-hell/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <media:content url="http://1.gravatar.com/avatar/9409d1d28b5c6abea0f194a89a33e2de?s=96&#38;d=http%3A%2F%2Fs.bloggles.info%2Ffavicon.ico" medium="image"> <media:title type="html">xpomul</media:title> </media:content> <media:thumbnail url="http://xpomul.bloggles.info/files/2008/04/2.png"/> <media:content url="http://xpomul.bloggles.info/files/2008/04/2.png" medium="image"> <media:title type="html">Enabling OSGi ClassLoader tracing</media:title> </media:content> <media:content url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=5&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F04%2F30%2Feclipse-classloading-hell%2F" medium="image"/> </item> <item> <title>Useful Eclipse Java Editor Templates: EasyMock</title> <link>http://xpomul.bloggles.info/2008/04/24/useful-eclipse-java-editor-templates-easymock/</link> <comments>http://xpomul.bloggles.info/2008/04/24/useful-eclipse-java-editor-templates-easymock/#comments</comments> <pubDate>Thu, 24 Apr 2008 09:54:45 +0000</pubDate> <dc:creator>xpomul</dc:creator> <category><![CDATA[Eclipse]]></category> <category><![CDATA[eclipse]]></category> <category><![CDATA[java]]></category> <category><![CDATA[templates]]></category> <guid isPermaLink="false">http://xpomul.bloggles.info/?p=4</guid> <description><![CDATA[EasyMock is a really useful tool for unit testing. If you want to test a class which is usually contained in a web of collaboration with other classes, you can easily simulate the other classes&#8217; behaviour using a rather simple and powerful mocking mechanism.And in order to save typing time, you can use this template [...]]]></description> <content:encoded><![CDATA[<!-- google_ad_section_start --><p><a title="EasyMock" href="http://www.easymock.org" target="_blank">EasyMock</a> is a really useful tool for unit testing. If you want to test a class which is usually contained in a web of collaboration with other classes, you can easily simulate the other classes&#8217; behaviour using a rather simple and powerful mocking mechanism.</p><p>And in order to save typing time, you can use this template to create your mock with one keystroke:</p><pre>${staticImport:importStatic('org.easymock.EasyMock.*')}
${testType:newName} ${cursor} ${mock:newName} = createMock("${mock}", ${testType}.class);
</pre><p>And, as usual, you can directly import the template using <a title="this XML" href="http://www.winklerweb.net/files/easymock-template.xml" target="_blank">this XML</a>.</p><p><map name='google_ad_map_4_cc04eee439b4d157'><area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/4?pos=0' coords='1,2,367,28'/><area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map><img usemap='#google_ad_map_4_cc04eee439b4d157' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=4&amp;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F04%2F24%2Fuseful-eclipse-java-editor-templates-easymock%2F'/></p>]]></content:encoded> <wfw:commentRss>http://xpomul.bloggles.info/2008/04/24/useful-eclipse-java-editor-templates-easymock/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <media:content url="http://1.gravatar.com/avatar/9409d1d28b5c6abea0f194a89a33e2de?s=96&#38;d=http%3A%2F%2Fs.bloggles.info%2Ffavicon.ico" medium="image"> <media:title type="html">xpomul</media:title> </media:content> <media:thumbnail url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=4&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F04%2F24%2Fuseful-eclipse-java-editor-templates-easymock%2F"/> <media:content url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=4&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F04%2F24%2Fuseful-eclipse-java-editor-templates-easymock%2F" medium="image"/> </item> <item> <title>Useful Eclipse Java Editor Templates: Error handling</title> <link>http://xpomul.bloggles.info/2008/04/24/useful-eclipse-java-editor-templates-error-handling/</link> <comments>http://xpomul.bloggles.info/2008/04/24/useful-eclipse-java-editor-templates-error-handling/#comments</comments> <pubDate>Thu, 24 Apr 2008 09:48:26 +0000</pubDate> <dc:creator>xpomul</dc:creator> <category><![CDATA[Eclipse]]></category> <category><![CDATA[eclipse]]></category> <category><![CDATA[java]]></category> <category><![CDATA[templates]]></category> <guid isPermaLink="false">http://xpomul.bloggles.info/?p=3</guid> <description><![CDATA[So you are writing Eclipse Plugin code and have to catch exceptions? Ok, but what to do with them?e.printStackTrace() is not very nice. And in order to report it to the user or to log it in the plugin&#8217;s log, you have to create an instance of Status first.Here is a template you can use [...]]]></description> <content:encoded><![CDATA[<!-- google_ad_section_start --><p>So you are writing Eclipse Plugin code and have to catch exceptions? Ok, but what to do with them?</p><p><code>e.printStackTrace()</code> is not very nice. And in order to report it to the user or to log it in the plugin&#8217;s log, you have to create an instance of <code>Status</code> first.</p><p>Here is a template you can use in your exception hander to save typing time:</p><pre>Status ${status:newName(org.eclipse.core.runtime.Status)} = new Status(
	IStatus.ERROR, ${plugin:link(Activator)}.PLUGIN_ID,
	"Error while ${cause:link(evaluating)}",
	${exception_variable_name}.getCause() == null ? ${exception_variable_name} : ${exception_variable_name}.getCause());

${plugin}.getDefault().getLog().log(${status});
ErrorDialog.openError(getShell(), "Error", "Error while ${cause}", ${status});</pre><p>Again, you can use <a title="this XML" href="http://www.winklerweb.net/files/exception-template.xml" target="_blank">this XML</a> to import the template directly.</p><p><map name='google_ad_map_3_cc04eee439b4d157'><area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/3?pos=0' coords='1,2,367,28'/><area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map><img usemap='#google_ad_map_3_cc04eee439b4d157' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=3&amp;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F04%2F24%2Fuseful-eclipse-java-editor-templates-error-handling%2F'/></p>]]></content:encoded> <wfw:commentRss>http://xpomul.bloggles.info/2008/04/24/useful-eclipse-java-editor-templates-error-handling/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <media:content url="http://1.gravatar.com/avatar/9409d1d28b5c6abea0f194a89a33e2de?s=96&#38;d=http%3A%2F%2Fs.bloggles.info%2Ffavicon.ico" medium="image"> <media:title type="html">xpomul</media:title> </media:content> <media:thumbnail url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=3&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F04%2F24%2Fuseful-eclipse-java-editor-templates-error-handling%2F"/> <media:content url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=3&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F04%2F24%2Fuseful-eclipse-java-editor-templates-error-handling%2F" medium="image"/> </item> <item> <title>Useful Eclipse Java Editor Templates: Tracing</title> <link>http://xpomul.bloggles.info/2008/04/24/useful-eclipse-java-editor-templates-tracing/</link> <comments>http://xpomul.bloggles.info/2008/04/24/useful-eclipse-java-editor-templates-tracing/#comments</comments> <pubDate>Thu, 24 Apr 2008 08:56:49 +0000</pubDate> <dc:creator>xpomul</dc:creator> <category><![CDATA[Eclipse]]></category> <category><![CDATA[eclipse]]></category> <category><![CDATA[java]]></category> <category><![CDATA[templates]]></category> <guid isPermaLink="false">http://xpomul.bloggles.info/?p=2</guid> <description><![CDATA[In this blog I&#8217;ll collect some nice Eclipse Java code templates which I use.I did not find any site collecting those, so there is no place I know of, where one can commit his favourite templates. So here we go:Adding a trace boolean in order to switch on or off tracing of a plugin:This inserts [...]]]></description> <content:encoded><![CDATA[<!-- google_ad_section_start --><p>In this blog I&#8217;ll collect some nice Eclipse Java code templates which I use.</p><p>I did not find any site collecting those, so there is no place I know of, where one can commit his favourite templates. So here we go:</p><h3>Adding a <em>trace</em> boolean in order to switch on or off tracing of a plugin:</h3><p>This inserts a static boolean which can be used to turn tracing on or off using the Tracing tab in the launch configuration dialog. In order to use this, you also have to create a file called <code>.options</code> in your project root. In this file add the line <code>&lt;project name&gt;/&lt;type name&gt;/debug=false</code>.</p><p>And here comes the template. Use it at class level:</p><pre>	private static boolean trace = false;

	static {
		String value = Platform
				.getDebugOption("${enclosing_project}/${enclosing_type}/debug");
		if (value != null &amp;&amp; value.equalsIgnoreCase("true")) {
			trace = true;
		}
	}</pre><h3>Quickly insert a method trace:</h3><p>If the trace infrastructure is set up, a method call can be logged very quickly using</p><pre>if(trace) {
	System.out.println("${enclosing_type}.${enclosing_method}()");
}</pre><p>at the beginning of the method.</p><h3>Generic trace output:</h3><p>In the middle of a method, use this:</p><pre>if(trace) {
    System.out.println("  ${cursor}");
}</pre><p>In order to import these templates, go to the Eclipse preferences dialog, navigate to Java &gt; Editor &gt; Templates and import <a title="this XML" href="http://www.winklerweb.net/files/tracing-templates.xml" target="_blank">this XML</a>.</p><p><map name='google_ad_map_2_cc04eee439b4d157'><area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/2?pos=0' coords='1,2,367,28'/><area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map><img usemap='#google_ad_map_2_cc04eee439b4d157' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=2&amp;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F04%2F24%2Fuseful-eclipse-java-editor-templates-tracing%2F'/></p>]]></content:encoded> <wfw:commentRss>http://xpomul.bloggles.info/2008/04/24/useful-eclipse-java-editor-templates-tracing/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <media:content url="http://1.gravatar.com/avatar/9409d1d28b5c6abea0f194a89a33e2de?s=96&#38;d=http%3A%2F%2Fs.bloggles.info%2Ffavicon.ico" medium="image"> <media:title type="html">xpomul</media:title> </media:content> <media:thumbnail url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=2&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F04%2F24%2Fuseful-eclipse-java-editor-templates-tracing%2F"/> <media:content url="http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&#38;client=&#38;channel=&#38;output=png&#38;cuid=2&#38;url= http%3A%2F%2Fxpomul.bloggles.info%2F2008%2F04%2F24%2Fuseful-eclipse-java-editor-templates-tracing%2F" medium="image"/> </item> </channel></rss>
<!--WP-HTML-Compression crunched this document by 2%. The file was 59051 bytes, but is now 57868 bytes--><!-- Compression = gzip -->