taT | Hacking Modules..

10 07 2009

Ever wondered, apart from extending the NetBeans IDE, or some application based on NetBeans Platform. What else can be done with the module?

Brief Overview

Well, NetBeans IDE provides Module Development Support by providing 4 kinds of Project Templates;

  1. Module
  2. Module Suite
  3. Library Wrapper Module
  4. NetBeans Platform Application

I have some knowledge of the first two, so we will stick to them for the rest of this post. So, lets have a look at the simplistic module structure;

Module Structure

This is what you see when you expand the Project node in Files View. We will focus on platform.properties, project.xml. If you switch to the Project View, you would see the files with following names, visible under Important Files node.

NetBeans Platform Config

So, that’s basically the logical view of the file platform.properties. In the past, I have written some pretty useful tips and Tricks (contributed to NetBeans Community Docs) based on this file;

  1. Configure Clusters and Modules
  2. Managing NetBeans Platforms

Project Metadata

This is the logical view of the file project.xml. There’s one more useful tips and Tricks (contributed), that’s based on this file, which lets you add your module as friends to those modules, if you want your module to depend on the specification version of the same.

NetBeans IDE 6.7 (Click to enlarge)

Playing Tricks..

I will be making use of NetBeans 6.7 IDE. Although, these tricks should work well with NetBeans 6.x IDE. So, lets answer the question I asked in the beginning.. Generally, when you create Module project, you get an option to either create it as Standalone Module or Add to Module Suite.

Standalone Module

When you choose this option, you also get an option to select NetBeans Platform of your choice, along with Manage.. button. If you want to know more about that, refer this contribution.

Suppose, I choose NetBeans 6.5 Build (added with name as 65 in Platform Manager) as Platform and move ahead. I would be able to use 6.7 IDE to create module, targeted for NetBeans 6.5 IDE. The module’s platform.properties looks like this;

nbplatform.active=65

This would enable the running IDE to achieve the desired result, as mentioned above. Now, running the module will ofcourse launch NetBeans 6.5 IDE as Target Instance to see how your module works. This process might be slow, as you’re running full-fledged 6.5 IDE.

NetBeans 6.5 boots with a b'day stamp on splash screen!

If your module doesn’t depend on clusters other than platform (which is by default). Then, you can tweak the file as follows;

enabled.clusters=\
 platform
nbplatform.active=65

These clusters are bare-minimum essentials, that are enabled by default when you create the NetBeans Platform Application project using 6.5/6.7 IDE. The property enabled.clusters helps to enable only those clusters which are necessary to run this module.

Splash Screen for empty NetBeans Platform Application

Now, run your module and it will look like you’re running a NetBeans Platform Application having a single user-defined module. Here’s how module’s project.xml looks like;

<project xmlns="http://www.netbeans.org/ns/project/1">
   <type>org.netbeans.modules.apisupport.project</type>
   <configuration>
      <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
          <code-name-base>code.name.base.of.your.module</code-name-base>
          <standalone/>
          <module-dependencies>
           <!-- Here are your module dependencies.. -->
          </module-dependencies>
          <public-packages/>
      </data>
   </configuration>
</project>

Note the bold-faced tag <standalone />, this tells the NetBeans IDE that your module is not part of any module suite. Its a standalone module, as you created.

Add to Module Suite

If you decide to go with this option, you would then browse the filesystem to find the appropriate Module Suite project and then, move ahead.

In case of Module Suite projects, the enabled.clusters property automatically occurs/disappears, when you check/uncheck the modules and/or clusters from its Project Properties Wizard.

Note that the module, that becomes part of the suite, would use only those clusters which the suite has enabled. Along with that, suite-private.properties file is added under /nbproject/private. Also, take a look at the module’s project.xml;

<project xmlns="http://www.netbeans.org/ns/project/1">
   <type>org.netbeans.modules.apisupport.project</type>
   <configuration>
      <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
          <code-name-base>code.name.base.of.your.module</code-name-base>
          <suite-component/>
          <module-dependencies>
           <!-- Here are your module dependencies.. -->
          </module-dependencies>
          <public-packages/>
      </data>
   </configuration>
</project>

Note the bold-faced tag <suite-component/>, this tells that NetBeans IDE that this module is part of a Module Suite project.

Tips to Remember

You may convert your standalone module to become part of suite, or vice-versa. Just add/remove suite-private.properties (Per Suite Locator) file and tweak your Module’s project.xml and Module Suite’s project.properties.

Also, note that some changes have taken place in NetBeans 6.7 IDE, you may find out more over the web. One more thing, NetBeans 6.5 IDE added suite.properties file under /nbproject and had same tag as <suite-component/>. I think NetBeans 6.0 and 6.1 might do the same. Please try it yourself and let me know.

Stay tuned..





taT | Hacking Project Properties

10 07 2009

Yesterday, I recreated one of the Visual Library Sample  (basically a tutorial based on it at Dzone) using NetBeans 6.7 IDE on Windows XP Professional SP2. The sample was Java Application that had two JAR’s (present in the platform7 cluster of NetBeans 6.0 IDE) in its classpath.

