Oracle Blog

Chuk's musing, rambling and spiel

Tuesday May 15, 2007

On my recent trip to/from JavaOne, I was fortunate enough to be on Singapore Airlines' new Boeing 777-300ER. What is cool about this is that it has a brand new in flight entertainment system with 100 movies in English, Chinese, Japanese, Korean, Hindi, Tamil, Spanish and French. About 50 TV programs (check out Sponge Bob, Simpsons and my favourite Futurama), games, music system with customizable playlist, audio books and StarOffice 8! Here are some pics and a running commentary on them. Click on image for a larger view.

This is the new menu system. Go to PC menu

You have word, spreadsheet, presentation and also a file manager which will browse your USB drive. More later. I select Star Impress which is my favourite tool ;-)

Star Impress starts up. Takes about 1 minute.

Impress started

"We are experiencing some turbulence. Please fasten your seat belts". When the announcement came on, you are lock out of StarOffice for the duration of the announcement

The About screen

The IO interface by the screen. There is a network port which does not work. A usb port for reading and writing your files. I do not know what is the top jack is for.

Insert my USB drive to load my Impress document

My presentation on the back of a seat!

The keyboard. BTW, the key is really difficult to press if you have even if your finger nails are just a bit long. You have to exert a lot of force to press the keys.

Friday Apr 13, 2007

As part of my scripting lab at JavaOne, I've dusted off one of my first NetBeans plugin and have updated it. The lab requires the participants to write code snippets and try them out in a scripting environment.

My original scripting plugin provides a scripting plugin has a console but it requires you to type in at the console. If you make a mistake you have to type again.

To make it more convenient for the user, I made the console accept drop items; you can either drop a script file or a code snippet on to the console. First open the console Script -> Script Console -> <select your favourite script console>; then you can do one of the following

Drag a script file from the Project window onto the opened script console. The console will now execute the script. Note that if you are dropping a JavaScript file onto the console, it stands to reason that the console should be a JavaScript console. (An idea just occured to me while I am writing this; I can open a 'stem cell console' (SCC) where the console is not affiliated with any particular script language. Just drop a file on it and the SCC will try to execute it with an appropriate engine.)

Highlight and select any text from NetBeans editor. The drag and drop the selected text onto the console. The console will now execute the text.

Finally you can perform the above 2 operations on files outside of NetBeans. So if you drag files from say Konqueror or from a text editor and drop that onto the console, the console will know what to do with it.

I am sure that I've not covered all the possible MIME types so let me know if you you find something that does not work. I've tested on Solaris and Linux but not on Windows and Mac. You can find the MIME type either from the terminal that you started NetBeans or from NetBeans' log files.

One final thing; the plugin requires JDK 6 so NetBeans must be running on JDK 6. Otherwise it will not work.

I was at St Petersburg this week for Sun's Techdays. This is my first trip to Russia. The city is beautiful. However it is a bit cold for me; in Singapore, any thing below 28C is consider cold. I did however get to see snowfall for the first time in my life. Unfortunately I was not able to get a picture of me frolicking in it as I was working.

Tuesday Mar 06, 2007

This is the initial release of DWR plugin for NetBeans. This version currently supports the following features:1. Add DWR supports to new or existing JavaEE based web application2. Multiview editor for dwr.xml file. Currently there are 3 views: Create, Convert and the raw XML file3. Drag and drop of exported Java objects to JSP pages

In lieu of a screencast, here is a simple text walkthrough:1. Create a new web application. Add DWR framework2. Add a JavaBean to your application. Now click on the bean icon at the editor menubar (see image below) to export the JavaBean as a JavaScript objectThere are other ways of doing this; context menu from the editor and the project editor window.3. You will now be presented with the DWR editor (see image). 4. Now drag 'Insert Dwr Object' from the palette to a JSP page. A dialog will be displayed (see image).

