<?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>Eclipse Papercuts &#187; Eclipse</title>
	<atom:link href="http://www.vogella.de/blog/tag/eclipse/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vogella.de/blog</link>
	<description>Tips around Java, Eclipse and Web programming</description>
	<lastBuildDate>Wed, 08 Sep 2010 07:33:56 +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>Joining Eclipse IRC</title>
		<link>http://www.vogella.de/blog/2010/04/02/eclipse-irc/</link>
		<comments>http://www.vogella.de/blog/2010/04/02/eclipse-irc/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 13:41:41 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[irc]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=2062</guid>
		<description><![CDATA[I recently became aware that the Eclipse developer comm [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.vogella.de/blog/2010/04/02/eclipse-irc/";
		var dzone_title = "Joining Eclipse IRC";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>I recently became aware that the Eclipse developer community also uses IRC for their communication.<br />
<a href="http://www.vogella.de/blog/wp-content/uploads/2010/04/1213619_78295027.jpg"><img src="http://www.vogella.de/blog/wp-content/uploads/2010/04/1213619_78295027-231x300.jpg" alt="" width="231" height="300" class="aligncenter size-medium wp-image-2286" /></a></p>
<p>See <a href="http://wiki.eclipse.org/IRC">http://wiki.eclipse.org/IRC</a> for details.</p>
<p>A nice firefox IRC plugin is <a href="http://chatzilla.hacksrus.com">chatzilla</a>. In case you cannot use a IRC client directly you can use this webclient: <a href="http://webchat.freenode.net/">http://webchat.freenode.net/</a>.</p>
<p>Join for example #eclipse, #eclipse-dev or #eclipse-e4 to discuss Eclipse development issues. </p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2010/04/02/eclipse-irc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse RCP &#8211; Removing the minimize and maximize buttons from Views</title>
		<link>http://www.vogella.de/blog/2009/11/13/rcp-minimize-maximize-view/</link>
		<comments>http://www.vogella.de/blog/2009/11/13/rcp-minimize-maximize-view/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 01:03:47 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[RCP]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=1269</guid>
		<description><![CDATA[I got the question how someone could remove the maximiz [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.vogella.de/blog/2009/11/13/rcp-minimize-maximize-view/";
		var dzone_title = "Eclipse RCP &#8211; Removing the minimize and maximize buttons from Views";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>I got the question how someone could remove the maximize and minimize buttons from a view in an Eclipse RCP application.</p>
<p>To archive this I know two ways. </p>
<p>Either set the layout to fixed in initialLayout() in Perspective.java</p>
<pre class="brush: java;">

package de.vogella.intro.rcp.fixedview;

import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

public class Perspective implements IPerspectiveFactory {

	public void createInitialLayout(IPageLayout layout) {
		String editorArea = layout.getEditorArea();
		layout.setEditorAreaVisible(false);
		layout.setFixed(true);

//		layout.addStandaloneView(View.ID,  false, IPageLayout.LEFT, 1.0f, editorArea);
	}

}
</pre>
<p>Or use the Perspective.java to add a standalone view.</p>
<pre class="brush: java;">

package de.vogella.intro.rcp.fixedview;

import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

public class Perspective implements IPerspectiveFactory {

	public void createInitialLayout(IPageLayout layout) {
		String editorArea = layout.getEditorArea();
		layout.setEditorAreaVisible(false);
//		layout.setFixed(true);

		layout.addStandaloneView(View.ID,  false, IPageLayout.LEFT, 1.0f, editorArea);
	}

}
</pre>
<p>If I add a standalone view via the extension &#8220;org.eclipse.ui.perspectiveExtensions&#8221; then the minimize and maximize buttons are still there. </p>
<pre class="brush: java;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;?eclipse version=&quot;3.4&quot;?&gt;
&lt;plugin&gt;

   &lt;extension
         id=&quot;application&quot;
         point=&quot;org.eclipse.core.runtime.applications&quot;&gt;
      &lt;application&gt;
         &lt;run
               class=&quot;de.vogella.intro.rcp.fixedview.Application&quot;&gt;
         &lt;/run&gt;
      &lt;/application&gt;
   &lt;/extension&gt;
   &lt;extension
         point=&quot;org.eclipse.ui.perspectives&quot;&gt;
      &lt;perspective
            name=&quot;Perspective&quot;
            class=&quot;de.vogella.intro.rcp.fixedview.Perspective&quot;
            id=&quot;de.vogella.intro.rcp.fixedview.perspective&quot;&gt;
      &lt;/perspective&gt;
   &lt;/extension&gt;
   &lt;extension
         point=&quot;org.eclipse.ui.views&quot;&gt;
      &lt;view
            name=&quot;View&quot;
            class=&quot;de.vogella.intro.rcp.fixedview.View&quot;
            id=&quot;de.vogella.intro.rcp.fixedview.view&quot;&gt;
      &lt;/view&gt;
   &lt;/extension&gt;
   &lt;extension
         point=&quot;org.eclipse.ui.perspectiveExtensions&quot;&gt;
      &lt;perspectiveExtension
            targetID=&quot;*&quot;&gt;
         &lt;view
               id=&quot;de.vogella.intro.rcp.fixedview.view&quot;
               minimized=&quot;false&quot;
               ratio=&quot;1.0f&quot;
               relationship=&quot;left&quot;
               relative=&quot;org.eclipse.ui.editorss&quot;
               standalone=&quot;true&quot;
               visible=&quot;true&quot;&gt;
         &lt;/view&gt;
      &lt;/perspectiveExtension&gt;
   &lt;/extension&gt;

&lt;/plugin&gt;
</pre>
<p><strong>The behavior seems inconsistent.</strong> If I use coding to add a standalone view the minimize / maximize buttons are not there, if I use extension points they are still there. </p>
<p>Does anymore know if I&#8217;m missing something? Or is this a bug? If you know please comment on this blog post or contact me via <a href="http://twitter.com/vogella">twitter</a>. </p>
<p><strong>Update</strong>: Projekt attached.</p>
<p><a href='http://www.vogella.de/blog/wp-content/uploads/2009/11/FixedView1.zip'>FixedView.zip</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/11/13/rcp-minimize-maximize-view/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>JavaScript in the SWT Browser widget</title>
		<link>http://www.vogella.de/blog/2009/10/29/javascript-swt-browser-widget/</link>
		<comments>http://www.vogella.de/blog/2009/10/29/javascript-swt-browser-widget/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 13:14:49 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[SWT]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=1252</guid>
		<description><![CDATA[At the Eclipse Summit Europe I listened to a talk of Bo [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.vogella.de/blog/2009/10/29/javascript-swt-browser-widget/";
		var dzone_title = "JavaScript in the SWT Browser widget";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>At the Eclipse Summit Europe I listened to a <a href="http://www.eclipsecon.org/summiteurope2009/sessions?id=1035">talk of Boris Bokowski </a> about Eclipse and the Web.</p>
<p>Among other things I learned that you can execute JavaScript directly on the SWT Browser Widget and I wanted to give a tiny example for this.</p>
<p>This Eclipse view will for example load my webpage and then execute a tiny JavaScript (alert(&#8220;1&#8243;);) in the browser.</p>
<pre class="brush: java;">

package de.vogella.swtbrowser;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

public class View extends ViewPart {

	public static final String ID = &quot;de.vogella.swtbrowser.view&quot;;

	public void createPartControl(Composite parent) {
		final Browser b = new Browser(parent, SWT.NONE);
		b.setUrl(&quot;www.vogella.de&quot;);
		b.addProgressListener(new ProgressListener() {
			@Override
			public void completed(ProgressEvent event) {
				System.out.println(&quot;Page loaded&quot;);
				System.out.println(b.execute(&quot;alert(\&quot;1\&quot;);&quot;));
			}
			@Override
			public void changed(ProgressEvent event) {
			}
		});
	}

	/**
	 * Passing the focus request to the viewer's control.
	 */
	public void setFocus() {
	}
}
</pre>
<p>Thanks to Boris for the great talk. </p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/10/29/javascript-swt-browser-widget/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>API for reading Eclipse plugin dependencies</title>
		<link>http://www.vogella.de/blog/2009/10/19/eclipse-plugin-dependencies/</link>
		<comments>http://www.vogella.de/blog/2009/10/19/eclipse-plugin-dependencies/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 05:04:02 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[bundle]]></category>
		<category><![CDATA[Commands]]></category>
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=1241</guid>
		<description><![CDATA[The Eclipse platform provides an API to allows that you [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.vogella.de/blog/2009/10/19/eclipse-plugin-dependencies/";
		var dzone_title = "API for reading Eclipse plugin dependencies";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>The Eclipse platform provides an API to allows that you can access in information of the MANIFEST.MF. For example you could read the dependencies of your plugin. </p>
<p>For this example create a plugin &#8220;de.vogella.pde.dependencies&#8221;. See <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html">Eclipse Plugin development</a> for examples on how to develop plugins. Use the &#8220;Hello, World Command&#8221; template.</p>
<p>Define dependendies to the following plugins:<br />
 &#8211; org.eclipse.ui<br />
 &#8211;  org.eclipse.core.runtime</p>
<p>Change the command to the following. </p>
<pre class="brush: java;">

package de.vogella.pde.dependencies.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;

public class PrintDependencies extends AbstractHandler {
	public Object execute(ExecutionEvent event) throws ExecutionException {
		String requireBundle = (String)Platform.getBundle(&quot;de.vogella.pde.dependencies&quot;).getHeaders().get(
				Constants.REQUIRE_BUNDLE);
				try {
					ManifestElement[] elements = ManifestElement.parseHeader(
					Constants.BUNDLE_CLASSPATH, requireBundle);
					for (ManifestElement manifestElement : elements) {
						System.out.println( manifestElement.getValue());
					}
				} catch (BundleException e) {
					e.printStackTrace();
				}
		return null;
	}
}
</pre>
<p>If you now run your new plugin it and select your command it will print out the dependencies of your plugin. </p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/10/19/eclipse-plugin-dependencies/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Eclipse Papercut #5 &#8211; Getting external libraries as bundles</title>
		<link>http://www.vogella.de/blog/2009/09/21/eclipse-plugin-libraries/</link>
		<comments>http://www.vogella.de/blog/2009/09/21/eclipse-plugin-libraries/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 05:45:11 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Papercut]]></category>
		<category><![CDATA[bundle]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=548</guid>
		<description><![CDATA[Explains why Eclipse Plugins are improving the definiti [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.vogella.de/blog/2009/09/21/eclipse-plugin-libraries/";
		var dzone_title = "Eclipse Papercut #5 &#8211; Getting external libraries as bundles";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>In this episode of <a href="http://www.vogella.de/blog/?p=385">Eclipse Papercuts</a> I explain how you get bundles for popolar Java libraries for your  <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html">Eclipse plugin</a> development. </p>
<p>I believe it has advantages to work with plugin projects instead of pure Java projects even if the plan is not to create <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html">Eclipse plugins</a> / <a href="http://www.vogella.de/articles/RichClientPlatform/article.html">RCP applications</a>.  </p>
<p>The core strength of OSGi for this scenario is in my opinion the encapsalation and protection of your inner classes. With <a href="http://www.vogella.de/articles/OSGi/article.html">OSGi bundles </a>  you decide which packages of your project are exported and therefore visible to other projects (via the tab Runtime in the editor for the file plugin.xml).</p>
<p>This leaves only one problem: If you are using externally libraries you <a href="http://www.vogella.de/articles/EclipseJarToPlugin/article.html">have to convert them into bundles / plugins</a>.</p>
<p>I would be nicer to consume pre-packages bundles. As I created a bug <a href="http://sourceforge.net/tracker/?func=detail&amp;aid=2860779&amp;group_id=15255&amp;atid=365255">iText should be OSGi</a> and <a href="http://twitter.com/vogella">tweeted </a>about it <a href="http://aniszczyk.org/">Chris Aniszczyk</a> pointed me to <a href="http://www.eclipse.org/orbit/">Eclipse Orbit</a>.</p>
<p>Eclipse Orbit provides lots of standard libraries already pre-packaged as bundles / plugins. </p>
<p>Lets see how you could get the iText version from Orbit. Check the <a href="http://wiki.eclipse.org/index.php/Orbit_Faq">Orbit FAQ </a>to find out more.</p>
<p>You need to <a href="http://www.vogella.de/articles/EclipseCodeAccess/article.html#versioncontrol_cvs">connect via cvs </a> to the Eclipse cvs repository. CVS URL is :pserver:anonymous@dev.eclipse.org/cvsroot/tools</p>
<p>Navigate to &#8220;org.eclipse.orbit&#8221;. Select &#8220;com.lowagie.text&#8221; and check it out.</p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/09/orbit10.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/09/orbit10.gif" alt="orbit10" width="388" height="138" class="aligncenter size-full wp-image-1125" /></a></p>
<p>Orbit keeps the different version of the library as cvs branches. Select your project and select Replace With -&gt; Another Branch or Version&#8230;<br />
<a href="http://www.vogella.de/blog/wp-content/uploads/2009/09/orbit20.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/09/orbit20.gif" alt="orbit20" width="586" height="560" class="aligncenter size-full wp-image-1126" /></a></p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/09/orbit30.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/09/orbit30.gif" alt="orbit30" width="447" height="321" class="aligncenter size-full wp-image-1142" /></a></p>
<p>After selecting the branch and pressing ok the system will download the library and you can start using the library.</p>
<p>In addition to Orbit you can also use the <a href="http://www.springsource.com/repository/app/">Springsource bundle repository</a>. On this website you can search for bundles and download then directly. You can then import them as plugin projects into your workspace. </p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/09/21/eclipse-plugin-libraries/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Eclipse Papercut #4 &#8211; Modifying Eclipse PDE default launch configuration</title>
		<link>http://www.vogella.de/blog/2009/07/27/modify-eclipse-pde-code/</link>
		<comments>http://www.vogella.de/blog/2009/07/27/modify-eclipse-pde-code/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 09:29:27 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Papercut]]></category>
		<category><![CDATA[PDE]]></category>
		<category><![CDATA[Planet]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=603</guid>
		<description><![CDATA[Explains how to change the default PDE launch configura [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.vogella.de/blog/2009/07/27/modify-eclipse-pde-code/";
		var dzone_title = "Eclipse Papercut #4 &#8211; Modifying Eclipse PDE default launch configuration";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>In this episode of the <a href="http://www.vogella.de/blog/category/papercut/"> Eclipse Papercut series </a> I will change the default PDE launch configuration. During this process I show how to get and modify Eclipse PDE code.</p>
<p>Lets define the papercut: </p>
<p>One thing I always have to do during <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html">plugin </a>and <a href="http://www.vogella.de/articles/RichClientPlatform/article.html">Eclipse RCP</a> development is to make the following settings in the launch configuration:</p>
<ol>
<li><a href="http://www.vogella.de/articles/RichClientPlatform/article.html#runconfiguration_parameters">add -consoleLog in the arguments tab </a></li>
<li><a href="http://www.vogella.de/articles/RichClientPlatform/article.html#runconfiguration_check">Select the flag &#8220;Validate plug-in automatically prio to launching&#8221; on the plug-ins tab</a></li>
</ol>
<p>This papercut has two dimensions. </p>
<p>The first one is that for everybody who knows about these settings it is not a problem to set them up. It is just time-consuming and error prone. Sometimes I&#8217;m searching why something does not work and then I&#8217;m banging my head because I forgot to set -consoleLog.</p>
<p>The second dimension is that this default launch configuration makes it harder for new plugin and Eclipse RCP developers to get started. I frequently see questions in the Eclipse newsgroup and other places which can be answered by: &#8220;please set -consoleLog&#8221; or &#8220;press the Validate button&#8221;.</p>
<p>So I seek to change the current behavior.</p>
<p>Adding &#8220;-consoleLog&#8221; is easy. Go to preference, select the target platform, select &#8220;Edit&#8221; and add -consoleLog as a argument. </p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/07/target10.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/07/target10.gif" alt="target10" width="655" height="421" class="alignnone size-full wp-image-647" /></a></p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/07/target20.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/07/target20.gif" alt="target20" width="664" height="294" class="alignnone size-full wp-image-648" /></a></p>
<p>Of course this does not help the new developers but I come back to this later in this post.</p>
<p>To set the &#8220;Validate plug-in automatically prio to launching&#8221; flag we have to look into Eclipse PDE code. </p>
<p>A launch configuration is contributed by the extension point &#8220;org.eclipse.debug.core.launchConfigurationTypes&#8221;. To search through your existing plugins <a href="http://www.vogella.de/articles/EclipseCodeAccess/article.html#importplugins">import your plugins into a new workspace</a>. A <a href="http://www.vogella.de/articles/EclipseCodeAccess/article.html#search_plugin">plugin search</a> reveals that &#8220;org.eclipse.pde.ui&#8221; contributes such an extension.</p>
<p>Eclipse PDE can be found in the <a href="http://wiki.eclipse.org/index.php/CVS_Howto">Eclipse cvs</a> via the repository path &#8220;/cvsroot/eclipse&#8221;. Search here for the folder &#8220;pde&#8221; which contains the pde plugins. Checkout the plugin &#8220;org.eclipse.pde.ui&#8221;. </p>
<p>Here we find quickly the right extension point.</p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/07/pde10.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/07/pde10-300x133.gif" alt="pde10" width="300" height="133" class="alignnone size-medium wp-image-656" /></a></p>
<p>After some pocking around the code and some <a href="http://www.vogella.de/articles/EclipseDebugging/article.html">debugging </a> I found the class &#8220;AbstractPluginBlock&#8221; and the method &#8220;setDefaults&#8221;. The change is trivial:</p>
<pre class="brush: java;">
public void setDefaults(ILaunchConfigurationWorkingCopy config) {
	config.setAttribute(IPDELauncherConstants.INCLUDE_OPTIONAL, true);
	config.setAttribute(IPDELauncherConstants.AUTOMATIC_ADD, true);
	config.setAttribute(IPDELauncherConstants.AUTOMATIC_VALIDATE, true); // This has changed from false to true
	config.setAttribute(IPDELauncherConstants.SHOW_SELECTED_ONLY, false);
}
</pre>
<p>If you now run Eclipse with this adjusted plugin the flag &#8220;Validate&#8230;&#8221; will be flagged for a new runtime configuration. </p>
<p>Now lets return to the addtion of &#8220;-consoleLog&#8221; to the target platform. I argued earlier that the absence of &#8220;-consoleLog&#8221; makes it harder for beginner to get started with plugin and RCP development. Changing the target platform is not trivial for starters, so the better solution was if was part of the standard code. </p>
<p>We find the relevant code easily with a text seach for an existing launch parameter, e.g. &#8220;-arch&#8221;. The responsible class is &#8220;LaunchArgumentsHelper&#8221; and the method getInitialProgramArguments(). We add &#8220;-consoleLog&#8221; to the following line:</p>
<pre class="brush: java;">

StringBuffer buffer = new StringBuffer(&quot;-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog&quot;); //$NON-NLS-1$
</pre>
<p>Thats it. By <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html#deployplugin">deploying the plugin </a>into our Eclipse IDE we have the changed behavior.</p>
<p>I have submitted bugs and attached the patches. <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=272076">Bug Report for &#8220;Validate plug-in automatically prio to launching&#8221;</a> and <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=284704"> Bug Report for -consoleLog</a>.</p>
<p>I hope that these patches will get accepted. If they would be accepted I believe it would be a little easier for new developers to get started.</p>
<p>If someone finds a reason why these settings should not always be the default I would suggest a new PDE <a href="http://www.vogella.de/articles/EclipsePreferences/article.html"> preference page</a> which contains the settings for these launch parameters. </p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/07/27/modify-eclipse-pde-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello Planet Eclipse,</title>
		<link>http://www.vogella.de/blog/2009/07/24/hello-planet-eclipse/</link>
		<comments>http://www.vogella.de/blog/2009/07/24/hello-planet-eclipse/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 17:44:57 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Planet]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=609</guid>
		<description><![CDATA[My blog posts are now aggregated on  Planet Eclipse  an [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.vogella.de/blog/2009/07/24/hello-planet-eclipse/";
		var dzone_title = "Hello Planet Eclipse,";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>My blog posts are now aggregated on <a href="http://www.planeteclipse.org/planet/"> Planet Eclipse </a> and I want to follow the ancient tradition of introducing myself. </p>
<p>I try to help others to learn the Eclipse platform by providing <a href="http://www.vogella.de/eclipse.html">Eclipse Tutorials</a>, for example about <a href="http://www.vogella.de/articles/RichClientPlatform/article.html">Eclipse RCP</a>. More about me can be found <a href="http://www.vogella.de/about.html"> here</a>.</p>
<p>While the intent of my articles is to cover larger and hopefully timeless topics, my <a href="http://www.vogella.de/blog">blog posts</a> cover less large and less timeless <img src='http://www.vogella.de/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  topics related to Eclipse. The remaining things I tweet at <a href="http://www.twitter.com/vogella">Twitter</a>.</p>
<p>Currently I&#8217;m writing the <a href="http://www.vogella.de/blog/category/papercut/">7 Papercuts in Eclipse </a> series in which I discuss usability issues in the Eclipse platform and how to overcome them.</p>
<p>I hope that you will find my posts enjoyable and useful. </p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/07/24/hello-planet-eclipse/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Eclipse Papercut #3 – Plugin to find unused methods</title>
		<link>http://www.vogella.de/blog/2009/07/15/find-unused-methods/</link>
		<comments>http://www.vogella.de/blog/2009/07/15/find-unused-methods/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 16:14:19 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Papercut]]></category>
		<category><![CDATA[JDT]]></category>
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=477</guid>
		<description><![CDATA[In this episode of  Eclipse Papercuts we will look at h [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.vogella.de/blog/2009/07/15/find-unused-methods/";
		var dzone_title = "Eclipse Papercut #3 – Plugin to find unused methods";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>In this episode of <a href="http://www.vogella.de/blog/?p=385"> Eclipse Papercuts</a> we will look at how we can analyse our own code to find &#8220;dead&#8221; code in your projects. We will write a plug-in to find methods which are not called (within the workspace).</p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/07/methodCalls.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/07/methodCalls.gif" alt="methodCalls" width="892" height="639" class="alignnone size-full wp-image-534" /></a></p>
<p>Of course if you are a framework developer all your exported public methods are API and you can hardly change it.  But in a lot of cases the development team has all code in one workspace. In this case it should be easy to identify dead code easily. Currently you have to select each method and select &#8220;Open Call Hierachy&#8221;.</p>
<p>This calls of course for a simpler solution, lets solve a papercut.</p>
<p>Create a <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html">Plug-in Project </a>&#8220;de.vogella.jdt.codeanalysis&#8221; .</p>
<p>Define the following model class which will store the results of the calucation.</p>
<pre class="brush: java;">

package de.vogella.jdt.infoview.model;

import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IMethod;

public class MethodInformation {
private final String methodName;
private final int numberOfCalls;
private final ICompilationUnit cu;
private final IMethod method;

public MethodInformation(String methodName, int numberOfCalls,
ICompilationUnit cu, IMethod method) {
this.methodName = methodName;
this.numberOfCalls = numberOfCalls;
this.cu = cu;
this.method = method;
}

/**
* @return the method
*/
public String getMethodName() {
return methodName;
}

/**
* @return the numberOfCalls
*/
public int getNumberOfCalls() {
return numberOfCalls;
}

/**
* @return the cu
*/
public ICompilationUnit getResource() {
return cu;
}

/**
* @return the method
*/
public IMethod getMethod() {
return method;
}

}
</pre>
<p>Define a <a href="http://www.vogella.de/articles/EclipseCommands/article.html"> Eclipse command </a> &#8220;de.vogella.jdt.codeanalysis.calculateUsage&#8221; with the default handler &#8220;de.vogella.jdt.codeanalysis.handler.CalculateUsage&#8221;.</p>
<p>Create these two helper classes with will search through a given Java project. The usage of the JDT functionality is explained in <a href="http://www.vogella.de/articles/EclipseJDT/article.html">Eclipse JDT</a>.</p>
<pre class="brush: java;">

package de.vogella.jdt.codeanalysis.analysis;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.SearchParticipant;
import org.eclipse.jdt.core.search.SearchPattern;

import de.vogella.jdt.codeanalysis.model.MethodInformation;

public class CodeAnalysis {

	public static List&lt;MethodInformation&gt; calculate(IJavaProject project) {
		List&lt;MethodInformation&gt; list = new ArrayList&lt;MethodInformation&gt;();
			try {
				if (project.isOpen()) {

					IPackageFragment[] packages = project
							.getPackageFragments();
					// parse(JavaCore.create(project));
					for (IPackageFragment mypackage : packages) {
						if (mypackage.getKind() == IPackageFragmentRoot.K_SOURCE) {
							for (ICompilationUnit unit : mypackage
									.getCompilationUnits()) {
								IType[] types = unit.getTypes();
								for (int i = 0; i &lt; types.length; i++) {
									IType type = types[i];
									IMethod[] methods = type.getMethods();
									for (int j = 0; j &lt; methods.length; j++) {
										IMethod method = methods[j];
										if (!method.isMainMethod()) {
											int number = performIMethodSearch(method);

											if (number == 0) {
												MethodInformation metric = new MethodInformation(
														method.getElementName(),
														number, unit, method);
												list.add(metric);
											}

										}

									}

								}

							}
						}

					}
				}
			} catch (CoreException e) {
				e.printStackTrace();
			}
		return list;
	}

	private static int performIMethodSearch(IMethod method)
			throws CoreException {
		SearchPattern pattern = SearchPattern.createPattern(method,
				IJavaSearchConstants.REFERENCES);
		IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
		MySearchRequestor requestor = new MySearchRequestor();
		SearchEngine searchEngine = new SearchEngine();
		searchEngine.search(pattern, new SearchParticipant[] { SearchEngine
				.getDefaultSearchParticipant() }, scope, requestor, null);
		return requestor.getNumberOfCalls();

	}
}
</pre>
<pre class="brush: java;">

package de.vogella.jdt.codeanalysis.analysis;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.search.MethodReferenceMatch;
import org.eclipse.jdt.core.search.SearchMatch;
import org.eclipse.jdt.core.search.SearchRequestor;

public class MySearchRequestor extends SearchRequestor {

	private int numberOfCalls = 0;

	@Override
	public void acceptSearchMatch(SearchMatch match) throws CoreException {
		if (match instanceof MethodReferenceMatch) {
//			MethodReferenceMatch methodMatch = (MethodReferenceMatch) match;
//			Object element = methodMatch.getElement();
			numberOfCalls++;
		}
	}

	/**
	 * @return the numberOfCall
	 */
	public int getNumberOfCalls() {
		return numberOfCalls;
	}

}
</pre>
<p>We create a little View with a Table (and its content and label provider)</p>
<pre class="brush: java;">

package de.vogella.jdt.codeanalysis.views;

import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.part.ViewPart;

import de.vogella.jdt.codeanalysis.model.MethodInformation;

public class ResultView extends ViewPart {
	public static final String ID = &quot;de.vogella.jdt.codeanalysis.ResultView&quot;;
	private TableViewer viewer;

	public void setInput(List&lt;MethodInformation&gt; list) {
		viewer.setInput(list);
	}

	@Override
	public void createPartControl(Composite parent) {
		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
				| SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
		buildTableColumns(viewer);
		viewer.setLabelProvider(new AnalysisLabelProvider());
		viewer.setContentProvider(new AnalysisContentProvider());

		viewer.getTable().addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				Object data = e.item.getData();
				if (!(data instanceof MethodInformation))
					return;
				MethodInformation info = (MethodInformation) data;
				IMethod method = info.getMethod();
				ICompilationUnit cu = info.getResource();
				if (cu == null)
					return;
				try {
					IEditorPart part = JavaUI.openInEditor(cu);
					JavaUI.revealInEditor(part, (IJavaElement) method);
				} catch (CoreException ex) {
					// error handling
				}
			}
		});
	}

	@Override
	public void setFocus() {
	}

	private void buildTableColumns(TableViewer viewer) {
		String[] titles = { &quot;File&quot;, &quot;Method&quot;, &quot;Number of Calls&quot; };
		int[] bounds = { 100, 100, 100 };

		for (int i = 0; i &lt; titles.length; i++) {
			TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
			column.getColumn().setText(titles[i]);
			column.getColumn().setWidth(bounds[i]);
			column.getColumn().setResizable(true);
			column.getColumn().setMoveable(true);
		}
		Table table = viewer.getTable();
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
	}

	public class AnalysisLabelProvider extends LabelProvider implements
			ITableLabelProvider {

		@Override
		public Image getColumnImage(Object element, int columnIndex) {
			return null;
		}

		@Override
		public String getColumnText(Object element, int columnIndex) {
			MethodInformation metric = (MethodInformation) element;
			switch (columnIndex) {
			case 0:
				return metric.getResource().getElementName();
			case 1:
				return metric.getMethodName();
			default:
				return String.valueOf(metric.getNumberOfCalls());
			}

		}
	}

	public class AnalysisContentProvider implements IStructuredContentProvider {

		@Override
		public Object[] getElements(Object inputElement) {
			List&lt;MethodInformation&gt; list = (List&lt;MethodInformation&gt;) inputElement;
			return list.toArray();
		}

		@Override
		public void dispose() {
		}

		@Override
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		}

	}

}
</pre>
<p>Finally we can create the handler:</p>
<pre class="brush: java;">

package de.vogella.jdt.codeanalysis.handler;

import java.util.List;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;

import de.vogella.jdt.codeanalysis.analysis.CodeAnalysis;
import de.vogella.jdt.codeanalysis.model.MethodInformation;
import de.vogella.jdt.codeanalysis.views.ResultView;

public class CalculateUsage extends AbstractHandler {

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

		IStructuredSelection selection = (IStructuredSelection) HandlerUtil
				.getActiveMenuSelection(event);
		if (selection == null || selection.getFirstElement() == null) {
			// Nothing selected, do nothing
			MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
					&quot;Information&quot;, &quot;Please select a project&quot;);
			return null;
		}
		final Object firstElement = selection.getFirstElement();
		if (!(firstElement instanceof IJavaProject)) {
			return null;
		}

		final IJavaProject project = (IJavaProject) firstElement;

		try {
			if (!project.isOpen()
					|| !(project.getProject()
							.hasNature(&quot;org.eclipse.jdt.core.javanature&quot;))) {
				MessageDialog.openInformation(
						HandlerUtil.getActiveShell(event), &quot;Information&quot;,
						&quot;Only works for open Java Projects&quot;);
				return null;
			}
		} catch (CoreException e1) {
			return null;
		}

		Job job = new Job(&quot;Calculate Usage of methods&quot;) {
			@Override
			protected IStatus run(IProgressMonitor monitor) {
				final List&lt;MethodInformation&gt; calculate = CodeAnalysis
						.calculate(project);
				// Open view in the UI thread
				Display.getDefault().asyncExec(new Runnable() {
					public void run() {
						try {
							final ResultView findView = (ResultView) HandlerUtil
									.getActiveWorkbenchWindow(event)
									.getActivePage().showView(ResultView.ID);
							findView.setInput(calculate);
						} catch (PartInitException e) {
							e.printStackTrace();
						}
					}

				});
				return Status.OK_STATUS;
			}

		};
		job.setUser(true);
		job.schedule();

		return null;
	}
}
</pre>
<p>As a last step add your command to the menu of the package explorer. This is also described <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html"> Eclipse Plugin Development</a> you results in the following plugin.xml</p>
<pre class="brush: xml;">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;?eclipse version=&quot;3.4&quot;?&gt;
&lt;plugin&gt;
   &lt;extension
         point=&quot;org.eclipse.ui.views&quot;&gt;
      &lt;view
            class=&quot;de.vogella.jdt.codeanalysis.views.ResultView&quot;
            id=&quot;de.vogella.jdt.codeanalysis.ResultView&quot;
            name=&quot;Analysis Result&quot;
            restorable=&quot;true&quot;&gt;
      &lt;/view&gt;
   &lt;/extension&gt;

   &lt;extension
         point=&quot;org.eclipse.ui.commands&quot;&gt;
      &lt;command
            defaultHandler=&quot;de.vogella.jdt.codeanalysis.handler.CalculateUsage&quot;
            id=&quot;de.vogella.jdt.codeanalysis.calculateUsage&quot;
            name=&quot;Calculate method usage&quot;&gt;
      &lt;/command&gt;
   &lt;/extension&gt;
   &lt;extension
         point=&quot;org.eclipse.ui.menus&quot;&gt;
      &lt;menuContribution
            locationURI=&quot;popup:org.eclipse.jdt.ui.PackageExplorer&quot;&gt;
         &lt;command
               commandId=&quot;de.vogella.jdt.codeanalysis.calculateUsage&quot;
               label=&quot;Calculate method usage&quot;
               style=&quot;push&quot;&gt;
         &lt;/command&gt;
      &lt;/menuContribution&gt;
   &lt;/extension&gt;

&lt;/plugin&gt;
</pre>
<p>If you now export your plugin into your Eclipse IDE you will have a new menu entry which allows you to start the usage calculation of your methods. Once finished your View should be opened / updated and the methods displayed which are not called. By double-clicking on them you can jump to the related method.</p>
<p>Note: project.isOpen() returns false, if you select an open project only with the right mouse click. If you click the project with the left mouse you should be fine.</p>
<p>Of course you can easily think of possible extensions to this approach:</p>
<ol>
<li>Calculate the usage of all methods and show then in the table</li>
<li>Make is work for several projects</li>
<li>Display in the table if a method has private, protected, default or public access</li>
<li>Introduce filter</li>
<li>Create marker in the editor for the identified methods. See <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html#resourcemarker"> Eclipse Plugin Development &#8211; Resource Markers </a></li>
</ol>
<p>And here is the project for download.</p>
<p><a href='http://www.vogella.de/blog/wp-content/uploads/2009/07/de.vogella.jdt.codeanalysis.source_1.0.0.200907151800.zip'>de.vogella.jdt.codeanalysis.source_1.0.0.200907151800</a></p>
<p>Last but not least if would be nice if the <a href="http://eclipsesource.com/blogs/2009/07/08/osgi-eclipse-and-api-management/"> Eclipse API Tools </a> could help us with finding &#8220;dead&#8221; code. If have therefore opened <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=283574">Bug 283574</a>.</p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/07/15/find-unused-methods/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Eclipse Activities &#8211; Hide / Display certain UI elements</title>
		<link>http://www.vogella.de/blog/2009/07/13/eclipse-activities/</link>
		<comments>http://www.vogella.de/blog/2009/07/13/eclipse-activities/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 12:25:13 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Activities]]></category>
		<category><![CDATA[Commands]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=485</guid>
		<description><![CDATA[Use Eclipse Activities (org.eclipse.ui.activities) to r [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.vogella.de/blog/2009/07/13/eclipse-activities/";
		var dzone_title = "Eclipse Activities &#8211; Hide / Display certain UI elements";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>Eclipse Activities can be used to hide / display certain UI elements, for example based on the role of the user. The related extension point is &#8220;org.eclipse.ui.activities&#8221;. A common use case for using activities is authorization, e.g. certain user get to see only a certain part of the ui which fits to their role.</p>
<p>Via activities you can for example restrict:</p>
<ul>
<li>Editors</li>
<li>Views</li>
<li>Menus</li>
<li>Wizards</li>
</ul>
<p>You define first the activities and then one or several activityPatternBindings. The activityPatternBindings defines which UI elements belong to an activities. These elements will only be displayed if the activity is set to true.</p>
<p>The Eclipse workbench will automatically persists activated activities.</p>
<p>The following will demonstate how activities can be used.</p>
<p>Create a new <a href="http://www.vogella.de/articles/RichClientPlatform/article.html">Eclipse RCP </a> project &#8220;de.vogella.rcp.activities&#8221; based on the &#8220;Hello RCP&#8221; template.</p>
<p>Add a view &#8220;de.vogella.rcp.activities.view&#8221; to your RCP application and add this view via &#8220;org.eclipse.ui.perspectiveExtensions&#8221; to your application. The view should have the id &#8220;de.vogella.rcp.activities.view&#8221;. This view will later be filtered by the activity.</p>
<p>See  <a href="http://www.vogella.de/articles/RichClientPlatform/article.html">Eclipse RCP Tutorial </a> for how to create a view and add it to the perspective.</p>
<p>Add now two commands &#8220;de.vogella.rcp.activities.activate&#8221; and &#8220;de.vogella.rcp.activities.deactivate&#8221; with the following default handler to your application. Comands are in detail described in <a href="http://www.vogella.de/articles/EclipseCommands/article.html">Eclipse Commands</a>.</p>
<pre class="brush: java;">

package de.vogella.rcp.activities.handler;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.activities.IActivityManager;
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
import org.eclipse.ui.handlers.HandlerUtil;

public class Activate extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchActivitySupport activitySupport = HandlerUtil
.getActiveWorkbenchWindow(event).getWorkbench()
.getActivitySupport();
IActivityManager activityManager = activitySupport.getActivityManager();
Set enabledActivities = new HashSet();
String id = &quot;de.vogella.rcp.activities.view&quot;;
if (activityManager.getActivity(id).isDefined()) {
enabledActivities.add(id);

}
activitySupport.setEnabledActivityIds(enabledActivities);
return null;
}

}
</pre>
<pre class="brush: java;">

package de.vogella.rcp.activities.handler;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
import org.eclipse.ui.handlers.HandlerUtil;

public class DeActivate extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchActivitySupport activitySupport = HandlerUtil
.getActiveWorkbenchWindow(event).getWorkbench()
.getActivitySupport();
Set&lt;String&gt; enabledActivities = new HashSet&lt;String&gt;();
activitySupport.setEnabledActivityIds(enabledActivities);
// Now I have to reset the perspective to update also the views
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().resetPerspective();
return null;
}
}
</pre>
<p>Add both commands to the menu.</p>
<p>Add also the standard command &#8220;org.eclipse.ui.views.showView&#8221; to your menu. This command will later also be filtered by the activity.</p>
<p>Now add the extension point &#8220;org.eclipse.ui.activities&#8221;. Add an activity with the id &#8220;de.vogella.rcp.activities.view&#8221;. As you see above this activity will be activated / deactivated by the commands from above.</p>
<p>Add then two activityPatternBinding to your extension point. To assign a ui element to an activity you can use patterns ( isEqualityPattern=false) or Strings ( isEqualityPattern=true). The first part of the pattern / string is the plug-in id and the second part is the UI element.</p>
<p>For example the correct String for the view is: &#8220;de.vogella.rcp.activities/de.vogella.rcp.activities.view&#8221;.</p>
<p>After doing this your extension point should look like this in plugin.xml:</p>
<pre class="brush: xml;">
   &lt;extension
         point=&quot;org.eclipse.ui.activities&quot;&gt;
      &lt;activity
            id=&quot;de.vogella.rcp.activities.view&quot;
            name=&quot;Activate View&quot;&gt;
      &lt;/activity&gt;
      &lt;activityPatternBinding
            activityId=&quot;de.vogella.rcp.activities.view&quot;
            isEqualityPattern=&quot;false&quot;
            pattern=&quot;de.vogella.rcp.activities/de.vogella.rcp.activities.view&quot;&gt;
      &lt;/activityPatternBinding&gt;
      &lt;activityPatternBinding
            activityId=&quot;de.vogella.rcp.activities.view&quot;
            isEqualityPattern=&quot;true&quot;
            pattern=&quot;de.vogella.rcp.activities/org.eclipse.ui.views.showView&quot;&gt;
      &lt;/activityPatternBinding&gt;
   &lt;/extension&gt;
</pre>
<p>If you run your application the view and menu item should not be there. If you press your command &#8220;Activate&#8221; then the view and the menu should get displayed. If you stop and re-start the application the activity should be still active as it gets persisted.</p>
<p>If you press your command &#8220;Deactivate&#8221; then the menu and the view is removed.</p>
<p>Activities can also be used together with core expressions and your own define expressions (which you define via ISourceProvider). See <a href="http://www.vogella.de/articles/EclipseCommands/article.html#commmands_sourceprovider">Eclipse Commands &#8211; Own expressions</a> on how to define them.</p>
<p>Expression based activities are even better for defining authorization in your application as they will ignore API calls to them.</p>
<p>The full project can be downloaded here:</p>
<p><a href='http://www.vogella.de/blog/wp-content/uploads/2009/07/de.vogella.rcp_.activities.zip'>de.vogella.rcp.activities</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/07/13/eclipse-activities/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Eclipse Papercut #2 – Changing Eclipse subversive default behavior</title>
		<link>http://www.vogella.de/blog/2009/07/08/modify-eclipse-code/</link>
		<comments>http://www.vogella.de/blog/2009/07/08/modify-eclipse-code/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 21:53:09 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Papercut]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Subversive]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=443</guid>
		<description><![CDATA[How to modify the Eclipse source code [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.vogella.de/blog/2009/07/08/modify-eclipse-code/";
		var dzone_title = "Eclipse Papercut #2 – Changing Eclipse subversive default behavior";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p><strong>Update: Igor Burilo (Eclipse Subversive developer) was kind enough to accept a modified version of patch developed in this episode. While I&#8217;m very happy about this, this unfortunately renders this example irrelevant . You still might want to read this to see how to checkout code from the Eclipse version control system</strong>.</p>
<p>In this second part of my <a href="http://www.vogella.de/blog/?p=385">7 Paper Cuts in Eclipse</a> I want to change some standard Eclipse code.</p>
<p>This second papercut is a bit more complex as the <a href="http://www.vogella.de/blog/?p=421"> first papercut</a>; I&#8217;m planning to return to simpler examples in the next papercut.</p>
<p>So lets define the papercut:</p>
<p>I frequently create example projects which I share in a svn repository. For related projects I use the mulitproject layout. The standard in subversion is &#8220;Simple Mode &#8211; One project for one repository&#8221;. Therefore everytime I share a project I have to switch in the subversion dialog from &#8220;Simple Mode&#8221; to &#8220;Advanced Mode&#8221;.</p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/07/papercut1_101.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/07/papercut1_101.gif" alt="papercut1_10" width="572" height="596" class="alignnone size-full wp-image-444" /></a></p>
<p>Nothing big? I agree, hence the perfect example for a papercut. </p>
<p>To change the coding of this dialog we need to find the class which is responsible to display this page. <a href="http://www.vogella.de/articles/EclipseCodeAccess/article.html#pluginspy">Plug-in Spy<a href="http://www.vogella.de/articles/EclipseCodeAccess/article.html#pluginspy"> </a> make this easy via Alt + Shift + F1.</p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/07/papercut1_201.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/07/papercut1_201.gif" alt="papercut1_20" width="576" height="598" class="alignnone size-full wp-image-445" /></a></p>
<p>Now you need to download the source code of the plug-in &#8221;<br />
org.eclipse.team.svn.ui&#8221;. This plug-in is stored in svn and can get access via subversion itself. The URL for the subversion repository view is: &#8220;http://dev.eclipse.org/svnroot/technology/org.eclipse.subversive&#8221;. See <a href="http://www.vogella.de/articles/EclipseCodeAccess/article.html#versioncontrol"> here </a> to learn how to use svn and cvs to access the Eclipse code</p>
<p>Add this repository in the &#8220;SVN Repository&#8221; view and check-out (download) the plug-ins &#8221;<br />
org.eclipse.team.svn.ui&#8221; and &#8220;org.eclipse.team.svn.core&#8221;. You find them in &#8220;trunk&#8221;.</p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/07/papercut1_301.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/07/papercut1_301.gif" alt="papercut1_30" width="407" height="482" class="alignnone size-full wp-image-453" /></a></p>
<p>Looking at the coding of SelectProjectNamePage.java changing the selection only requires a few lines to be changed.</p>
<p>I use <a href="http://www.vogella.de/articles/EclipsePreferences/article.html">Eclipse Preferences </a> to remember the last user selection.</p>
<pre class="brush: java;">
protected SelectProjectNamePageSimpleModeComposite simpleModeComposite;
	protected ShareProjectNameAdvancedModeComposite advancedModeComposite;
	private static String SELECTION_MODE = &quot;isSimpleMode&quot;;

	public SelectProjectNamePage() {
		super(
			SelectProjectNamePage.class.getName(),
			&quot;&quot;,  //$NON-NLS-1$
			SVNTeamUIPlugin.instance().getImageDescriptor(&quot;icons/wizards/newconnect.gif&quot;)); //$NON-NLS-1$
		Preferences preferences = new ConfigurationScope()
		.getNode(&quot;org.eclipse.team.svn.ui.wizard.shareproject&quot;);
		Preferences preference = preferences.node(&quot;note1&quot;);
		this.isSimpleMode = preference.getBoolean(SELECTION_MODE, true);;
	}
</pre>
<p>and I have to change a few more lines to use isSimpleMode everywhere:</p>
<pre class="brush: java;">
this.simpleModeRadionButton.setSelection(this.isSimpleMode);
....
this.advancedModeRadionButton.setSelection(!this.isSimpleMode); // Either or
this.advancedModeRadionButton.addSelectionListener(modeListener);
</pre>
<p>And I have to set the preference in the ModeListener</p>
<pre class="brush: java;">

	protected class ModeListener extends SelectionAdapter {
		public void widgetSelected(SelectionEvent e) {
			//change controls area mode
			Button modeButton = (Button) e.widget;
			if (SelectProjectNamePage.this.simpleModeRadionButton == modeButton &amp;&amp; SelectProjectNamePage.this.isSimpleMode == false) {
				SelectProjectNamePage.this.isSimpleMode = true;
				preference.putBoolean(SELECTION_MODE, true);
				enableControlsArea();
			} else if (SelectProjectNamePage.this.advancedModeRadionButton == modeButton &amp;&amp; SelectProjectNamePage.this.isSimpleMode == true) {
				SelectProjectNamePage.this.isSimpleMode = false;
				preference.putBoolean(SELECTION_MODE, false);
				enableControlsArea();
			}
		}
	}
</pre>
<p>The full source code is attached.</p>
<p><a href='http://www.vogella.de/blog/wp-content/uploads/2009/07/SelectProjectNamePage1.zip'>SelectProjectNamePage</a></p>
<p>If you now export these two plug-ins into your runnig Eclipse, this dialog will remember the last selection (Simple vrs. Advanced).</p>
<p>As I hope this behavior is useful to others I created a bug report (with a patch). See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=282583"> Bug </a>. I hope the subversion programmers will consider this patch (or an improved version of it).</p>
<p>Remember sharing is good. Open Source does not only allow you to solve your issues but it makes it easy to contribute back.</p>
<p>See <a href="http://www.vogella.de/blog/?cat=10"> Eclipse Papercuts</a> to get all posts in this series.</p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/07/08/modify-eclipse-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