I followed the tutorial and successfully executed the application. Fortunately, I have NetBeans IDE from 5.5 onwards, so there wasn’t any issue finding the JAR’s and adding them in the application’s classpath.

I didn’t knew whether it will work with cluster from higher release or not. Hence, I decided to give it a try by making use of clusters from 6.1, 6.5 and finally, 6.7.

Playing Tricks..

Now, removing/adding JAR’s again and again can be boring/cumbersome if you have several releases stored under different hierarchies of your filesystem. So, I looked into the various files created under /nbproject to inspect how these JAR’s being referred.

When you right-click Libraries Node and click Add JAR/Folder..

right-click Libraries Node (Click to enlarge)

You’re prompted with the dialog for browsing and then, selecting Reference/Absolute Path as per your choice.

Browse to select platform7 cluster (Click to enlarge)

I selected the platform7 cluster (see above figure) and selected the JAR’s shown in the following figure.

Selected JARs from platform7 cluster

/nbproject/project.properties

This file contains all the project related properties, that are accessed by build-impl.xml (created from project.xml automatically) for necessary Ant operations.

file.reference.org-netbeans-api-visual.jar=\
  path\\to\\cluster\\modules\\org-netbeans-api-visual.jar
file.reference.org-openide-util.jar=\
  path\\to\\cluster\\lib\\org-openide-util.jar
includes=**
jar.compress=false
javac.classpath=\
 ${file.reference.org-openide-util.jar}:\
 ${file.reference.org-netbeans-api-visual.jar}:\
 ${libs.swing-layout.classpath}

The bold-faced text is added, once referenced JAR’s are added from Projects Window/Project Properties Wizard. Also, path\\to\\cluster refers to the directory where the platform cluster is stored. In case of the above application, here’s the path;

E:\\OpenSource\\NetBeans_Archies\\NetBeans 6.0\\platform7

Playing with Clusters

Now, as you can see the path\\to\\cluster is the same in this case. So, I introduce another property that will have the path as value.

path.to.cluster.platform=\
  E:\\OpenSource\\NetBeans_Archies\\NetBeans 6.0\\platform7
file.reference.org-netbeans-api-visual.jar=\
  ${path.to.cluster.platform}\\modules\\org-netbeans-api-visual.jar
file.reference.org-openide-util.jar=\
  ${path.to.cluster.platform}\\lib\\org-openide-util.jar

This way, the referenced JAR’s become dependent on this property. Now, one can also change the value of this property, i.e. if one is interested in using JAR’s from platform cluster of higher releases of the NetBeans IDE.

Then, NetBeans will automatically scan the project, to update dependencies. For instance, I opted for platform9 cluster from NetBeans 6.5 IDE.

path.to.cluster.platform=\
  E:\\OpenSource\\NetBeans 6.5\\platform9

I just made changes at one place, that will be automatically reflected in other properties that depend on it directly/indirectly.

Tips to Remember

However, you need to check your code, once you do these changes, as this might cause warnings on deprecated usage of certain API, when you build your application.

Also, if you do any error while editing your project.properties as for this scenario, or any other. You may end up seeing lots of error badges in your code and possibly, get an added menu item (Resolve Reference Problems..) in the project’s context menu.

Stay tuned..





taT | Managing NetBeans Platforms

3 06 2009

Recently, I asked a question on NetBeans Developers Mailing List about gaining better understanding of managing NetBeans Platform(s) within the NetBeans IDE.

You didn’t knew that, right? Well, I have also recently discovered that there’s a provision to manage “NetBeans Platforms” for almost every NetBeans Module Project (I guess). Although, I think I knew that this feature was there but never actually devoted time to see what exactly it does.

Yesterday, when I re-discovered this feature and decided to give it a try. I started exploring it and then, faced some issues. So, I raised the above question on the mailing list. I did receive a reply, however it has a different approach to the above problem. Not directly related to scenario’s I came across. As I await more clarification

Now, I got clarification I needed and indeed it should help me understand the way, NetBeans works in this scenario. I thought why not share this scenario with you people. Maybe, you might have faced same issues.

So, how exactly we make use of this feature? Just follow the steps and let me know, what did you observe?

Here are the Tricks,

Firstly, run NetBeans IDE (bundled with either Java SE, Java or All technologies). I am using NetBeans 6.5 FCS for demonstration.

NetBeans 6.5 boots with a b'day stamp on splash screen!

Now, goto Tools | NetBeans Platforms and generally, you would find same platform configured with your NetBeans IDE and that might be possible, only if you are not running any daily builds.

Click to enlarge!

So, this figure might look familiar to you, if the above statements are correct. You can configure several platforms with your distribution. For instance, I have NetBeans 6.0, 6.1 installed, along with 6.5 which I am running. So, I will show you how to configure one of them,

Add Platform…

Click to enlarge!

Choose Platform Folder

This step will let you select the installation directory of other NetBeans distributions and let you configure the platform supplied by them.

Click to enlarge!

Platform Name

You may edit the Platform Name as per your need, or keep defaults and click Finish.

Click to enlarge!

This way you have added platform supplied by NetBeans 6.0 in NetBeans 6.5. Now, switch over to Harness tab and click the 2nd radio button to complete the configuration. This is done to let this platform use its harness to perform tasks related with module projects.