Select the method you want to paste on the page. You can customize the call in the editorpane. If you have installed NetBean's JavaScript editor like I did in the image, then you will will get syntax coloring, etc.5. Don't forget the add Dwr library declaration. Drag 'DWR Libraries' to insert engine.js and util.js declarations.6. Deploy and test

Currently the plugin only supports 'create' with the 'new' operation. Some features that I hope to support in the next version:1. Exporting Struts form bean2. A new view in the editor for signatures. I'm still thinking how to create an editor that will intuitively allow me to express conversions3. Exporting JSF managed beans

You can find the NBM here and the source is available from https://ajax.dev.java.net CVS. I've not tested the plugin extensively on handcrafted dwr.xml file so I'm not sure how robust it is. Please report any bugs you find to me.

Sunday Jan 28, 2007

I've been using NetBeans quite a lot recently. One of the thing that I find really irritating is that to copy files from my desktop. I have to first add it to Favourites, then copy it over to my project. I've discuss this with a few people about this but apparently DnD from desktop onto the file explorer is not something that is currently supported.

I did not want to spend a lot of time implementing DnD in NetBeans so I did the next most logical thing; create a drop area that targets a specific directory. Here is how it works; you right click on any directory including packages and select 'Open File Drop Area'. A panel will open in the editor area. Now you drag and drop files (and directories) from your desktop onto this area. These files will be copied to the target directory. See image below:

Click to enlarge

The precompiled NBMs are available here and here; the source is available here. Whey 2 NBM? Well I want to do this module fast so instead of writing a directory copy, I used Apache Commons IO. The downside is that I have am distributing all the other classes that I'm not using.

I've tested this on Solaris and Linux but not on Windows and there might be a problem. The issue is that if you drag 2 or more files on to the drop area, the Transferable.getTransferData(flavour) method returns a String with the 2 files' URL delimited by newlines. I parse the string with a split() using "\\n". I figure that since windows uses "\\r\\n" I would still be able to break the string into individual files and then clean up the remaining "\\r" with a trim(). I'm not sure if this works. Let me know.

While this solution is not quite as elegant as dropping directly onto a node, I hope it will solve some of your file copy issues.

Monday Oct 30, 2006

Recently I was working on a Swing application that requires fullscreen
(FS) support. I experimented with both JDK 5 and JDK 6. Unfortunately
for me JDK 5 does not have support FS for the Linux distro that I'm
using; I have better luck with JDK 6.

After
learning a thing or two about Java's fullscreen support I thought I
would try to add FS to NetBeans as a module. After some hacking here is
my effort:(Click to enlarge)

You can get the NBM here. The source is available here. Note that the NBM is compiled with JDK 6 build 103. So if you are trying this module, NetBeans have to be running in JDK 6.

Wednesday Oct 04, 2006

I do a lot of presentation for Sun. Recently I was watching my collegue, Rags, presenting a Java Puzzler session. If you are not familiar with Java Puzzler session, this is the session made popular by Joshua Bloch and Neal Gafter at the last 2 JavaOne.

I saw Rags presented this session in Singapore, Manila and various Indian cities and of course in China. What he would typically do is to ask the audience raise their hands if they thought the answer is A or B or C. The problem with this approach is that Rags and the audience could not tell the number of people chose A, B or C. Further more a Puzzler session is more of a 2 way thing rather than your usual one way presentation viz. info going from the presenter to the audience.

I also notice that in some of the cities that we were in a large number
of the audience have either a notebook or a PDA device. We also have wireless in the hall.

Around that time, I was exploring the HttpServer class in JDK 6. What this class allows you to do is to start an instance of web server in your JavaSE application. You can implement a HttpHandler interface to interact with the incoming request.

Interaction with audience, wireless, PDA, web servers. Reminds me of this memorable conversation from Sleepless in SeattleJay:
Well, this is fate! She's divorced, we don't want to redo the cabinets,
and you need a wife. What do they call it when everything intersects? Sam Baldwin:
The Bermuda Triangle.

