<?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>Silveira Neto &#187; dialogs API</title>
	<atom:link href="http://silveiraneto.net/tag/dialogs-api/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net</link>
	<description>the world is a pixel</description>
	<lastBuildDate>Sun, 08 Jan 2012 05:17:57 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Netbeans: your first plugin</title>
		<link>http://silveiraneto.net/2008/02/24/netbeans-your-first-plugin/</link>
		<comments>http://silveiraneto.net/2008/02/24/netbeans-your-first-plugin/#comments</comments>
		<pubDate>Sun, 24 Feb 2008 17:19:17 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[dialogs API]]></category>
		<category><![CDATA[en]]></category>
		<category><![CDATA[helloyou]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/2008/02/24/netbeans-your-first-plugin/</guid>
		<description><![CDATA[Netbeans have a modular architecture that permits plug and unplug functionalities easily using the Plugin Manager. It&#8217;s also easy create new plugins using Netbeans itself.http://silveiraneto.net/wp-admin/media-upload.php?post_id=705&#038;TB_iframe=true 1º Step: A new module. Create a New Project clicking in File → New Project. Figure 1. Creating a new project In Categories select Netbeans Module and in Projects select [...]]]></description>
			<content:encoded><![CDATA[<p>Netbeans have a <a href="http://www.netbeans.org/features/platform/index.html">modular architecture</a> that permits plug and unplug functionalities easily using the <em>Plugin Manager</em>.</p>
<p>It&#8217;s also easy create new plugins using Netbeans itself.http://silveiraneto.net/wp-admin/media-upload.php?post_id=705&#038;TB_iframe=true</p>
<p><span id="more-705"></span></p>
<p><strong>1º Step: A new module.</strong></p>
<p>Create a New Project clicking in <em>File → New Project</em>.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/filenewproject.png" alt="Netbeans: File → New Project" /><br />
<small>Figure 1. Creating a new project</small></p>
<p>In <em>Categories</em> select <em>Netbeans Module</em> and in <em>Projects</em> select <em>Module</em>.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/newmodule.png" alt="Netbeans New Module" /><br />
<small>Figure 2. Creating a new module.</small></p>
<p>Click in <em>Next</em>.</p>
<p>In the next screen you can choose your module name, like HelloYou. Leave the rest with the default values.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/nameandlocation.png" alt="Netbeans Module Name and Location" /><br />
<small>Figure 3. Naming the module.</small></p>
<p>Now you have to set up the package base name, something like <em>org.yourorg.helloyou</em>.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/basicmoduleconfiguration.png" alt="Basic Module Configuration" /><br />
<small>Figure 4. Package name.</small></p>
<p>Now you have an empty module, but we need some action.</p>
<p><strong>2º Step: Some action.</strong></p>
<p>Right click in your source package and click in <strong>New → Action</strong>.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/newaction.png" alt="Netbeans Add Action" /><br />
<small>Figure 5. Adding some action.</small></p>
<p>Now we&#8217;ll fill another wizard. The first screen is about <em>Action Type</em>. Leave all with the default values (the <em>Always Enabled</em> option) and click <em>Next</em>.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/actiontype.png" alt="Action Type" /><br />
<small>Figure 6. Filling the Action Type.</small></p>
<p>In the <em>GUI Registration</em> screen we can set where we want our action appears as an menu item. We chose Menu file and select <em>Global Toolbar Button</em>. In <em>Toolbar</em> select <em>Build</em> and in <em>Position</em> select <em>Profile Main Project&#8230;- HERE</em>. Click <em>Next</em>.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/guiregistration.png" alt="Gui Registration" /><br />
<small>Figure 7. GUI Registration.</small></p>
<p>Now we will set up the screen <em>Name, Icon and Location</em>. In <em>Class Name</em> we choose HelloAction. Display Name is how the class will appear in the menu, so we can spaces. You should select an icon in dimensions of 16&#215;16. In the same directory you can put to an icon in 24&#215;24. If your 16&#215;16 icon is named ball.png your 24&#215;24 icon should be ball24.png. Doesn&#8217;t matter where is this icon, it&#8217;ll be automatically copied to the module directory.  Now click <strong>Finish</strong>.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/nameiconlocation.png" alt="Netbeans Name Icon and Location." /><br />
<small>Figure 8. Name, Icon and Location.<br />
</small></p>
<p>I used an smile icon from the <a href="http://www.pidgin.im/">Pidgin Project</a>.</p>
<p><img src="http://silveiraneto.net/wp-content/uploads/2008/02/wink.png" alt="Wink" /><img src="http://silveiraneto.net/wp-content/uploads/2008/02/wink24.png" alt="Wink24" /></p>
<p>After clicked in <strong>Finish</strong> your project will look like that:</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/likethatcode.png" alt="Look like that" /><br />
<small>Figure 9. Empty action.<br />
</small></p>
<p>At this point we can already test our module! For doing that right click in <img src="http://silveiraneto.net/wp-content/uploads/2008/02/puzzle1.png" alt="Puzzle" /><em>HelloYou</em> (puzzle icon) and select <em>Install/Reload in Target Platform</em>. This will open a new instance of Netbeans with your module installed!</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/firstinstallreloadintargetplatform.png" alt="Install or reload in target platform" /><br />
<small>Figure 10. Install/Reload in target platform.</small></p>
<p>If everything goes alright you will see your icon in the toolbar.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/noticethesmile.png" alt="Notice the smile" /><br />
<small>Figure 11. Look! We got an plugin!<br />
</small></p>
<p>But if you click in the smile nothing happens. We have defined no action at all.</p>
<p><strong>3º Step: Creating dependencies.</strong></p>
<p>A module can have dependencies from others modules. When you try to install it, Netbeans will ask about install their modules dependencies. Is much like an Linux package system.</p>
<p>We can see and set up the dependencies in our module properties screen. You can right click <img src="http://silveiraneto.net/wp-content/uploads/2008/02/puzzle1.png" alt="Puzzle" /><em>HelloYou</em> and go in <em>Properties</em>. Another way to do the same is going in <em>File → &#8220;HelloYou&#8221; Properties</em>.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/menuhelloyouproperties.png" alt="Helloyou properties" /><br />
<small>Figure 12. File → &#8220;HelloYou&#8221; Properties.<br />
</small></p>
<p>In the <em>Project Properties</em> screen select <em>Libraries</em> in the left side, <em>Categories</em>. There are listed the Java, Netbeans and all <em>Module Dependencies</em> of your module. By default you&#8217;ll see <em>Utilities API</em> module dependence.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/projectproperties.png" alt="Netbeans Project Properties" /><br />
<small>Figure 13. Module Dependences.</small></p>
<p>Click in the button <em>Add </em>(that one near the module dependencies). You&#8217;ll see the <em>Add Module Dependency</em> screen where are listed all Netbeans modules.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/addmodulesdependencies.png" alt="Netbeans add modules dependency" /><br />
<small>Figure 14. Add Modules Dependency</small></p>
<p>We want add an dependency for the <em>Dialogs API</em>. Type &#8220;dialogs&#8221; in the filter text field.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/dialogsapi.png" alt="Netbeans Dialogs API" /><br />
<small>Figure 15. Dialogs API.</small></p>
<p>Select the module <em>Dialogs API</em> and click <em>OK</em>. Now our module have two dependencies: <em>Utilities API</em> and <em>Dialogs API</em>.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/moremodulesdependecies.png" alt="More module dependencies" /><br />
<small>Figure 16. Dialogs API and Utilities API. </small></p>
<p>Now for the first time, let&#8217;s right some code.</p>
<p>In HelloAction.java file there&#8217;s a class <em>HelloAction</em> that extends <a href="http://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/actions/CallableSystemAction.html" title="Netbeans API"><em>CallableSystemAction</em></a> (an abstract class). In the method <em>performAction</em>() there&#8217;s nothing but:</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//TODO implement action body</span></pre>
</div>
</div>
<p>We will rewrite the <em>performAction</em> method:</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> performAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #003399;">String</span> msg <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hello Netbeans World!&quot;</span>;
   <span style="color: #000066; font-weight: bold;">int</span> msgType <span style="color: #339933;">=</span> NotifyDescriptor.<span style="color: #006633;">INFORMATION_MESSAGE</span>;
   NotifyDescriptor d <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NotifyDescriptor.<span style="color: #006633;">Message</span><span style="color: #009900;">&#40;</span>msg, msgType<span style="color: #009900;">&#41;</span>;
   DialogDisplayer.<span style="color: #006633;">getDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">notify</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>You will see some warnings (cannot find symbol). Just fix the imports (Ctrl+Shift+I). To test your module, do it again: <img src="http://silveiraneto.net/wp-content/uploads/2008/02/puzzle1.png" alt="Puzzle" /><em>HelloYou</em> → <em>Install/Reload in Target Platform</em>. A new instance of Netbeans will open and you&#8217;ll see our smile face button again. When you click it, Netbeans will show an dialog.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/netbeanshelloworld.png" alt="Netbeans Hello World" /><br />
<small>Figure 17. Hello Netbeans World.</small></p>
<p>Let&#8217;s do more. Let&#8217;s talk with the user using <em><a href="http://bits.netbeans.org/dev/javadoc/org-openide-dialogs/org/openide/NotifyDescriptor.InputLine.html">NotifyDescriptor.InputLine</a></em>. Will create an input line dialog, get the user name (if he clicks in Ok) and display a message to him.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> performAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    NotifyDescriptor.<span style="color: #006633;">InputLine</span> question;
    question <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NotifyDescriptor.<span style="color: #006633;">InputLine</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Name:&quot;</span>,
        <span style="color: #0000ff;">&quot;What's your name?&quot;</span>,
        NotifyDescriptor.<span style="color: #006633;">OK_CANCEL_OPTION</span>,
        NotifyDescriptor.<span style="color: #006633;">QUESTION_MESSAGE</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>DialogDisplayer.<span style="color: #006633;">getDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">notify</span><span style="color: #009900;">&#40;</span>question<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> NotifyDescriptor.<span style="color: #006633;">OK_OPTION</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #003399;">String</span> msg <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hello &quot;</span><span style="color: #339933;">+</span>question.<span style="color: #006633;">getInputText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;!&quot;</span>;
         <span style="color: #000066; font-weight: bold;">int</span> msgType <span style="color: #339933;">=</span> NotifyDescriptor.<span style="color: #006633;">INFORMATION_MESSAGE</span>;
         NotifyDescriptor d <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NotifyDescriptor.<span style="color: #006633;">Message</span><span style="color: #009900;">&#40;</span>msg, msgType<span style="color: #009900;">&#41;</span>;
         DialogDisplayer.<span style="color: #006633;">getDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">notify</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span>;
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>Again, <img src="http://silveiraneto.net/wp-content/uploads/2008/02/puzzle1.png" alt="Puzzle" /><em>HelloYou</em> → <em>Install/Reload in Target Platform</em>.</p>
<p>After the new Netbeans instance opens, click in our smile face.</p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/typeyourname.png" alt="Type your name" /></p>
<p style="text-align: center"><img src="http://silveiraneto.net/wp-content/uploads/2008/02/hellosilveira.png" alt="Hello Silveira" /></p>
<p>That&#8217;s it. You made your Netbeans plugin!</p>
<p><strong>Learn more about Netbeans Module Development:</strong></p>
<ul>
<li><strong><a href="http://platform.netbeans.org/tutorials/quickstart-nbm.html">Introduction to NetBeans Module Development Tutorial</a></strong> &#8211; A tutorial I based to make this one.</li>
<li><strong><a href="http://www.netbeans.org/kb/trails/platform.html">NetBeans Modules and Rich-Client Applications Learning Trail</a></strong> &#8211; All resources you need to learn more about Netbeans Platform. Lot&#8217;s of tutorials.</li>
<li><strong><a href="http://plugins.netbeans.org/PluginPortal/">Netbeans Plugin Portal</a></strong> &#8211; You can download and also make a <a href="http://autoupdate.netbeans.org/nbm/nbm_package.html">NBM file</a> to share your plugins with the community.</li>
<li><strong><a href="http://www.amazon.com/Rich-Client-Programming-Plugging-NetBeans/dp/0132354802">Rich Client Programming: Plugging into the NetBeans Platform</a></strong> &#8211;  <a href="http://weblogs.java.net/blog/timboudreau/">Tim Boudreau</a>,  <a href="http://www.ohloh.net/accounts/8184">Jaroslav Tulach</a> and <a href="http://blogs.sun.com/geertjan/">Geertjan Wielenga</a> wrote the best book about Netbeans platform. I&#8217;m reading it.</li>
<li><strong><a href="http://wiki.netbeans.org/NetBeansDeveloperFAQ">Netbeans Developer FAQ</a></strong> &#8211; An big FAQ for person writing NetBeans extension modules (plug-ins), or applications based on the NetBeans platform.</li>
</ul>
<p><strong>added in 02.</strong><strong>27</strong><strong>.08:</strong> now this tutorial is also available in the <a href="http://wiki.netbeans.org/YourFirstNetbeansModule" title="Wiki">Netbeans Wiki</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/02/24/netbeans-your-first-plugin/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>