Click to enlarge!

Similarly, doing for 6.1, the following figure shows that I have successfully configured the above NetBeans Platforms,

Click to enlarge!

Now, you know how to add/remove NetBeans Platforms. Lets go further ahead and explore a bit more by taking a typical scenario..

and some tips,

Assuming you made a plug in using NetBeans 6.0 (released in Dec ‘07) to be compatible with the same. Soon after NetBeans 6.5 FCS (released Nov ‘08) was available, you find that 6.5 work very fast compared to 6.1 and due its improved features, it will help you in reducing your development time.

So, you decide to rework on your module using latest features, however you still want that plug in to work only for NetBeans 6.0, here’s what you need to do.

Firstly, open your plug in project and right-click project node to select its properties. Now, goto Libraries and you would see there’s a drop-down list for selecting your choice of NetBeans Platform, against which you can build your module. This list of platform’s can be configured by clicking “Manage Platforms…” button and you will see the same image, shown earlier.

See how they are all related.. Isn’t it cool? By default,  the platform supplied by the NetBeans IDE you are running is selected.

Here’s one thing to keep in mind, that as you are reworking on an old project like this, you must make sure that you configure the NetBeans Platform for it with care, as not doing so will result in failing the build and adding irrelevant versions of module dependencies.

In our case, if you have configured NetBeans 6.0 as demonstrated above, you need to select that from drop-down list and then, select NetBeans 6.0 build to let your module perform tasks against platform supplied with NetBeans 6.0.

Click to enlarge!

When, you run the module project, the above splash screen for NetBeans 6.0 pops up and now, you can see whether your module works or not. Hope this helps!

This blog has been contributed to NetBeans Community Docs Program and for latest updates on this content, refer to the contribution.

Acknowledgements

Thanks to Tom Wheeler (NetBeans Dream Team Member and NetBeans Governance Board Member) for answering my question on the mailing list.





taT | “Deploy on Build” Using JBoss

9 03 2009

Recently, I had asked a question on NetBeans Forums on the “Deploy-on-Save” feature supported by NetBeans 6.5 IDE. Well, I know I can’t configure build script in such a way, so that it can deploy on save. However, I found a trick to deploy the war file everytime I build OR clean and build .

Brief Overview

This trick will save your time and do lot more stuff with an existing shortcut, which you might have missed otherwise. Actually, I was working on a “Dynamic Web project” in Eclipse IDE where I was supposed to make use of its 2.0.0.Beta2 version using JBoss 4.0.5 GA (with Java EE Platform set to “J2EE 1.4″ ). Eclipse was so slow and its editor support for JSP pages was doing no good. Probably, if I could have used a new release of Eclipse, then that might have helped. Still, I am not sure, its just an assumption.

Also, everytime I made changes I had to first right-click project node, then select “Run As > Run on Server” and if I made any changes during runtime, it was not deploying automatically. Although, “Project” menu showed project to be build automatically . So, I had to repeat the cycle again and again.

Due to the above stated issues/problems, I decided to import the complete project into NetBeans 6.5 IDE. Import was successful and I added the JBoss server into NetBeans IDE (“Tools > Servers” ). Now, project is successfully building and deploying. Its absolutely working fine.

Now, NetBeans 6.5 didn’t supported “Deploy on Save” feature for the web applications that were using JBoss Application Server (I am referring to the above release), as per my recent observation.

Then, when I made changes to the webpages in the earlier mentioned project, I still couldn’t deploy on save/build. So, I had to right-click the “Project Node” and click “Deploy”. This cycle is shorter one, still frustating if one makes changes frequently.

Tricks..

Now, open your project’s build.xml file and here’s the trick you need to do;
Add the following tags;

  <target name="-post-dist">
    <echo>Automatic-deploy</echo>
    <!--antcall target="run-deploy" inheritrefs="-init-deploy-ant"/-->
    <antcall target="run-display-browser" inheritrefs="-init-deploy-ant"/>
    <echo>Done...</echo>
  </target>

below;

  <import file="nbproject/build-impl.xml"/>

This was done to override the above mentioned target present in build-impl.xml file, but thats empty.

    <target name="-post-dist">
        <!-- Empty placeholder for easier customization. -->
        <!-- You can override this target in the ../build.xml file. -->
    </target>

Now, whenever you do “Shift-F11″ or “F11″, it will “clean & build” or “build” respectively and then, deploy the project to the server.

Tips to Remember..

If you replace the following tag;

    <antcall target="run-display-browser" inheritrefs="-init-deploy-ant"/>

with

    <antcall target="run-deploy" inheritrefs="-init-deploy-ant"/>

The moment you use “Shift-F11″ or “F11″, the project will deploy the “war” file, however it will not run the browser for you, as it was doing earlier. If you have better solution, or encounter some problems, do let me know. Hope this helps.

This blog has been contributed to NetBeans Community Docs Program and for latest updates on this content, refer to the contribution.

Enjoy NetBeaning!





taT | I want to use GSF API’s?

11 11 2008

Blogging after 2 weeks…I have been focusing on my college activities more, I should rather say that I was working on my final year project. So, I thought of sharing some key learnings with you!

Final Year Project