The idea was to have audiences posting results while Rags showed a puzzle. So I developed a very simple Java application to host a StarOffice/OpenOffice presentation; I created an instance of HttpServer to receive incoming request. The results are tablulated below the presentation as shown in the following figure:

(Click to enlarge)

To access the voting page all you have to do is point your browser to http://your_ip:8080/puzzler:

(Click to enlarge)

The cool thing is that you do not even need an Internet access just wirless. Audience connects to the private/closed wirelss and access the application.

If you want to try this idea out, the source code is available here. Because it is a hack job, the 'web page' is hard coded in PollHandler.java. So if you want to the browser to submit a form with more fields, you will have to go in and modify PollHandler.java.

I have 2 run scripts in the source package runpreso.sh and runpreso.bat. Modify the appropriate variables. The default port that the web server use is 8080. You can override this by specifying a port number when you run runpreso.sh/.bat.

Some limitations you should be aware of:

You cannot run the application in full screen. If you put StarOffice in full screen mode, you will not be able to see the results

StarOffice sometimes cannot receive keyboard events. I though this may have to do with mixing heavywight and lightweight components but I tried using widgets only from AWT. The problem presists.

I believe that the idea of an interactive presentation is very powerful for the unconference model. If you want to know what happend in Beijing read on:

The interactive StarOffice app was a pretty simple application. I tested and it worked. Rags and I
were all set to try this idea out in Beijing Techdays. Disaster struck.
For some reason unknown to me at that time, I was not able to access
the server except from localhost. We were sitting by the stage waiting
for our turn and debugging the program. Rags was going "Okay we have 5
more minutes, you got it yet?" "Check this part...". Haven't had this
much excitement for a long time. To make a long stroy short, there were
no fairy tale endings. I just could not access the web server.

Later I found out that I accidentally bound the address to localhost.
Rags had actually pointed this out to me but I didn't think it was a
problem. So anyway I've correct that problem and its working now.
Cannot wait to give this a second try.

Thursday Sep 07, 2006

This is the second release of my
attempt at integrating JMeter
with NetBeans. In this release, I've added support for local load
generators. I know I should have added support for remote load
generators as well. Work got in the way. Here is a screenshot
of my latest attempt.

Click to enlarge

The local load generators are in the
Runtime tab. Can execute a test plan by

right clicking on the localhost
and select 'Generate load'. However, you must first load a test plan
into the editor. Otherwise you will get a message asking you to load
a test file. Hopefully in the next release you should just select a
test file and it should work. Still trying to figure out how to get
a list of current selected node in NetBeans. Pointers appeciated.

or you can select a test file in the
project window, right click and select 'Generate load'. With this
method, you do not need to load a test plan into the editor.

I've also integrated JMeter's status
bar into NetBeans. So when you start a load generator, you can see
the number of threads starting up at the bottom right hand corner. To
stop just reselect 'Generate load' again. This is a toggle action. If
you are running a load generator on a say testplan_a and you wish to
now generate load for testplan_b. You do not need to shutdown
testplan_a. Just go to testplan_b file, right click and select
'Generate load'. The module will stop testplan_a, save testplan_b
changes and start the load generator for it.

You can get the NBM here.
I forgot to post the sources when I blog about this the last time.
Here is the latest sources.

Thursday Aug 24, 2006

About 2 months ago, I was chatting with one of the SE here in Singapore. We were talking about the state of Sun's developer tools offering and NetBeans came up. One of the thing that he lament was that there is no load generator for NetBeans. My foray into scripting and Jackpot was coming to an end and I wanted another project to sink my teeth into. I asked him what are some of Sun's customers and partners are using for load generation. A few names came up; JMeter was one of these names. He said that JMeter is quite popular as it is free. So I decided to see if it was possible to add JMeter into NetBeans.

