<?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>Radek's Tech Blog &#187; command</title>
	<atom:link href="http://urbas.tk/index.php/tag/command/feed/" rel="self" type="application/rss+xml" />
	<link>http://urbas.tk</link>
	<description>Radoslaw H. Urbas homepage / blog</description>
	<lastBuildDate>Tue, 01 Jun 2010 20:31:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Adding menu item, command and handler</title>
		<link>http://urbas.tk/index.php/2009/10/27/adding-menu-item-command-and-handler/</link>
		<comments>http://urbas.tk/index.php/2009/10/27/adding-menu-item-command-and-handler/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 23:12:52 +0000</pubDate>
		<dc:creator>Radoslaw Urbas</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[eclipse rcp]]></category>
		<category><![CDATA[handler]]></category>
		<category><![CDATA[menu item]]></category>

		<guid isPermaLink="false">http://urbas.tk/?p=172</guid>
		<description><![CDATA[Step by step in Eclipse IDE Create new Eclipse plug-in: File -&#62; New -&#62; Other -&#62; Plug-in Development -&#62; Plug-in Project Add dependency: MANIFEST.MF -&#62; Dependencies tab -&#62; Add -&#62; org.eclipse.ui Add extension point org.eclipse.ui.menus: plugin.xml -&#62; Extension -&#62; Add -&#62; org.eclipse.ui.menus Right-click -&#62; New -&#62; menuContribution Enter locationURI: menu:file Right click -&#62; New -&#62; command Enter [...]]]></description>
			<content:encoded><![CDATA[<h4>Step by step in Eclipse IDE</h4>
<ul>
<li>Create new Eclipse plug-in: File -&gt; New -&gt; Other -&gt; Plug-in Development -&gt; Plug-in Project</li>
<li>Add dependency: MANIFEST.MF -&gt; Dependencies tab -&gt; Add -&gt; <em>org.eclipse.ui</em></li>
<li>Add extension point org.eclipse.ui.menus: plugin.xml -&gt; Extension -&gt; Add -&gt; <em>org.eclipse.ui.menus </em>
<ul>
<li>Right-click -&gt; New -&gt; menuContribution
<ul>
<li>Enter locationURI: menu:file
<ul>
<li>Right click -&gt; New -&gt; command</li>
<li>Enter commandId: <em><strong>tk.urbas.eclipse.sample.sampleCommand</strong></em></li>
<li>Enter label: Sample Menu Item</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>Add extension point org.eclipse.ui.commands: plugin.xml -&gt; Extensions -&gt; Add -&gt; <em>org.eclipse.ui.commands </em>
<ul>
<li>Right-click -&gt; New -&gt; command
<ul>
<li>Enter id: <em><strong>tk.urbas.eclipse.sample.sampleCommand</strong></em></li>
<li>Enter label: Sample Command</li>
</ul>
</li>
</ul>
</li>
<li>Add extension point org.eclipse.ui.handlers: plugin.xml -&gt; Extensions -&gt; Add -&gt; <em>org.eclipse.ui.handlers </em>
<ul>
<li>Right-click -&gt; New -&gt; handler
<ul>
<li>Enter commandId: <em><strong>tk.urbas.eclipse.sample.sampleCommand</strong></em></li>
<li>Enter class: tk.urbas.eclipse.sample.SampleHandler</li>
<li>Click class link and create class</li>
<li>Provide sample implementation of the handler class implementing <em>org.eclipse.core.commands.IHandler</em> or extending <em>org.eclipse.core.commands.AbstractHandler</em></li>
</ul>
</li>
</ul>
</li>
</ul>
<p></p>
<div id="attachment_179" class="wp-caption alignleft" style="width: 364px"><img src="http://urbas.tk/wp-content/adding_handler.png" alt="Menu, command, handler" title="adding_handler" width="354" height="466" class="size-full wp-image-179" /><p class="wp-caption-text">Menu, command, handler</p></div>
<h4>MANIFEST.MF</h4>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Sample Handler
Bundle-SymbolicName: tk.urbas.eclipse.sample;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: urbas.tk
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.ui</pre></div></div>

<h4>plugin.xml</h4>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?eclipse</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;3.4&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;extension</span></span>
<span style="color: #009900;">         <span style="color: #000066;">point</span>=<span style="color: #ff0000;">&quot;org.eclipse.ui.menus&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;menuContribution</span></span>
<span style="color: #009900;">            <span style="color: #000066;">locationURI</span>=<span style="color: #ff0000;">&quot;menu:file&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;command</span></span>
<span style="color: #009900;">               <span style="color: #000066;">commandId</span>=<span style="color: #ff0000;">&quot;tk.urbas.eclipse.sample.sampleCommand&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Sample Menu Item&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;push&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/command<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/menuContribution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/extension<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;extension</span></span>
<span style="color: #009900;">         <span style="color: #000066;">point</span>=<span style="color: #ff0000;">&quot;org.eclipse.ui.commands&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;command</span></span>
<span style="color: #009900;">            <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;tk.urbas.eclipse.sample.sampleCommand&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Sample Command&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/command<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/extension<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;extension</span></span>
<span style="color: #009900;">         <span style="color: #000066;">point</span>=<span style="color: #ff0000;">&quot;org.eclipse.ui.handlers&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;handler</span></span>
<span style="color: #009900;">            <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;tk.urbas.eclipse.sample.SampleHandler&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">commandId</span>=<span style="color: #ff0000;">&quot;tk.urbas.eclipse.sample.sampleCommand&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/handler<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/extension<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h4>Handler &#8211; sample implementation showing a message</h4>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">tk.urbas.eclipse.sample</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.core.commands.AbstractHandler</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.core.commands.ExecutionEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.core.commands.ExecutionException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jface.dialogs.MessageDialog</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.widgets.Display</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SampleHandler <span style="color: #000000; font-weight: bold;">extends</span> AbstractHandler <span style="color: #009900;">&#123;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> execute<span style="color: #009900;">&#40;</span>ExecutionEvent event<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ExecutionException <span style="color: #009900;">&#123;</span>
		MessageDialog.<span style="color: #006633;">openInformation</span><span style="color: #009900;">&#40;</span>Display.<span style="color: #006633;">getDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getActiveShell</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
				<span style="color: #0000ff;">&quot;Sample Handler&quot;</span>, <span style="color: #0000ff;">&quot;Sample Handler&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://urbas.tk/index.php/2009/10/27/adding-menu-item-command-and-handler/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