I am working on a project that’s based on NetBeans Platform. Initially, its intended to provide first-class support for NetBeans Wiki markup editing, syntax highlighting, auto completion, etc. This would help any user using NetBeans Wiki, to edit/create the pages and then, preview them locally (offline).

So, I asked Caoyuan Deng (NetBeans Dream Team Member), winner of NBIG Gold Award, experienced developer on integrating languages like Erlang, Scala into the IDE, on how to go about using GSF?

If you want to make use of Specification Version of GSF modules, he suggested to add my module as friend to the GSF modules. Making friends is an easy task (as per my experience). That’s possible in two ways-

Case #1- I commit my code to /main/contrib and request the GSF Module Owner to add my specific modules as friends. As I had already versioned my project with SVN at java.net! So, I went for the second way.

Case #2- I should clone the NetBeans sources, and then run my choice of NetBeans IDE. Then, open the necessary GSF modules (from the clone repos)- tweak them (so as to add my module as a friend).

Tips and Tricks

Actually, I made my module friend of all the three GSF modules- /gsf, /gsf.api and /gsfpath.api

So, you are required to open the /nbproject/project.xml file of one of the GSF modules and add a friend tag with text equivalent to the Code Name Base of your module.

<friend-packages>
   <!--Many modules added as friends are added here-->
   <friend>code.name.base.of.my.module</friend>
</friend-packages>

So, open all these modules in your NetBeans IDE (6.0/6.1 onwards). Tweak those project.xml files by searching for a tag “<friend-packages>” there you would see many module’s code name base have been added as friends using tag “<friend>”, also specific packages can be added using tag “<package>”.

Build the sources…

Once you have followed the second approach, its time to build the sources. Firstly, open the project NetBeans Build System (/main-golden/nbbuild). To know more about how to build the sources, give it a read :) Here’s an excerpt from the entry-

I referred a document for information on Mercurial Access. So, I found out /main-golden would be fine for us. As its guaranteed that build would succeed..

Once you get the build successful, you must now run the IDE either from /main-golden/nbbuild/netbeans/bin/ OR extract the distributable zip you must have created by running the target “build”.

This blog has been contributed to NetBeans Community Docs Program and for latest updates on this content, refer to the contribution.

Finally,

Its done, now you can open your project modules in the newly created build of NetBeans IDE. As and when you make use of the Gsf API’s, build would definitely succeed.





taT | Configure Clusters and Modules

19 10 2008

Yesterday, someone asked on the OpenIDE mailing list, “I wonder what is the absolute minimum of modules needed to start developing an app on the platform and after that adding my own modules.”

Tom Wheeler (NetBeans Dream Team Member) gave an excellent reply, and in his detailed answer, I found something that I will blog here and it will be another taT, that would help you tweak your “NetBeans Platform Application” and “Module Suite”.

As you know NetBeans 6.5 has a new Project Template for NetBeans Modules, its known as “NetBeans Platform Application”. You might find some Developer FAQ’s on several How To’s on Branding the Application, Disabling Modules, etc. Let me show you a cool way to manipulate the “NetBeans Platform Config” file to configure the Platform clusters and modules.

Brief Overview

Assuming the concerned project is opened, so Right-click the “Project Node” in Logical View, and select “Properties”. Now, on the left of the Wizard, you select “Libraries”, and on the right, you see related options to configure “Java Platform”, “NetBeans Platform”, as well as “Platform Modules” which are inclusive of “Clusters and Modules”.

Clusters and Modules

Generally, you would uncheck those clusters which you don’t want your application to be dependent on, that also means your application would build faster.

Also, changes get reflected in your App’s “platform.properties” file. So, if you want to avoid using GUI for removing a cluster, not specific modules within that cluster, and tweak it directly in the file.

Continue reading…

Tricks

Daily builds for NetBeans 6.5 have NetBeans Platform with following clusters-

apisupport1, gsf1, harness, ide10, java2, nb6.5,
platform9, profiler3, websvccommon1

By default, your application’s “platform.properties” file stored under nbproject and displayed as “NetBeans Platform Config” in Logical View, has contents..

nbplatform.active=default

That’s the only property you have. Now, suppose I want to remove gsf1 cluster from the above list, add the following property-

enabled.clusters=\
    apisupport,\
    harness,\
    ide,\
    java,\
    nb,\
    platform,\
    profiler,\
    websvccommon

So, as you can see the properties file doesn’t show version of the clusters (ordered alphabetically always), so its version independent as well. This is what you see when you remove gsf1 cluster using “Project Properties Wizard“, and rest are meant to be enabled by the Application you are using.

Now, if I want to restore gsf1, and remove websvccommon1, then you need to just tweak it as follows-

enabled.clusters=\
    apisupport,\
    gsf,\
    harness,\
    ide,\
    java,\
    nb,\
    platform,\
    profiler

If you remove some specific modules from a particular cluster, then following properties are added into the properties file-

disabled.modules=\
    {codename.base.of.modules}
enabled.clusters=\
    apisupport,\
    gsf,\
    harness,\
    ide,\
    java,\
    nb,\
    platform,\
    profiler,\
    websvccommon