I've never used JMeter. I started trying it out. As luck would have it, there was a series of articles that was published at that time so that helped me a bit. About 2 weeks ago, NetBeans 6 M2 was released. Lo and behold, JMeter is now supported in NetBeans as part of the profiler (see here). I was thinking of stopping my work; however I found that JMeter is only supported as an external tool. I wanted the entire JMeter to be inside NetBeans. So I continued.

So here is my first attempt at integrating JMeter into NetBeans. Here are some requirements:

The module does not bundle JMeter. You have to first install JMeter. The version that I'm working with is version 2.2. You can get it here

Now install the nbm for JMeter. The nbm is only tested with NetBeans 5. You must also install the beta for Matisse.

After you have installed the module, go to Option -> JMeter and configure the JMeter installation directory

Now create a project. Select File -> JMeter to create a new test plan. I've also bundled all the demo test plan from JMeter under File -> JMeter -> Sample Templates

Here is a screenshot of the integration

Click to enlarge.

So what can you do? Well, you can only edit the test plan and browse the help docs. To access the function docs, click on the question mark '?' under the test plan tree. This will open the functin helper in the output area. If you now click on 'Help', the JMeter docs will open in the editor area. Note that you have to set your the -Xms and -Xmx in netbeans.conf to be above 256mb. Otherwise you will get out of heap space exception.

The servers are not integrated yet. Hopefully this will happen in the next release.

Monday Aug 14, 2006

I've added scripting support for developing Transformers in Jackpot . The way you use it is similar to running Query. Open the 'Query and Refactor' (CTRL-Shift-Q), and select 'Transformer scripting runner'.

I have converted all the example scripts on the Jackpot website to Javascript so you can try these scripts, both query and transformer, on your projects. I've not really pushed the scripts so let me know if you find any errors. There are 2 scripts that are not working

find_unused_variables.js – I cannot seem to instantiate a Finder object.

beanize.js – I got exactly the same result as Beanize.java class. But for some strange reason, when I tried to view what source changes were made, Jackpot could not report the changes viz. the visual diff window did not open. I got the same result with the Java implementation. Also, while I was porting Beanize.java to Javascript, I found some missing methods like getMemberDecls() from Tree. Seems like Beanize.java is quite dated. Anyway if you manage to get this working let me know.

Here are the list of modules you will need if you are interested in trying this:

Script engine – here. I've fix some bugs. The continuation character '\\' is now working in the script console. You can get the source here. The sources includes the window module.

Thursday Jul 20, 2006

Sven Reimers has found a major bug in the NetBeans scripting module. The script engines were not initialize when you open a script console; so when you entered any command, the script engine will choke. I've fixed the problem. Thanks Sven.

While was using the jython script engine to test the console and I found a few problems with jython

The jython engine does not honour the classloader in the ScriptEngineManager. The ScriptEngineManager allows you to associate a classloader when you are instantiating it. The idea is to be able to load and create script engines dynamically. I can get a reference to Jython's script engine but when I tried to execute a statement, print(“hello world”), I got a class not found exception on PyRunnable. I was pretty sure that PyRunnable was in the URLClassloader's path that I passed to ScriptEngineManager. Another Sun colleague, Sundar has told me the workaround but I completely forgot about it. It is not enough to have the jython's Jars in the classloader, you have to explicitly set the classloader to the current thread's context classloader.

I could not redirect jython's output to the console. There is a method in the ScriptContext call setWriter that allows you to redirect the engine's output to wherever you like. Again, jython is not honouring this. So the output is displayed to System.out. For those who are using the console, I suggest you write a globals.py file; stick this under console directory. In globals.py redirect all output to Console.println(). Console is an exported object. See the help for more details

The jython engine comes with a set of Python libraries. You can find this under jython_home/lib/python. I do not know Python to test out the environment, so if you are testing, please let me know how this is resolved. I know that you have to set python.path. But currently this is not set, so what is the default?

