<?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>Developer Papercuts &#187; Papercut</title>
	<atom:link href="http://www.vogella.de/blog/category/papercut/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vogella.de/blog</link>
	<description>Tips around Eclipse and Android programming</description>
	<lastBuildDate>Wed, 08 Feb 2012 17:31:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Eclipse Papercut #7 &#8211; Adding the PDE Plugin creation wizard to the Eclipse toolbar</title>
		<link>http://www.vogella.de/blog/2011/01/13/eclipse-papercut-7-adding-the-pde-plugin-creation-wizard-to-the-eclipse-toolbar/</link>
		<comments>http://www.vogella.de/blog/2011/01/13/eclipse-papercut-7-adding-the-pde-plugin-creation-wizard-to-the-eclipse-toolbar/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 05:39:56 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Papercut]]></category>
		<category><![CDATA[PDE]]></category>
		<category><![CDATA[Plug-in]]></category>
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=3732</guid>
		<description><![CDATA[Its been a while since I wrote my last Eclipse papercut blog entry.

Today I demonstrate how to add the PDE wizard for creating new plugins to the Eclipse toolbar. I personally create plugin projects on a regular basis therefore it is annoying to select the wizard via File-&#62; New -&#62; blablabla.

I know that I ...]]></description>
			<content:encoded><![CDATA[<p>Its been a while since I wrote my last <a href="http://www.vogella.de/blog/category/papercut/">Eclipse papercut</a> blog entry.</p>
<p>Today I demonstrate how to add the PDE wizard for creating new <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html">plugins</a> to the Eclipse toolbar. I personally create plugin projects on a regular basis therefore it is annoying to select the wizard via File-&gt; New -&gt; blablabla.</p>
<p>I know that I can use Ctrl+3 to select the wizard but I want to be able to select this wizard from the main toolbar. </p>
<p>This is really easily. First find the related Wizard via the <a href="http://www.vogella.de/articles/EclipseCodeAccess/article.html#pluginspy_ui">Plugin Spy</a>. We see that the wizard is called NewPluginProjectWizard.</p>
<p>Then create a <a href="http://www.vogella.de/articles/EclipseCommands/article.html">command</a> with the following default handler.</p>
<pre class="brush: plain; title: ; notranslate">

package de.vogella.plugin.pdewizard.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.pde.internal.ui.wizards.plugin.NewPluginProjectWizard;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;

public class SampleHandler extends AbstractHandler {
	public Object execute(ExecutionEvent event) throws ExecutionException {
		Shell shell = HandlerUtil.getActiveShell(event);
		WizardDialog wizard = new WizardDialog(shell,
				new NewPluginProjectWizard());
		wizard.open();
		return null;
	}
}
</pre>
<p>Via the <a href="http://www.vogella.de/articles/EclipseCodeAccess/article.html#pluginspy_menu">plugin menu spy</a> you also find quickly a nice place to put your new toolitem to <a href="http://www.vogella.de/articles/EclipseCommands/article.html#toolbar">the main toobar</a> </p>
<pre class="brush: plain; title: ; notranslate">
&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.commands&quot;&gt;
      &lt;command
            defaultHandler=&quot;de.vogella.plugin.pdewizard.handlers.NewPluginWizardHandler&quot;
            id=&quot;de.vogella.plugin.pdewizard.commands.pluginwizard&quot;
            name=&quot;New Plugin Wizard&quot;&gt;
      &lt;/command&gt;
   &lt;/extension&gt;
   &lt;extension
         id=&quot;toolbar:org.eclipse.ui.workbench.file?after=newWizardDropDown&quot;
         point=&quot;org.eclipse.ui.menus&quot;&gt;
      &lt;menuContribution
            locationURI=&quot;toolbar:org.eclipse.ui.workbench.file&quot;&gt;
            &lt;command
                  commandId=&quot;de.vogella.plugin.pdewizard.commands.pluginwizard&quot;
                  icon=&quot;icons/sample.gif&quot;
                  tooltip=&quot;Create new plugin&quot;&gt;
            &lt;/command&gt;
      &lt;/menuContribution&gt;
   &lt;/extension&gt;

&lt;/plugin&gt;
</pre>
<p>If you also add the dependencies to org.eclipse.ui, org.eclipse.pde.ui, org.eclipse.pde.ui.templates and org.eclipse.core.runtime then you should be able to create a new plugin project via your new button in the main toolbar. </p>
<p>I hope this help. You can <a href="http://www.twitter.com/vogella">follow me on Twitter</a>. </p>
<p>EDIT: A simpler solution was proposed by <a href="http://blog.hantsuki.org/">Remy Suen</a>: Since the new/import/export wizards are parameterized commands, the same effect can actually be achieved with pure XML.</p>
<pre class="brush: plain; title: ; notranslate">
&lt;extension
id=&quot;toolbar:org.eclipse.ui.workbench.file?after=newWizardDropDown&quot;
point=&quot;org.eclipse.ui.menus&quot;&gt;
&lt;menuContribution
locationURI=&quot;toolbar:org.eclipse.ui.workbench.file&quot;&gt;
&lt;command
commandId=&quot;org.eclipse.ui.newWizard&quot;&gt;
&lt;parameter
name=&quot;newWizardId&quot;
value=&quot;org.eclipse.pde.ui.NewProjectWizard&quot;&gt;
&lt;/parameter&gt;
&lt;/command&gt;
&lt;/menuContribution&gt;
&lt;/extension&gt;
</pre>
<p class="wp-flattr-button"></p> <p><a href="http://www.vogella.de/blog/?flattrss_redirect&amp;id=3732&amp;md5=085102e12f6265877e50ecfe82220a1b" title="Flattr" target="_blank"><img src="http://www.vogella.de/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2011/01/13/eclipse-papercut-7-adding-the-pde-plugin-creation-wizard-to-the-eclipse-toolbar/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Eclipse Papercut #6 &#8211; Modifying Mylyn Context</title>
		<link>http://www.vogella.de/blog/2009/10/05/modifying-mylyn-context/</link>
		<comments>http://www.vogella.de/blog/2009/10/05/modifying-mylyn-context/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 06:06:55 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Papercut]]></category>
		<category><![CDATA[Commands]]></category>
		<category><![CDATA[JDT]]></category>
		<category><![CDATA[Mylyn]]></category>
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=1183</guid>
		<description><![CDATA[Change the Mylyn context in a task]]></description>
			<content:encoded><![CDATA[<p>In this episode of <a href="http://www.vogella.de/blog/2009/06/29/paper-cuts/">Eclipse Papercuts </a> I will demonstrate how to modify the <a href="www.eclipse.org/mylyn/?phpMyAdmin=pGYgzr5q5pQd6aMfv3bd9m1zbi3">Mylyn</a> tasks context. Many thanks to <a href="http://greensopinion.blogspot.com/">David Green </a> for providing sample code to access the Mylyn context.</p>
<p><a href="http://www.vogella.de/articles/Mylyn/article.html">Mylyn</a> makes certain assumptions how the developer works. If you start a new task the Mylyn context is empty and fills up based on the selected files. </p>
<p>Which is not always the way I work. Frequently I know that for my task a whole package (or project) is relevant. I would like to include all classes in this package / project in my Mylyn task.</p>
<p>Ok, lets see how we can solve this papercut. I describe how to add Java classes from a package to an active task.</p>
<p>Create an command which extends the package explorer with a new popup commands as described here <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html#packageexplorer">Extend the package explorer</a>.</p>
<p>Create the command handler with the following coding:</p>
<pre class="brush: java; title: ; notranslate">

package de.vogella.mylyn.tasksmodify.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.mylyn.context.core.ContextCore;
import org.eclipse.mylyn.context.core.IInteractionContext;
import org.eclipse.mylyn.internal.context.core.ContextCorePlugin;
import org.eclipse.mylyn.monitor.core.InteractionEvent;
import org.eclipse.mylyn.monitor.core.InteractionEvent.Kind;
import org.eclipse.ui.handlers.HandlerUtil;

public class SampleHandler extends AbstractHandler {
	public Object execute(ExecutionEvent event) throws ExecutionException {

		IStructuredSelection selection = (IStructuredSelection) HandlerUtil
				.getActiveMenuSelection(event);
		if (selection ==null){
			return null;
		}

		Object firstElement = selection.getFirstElement();

		if (firstElement instanceof IPackageFragment) {
			IPackageFragment mypackage = (IPackageFragment) firstElement;
			try {
				if (mypackage.getKind() == IPackageFragmentRoot.K_SOURCE){
					 ICompilationUnit[] compilationUnits = mypackage.getCompilationUnits();
					 for (ICompilationUnit iCompilationUnit : compilationUnits) {
						 IInteractionContext activeContext = ContextCore.getContextManager()
							.getActiveContext();
						 ContextCorePlugin.getContextManager().processInteractionEvent(iCompilationUnit,
									Kind.PROPAGATION, InteractionEvent.ID_UNKNOWN, activeContext);
					}
				}
			} catch (JavaModelException e) {
				e.printStackTrace();
			}
		}

		return null;
	}
}
</pre>
<p>Launch your plugin. Create a Mylyn task and select a package in the package explorer. Select your commands and all files of this package will be added to the task.</p>
<p>Further reading: If you want to access other Java Elements, e.g. Project and add them to the Mylyn task this tutorial might help you: <a href="http://www.vogella.de/articles/EclipseJDT/article.html">Eclipse JDT</a>.</p>
<p>Please note that ContextCorePlugin is supposed to be internal API but I did not find another way of accessing the Mylyn tasks. </p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/10/05/modifying-mylyn-context/feed/</wfw:commentRss>
		<slash:comments>4</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 definition of the external API and how to get prepared Eclipse plugins via the Springsource bundle repository. ]]></description>
			<content:encoded><![CDATA[<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>
<p class="wp-flattr-button"></p>]]></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 configuration. Demonstrates how to get and modify Eclipse PDE code.]]></description>
			<content:encoded><![CDATA[<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; title: ; notranslate">
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; title: ; notranslate">

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>
<p class="wp-flattr-button"></p>]]></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>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 how we can analyse our own code to find "dead" code in your projects. We will write a plug-in to find methods which are not called (within the workspace).