Here you would see that when I disable (Please use GUI Wizard to disable) some modules from (suppose) java2 cluster, their “Code Name Base” would be added into the disabled.modules property. Also, you are required to add enabled.clusters property, with all clusters included.

Tips to Remember

This is also applicable to Module Suite project template, and you would see same files, where you can tweak as shown above. If you remove the property-

enabled.clusters=

Then, you would see your application/suite using all the clusters bundled with NetBeans Platform.

Suppose, when you disable a module A of cluster B, always add the enabled.clusters property as well and also, include the cluster B.

disabled.modules=\
    A
enabled.clusters=\
    B,\
    C,\
    D

If you disable the cluster, all the modules within the cluster automatically gets disabled. Not, vice-versa :)

Also, I recommend you to use GUI Wizard to disable specific modules, whether you’re an expert/not. Reason being that you might not know what dependencies the other modules have on this module A.

Someone has rightly said, “Prevention is better than cure”

However, if you want to enable some of the modules disabled using Wizard, then of course you may use the tweaks shown above to do the trick.

This blog has been contributed to NetBeans Community Docs Program and for latest updates on this content, refer to the contribution.

Hope this helps..





taT | Open Projects w/o Browsing

6 10 2008

Its been 2 months, and I have not written any taT’s since then :| Anyways, its time to move on, and try out another cool trick :)

A different way of starting the IDE

Geertjan once blogged this entry, and said, “Drag and drop a desktop icon of a file onto the NetBeans desktop icon……and the IDE will start up, with the specified file open in the editor. That’s always been possible, but is [as far as I am aware] completely unknown.”

There are several such observations, which could be made, but it generally happens accidentally :P

Opening Projects..

Now, there are two ways of opening projects (created/maintained locally), that I have seen.

General way- Browsing from Inside

Firstly, you know that one has to go to “File > Open Project..” OR, use a shortcut key- “Ctrl+Shift+O”

Then, you browse to the location of the project and then you “Open” it in the IDE.

New way- Without Internal Browsing

Now, what you can do? Whether NetBeans IDE is running or not, it doesn’t matter, just use your system file browser which is faster than the IDE, and locate your project root.

Drag-n-Drop the folder over NetBeans Desktop Icon, if its not running, OR Drag-n-Drop it over NetBeans running instance. It will take some time, and project would be opened, that too as Main Project, by default.

What you have to do?

Execute this trick and comment, if you like. Also, if you have some of the tricks to share, which makes life easier for users, share it with NetBeans Community through NetBeans Community Docs Program! Another thing, if you’re not a blogger and want to share similar DnD discoveries with the community, you can mail me – nvarun AT netbeans DOT org

So, that I can blog about your discoveries, and contribute them to the above documentation project as well.

This blog has been contributed to NetBeans Community Docs Program and for latest updates on this content, refer to the contribution.

Have a good day :)





taT | Sort Key and Woodstock

2 08 2008

Have you used PluginPortal, you might not have realised but its a JSF Web application. I am using the portal for the past 6 months, and never thought of this.

Anyways, I have been recently working with JSF 1.2 with Woodstock Components, and as I see James blogging some tips and Tricks these days. So, I thought of doing the same.

PluginPortal Users

Firstly, I will ask you something, if you have submitted any plugins, you would see your My Plugins section, once you logged in.

Table is shown, and recently I saw it has a sortable header, when I click it either it arranges plugin’s info in descending/ascending order.

How do we get that?

Now, how do we get this feature in your web application. If you have any Tabular component in your application, then select any column and goto Properties Window (Ctrl+Shift+7), there would see a property sort under section Data.

When you enter a unique ID (Sort Key),

the changes that took place in JSP is the following attribute gets added-
sort=”$uniqueID

OR, you could have added this attribute yourself in JSP, and when you switch to Design View, and changes are reflected with the sort header icon present in the respective column.

Well, I had stopped blogging on weekends, but I couldn’t resist, so see this as well as, upcoming blogs and have fun ;)

This blog has been contributed to NetBeans Community Docs Program and for latest updates on this content, refer to the contribution.





taT | Editor Windows Reactivated

25 07 2008

Hey,

I have been blogging around for a while on hyperlinks in NetBeans IDE, what about the API’s, yeah the NetBeans API’s that helped me achieve a crucial milestone, i.e. activating the Opened panes! Also, the members of OpenIDE mailing lists, for giving accurate suggestions for making it possible.

Tricks

You must see numerous Developer FAQ’s based on Editor and Edited Files. Some of them referring to get access of relevant opened Window for editing. Still, something was missing. So, I would share what I experienced recently.

TopComponent[] comps = TopComponent.getRegistry().getOpened();
for (int i = 0; i < comps.length; i++) {
    Node[] arr = comps[i].getActivatedNodes();
    for (int j = 0; j < arr.length; j++) {
        EditorCookie ec = (EditorCookie)
arr[j].getCookie(EditorCookie.class);
        if (ec != null) {
            JEditorPane[] panes = ec.getOpenedPanes();
            if (panes != null) {
                // USE panes
            }
        }
    }
}

This has one issue, it no longers returns an array of TopComponent’s in the 1st line, in 6.0 and 6.1, I saw it returned Set<TopComponent>, so outer loop also changes like this-