Wednesday Jul 19, 2006

I have written an ScriptModule for Jackpot. As I have mentioned in my earlier blog, one of my motivation for experimenting with a scripting interface for NetBeans is to be able to script Jackpot. What is Jackpot? Very briefly, Jackpot is a source transformation engine. The Jackpot engine allows a developer to query and transform Java source. See Tom Ball's JavaOne presentation.

As you probably know, to use Jackpot today, you either describe your query/transformation the Jackpot rules language or develop a NetBeans modules which allows you access to the full Jackpot and Javac APIs. The rule language is easy to learn and use if you can express your queries/transformations as axioms. For more powerful Jackpot features, you have to resort to the Jackpot APIs which are only available in NetBean modules. So if you want to develop a sufficiently complex Jackpot query, you have to buy into NetBean's module (nothing against developing NetBeans modules). There is nothing in between the two methods.

The idea of the Jackpot script module is:

To expose the full power of the Jackpot API but not the NetBean module gut.

Use scripting as a prototype before implementing it in Java

Quick, use once and unique to you but complex Jackpot hacks; eg. converting your application from Hungarian notation to Java naming convention

Reduce Jackpot develop/debug cycle. You modify the script instead of the Query class for example.

It is NOT the intention of this module to totally replace the Jackpot/NetBeans module method of development.

As a proof of concept, I've only implemented Query; supporting Transformers should not be that difficult (famous last words). Here is what you need to do to try this module:

NetBeans must be running on Mustang. Use the –jdkhome switch. Also, you must get Mustang b79, b80, b81 or b82. This is a Jackpot requirement. I've build and tested the module on b82

Get some of the sample query scripts from here. All the scripts, except one, are reimplementation of the query examples from the Jackpot website.

Once you have installed the module, open up the 'Query and Refactor' and select 'Query scripting runner'.

A filechooser dialog box will open up. Select any one of the JavaScript examples.

Currently the script environment supports the following objects CallGraph, NodeScanner and TreeScanner. I tried adding support for Finder object (because of FindUnusedVariables.java example) but could not instantiate Finder class. Try running find_unused_variables.js to see what I mean. If you manage to find the problem, let me know.

The source is available here. If there is enough interest, I'll work on Transformers. Let me know what you think.

Try running the Jackpot module with other scripting engine and let me know your experience. You need to get JSR-223 enable scripts. You can get a some of these script engines from http://scripting.dev.java.net.

BTW, this blog is written with “Sun Blogger for OpenOffice.org and StarOffice”. Pretty cool. It would be really nice if I can view my files as well. Next version?

Monday Jul 17, 2006

I've just updated the my NetBeans Script module (see blog). Here is a list of the new features

The script related menu items have its own menu call 'Scripts' in the main toolbar

A script environment view which lets you look at what are the script modules and script engines that are installed

A simple file system view of the script repository directory. Can you do most things like create and delete scripts and directory. However you cannot drag and drop files/directorys. Did not want to turn this into a full fledge file management thingy. The update view is not very optimized. Every time you add or delete a file, the entire view is reloaded.

I've added a simple script console. For every script engine, you can now open a script console in NetBeans. Furthermore every console opened will have an object call Console that allows you to manipulate the console. JavaScript console will be the best support. The JS console is initialized with init.js from Mustang as well as a few additional functions. You can add console initialization scripts (aka .profile) in console directory. The name of this initialization script has to called globals.<script suffix>.

I've added documentation to on the new features, programming objects, etc. It's probably not enough but will have to do for the time being. Go to Help -> Help Contents -> ScriptEngine entry

Here is a screenshot of the new features

Click to enlarge

You can get the latest NBM here and here. I've also change the license from CDDL to BSD. If you are going to try the script module, here are the requirements

NetBeans must be running on Mustang viz. use the --jdkhome when you start NB

Thursday Jun 29, 2006

