<?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; Commands</title>
	<atom:link href="http://www.vogella.de/blog/tag/commands/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 3.6M4 &#8211; Tiny nice things</title>
		<link>http://www.vogella.de/blog/2009/12/12/eclipse-3-6-ease-of-use/</link>
		<comments>http://www.vogella.de/blog/2009/12/12/eclipse-3-6-ease-of-use/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 17:31:00 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Commands]]></category>
		<category><![CDATA[Planet]]></category>
		<category><![CDATA[RCP]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=1646</guid>
		<description><![CDATA[I personally believe that little things make a difference. Eclipse 3.6 is going to be great for new (and perhaps also for experienced) plugin and RCP developers. 

Especially I like in the Eclipse 3.6M4 release:


-consoleLog included per default in a new launch configuration
RCP with a View


I believe the solution of  Bug for -consoleLog ...]]></description>
			<content:encoded><![CDATA[<p>I personally believe that little things make a difference. Eclipse 3.6 is going to be great for new (and perhaps also for experienced) plugin and RCP developers. </p>
<p>Especially I like in the Eclipse 3.6M4 release:</p>
<p><a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=284704">-consoleLog included per default in a new launch configuration</a><br />
<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=295145">RCP with a View</a></p>
<p>I believe the solution of <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=284704"> Bug for -consoleLog </a> will solve the most common problem with getting started for new Plugin / RCP developers. Also the update of the PDE RCP templates will hopefully guide new developers in using commands instead of actions. </p>
<p>The change in <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=284704"> Bug for -consoleLog </a> was also a <a href="http://www.vogella.de/blog/2009/11/30/consolelog-runtime-configuration/">community decision</a>, which is a good example that Eclipse does consider user feedback. </p>
<p>Thanks to all involved parties and the Eclipse community for these changes. <img src='http://www.vogella.de/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>Update</strong> Unfortunately <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=253105">Mail Template</a> was not part of M4.</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/12/12/eclipse-3-6-ease-of-use/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Defining menu entries (commands) at runtime in Eclipse RCP</title>
		<link>http://www.vogella.de/blog/2009/12/03/commands-menu-runtime/</link>
		<comments>http://www.vogella.de/blog/2009/12/03/commands-menu-runtime/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 07:38:53 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Commands]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[RCP]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=1456</guid>
		<description><![CDATA[A common question I receive is how menu entries can be defined at runtime in an RCP application. The following gives an example how this can be done.

Create the RCP project "de.vogella.rcp.commands.runtimecommands" using the "Hello RCP" template.

Define a menu contribution. Maintain the class "de.vogella.rcp.commands.runtimecommands.DefineCommands" in this menu contribution.



Create the following class. 



Run the example, ...]]></description>
			<content:encoded><![CDATA[<p>A common question I receive is how menu entries can be defined at runtime in an RCP application. The following gives an example how this can be done.</p>
<p>Create the RCP project &#8220;de.vogella.rcp.commands.runtimecommands&#8221; using the &#8220;Hello RCP&#8221; template.</p>
<p>Define a menu contribution. Maintain the class &#8220;de.vogella.rcp.commands.runtimecommands.DefineCommands&#8221; in this menu contribution.</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
         id=&quot;application&quot;
         point=&quot;org.eclipse.core.runtime.applications&quot;&gt;
      &lt;application&gt;
         &lt;run
               class=&quot;de.vogella.rcp.commands.runtimecommands.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;RCP Perspective&quot;
            class=&quot;de.vogella.rcp.commands.runtimecommands.Perspective&quot;
            id=&quot;de.vogella.rcp.commands.runtimecommands.perspective&quot;&gt;
      &lt;/perspective&gt;
   &lt;/extension&gt;
   &lt;extension
         point=&quot;org.eclipse.ui.menus&quot;&gt;
      &lt;menuContribution
            class=&quot;de.vogella.rcp.commands.runtimecommands.DefineCommands&quot;
            locationURI=&quot;menu:org.eclipse.ui.main.menu&quot;&gt;
      &lt;/menuContribution&gt;
   &lt;/extension&gt;

&lt;/plugin&gt;
</pre>
<p>Create the following class. </p>
<pre class="brush: java; title: ; notranslate">
package de.vogella.rcp.commands.runtimecommands;

import org.eclipse.swt.SWT;
import org.eclipse.ui.menus.CommandContributionItem;
import org.eclipse.ui.menus.CommandContributionItemParameter;
import org.eclipse.ui.menus.ExtensionContributionFactory;
import org.eclipse.ui.menus.IContributionRoot;
import org.eclipse.ui.services.IServiceLocator;

public class DefineCommands extends ExtensionContributionFactory {

	@Override
	public void createContributionItems(IServiceLocator serviceLocator,
			IContributionRoot additions) {
		CommandContributionItemParameter p = new CommandContributionItemParameter(
				serviceLocator, &quot;&quot;,
				&quot;org.eclipse.ui.file.exit&quot;,
				SWT.PUSH);
		p.label = &quot;Exit the application&quot;;
		p.icon = Activator.getImageDescriptor(&quot;icons/alt_window_16.gif&quot;);

		CommandContributionItem item = new CommandContributionItem(p);
		item.setVisible(true);
		additions.addContributionItem(item, null);
	}

}
</pre>
<p>Run the example, your application should have the Exit command in the menu.  </p>
<p>Thanks to <a href="http://www.einsle.de/">Robert Einsle </a>for the tip. </p>
<p>This description has also be added to my <a href="http://www.vogella.de/articles/EclipseCommands/article.html">Eclipse command tutorial</a>. </p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/12/03/commands-menu-runtime/feed/</wfw:commentRss>
		<slash:comments>8</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 can access in information of the MANIFEST.MF. For example you could read the dependencies of your plugin. 

For this example create a plugin "de.vogella.pde.dependencies". See Eclipse Plugin development for examples on how to develop plugins. Use the "Hello, World Command" template.

Define dependendies to the ...]]></description>
			<content:encoded><![CDATA[<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; title: ; notranslate">

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>
<p class="wp-flattr-button"></p>]]></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 #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 PDE templates &#8211; Your action is my command</title>
		<link>http://www.vogella.de/blog/2009/09/23/pde-templates-commands/</link>
		<comments>http://www.vogella.de/blog/2009/09/23/pde-templates-commands/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 22:10:37 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Commands]]></category>
		<category><![CDATA[PDE]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[RCP]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=1153</guid>
		<description><![CDATA[The Eclipse PDE templates are fantastic to help people to learn the platform and to get oven the first initial resistence to start with Eclipse RCP  or Eclipse Plugin development.

Templates indicates to their consumers that they represent best development practices. This puts a certain burden on the quality to the templates. Unfortunately the ...]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.eclipse.org/pde/">Eclipse PDE</a> templates are fantastic to help people to learn the platform and to get oven the first initial resistence to start with <a href="http://www.vogella.de/articles/RichClientPlatform/article.html">Eclipse RCP </a> or <a href="http://www.vogella.de/articles/EclipsePlugIn/article.html">Eclipse Plugin</a> development.</p>
<p>Templates indicates to their consumers that they represent best development practices. This puts a certain burden on the quality to the templates. Unfortunately the PDE RCP templates in Eclipse 3.5 were all based on actions which I believe are superseded by <a href="http://www.vogella.de/articles/EclipseCommands/article.html">Eclipse Commands</a>.</p>
<p>I have seen in the past lots of questions regarding actions in the Eclipse RCP and PDE newsgroups. I believe that at least some of these questions are based on the fact that the PDE templates still promote actions.</p>
<p>I&#8217;m therefore happy to see the changes of <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=265231"> Bug 265231</a> applied for the &#8220;RCP with a view&#8221; template for the upcoming Eclipse 3.6.  Special thanks for this to <a href="http://aniszczyk.org/">Chris Aniszczyk</a>.</p>
<p>It also looks good for the mail example. It seems that work is happening in <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=253105"> Bug 253105</a></p>
<p>Actions are (a little bit more) dead. Long live the command! <img src='http://www.vogella.de/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/09/23/pde-templates-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add the error log view to your Eclipse RCP application</title>
		<link>http://www.vogella.de/blog/2009/08/17/eclipse-rcp-error-view/</link>
		<comments>http://www.vogella.de/blog/2009/08/17/eclipse-rcp-error-view/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 10:42:30 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Commands]]></category>
		<category><![CDATA[RCP]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=973</guid>
		<description><![CDATA[Describes how to add the Error log view to an Eclipse RCP application.]]></description>
			<content:encoded><![CDATA[<p>The Eclipse platform provide error message in case something goes wrong. </p>
<p>During development I use the launch parameter -consoleLog to see if any error has occured. I assume most plugin developer use -consoleLog that is why I opened <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=284704">Bug for making -consoleLog a default in a new launch configuration</a>.</p>
<p>Obviously you don&#8217;t want your users to check the console for errors. To make errors visible to the user you can add the exiting error log to your RCP application.</p>
<p>Create a new <a href="http://www.vogella.de/articles/RichClientPlatform/article.html">Eclipse RCP project</a> &#8220;de.vogella.rcp.intro.errorview&#8221; for this purpose. Use the &#8220;Hello RCP&#8221; as a template. </p>
<p>Select the plugin.xml and add the dependency to org.eclipse.ui.views.log.</p>
<p>Ddd the standard Eclipse command &#8220;org.eclipse.ui.views.showView&#8221; to your menu under the Entry &#8220;Admin&#8221;. See <a href="http://www.vogella.de/articles/EclipseCommands/article.html">Eclipse Commands how to do this</a>.</p>
<p>This will result 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
         id=&quot;application&quot;
         point=&quot;org.eclipse.core.runtime.applications&quot;&gt;
      &lt;application&gt;
         &lt;run
               class=&quot;de.vogella.rcp.intro.errorview.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;RCP Perspective&quot;
            class=&quot;de.vogella.rcp.intro.errorview.Perspective&quot;
            id=&quot;de.vogella.rcp.intro.errorview.perspective&quot;&gt;
      &lt;/perspective&gt;
   &lt;/extension&gt;
   &lt;extension
         point=&quot;org.eclipse.ui.menus&quot;&gt;
      &lt;menuContribution
            locationURI=&quot;menu:org.eclipse.ui.main.menu&quot;&gt;
         &lt;menu
               label=&quot;Admin&quot;&gt;
            &lt;command
                  commandId=&quot;org.eclipse.ui.views.showView&quot;
                  label=&quot;Show Error View&quot;
                  style=&quot;push&quot;&gt;
               &lt;parameter
                     name=&quot;org.eclipse.ui.views.showView.viewId&quot;
                     value=&quot;org.eclipse.pde.runtime.LogView&quot;&gt;
               &lt;/parameter&gt;
            &lt;/command&gt;
         &lt;/menu&gt;
      &lt;/menuContribution&gt;
   &lt;/extension&gt;

&lt;/plugin&gt;
</pre>
<p>Run your new application. You should have a menu entry &#8220;Admin&#8221; with an entry &#8220;Show Error View&#8221;. If you select it the error view should open.</p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/08/errorLogView10.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/08/errorLogView10.gif" alt="errorLogView10" width="398" height="295" class="aligncenter size-full wp-image-981" /></a></p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/08/17/eclipse-rcp-error-view/feed/</wfw:commentRss>
		<slash:comments>25</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 restrict your ui.]]></description>
			<content:encoded><![CDATA[<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; title: ; notranslate">

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

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; title: ; notranslate">
   &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>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/07/13/eclipse-activities/feed/</wfw:commentRss>
		<slash:comments>7</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>Eclipse RCP File browser</title>
		<link>http://www.vogella.de/blog/2009/06/23/eclipse-rcp-file-browser/</link>
		<comments>http://www.vogella.de/blog/2009/06/23/eclipse-rcp-file-browser/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 15:35:20 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Commands]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[RCP]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=318</guid>
		<description><![CDATA[Eclipse RCP  allow you to create easily utility programs.

Lets for example create a mini-file browser which will open a folder / file if you double-click the selection via the standard program.

To create a RCP based file browser create a new Eclipse RCP  project, e.g. de.vogella.rcp.intro.filebrowser.

Create a package "de.vogella.rcp.intro.filebrowser.provider" and create the following ...]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vogella.de/articles/RichClientPlatform/article.html">Eclipse RCP </a> allow you to create easily utility programs.</p>
<p>Lets for example create a mini-file browser which will open a folder / file if you double-click the selection via the standard program.</p>
<p>To create a RCP based file browser create a new <a href="http://www.vogella.de/articles/RichClientPlatform/article.html">Eclipse RCP </a> project, e.g. de.vogella.rcp.intro.filebrowser.</p>
<p>Create a package &#8220;de.vogella.rcp.intro.filebrowser.provider&#8221; and create the following label and content provider.</p>
<pre>

package de.vogella.rcp.intro.filebrowser.provider;

import java.io.File;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

public class FileContentProvider implements ITreeContentProvider {

@Override
public Object[] getChildren(Object parent) {
File file = (File) parent;
return file.listFiles();
}

public Object[] getElements(Object inputElement) {
return (Object[]) inputElement;
}

@Override
public Object getParent(Object element) {
File file = (File) element;
return file.getParentFile();
}

@Override
public boolean hasChildren(Object parent) {
File file = (File) parent;
return file.isDirectory();
}

@Override
public void dispose() {

}

@Override
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
}

}
</pre>
<pre>

package de.vogella.rcp.intro.filebrowser.provider;

import java.io.File;

import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;

public class FileLabelProvider extends LabelProvider {
private static final Image folderImage = AbstractUIPlugin
.imageDescriptorFromPlugin("de.vogella.rcp.intro.filebrowser",
"icons/folder.gif").createImage();
private static final Image driveImage = AbstractUIPlugin
.imageDescriptorFromPlugin("de.vogella.rcp.intro.filebrowser",
"icons/filenav_nav.gif").createImage();
private static final Image fileImage = AbstractUIPlugin
.imageDescriptorFromPlugin("de.vogella.rcp.intro.filebrowser",
"icons/file_obj.gif").createImage();

@Override
public Image getImage(Object element) {
File file = (File) element;
if (file.isDirectory())
return file.getParent() != null ? folderImage : driveImage;
return fileImage;
}

@Override
public String getText(Object element) {
String fileName = ((File) element).getName();
if (fileName.length() &gt; 0) {
return fileName;
}
return ((File) element).getPath();
}
}
</pre>
<p>For the label provider you need the referred icons in your folder icons. You can use the following download.</p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/06/icons.zip">Download the Icons</a></p>
<p>Adjust then the view.</p>
<pre>
package de.vogella.rcp.intro.filebrowser;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.OpenEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

import de.vogella.rcp.intro.filebrowser.provider.FileContentProvider;
import de.vogella.rcp.intro.filebrowser.provider.FileLabelProvider;

public class View extends ViewPart {
	public static final String ID = "de.vogella.rcp.intro.filebrowser.view";
	private TreeViewer viewer;

	public void createPartControl(Composite parent) {
		viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
		viewer.setContentProvider(new FileContentProvider());
		viewer.setLabelProvider(new FileLabelProvider());
		viewer.setInput(File.listRoots());
		viewer.addOpenListener(new IOpenListener() {

			@Override
			public void open(OpenEvent event) {
				IStructuredSelection selection = (IStructuredSelection) event
						.getSelection();

				File file = (File) selection.getFirstElement();
				if (Desktop.isDesktopSupported()) {
					Desktop desktop = Desktop.getDesktop();
					if (desktop.isSupported(Desktop.Action.OPEN)) {
						try {
							desktop.open(file);
						} catch (IOException e) {
							// DO NOTHING
						}
					}
				}
			}
		});
	}

	public void setFocus() {
		viewer.getControl().setFocus();
	}
}
</pre>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/06/23/eclipse-rcp-file-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