Set<TopComponent> comps = TopComponent.getRegistry().getOpened();
for (TopComponent tc: comps) {
    Node[] arr = tc.getActivatedNodes();
    for (int j = 0; j < arr.length; j++) {
        EditorCookie ec = (EditorCookie)
arr[j].getCookie(EditorCookie.class);
        if (ec != null) {
            JEditorPane[] panes = ec.getOpenedPanes();
            if (panes != null) {
                // USE panes
            }
        }
    }
}

What about My Usecase?

Oh, yeah! I wanted to tell you about re-activating opened panes. After interacting with Wade on OpenIDE mailing lists. I created this method- verifyHyperlinkStatus(), please have a look, you might have to scroll a bit. So, I have commented 2 lines there-

//final int index = k;
/*
After some coding...
*/
//tc[index].requestActive();

tc[index] is a particular TopComponent instance obtained by iterating over an Array of TopComponent’s. Array? But, we have just discussed its Set<TopComponent> not an Array. You’re in for another surprise-

//To obtain an array, use this-
final TopComponent[] tc = TopComponent.getRegistry().
getOpened().toArray(new TopComponent[0]);
//As mentioned in the following reference tutorial.

Referenced Tutorial- http://wiki.netbeans.org/RevampedHyperlinkNavigation

final, but why?

Actually, when you deal with methods that required to run within a AWT Thread, invoked by various means, then the variables used, within their implemented run() method, if defined outside should be made final so as to prevent it from any modification. In Java, final modifier means that an identifier would be constant within a block of code. In this case, within a method- verifyHyperlinkStatus()

So, index was modified as final, and was used within an AWT Thread inside a if-block, which invoked tc[index].requestActive(), i.e. to activate that window, if its already opened.

Why I am doing this?

As I have to re-activate a opened editor window which was already opened by clicking a hyperlink in HTML file. So, I was earlier using setCaretPositon(), that’s why I had to requestActive(), to show that editor window again.

Tips to Remember

Vita suggested to use NbEditorUtilities instead of a combination of setCaretPosition() and requestActive(). So, I did that by commenting the following statements present in one of the setPosition() methods.

NbEditorUtilities.getLine(d, index, true).show(Line.SHOW_GOTO);
//pane[pos].setCaretPosition(index);

Here, index is found using indexOf(), and d is the document, whose contents were used to retrieve the index. This is indeed a great utility, why? Because, it opens/re-activates the opened document and places the cursor at the beginning of the line, that was searched.

This blog has been contributed to NetBeans Community Docs Program and for latest updates on this content, refer to the contribution.

Final thoughts

This time all was said and done, rather than the saying “All is said, more than done!”.





taT | Reload Debugging (debug-fix-nb)

17 07 2008

Just few days back, I talked about that its rather a good practice to debug, not to run! While following that, I discovered another thing, which was there for quite some time, but I didn’t notice it, as I didn’t debug :P

    <target name="debug-fix-nb" if="netbeans.home"
depends="init,-pre-debug-fix,compile-single">
        <nbjpdareload>
            <fileset includes="${fix.class}*.class"
dir="${build.classes.dir}"/>
        </nbjpdareload>
    </target>

You must be thinking, what’s “debug-fix-nb”, its actually an Ant target, ran while we apply Code fixes during Debugging! Shocking, Indeed! I felt the same way, actually while building a module to run it in Target Platform, I realized I could reload it as well, without building whole module again.

Goto Installation Directory, and look for harness/common.xml
It contains many Ant targets, including the above…

Similar functionality exists, when you want to reload while debugging, HOW? Here lies the trick, while I was debugging a Module in Target Platform, I realized an error just after a break-point, so thought of fixing code, just before error could be detected.

Then, I came across an Icon in Toolbar, whose tool-tip suggested its used for applying code fixes. So, I made changes wherever needed, and clicked on that Icon, it reloaded that class and the debugging continued, from same point!

Now, that’s what I call a utility.
Amazing, never thought debugging could be fun ;)

This blog has been contributed to NetBeans Community Docs Program and for latest updates on this content, refer to the contribution.





taT | Editor Fold Utility

8 07 2008

Hey,

Another tips and Tricks for today! Whenever you have created a JFrame in NetBeans, the auto-generated code which is in sync with Matisse Builder, has a method initComponents() initially, right?

When you make a switch to the Source view, you see a collapsed section of code, with a label on it- “Generated Code”. Ever thought, how it happens.

Here’s the trick

Write code between following comments;

        //<editor-fold defaultstate="$state" desc="$label">
        /* Place your code over here */
        //</editor-fold>

Replace $state with expanded/collapsed and $label with any name/phrase you choose. Also, replace the following;

        /* Place your code over here */

with your code, it could be either inside a method, or inside a Java class, wrapping various methods, variable declarations etc.

Tips to Remember

Keep in mind that, the editor-fold tags must be inside same block of code, either inside a Java class, or inside a method! You can’t opening tag inside a Java class, and closing tag inside a method OR vice-versa!

It works in all Java classes. Also, its basic use is to categorize the sections of code. Like, you may have an editor-fold for only variable declarations, and/or for user created methods, and/or for getter/setter methods!