Scripting languages are popular (probably an understatement). JavaSE 6 (aka Mustang) will have first-class support for scripting languages. There is already a project at scripting.dev.java.net that have quite a few scripting engines for Mustang.

NetBeans is a top notch IDE. However to extend NetBeans, you have to resort to writing modules. People may what to invest time and energy into a hack and slash project like my recent FIFA World Cup module (Go England!). NetBeans current has a project call Coyote that adds scripting languages support. But from Coyote's website, there is no mention of scripting NetBeans itself. So I've decide to add support for scripting into NetBeans.

Bear in mind that this module is stricly experimental. There are a lot of concepts that are not fully developed. The idea of this scrpting module is to perform most NetBean stuff (eg. creating a Editor TopCompont) but not to the level of the OpenIDE API.

Still interested? Here is what you need to do:

Download and install Mustang. I've only tested this with build 89 and on Solaris/Linux only. YMMW on Windows.

Install the excellent NetBeans 5 and all the related patches or updates.

Startup NetBeans in Mustang. This is essential. There are 2 ways of doing this: either change $NETBEANS_HOME/etc/netbeans.conf or use the --jdkhome switch. Since the module is experimental, I would also like to encourage you to use the --userdir switch as well.

Install the example scripts. You can unzip this in any directory. The test scripts are examples to get you started until proper documentation are available

So once you have installed the modules, go to Tools -> Options -> Miscellaneous -> Scripts and set the 'Script repository' field to the script directory that you've expanded.

Here are things you can try:

Now go to to Tools -> Scripts and select any one of the .js script. Note: If you did not install window system module, then you will not be able to run window.js

Exit NetBeans and restart it. Observe. Now exit NetBeans again

Here is how the module works. The script engine module will look for 2 directory in its script repository directroy.

actions - all scripts that are saved here will appear in Tools -> Scripts. If you have added new script to this directroy do a Tools -> Scripts -> Reload. Currently the engine does not go recursively into the directory.

load - all scripts that are saved here will be loaded when NetBeans starts up. This allows you to register events, etc.

When you configure the script repository path, there is a check box that says 'Initialize script repository'. This creates the actions and load directory in you script repository. If you are starting a new repository, check this.

You can introduce new functionalities into the script enviroment by creating ScriptModule. See the source for details; look at windowscriptmodule project. I will \*TRY\* to document this, promise.

One module that I'm itching to do is Jackpot. Today if you want to develop Jackpot, you either use the Jackpot rule file or develop a NetBeans module. Nothing in between. Hopefully a Jackpot ScriptModule will solve this.

A word on WindowScriptModule. The idea of this module is to be able to manipulate NetBeans windows. Currently the module is in its primordial stage. The only functionality there is to create windows, and not correctly I might add (see bugs below).

Bugs

Adding script engine in the option pane does not work yet. I'm having some classloader issues. If you manage to debug it, let me know. Here is the Groovy engine to try (JAR1,JAR2).

TopComponet is not opening properly viz. an Explorer TopComponent is opening up in the editor space. In fact \*ALL\* TopComponents are opening up in editor space. I think my problem is TopComponent singletons. I've basically commented out all the default code in findInstance() method and just return a new TopComponent each time. How do I create a non-singleton TopComponent?

The realy irony here is that you cannot create scripts in NetBeans. NetBeans does not allow you to casually mount a directory and edit files (I miss the mount feature). The only script editor that I've found is a Javascript editor which you can find here. Hopefully I'll remedy this in the next version, providing a nicer user inerface. I need to use Nodes and stuff like that
but I'm fairly new to NetBeans so I'm currently reading Tim Boudreau
series of articles on this.

Whao! this is already more than a minute! Send me your comments

Oops!Sundar tried my module and got the following error:Unfortunately I'm using the beta release of Matisse. So you'll have to update Matisse to get this to work. Thanks Sundar.