Of course if you are a framework developer all your exported public methods are API ...]]></description>
			<content:encoded><![CDATA[<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; title: ; notranslate">

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; title: ; notranslate">

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; title: ; notranslate">

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; title: ; notranslate">

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; title: ; notranslate">

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; title: ; notranslate">

&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>
<p class="wp-flattr-button"></p>]]></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 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[<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; title: ; notranslate">
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; title: ; notranslate">
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; title: ; notranslate">

	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>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/07/08/modify-eclipse-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Eclipse Papercut #1 &#8211; The annoying creation of the project package</title>
		<link>http://www.vogella.de/blog/2009/07/06/create-package-via-jdt/</link>
		<comments>http://www.vogella.de/blog/2009/07/06/create-package-via-jdt/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 08:38:54 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Papercut]]></category>
		<category><![CDATA[Commands]]></category>
		<category><![CDATA[JDT]]></category>
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=421</guid>
		<description><![CDATA[Extending the Eclipse Package Explorer to create a project specific package.]]></description>
			<content:encoded><![CDATA[<p>This series is about simplifying the handling of Eclipse for simple but repetitive tasks. See <a href="http://www.vogella.de/blog/?p=385">7 Paper Cuts in Eclipse</a>.</p>
<p>Ok lets start with something simple.</p>
<p>By convension Eclipse projects are named based on reverse URL&#8217;s, e.g. &#8220;org.eclipse.jdt&#8221; or &#8220;de.vogella.test&#8221;. Also this convension suggests to create a package with the same name as the project. For this you have to select the src folder in the  project, right click on it, select New &#8211; Package then copy the name of the project from the first line and paste it into the second line of the dialog.</p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/07/papercut1_10.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/07/papercut1_10.gif" alt="papercut1_10" width="498" height="267" class="alignnone size-full wp-image-422" /></a></p>
<p>While you may argue that this is not to bad as the amount of project you are creating is limited; I personally find this annoying as I&#8217;m writting lots of example for my articles on <a href="http://www.vogella.de/">http://www.vogella.de/</a>.</p>
<p>Time to simplify (at least a little bit). </p>
<p>Create an <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html">Eclipse plug-in </a> called &#8220;de.vogella.jdt.packageexplorer&#8221;. Add a <a href="http://www.vogella.de/articles/EclipseCommands/article.html">Eclipse command </a> to it with the following default handler.</p>
<pre class="brush: java; title: ; notranslate">

package de.vogella.jdt.packageexplorer.handler;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFolder;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

public class AddPackage extends AbstractHandler {

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

		IStructuredSelection selection = (IStructuredSelection) HandlerUtil
				.getActiveMenuSelection(event);
		Object firstElement = selection.getFirstElement();
		if (firstElement instanceof IJavaProject) {
			IJavaProject javaProject = (IJavaProject) firstElement;
			try {
				IFolder folder = javaProject.getProject().getFolder(&quot;src&quot;);
				// folder.create(true, true, null);
				IPackageFragmentRoot srcFolder = javaProject
						.getPackageFragmentRoot(folder);
				srcFolder.createPackageFragment(javaProject.getProject()
						.getName(), true, null);
			} catch (JavaModelException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
}
</pre>
<p>Add this command to the content menu in the package explorer as described in <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html">Eclipse plug-in Development</a>. </p>
<p>The resulting plugin.xml looks like the following:</p>
<pre class="brush: xml; title: ; notranslate">
&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.menus&quot;&gt;
      &lt;menuContribution
            locationURI=&quot;popup:org.eclipse.jdt.ui.PackageExplorer&quot;&gt;
         &lt;command
               commandId=&quot;de.vogella.jdt.packageexplorer.AddPackage&quot;
               label=&quot;Add Default Package&quot;
               style=&quot;push&quot;&gt;
         &lt;/command&gt;
      &lt;/menuContribution&gt;
   &lt;/extension&gt;
   &lt;extension
         point=&quot;org.eclipse.ui.commands&quot;&gt;
      &lt;command
            defaultHandler=&quot;de.vogella.jdt.packageexplorer.handler.AddPackage&quot;
            id=&quot;de.vogella.jdt.packageexplorer.AddPackage&quot;
            name=&quot;Add Default Package&quot;&gt;
      &lt;/command&gt;
   &lt;/extension&gt;

&lt;/plugin&gt;
</pre>
<p>Export your plug-in and put it into the dropin folder in your Eclipse installation. Restart Eclipse.</p>
<p>If you now create a new project you can right click on the project and directly create your project / default package.</p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/07/papercut1_30.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/07/papercut1_30.gif" alt="papercut1_30" width="354" height="644" class="alignnone size-full wp-image-424" /></a></p>
<p>If you want to improve this further you can assign a keybinding to your command and use a shortcut to create the package. Or if you have more artifacts to create you can use the handler to create .java files, more packages, etc.</p>
<p>Here is the source bundle to download:<br />
<a href='http://www.vogella.de/blog/wp-content/uploads/2009/07/de.vogella.jdt.packageexplorer.source_1.0.0.zip'>de.vogella.jdt.packageexplorer.source_1.0.0</a></p>
<p>Here is the exported plugin (you need you rename zip to jar before putting this into the Eclipse/dropin folder)</p>
<p><a href='http://www.vogella.de/blog/wp-content/uploads/2009/07/de.vogella.jdt.packageexplorer_1.0.0.zip'>de.vogella.jdt.packageexplorer_1.0.0</a></p>
<p>See <a href="http://www.vogella.de/blog/?cat=10"> Eclipse Papercuts</a> to get all posts in this series.</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/07/06/create-package-via-jdt/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>7 Paper Cuts in Eclipse</title>
		<link>http://www.vogella.de/blog/2009/06/29/paper-cuts/</link>
		<comments>http://www.vogella.de/blog/2009/06/29/paper-cuts/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 20:51:41 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Papercut]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=385</guid>
		<description><![CDATA[Ubuntu is currently running  One Hundred Paper Cuts . This project aims to improve user experience by identifying 100 bugs that appear relatively easy to fix but that negatively impact user experience.

I will try to do the same for my Eclipse but with a more limited scope.

I will try to identify 7 things ...]]></description>
			<content:encoded><![CDATA[<p>Ubuntu is currently running <a href="https://launchpad.net/hundredpapercuts"> One Hundred Paper Cuts </a>. This project aims to improve user experience by identifying 100 bugs that appear relatively easy to fix but that negatively impact user experience.</p>
<p>I will try to do the same for my Eclipse but with a more limited scope.</p>
<p>I will try to identify 7 things in Eclipse which are time consuming and / or annoying and will try to solve them most likely via <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html">  Eclipse plug-ins </a>. It can be simple things which I just find dull or real improvements. </p>
<p>So now I have to start watching me using Eclipse and try to see what I could improve&#8230;.</p>
<p>See <a href="http://www.vogella.de/blog/?cat=10"> Eclipse Papercuts</a> to get all posts in this series.</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/06/29/paper-cuts/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