eNjoy Technology…





taT | Play with XML Layer (Part 3)

7 07 2008

Hey,

So, I am writing a third part, Wow ;) Really, I must admit, I just didn’t thought I would write so frequently, and that too, on NetBeans Platform. Its something, that needs a lot of time to understand its usability, functionality and extensibility… :) Anyways, in my previous entry- Part Two of this series, I wrote on how to transform an Action type from one form to another- CallableSystem TO Cookie! By the way, I have already done the reversal in form of a tutorial, and contributed to the Community Docs.

Here, I present to you tricks to add/remove entries into/from XML Layer, that would enable/disable context-aware actions.

Pre-requisites

Just have a look at this webpage- Tryst with Platform! Its basically an index of what all documentations (11), I have contributed to the NetBeans Community, be it blogs, tutorials, articles, tips and Tricks, Dzone entries, etc, in the last week of June.

Tips and Tricks

Following tips/tricks apply to CookieAction, not CallableSystemAction! Also, check out the references section (at the end of this entry), this part of blog series is inspired by those references!

Syntax of the MIME Type: type/subtype

Tricks for Context Menu Items

Trick #1 – If making the action, file type context-sensitive. Then, you have to add an entry in folder “Loaders” as follows into XML Layer.

    <folder name="Loaders">
        <folder name="type">
            <folder name="subtype">
                <folder name="Actions">
                    <file name="org-nvarun-tat-SayCheez.instance"/>
                </folder>
            </folder>
        </folder>
    </folder>

Trick #2 – If making the action, editor context-sensitive. Then, you have to add an entry in folder “Editors” as follows into XML Layer.

    <folder name="Editors">
        <folder name="type">
            <folder name="subtype">
                <folder name="Popup">
                    <file name="org-nvarun-tat-SayCheez.instance"/>
                </folder>
            </folder>
        </folder>
    </folder>

Tips To Remember

In our case, I replaced type with text and subtype with x-java! What I did, I registered the Action into the Java Editor Context Menu, i.e. whenever you open a Java File, and do right-click, popup menu would show the above action. Also, when you expand relevant Package Node of a Project Node, to uncover Java File Nodes, right-click to see the Action in the popup menu!

However, it would be still be enabled, if you had earlier chosen EditorCookie, EditCookie, DataObject OR OpenCookie. It would be disabled, if you choose Project interface as Cookie class.

Now, what?

You can find out what all MIME Types are registered into the IDE, by clicking on Tools > Options, and click on button Advanced Options! There you expand nodes in this order- IDE Configuration —> System —> Object Types

Now, select any sub-node, and you could see its property sheet on right panel, where all possible MIME Types for that particular Object Type are listed. Try this on existing MIME Types, also you may do this for your own created languages (which you might like to integrate into the IDE).

This blog has been contributed to NetBeans Community Docs Program and for latest updates on this content, refer to the contribution.

References
[A] http://en.wikipedia.org/wiki/MIME#Content-Type
[B] Recognizing a File Type Tutorial
[C] http://wiki.netbeans.org/DevFaqActionAddEditorPopup
[D] http://wiki.netbeans.org/DevFaqActionAddFileMime





taT | Play with XML Layer (Part 2)

24 06 2008

Wow!

I am really enjoying playing with XML Layer. I had mentioned an important note in my previous blog entry- Part One of this series! Its time to work with the CookieAction, i.e. make some Conditionally Enabled Actions and play with it.

By the way, I came to know, that CookieAction does support Shortcut Keys, however I used to think it doesn’t as it was always disabled, when I used Action Wizard to create it.
Its a bug, that’s present since 5.5 and I never realised- I have filed a bug report!

Pre-requisites

Read my previous blog entry- Part One of this series! You should be thorough with all that was explained previously. If not, get it clarified by me OR on Netbeans Community mailing lists.

Problem Description

Here, we are going to transform an Action from one type to another, i.e. from CallableSystemAction TO CookieAction, sounds cool! Though, never tried. Well, here I am sharing with you another trick to make it possible, without using New File Type Wizard. We will make use of SayCheez.java, which was made in previous entry.

Solution

So, to start with, remove the CallableSystemAction and let the class SayCheez extend CookieAction, like this;

public final class SayCheez extends CookieAction {

Now, don’t remove the already existing implementations of abstract methods of CallableSystemAction, just add following two to let the class SayCheez implement all the abstract methods defined by CookieAction.

@Override
protected Class<?>[] cookieClasses() {
return new Class[]{{$Interface}.class};
}

protected int mode() {
return CookieAction.{$mode};
}

Please note, that {$Interface} needs to be replaced by appropriate interface, i.e. it could be either of the following Cookie class(es), which are basically interfaces/abstract class(es);

  1. Project
  2. OpenCookie
  3. EditCookie
  4. EditorCookie
  5. DataObject (Abstract Class, NOT an Interface)

Also, {$mode} needs to be replaced with either MODE_EXACTLY_ONE[1] or MODE_ALL[2].

  1. User Selects One Node
  2. User May Select Multiple Nodes

MODE_EXACTLY_ONE -
Action will be enabled if there is exactly one selected node and it supports the given cookies.

MODE_ALL -
Action will be enabled if there are one or more selected nodes and all of them support the given cookies.

In our case, its EditorCookie!

Now, alter the performAction method like this,

protected void performAction(Node[] activatedNodes) {
{$Interface} ref = activatedNodes[0].getLookup().lookup({$Interface}.class);
// TODO use {$Interface}
}

Here, ref is basically the reference to either the interface/class being made, which is being assigned a subclass reference, it could be of great use. Now, add your code for DialogDisplayer used in previous blog entry, in place of TODO comment.

See, it was too easy! Anyways, the changes in XML Layer, which shall be done with respect to the change in the Action type, some of them are as follows and rest will be the mentioned in the next part of this series.

Tricks for Menu Item, Toolbar Button, Shortcut Keys

Trick #1 - If you had made a Global Menu Item OR Toolbar Button with CallableSystemAction, then no changes required.

Trick #2 - If you had made use of Shortcut Keys earlier, now you have to remove them, as CookieAction doesn’t support Shortcut Keys! Well, I don’t know why. So, remove following code from our XML Layer, formed earlier.

Thanks for following, enjoy and have fun! Surprise to be revealed soon…keep an eye on my blog!

Previously posted on NetBeans Zone -
Playing with NetBeans XML Layer Files (Part 1)

Add to Technorati Favorites

sTay Tuned for More…





taT | Play with XML Layer

23 06 2008

Hey,

As I mentioned in my previous entry, that I am starting with a new blog series. This is it- Part One, of Blog Series: XML Layer! Hope you would enjoy, following it. Anyways, coming back to the point. Let me share with you another trick, which I was observing for few weeks, and its really cool! Its based on NetBeans Platform. This is my first full-fledged post on NetBeans Platform, as I’m dealing with it almost daily for over a week, for some cool plugin development.

Pre-requisites

This trick makes use of the existing tutorial, which is the base on which I have carried out the trick. Also, you must read this tutorial, if you don’t have prior experience with NetBeans Platform. Hey, give this a read as well,

This overview will quickly familiarize you with how NetBeans plug-in modules interact with the NetBeans infrastructure and with each other.

Problem Description

As mentioned in the tutorial, I created an Action Type (CallableSystemAction), made it a Global MenuItem and Toolbar Button. I named the Action Type (Java file) as SayCheez, and display Name as Say Cheez…

Now, I have made this action, as expected in the tutorial. Now, right-click Project & click on Install/Reload in Target Platform in the context-sensitive popup menu (context-menu). Its running successfully!

Now, let me show you the structure of XML Layer (layer.xml), its similar to the one shown in the tutorial, i.e. how it registers the action into the NetBeans IDE. See this image;

So, the trick is how to play with the Layer and don’t waste time, placing actions anywhere else in the IDE, by recreating them.

Solution

Note, all the following tricks would work for CallableSystemAction only, I have not tested for CookieAction, though it should work for CookieAction as well, if you are working with only MenuItem, Toolbar Button OR Shortcut Keys! For Editor and File Type Context MenuItem, there would be some other way round, I will see if its comfortable playing with them as well ;)

By Code Deduction

Trick #1- If you want to remove either one of the separators, OR even both of them, then see the following image, the code present in that remove it from the XML Layer, as per your need.

Trick #2 – If you want to remove the Action, from Toolbar, then remove the following code;

Trick #3 – If you want to remove the Action from Tools Menu, and retain it only on the Toolbar, then remove the following code;

By Code Replacement

Trick #4 – If you want to make a Shortcut key for this action, add the following code,

Trick #5 – Sometimes, it might happen, that your action is not suitable for any existing Menu, and you are looking to create your own Menu. By the time, you get ready with your Menu, you can just have this Shortcut Keys alone, i.e. no Menu Item, no Toolbar Button.

Tips to remember

This code has a shortcut key “Alt+F3″, which is represented as “O-F3.shadow”, so this means, if you have some key combination, that uses “Alt”, then use “O”, and for each “+” sign use “-” ,finally concatenate with the just formed combination with “.shadow”! If you use “Ctrl”, then use “D” and for “Shift”, use “S”!

Following are some key equivalents used in XML Layer;

  1. A to Z (as it is), F1 to F12 (as it is), 0 to 9 (as it is)
  2. / as SLASH, as BACK_SLASH
  3. ; as SEMI_COLON
  4. . as PERIOD
  5. as QUOTE

These were some of the frequently used keys in Shortcut Key combination, if you want to know some more, you can post a comment over here. I would be glad to help you out!

Actually, I was developing a module for past one week, and more intensely on the weekend, and have observed this by hit-and-trial, and thought of sharing the trick with you people. By the way, there’s a surprise! Any guesses, well no prizes for guessing!

HINT
Its related to the module, I’m working on for past one week.

Playing with XML Layer, reminded me that I have to resume working on XML Hyperlink Module as well :) Anyways, thanks for following, enjoy and have fun! To know more about the surprise, keep an eye on my blog!

Previously Posted on NetBeans Zone -
Update on Issue #136216: MySQL Server Node Error

This blog has been contributed to NetBeans Community Docs Program and for latest updates on this content, refer to the contribution.

Add to Technorati Favorites

sTay Tuned for More…