Wednesday February 28, 2007
About Those Blue Blocks...
There's a school of thought that sporadically raises its head to complain about the NetBeans "blue blocks", i.e., the guarded blocks that contain the generated code provided by the "Matisse" GUI Builder. Especially those that want maximum control over their code tend to get a bit worried, justifiably, that they can't fiddle and tweak with what is, after all, their very own code.
Not everyone seems to know that it has always been possible to do so, however. You can select any Swing component in the GUI Builder, open the Properties window, and then open the Code tab. In there, you'll find 'properties' like "Pre-Init Code" and "Post-Init Code". When you click the elipsis, you get a full-blown albeit small Java editor (e.g., including code completion and syntax highlighting). There you can add initialization code, creation code, and so on. Admittedly, this is still not ideal. It's a bit cumbersome and odd to add bits of code like that. And there are many places in the code that are not covered by these 'properties'. Well, the first bit of good news is that in 6.0, there are about twice as many of these 'properties'. For example , "Pre-Declaration" and "Post-Listeners". However, as in 5.5 and before, you need to do a bit of trial-and-error to see where the code you specify as one of these properties ends up.
So... how cool would it be if you could right-click a Swing component and then choose "Customize Code". You'd then get all the code related to the Swing component and then you'd be able to edit it all and click OK in the knowledge that it would be safely integrated into the blue block? Well...
The above dialog appears when you right-click on a Swing component in the GUI Builder (in NetBeans IDE 6.0 Milestone 6, and probably before that milestone, and probably definitely after that milestone) and choose "Customize Code". There's all sorts of code and settings that you can specify for the entire Swing component, all in one place.
This is unlikely to satisfy the hard-core blue block haters. However, it is clear that this new dialog is a response to the oft-heard unhappiness around this aspect of the NetBeans GUI Builder. At the very least you've got to admit that this is a pretty strong compromise. You're still not able to tinker with the entire piece of generated code. However, you are able to tinker with all the code relevant to specific Swing components. It's worth your while to play with this for a bit and see how it works for you. You'll be surprised how far you can get with this, in terms of controlling the code that the IDE generates for you.
And, finally, it makes sense that there are some limits to this. If you were going to completely wreck your source code, how would the GUI Builder be able to deal with that? At the very least, you can always be sure that the source and the design view are in sync, because the generated code is guarded. But, as you can see, you'll be given a lot more room to manoeuvre within these constraints than before.
Feb 28 2007, 06:17:12 AM PST Permalink
Bye Bye Bangalore
I've had a really good time at Sun's IEC (India Engineering Center) in Bangalore. I got up to a lot more and met a far wider variety of people than I had expected. I spent Monday and Tuesday last week there, then spent 3 days in Hyderabad at the Sun Tech Days, and then yesterday and today again in Bangalore. In this time, these were my activities (in no particular order):
- Met the writing team at the IEC for the first time. They're really cool people and easy to talk to. There's about 30 of them! Geetha, the manager, really looked after me. Even on personal trips, like to Mysore last Sunday, arranging a taxi for me, for example. Peter Fernandez, who is based in the States, and to whom Geetha reports (i.e., so a level up from Geetha) was here too and also in Hyderabad. It was great seeing him again and getting support from him too. I hung out with several of the writers here, they're really nice people and very very technical, more technical than most technical writers I've encountered. We went out today to a Punjab restaurant, which was a first for me (and I managed successfully once again to avoid the ultra hot food).
- Met with the content development team for Sun's Java courses. These four people know a LOT about NetBeans and its packs. They were really cool to talk to and I even interviewed them for NetBeans.org. More to come on this point soon. You'll see a picture of them, find out how they write some of the Java courses, and hear what they think about NetBeans and NetBeans.org.
- Attended a very good all hands meeting, at which Rich Green held an extremely inspiring speech. I love how the open source approach drives everything he says (and, probably, thinks). There was also a great internal documentation all hands by Peter Fernandez, that looked at where we are as a documentation group and where we are going in the future. The Sun documentation groups, wherever they are, are really doing cool stuff and thinking outside the box. That's a pretty cool environment to work in (believe me, because I've worked in several others too).
- Learned how (most of) the technical writers here write/store/maintain documentation, using an editor called Epic, on top of a Sun-oriented subset of DocBook. Possibly we in Prague will be moving to the same set up, so we have a lot to learn from the writers in Bangalore.
- Met with a few engineers. I even met an entire development group, who work on internal Sun software on top of the NetBeans Platform. One of them is Vadiraj, who has started providing incredibly technical blogs on the XML MultiView API (and ultimately also the Visual Library API) here. I also met another technical engineer, Rohan, who is also creating modules on top of the NetBeans Platform for some internal Sun tooling. But both groups of engineers are talking about open sourcing their modules at some stage. So watch this space!
- Went to Hyderabad Sun Tech Days, presented the NetBeans Extreme Programming session on Day 1, then two presentations at NetBeans Day. Got lots of discussion out of my presentation abour porting Java applications to the NetBeans Platform. Showed the immense performance improvements between the 5.5 Java editor in NetBeans and the forthcoming 6.0 Java editor. Spent a bit of time with Frank, Nilesh, and Venu at the NetBeans booth. Blogged about these experiences, got several new e-mail contacts and read a few cool blog entries as a result.
- Held a session on blogging. This was a 'tech talk' that is held periodically at the IEC, on a variety of topics. I had the honor of talking about blogging. Basically, I covered some do's and don'ts, as well as some common negative impressions people have to blogging. So I was a bit like Al Gore, but instead of talking about the reasons that people don't believe in climate change, I talked about the reasons people don't believe in blogging. Here's the presentation, if you want to see it, in PDF format.
- Held a workshop on "10 Things I Learned from Working with Developers". This was an extrapolation of one of my blog entries from sometime ago. First I quickly went through the slides, to a group of about 25 technical writers, and then they discussed in groups of two/three which two "things" they found most relevant. And then each group had to talk about one of the two things. We really ended up reaffirming the 10 points and we also came up with some new ones. Underlying everything was the perception that a technical writer shouldn't hesitate to look stupid in asking lots of questions, because if they don't, then that's how the end user will end up feeling. Here's the presentation, especially useful for people who are technical writers working with technical engineers.
- Held a truncated "NetBeans Extreme Programming" session to a random group of IEC people this afternoon, introducing them to NetBeans IDE. Several of them had never seen or used NetBeans IDE before, so this was their first impression. I basically hit the high notes of my NetBeans Extreme Programming presentation. The biggest problem with this presentation is that NetBeans now covers SO much material, SO many specifications, SO many approaches to programming, that it is completely impossible to give a thorough impression within an hour. But I did my best. Here's the presentation, covering some of the major highlights of NetBeans IDE.
- Met with a few NetBeans-interested people outside of work. One group, from 3MRT, I will be meeting this evening...
...and the other tomorrow. Both interested in moving to the NetBeans Platform and looking for some discussion on that.
I probably left some things out in the list above. But it's been a great, productive time. Tomorrow I leave for some time in Goa, during which time we need to do a lot of work on finalizing the NetBeans Platform book, because copy edits keep rolling in from Prentice Hall, the publisher. But I hope to catch some rays on the beach and maybe a bit of scuba diving as well. The weather is great in India, 28.5'C, as Sun's elevator at the IEC told me earlier today. I wonder if that message is driven by Java...
So bye everyone, thanks for the cool time.
In other news. Purchase the Rough Cuts version of "Rich Client Programming: Plugging into the NetBeans Platform" TODAY!
Feb 27 2007, 04:56:21 AM PST Permalink
How real is the NetBeans Platform book?
"Rich Client Programming: Plugging into the NetBeans Platform" has been mentioned several times, from its inception to the later stages, with pilot chapters being available and comments being welcomed from all corners of the world. That has been facilitated by the mailing lists, by this blog, and by the book's official site (recently created) at http://www.netbeans.org/books/rcp.html.
However, you might have been thinking: "Those are all nice words. I'll believe it when I'm holding it in my own two hands." Well, that's not quite possible yet. What is already possible, though, is to show you what the curent state of the front cover is. That's about as concrete as it gets. If someone has been roped in to put a book's cover together, that means that things are pretty far down the road to release. So... here it is:
Plus there's a page on the Prentice Hall site that is dedicated to the book. Soon you will be able to buy the "rough cut", which is basically a draft form of the book. You'll find editing hasn't been completed on the rough cut, for example, or that code might not be well formatted yet, and other glitches like that. But you'll have the central argument of the book and all its pages. The order of the chapters in the final book might change, and many wobbly areas in the book will have been smoothed out. But, despite that, the main focus of the book will be as you find it in the rough cut.
Click here to jump to the rough cut's page. You'll see it is not available for buying yet. You can already see the table of contents, the preface, and information about the three principal authors.
This is definitely a significant step forward. Thanks Prentice Hall, for putting this together.
Update 27 February 2007: Purchase the Rough Cuts version of "Rich Client Programming: Plugging into the NetBeans Platform" TODAY!
Feb 26 2007, 12:28:22 AM PST Permalink
Sun Bear
Today I learned in India's Mysore Zoo that a bear has been named after Sun Microsystems. Or maybe not, but there definitely is a type of bear named "Sun Bear". Here's the proof:
I must say that Sun Bear is a bit odd looking, as if it has been open sourced one too many times, with multiple engineers adding the very best features without checking whether they work together or not... :-)
And here's a full description of Sun Bear. It eats fruit and lives in trees. Hmmm. Doesn't really fulfil my expectations of the concept "bear". Maybe this is post-modern bear, declawed and vegetarian.
Feb 25 2007, 06:53:01 AM PST Permalink
JDIC Browser on the NetBeans Platform
A completely unexpected thing that came out of NetBeans Day, for me, is that I now have my own JDIC browser integrated in NetBeans IDE. In fact, I am typing this blog inside a TopComponent. All the way back on November 1, 2005, I was already able to do this (and was pretty excited about it). But, in that case, I used an implementation of JDIC by Rich Unger. Now, however, I've done it myself. It all started yesterday when I was going through the list of names and e-mails that I had gathered from various people I had met at Sun Tech Days Hyderabad. One of them, who I briefly talked to after NetBeans Day, was from Aswin. He had left me the URL to his blog. So I went there and browsed around a bit. And guess what I found? A very cool blog entry by Aswin called Two Minute Web Browser in Java. In this really cool blog entry, Aswin shows how easy it is to create a JDIC browser in a Java application. It was really tempting to... begin thinking about porting his application to the NetBeans Platform. And so I did.
First, I built the application he described. Really cool, nice, clear and wonderful. It required virtually no coding. However, I encountered problems that many others had before me. For example, I ended up using the IE version of the embedded browser, which has problems with scrollbars, as you can see here... no horizontal scrollbar to be seen:

However, it wasn't long before I had done a 'simple port'. In other words, I moved the code into a NetBeans API TopComponent, and put the jdic.jar and native libraries in a library wrapper module. I also added 'Back', 'Forward', and 'Refresh' buttons, which were easy to program because of methods provided by JDIC. Here's the result, which I was already happy with, despite its limitations:

Note that I put the text field and buttons below the returned web page, instead of the normal place, which is above it. Why? Because of the lightweight/heavyweight component problem, which resulted in the drop-down list not rendering correctly, being hidden behind the returned web page. I looked around for solutions, and have found some, but just haven't implemented one yet. In the meantime, I moved the controls to the bottom of the browser, so that there wouldn't be a problem using the browser.
The next problem was that I was using JTabbedPanes, just like Aswin's original. However, there is no way of closing an individual tab. Normally, one would expect one of those little X symbols, which need to be clicked to close a tab. Both Joerg Plewe, who is a NetBeans Dream Team member, and Kirill Grouchnikov have blogged extensively about this issue. I initially adopted Kirill's approach, which meant I had to install the Substance look and feel. This was the result:

I was pretty happy with that, at least now I could close the tabs. However, I had reached the limitations of my 'simple port'. Everything was working in my TopComponent, but I hadn't leveraged anything else of the NetBeans Platform. I then began using more of what the NetBeans Platform has to offer, spreading out the ui more logically across the 'real estate' of the IDE. So, now, as a result of these additional steps, a new instance of a TopComponent opens, whenever I press enter in the text field afer entering a valid URL. And, good news, each instance of the TopComponent has its own X sign, as well as many other out of the box features, so this is a much better option than sticking with the JTabbedPane. However, within the TopComponent I still have a JTabbedPane. That seems to be the only container that can display a JDIC web browser. It is very odd. So now I have two tabs per web page, one from the JTabbedPane and one from the TopComponent. Not ideal, but still better than using only JTabbedPanes. So here's the result, with this blog entry used in the screenshot:

Note that here the controls (i.e., the text field and buttons) are in the toolbar, instead of being part of the TopComponent. And what you can't see here is that the status bar gives the user messages when the URL is invalid. In other words, this porting procedure has gone beyond the 'simple' TopComponent port, to a more complete transfer. Still far from complete, but clearly a functioning browser that is already 100 times better than the Swing browser that is bundled with the IDE. Notice that it is completely integrated in the IDE, so that, for example, you can flip from one browser page to a Java class, just like any other window in NetBeans IDE, for which no coding was necessary on my part:

Plus, it can be installed in any application built on the NetBeans Platform (and there can't be many that wouldn't benefit from a high quality web browser), although currently only on Windows operating systems. And it all came out of coming across Aswin's cool instructions for creating a small browser, out of a few lines of code. Thanks Aswin!
Feb 24 2007, 03:36:23 AM PST Permalink
NetBeans Day Hyderabad: Standing Room Only
Unfortunately, right at the point where I was about to make my first picture of the crowd (which must have been over 900 people, according to Ashwin, the NetBeans evangelist who ran the day), my camera's battery died. But Ashwin made lots of pics and anyone else who did who was there is welcome to send theirs to me (and I will publish them in my blog if they meet my subjective standards).
The day began with an introduction by Ashwin, where he outlined strategies and roadmaps and so on, after which I followed with a truncated 20 minute version of "On the Move with NetBeans". Normally, this session is 50 minutes, but because of involvement by partners, it was cut short, also on the agenda. So I knew I didn't have much time and had to do something useful. So I compared the NetBeans editor in 5.5 to the editor in 6.0 (and one or two things broadly related to the editor). I literally had both IDEs open simultaneously and continually switched from one to the other to prove a point. Based on Vincent's excellent Flash demo as my starting point, I covered the following improvements, in this order:
- project groups
- stop-and-replay on run
- generating parameterized constructor from code completion box
- instant rename
- smart code completion ("import" statement below package declaration)
- removing unused import statements
- highlighted method exit points
- simplified 'surround with'
- drag and drop of file and folder from desktop to editor and project
I explained at some point that the rewritten editor is equivalent to performing open heart surgeory. In other words, incisive and definitive, not tweaking, but transforming. I also mentioned that since the underlying APIs are being rewritten, anything created on top of the NetBeans Platform is automatically going to benefit as well. Both Ashwin and I thought that I went a bit over the top in slamming the pre-6.0 editor. Especially since many people might not have had much to complain about in the current editor and would have considered the forthcoming enhancements as simple improvements rather than something as dramatic as 'open heart surgeory'. Ah well. I could see quite a few people looking up admiringly at some of these cool enhancements, such as the 'stop-and-replay on run' feature, which I sold as "useful especially when you are a beginner and you tend to end up in loops you never wanted to be in in the first place".
Then followed some presentations by partners. Also Sun people were involved. There was an excellent and thorough session on Java EE 5 and Infosys, one of Sun's major partners in India, also had a great speech and very encouraging words about NetBeans. Everyone in the room applauded when we were told by Infosys that they had definitely decided to use NetBeans. Another partner did a very technical presentation on business rules management, with a demo of modules built on the NetBeans Platform for setting business rules and applying them to loan requests. Both these sessions received a lot of comments and questions at the end. There were different queues with microphones, there were two large screens to show the action on the slides. From way in the back of that long narrow room, the speakers must have seemed quite small. From up front on the stage, the crowd looked very friendly and colorful.
Then followed Ashwin, doing "Unpack Your Favorite Feature". He did some cool demos on areas that I knew very little about, like the Enterprise Pack stuff. All that is very XML-oriented and not in my immediate area of interest, since I'm more and more into Java, but it is cool to see how much the IDE can generate with wizards and so on. Ashwin also demoed the power of the Profiler. It seems like a pretty complicated piece of software to me, and important to know what exactly every little bar and graph actually means, in order to do anything with the information. Then followed some Visual Web Pack demos, which are always great crowd pleasers and was done very thoroughly, I thought, by Ashwin.
And then it was my turn! My long awaited presentation, officially entitled "Step Onto Our Platform". However, I've totally redone that presentation. It is now called "Porting a Java Application to the NetBeans Platform". Click here to download it in PDF format. For once in my life, my demo went without a hitch. And I felt completely comfortable. The demo involved moving a simple JMF client to a TopComponent, and then installing it in the IDE, and then in the bare NetBeans Platform. It went pretty well, I thought, and I had a bunch of interesting conversations afterwards. Some great questions and areas to look into in the NetBeans Platform area. I made very clear that if they are new to Java, they should first learn basic Java programming, such as threads and Swing, before even thinking about the NetBeans Platform. Here are the notes I gathered from the discussions afterwards (people wrote some notes in notepad on my laptop while I spoke to others, there was just so much interest in the NetBeans Platform story):
- "Quite interested in your mail client system... and looking forward to updates on it ASAP."
- "Can an installer integrate into a NetBeans Platform application?" Several people asked this question. I know Sven Reimers and Toni Epple are planning to do something with IzPack integration for NetBeans. Maybe what they have is already usable, would be good to find out.
- Yet again the failures of the library wrapper module came up! All the way in India people want the Library Manager to be somehow integrated with library wrapper modules, so that JARs, sources, and Javadoc can easily be selected and used in a NetBeans Platform application.
- There were at least two people asking questions about JasperReport integration in NetBeans IDE. Actually, the questions weren't about JasperReports specifically, but about any kind of reporting tool integration in NetBeans IDE. I told them about Toni's Jarvis project and they wanted to know when they could do something with it. I mentioned that it is already possible to drag and drop tables from a database onto a report and have the data be displayed automatically.
- A 'silent mode' for deploying Sun products was asked for. Someone, from Sun, asked about the possibility of a batch process for deploying multiple Sun products and add on packs in the background. Or something like that, maybe I didn't understand.
- There was a question about Maven builds and Cruise Control for NetBeans Platform applications.
- "How do I get a NetBeans Platform application's icon in the System Tray?" That's a cool question and it must somehow be possible with JDK 6. But the implementation would have to be different per operating system, which is kind of a bummer.
- "How to change the look of NetBeans?" Here we talked about skins and themes and the Substance look and feel.
- Someone wanted to install a NetBeans Platform application as a service, for data uploading, something related to databases. And someone else mentioned a Java to COM bridge as a solution.
And these were only the questions that were written down. There were many more. I also very heavily evangelized the Developer Collaboration module. I introduced the topic by, part way through my presentation, showing them this screenshot (as an example of a set of modules that you could, potentially, install in your own application, although I wonder if this would work so well since there are so many dependencies on IDE modules), and reading line for line what you see in it:

To me, the above exchange is fantastic. Someone called Sandy, who is here in Hyderabad, yesterday learned something brand new about the Java programming language from Bruno Souza (in Brazil), Vincent Brabant (in Belgium), Wade Chandler (in the States), and others. Sandy logged into the Collaboration module for the very first time last night. I hope he stays and many others join him. At some point, there were 7 of us chatting last night. Now that's pretty cool. We were also sharing code and discussing it. For this reason, at the end of my presentation, my final words were, again, encouraging people to get into the 'Developer Collaboration' modules and just hang out, chat, and learn about Java. Sure, it's not perfect and sure there are many small and large areas that can be improved. But isn't the chance greater that they will be improved if lots and lots of people are making use of it?
So, really, NetBeans Day was a great success, I think. The attendees were both from the school and college community as well as from working environments. The diversity of topics was pretty cool and the massive crowd, all the way to the back of the room, will stay with me a long time. Ashwin, can you prove it by publishing your photos somehow?
In other news. Have a look at Vadiraj's blog. He's one of the engineers I had a meeting with at the beginning of the week in Bangalore. We had a really cool discussion about their work on NetBeans modules they are creating to support their software. Let's hope even more bloggers get started!
Feb 23 2007, 01:56:30 AM PST Permalink
Programmatically Hiding Actions in NetBeans Platform Applications
I got a very interesting question yesterday from two engineers from a local company, Samyak Infotech Pvt. Ltd., which is close to Hyderabad. They said they read my blog, so hopefully this will find them and not confuse them too much. :-) (No guarantees that the approach taken in this blog is correct, by the way.) They're obviously very advanced NetBeans module writers. Their question boiled down to the scenario where you have users in a database and, depending on whether their login succeeds, some additional menus are shown in the application's menu bar. How to implement this? Jesse Glick and Tonny Kohar gave some advice. It ended up being a bit of a puzzle and it still isn't complete, but here's the basic outline (and I'm hoping that it will make more sense to me as I write about it).
First, some pictures. In this scenario, the user types a name in the Options window. Ultimately, this would be connected somehow to a database and maybe you wouldn't use the Options window at all for this. However, to set the scene, I had to be able to type in a name somewhere. So here it is:

Now I click OK. Next (i.e., immediately), only if I typed "Tom", do I see the following menus:

If I do not type "Tom", then the above screenshot would not have (1) "Some", (2) "Menu for Tom", and (3) "Super secret submenu". All three of these would not be there. When I go back to the Options window and change the name to anything else, and when I then click OK in the Options window, all three of the above disappear. They reappear when I go back and enter "Tom" again.
If I understood it correctly, this is exactly what the engineers that I met wanted to implement.
So here are the pieces of this solution (I am sure there are other, and probably better, solutions, by the way):
- Use the Options window wizard to generate stubs for implementing a new category in the Options window's Miscellaneous panel. Use the Preferences API, as described in detail elsewhere in this blog, to persist the name typed in the text field.
- Use the Action wizard to create a stub for implementing a new menu item. However, delete the Menu entries generated in the layer.xml file. If you keep that entry there, under the Menu folder, the menu item will automatically be displayed. You do not want this to happen. You want it to be hidden. You will create the required entry in the NetBeans user directory programmatically in the next step, when the correct name is entered in the text field.
- Use the Module Installer wizard to create a stub for implementing a new module installer. Using a module installer in general is a bad idea, because it slows down start up time. However, how else is the application going to know at start up whether to show or hide the menu item? The module installer discovers that the login works (it is persisted via the Persistence API, so here the module installer retrieves the preference, which is also described in this blog) and then writes entries in the NetBeans user directory.
Here's some code that I have in the installer. If name equals Tom, the code below creates the new folder Menu/Some. It then writes a shadow file with a reference to the action's actual instance class:
//Create the folders: FileObject menuSomeFolder = Repository.getDefault().getDefaultFileSystem().getRoot().getFileObject("Menu/Some"); if (menuSomeFolder == null) { try { menuSomeFolder = Repository.getDefault().getDefaultFileSystem().getRoot().createFolder("Menu/Some"); } catch (IOException ex) { ex.printStackTrace(); } } //Create the shadow file in the above folder, //with content connecting the shadow file to the real instance: FileObject newMenuItem = Repository.getDefault().getDefaultFileSystem().getRoot().getFileObject("Menu/Some/org-netbeans-modules-test-TestAction.shadow"); if (newMenuItem == null) { try { newMenuItem = menuSomeFolder.createData("org-netbeans-modules-test-TestAction","shadow"); JOptionPane.showMessageDialog(null,newMenuItem.toString()); FileLock lock = newMenuItem.lock(); OutputStream out = newMenuItem.getOutputStream(lock); //In the shadow file, write the reference to the instance file, //which must match the registration in the module's layer.xml file: OutputStreamWriter out1 = new OutputStreamWriter(out, "UTF-8"); out1.write("nbfs://nbhost/SystemFileSystem/Actions/Build/org-netbeans-modules-test-TestAction.instance"); out1.flush(); out1.close(); out.close(); lock.releaseLock(); } catch (IOException ex) { ex.printStackTrace(); } }Note: The line Actions/Build/org-netbeans-modules-test-TestAction.instance matches the Actions registration entry generated by the Action wizard in my layer.xml file. This line is needed to connect the shadow file to the real Java class. (I discovered this after copying a menu item, in the Advanced section of the Options window, from one menu to another. When you do that, the IDE generates a shadow file in your NetBeans user directory. When you open that you will find just one line, which is in the format shown above.)
- At this point, I simply did a null check on the folders and shadow file. If they were not null, while the username was not Tom, the file objects are deleted. As a result, they are no longer in the NetBeans user directory. As a result of that, they're not in the menu bar either. Whenever the preference changes, the file objects for the folder and shadow file are either created or deleted. Simple and effective.
- Next, I used Jesse's suggestion of taking the NetBeans API DynamicMenuContent class. Here's the relevant code added to the action class created in step 2, in order to implement DynamicMenuContent:
public JComponent[] getMenuPresenters() { JMenu m = new JMenu("Menu for " + Installer.getUserName()); JMenuItem item = new JMenuItem("Super secret submenu"); m.add(item); return new JComponent[] {m}; } public JComponent[] synchMenuPresenters(JComponent[] items) { return getMenuPresenters(); }So the name "Tom" is retrieved from the module installer, added as text to the menu, to which a submenu is added. However, since I created the folder Menu/Some, any shadow file in that folder, pointing to a corresponding instance file, is displayed in the new menu. So, I could create a whole new module (i.e., the third party vendor could do this too) and add my own action to the same folder, as shown here, where I've added "Some Other" menu item:

In fact, the DynamicMenuContent class is not needed at all in this scenario, because all submenus are automatically retrieved from the layer.xml file's Menu/Some folder. However, the Action wizard doesn't show my original "Menu for Tom" action and neither do the nodes representing the layer.xml file. This must be a bug. Here's proof:

So, before installing the "Some Other" action in the "Some" folder, the "Some" folder wouldn't have been visible in the screenshot above, even though I was working in an IDE which had the module including the "Menu for Tom" action installed in the "Some" folder.
Again, I don't know if this is the best approach, or even a good approach. But it works and it shows yet again the versatility of the NetBeans layer.xml file concept. I am able to show and hide menus and submenus, even entire actions, depending on a name set and retrieved by the Persistence API. In fact, note that I am not hiding the action, but showing it, because by default there is no action in this scenario. It is programmatically created and deleted as needed. And any third party vendor can add menu items as submenus below my action, since they're only going to be shown when the action is shown, which is exactly how one would want it. Hurray.
Postscript: Some caveats on this approach, received from Jesse: I'm unclear why you are modifying the SFS; you shouldn't need to, AFAIK. Generally modifying the SFS is a poor idea as changes are persisted to the userdir. It is also likely to be bad for performance. Anyway, if you do, use FileUtil.createData on Repo.default.defaultFS.root; and don't write that ugly URL to the body of the file, leave it empty but set the attr originalFile to the full path.
Feb 22 2007, 06:09:23 AM PST Permalink
Day One of Hyderabad Sun Tech Days
It was a pretty amazing day today. The room where the keynote was held was able to hold 9000. (Correction: Apparently there are 4200 people registered, so the 9000 figure is probably way over the top. Still, 4200 people is a massive crowd.) And, as far as could be told, there was pretty much standing room only. I met lots of NetBeans users. My presentation, "NetBeans Extreme Programming: 7 Reasons Explaining the Success of NetBeans IDE", was pretty well received (and there were apparently around 500 in attendance, but I'll try and get the exact number), despite some glitches and the fact that I ran out of time. (Weird how glitches happen in the areas you were most confident about, while the other areas go smoothly.) I had a lot of really interesting conversations before and afterwards. Throughout the day, I took a lot of pics, here is a selection, hopefully not too small.
In the first pic, you see Roumen's first reason to dig NetBeans... the GUI Builder. Here's someone at the booth watching Roumen's Flash demo on the highlights of NetBeans IDE. (His Flash demos played throughout the day.) Behind the booth are Nilesh and Frank from the India Engineering Center (IEC) docs team, who ran the NetBeans booth, together with several other docs writers and content developers:

Throughout the day, some of the intrepid Sun guys ran a NetBeans coding competition. Here's my favorite pic of the day, of a group of entrants working through part of the competition together:

Here's another cool shot of hard working people engrossed in the NetBeans competition:

What were the rulesof the competition? You had to create some kind of web application with JPA and JSF, within 30 minutes. Here are the rules (a bit small, sorry):

Ashwin Rao at the NetBeans competition:

Me at the NetBeans competition:

Looking at some code in NetBeans IDE, during the competition:

Evaluating a submission to the NetBeans competition:

Just for participating, people who entered the competition received 'SunBucks', to be spent at a Sun store near you:

And what was the prize for the best application developed in NetBeans IDE? I guess we'll find out tomorrow.
At the end of the day, there was a local singer guy. First time I watched Indian music being performed live. (And I had a flash back to the Norwegian equivalent at JavaZone, which was a heavy metal Viking punk death suicide anarchy band, as far as I could tell.)

By the way, at some weird point, Rich Green got totally mobbed by his groupies (he's in this picture somewhere, but hard to spot):

Feb 21 2007, 07:11:48 AM PST Permalink
Interview: Sketsa's Lead Developer, Tonny Kohar
I blogged about Tonny Kohar and his team of developers before. They're based in Indonesia and created the cool Sketsa SVG Editor. This editor has also been mentioned in a few other blogs, such as here in Roumen's blog. I had the pleasure of interviewing him in some detail. Among many other things, he talks about the problems they had with their in-house application framework and why they chose the NetBeans Platform to replace it. To read the interview, go here:
Meet a NetBeans Module Writer: Tonny Kohar
And, if you are a module writer, or know of module writers who would like to be "subjected" to a similar interview (all via non-threatening e-mail), please let me know. It's great to hear about people's real life experiences with the NetBeans Platform. Note that these interviews always have the possibility of including a critical tone somewhere along the line, because there are many things which could be improved in the NetBeans Platform. But, at the end of the day, they tend to have an underlying sense of "Wow, this NetBeans Platform is pretty cool and saves me so much work!" In other words, these are honest technical interviews, rather than sugary "I love NetBeans" exclamations. If you go to http://platform.netbeans.org, or any of its sub pages, you'll find all of them grouped in the right sidebar, under "Learning from Others".
One especially cool thing I learned from interviewing Tonny is his creative approach to popup menus, which I blogged about recently. He builds them from entries in a layer.xml file, which opens his application up to contributions from third-party vendors. Yesterday I applied this approach to the Timezone Converter that I created in Prague airport while waiting to catch my plane to India. Here's the result:

So you right-click on a timezone, provided by a web service, and then you see menu items displaying the current date and time, thanks to the same web service. The performAction() events are empty, so nothing happens when you click the menu item. So, the menu item only exists to display the information, which is dynamic and depends on the returned data from the web service. (Having the info in a menu item's text is nicer, in some ways, than displaying it in a JLabel or something similar, because a JLabel would take up real estate in your user interface, while a popup doesn't.) And, thanks to Tonny's approach, I registered the menu items in a new folder in my layer.xml file, which means anyone else can do the same and contribute menu items to my popup from their own third-party module. Here are my menu items in the layer.xml file:
<folder name="Time">
<folder name="Zone">
<folder name="Popup">
<file name="DayTCAction.shadow">
<attr name="originalFile" stringvalue="Actions/Window/org-netbeans-modules-timezonecalculatormodule-DayTCAction.instance"/>
</file>
<file name="TimeZoneTCAction.shadow">
<attr name="originalFile" stringvalue="Actions/Window/org-netbeans-modules-timezonecalculatormodule-TimeZoneTCAction.instance"/>
</file>
</folder>
</folder>
</folder>
Full code, from A to Z, is provided in Tonny's interview. So, if you're a NetBeans module developer, you have even more reason to read that interview, because you get a very useful code snippet as well.
In other news. This morning I met Rohan Ranade, one of several NetBeans module developers working in Sun's India Engineering Center (IEC), here in Bangalore. He gave me a lot of info about a project he's working on, but along the way I learned from him that schema-based code completion in XML files is possible already! There's a catch... you need to be using NetBeans IDE 5.5.1 and you need to have the Enterprise Pack installed. That's where the functionality is currently found. However, it's good to hear that this is now possible. I'm going to be looking at this in some future blog entry. By the way, actually, schema-based code completion for XML files was possible since 5.5 Enterprise Pack, but there was an important issue that was fixed in 5.5.1, see issue 91333 for details.
Feb 20 2007, 01:10:03 AM PST Permalink
Temporary in NetBeans Land?
Temporary in Netbeans land might end up staying a bit longer. He has a genuinely good analysis of the pros and cons of desktop client development on the NetBeans Platform. On the 'pro' side we have... drum roll... Swing and Matisse. Exactly. Those are (also in my humble opinion) the distinguishing features. For the rest, look and feel, performance, extent of the infrastructure offered... not much difference between Eclipse RCP and NetBeans Platform. But the fact that we're using Swing and Matisse are the clinchers. Time and again, people in the real world (i.e., not in some marketing office, even assuming NetBeans had one of those) have testified to this being true.
On the 'con' side, however... there are some accurate assessments. See them here. However, if these are all his problems, then NetBeans IDE 6.0 Milestone 6 is going to put a smile on his face.
Firstly, let's look at his issue with error reporting:
It always takes a while to notice coding errors. I sometimes stop in the middle of typing, waiting for the errors to show and the small light bulb appear. Eclipse is much better in that respect. Also the quick fixes in Netbeans are not as good as in Eclipse.
I think this comment is inaccurate, in that it doesn't paint the full painful picture. Not only do the errors take a long time to show up, they also take a long time to go away! After fixing an error, I frequently need to either (1) ignore the remaining error marks or (2) do a "Clean and Build" to refresh the state of the error markings. So, things are worse than is stated in that blog entry. And that's just the start of it. I've been frustrated on a number of other levels in the editor in NetBeans IDE 5.5. Then... I tried NetBeans IDE 6.0 Milestone 6. Read this document and see why I am no longer concerned anymore about the issues I had with the editor before. They'll all be dealt with in 6.0. Most noticeably, aside from all the colors and highlights and so on, the speed of coding is vastly improved. I can code faster, see code completion earlier, and surround code much more easily. And when you press "Ctrl-R", each occurrence of the identifier under the cursor is highlighted and you can change them all instantly, in place, as shown here:

Your fingers need never leave the keyboard again!
Hints, also known as "quick fixes", have been beefed up as well. The one I particularly like is the hint that tells you when import statements are no longer used, by coloring the unused ones in grey, and then even offers to remove them for you, as shown here:

Secondly, here's another comment from that blog entry:
I’m mostly doing plugin projects and they behave different from Java projects. I can’t find a way to add more source directories.
Well, here's something really cool that I discovered today. In NetBeans 6 Milestone 6, you can drag and drop files from outside the IDE straight into either the editor or explorer views. This is pretty awesome. Literally, just go to your filesystem, (i.e., outside of NetBeans IDE) and simply start dragging. Once you get to the editor, you'll see the cursor change and you'll be able to drop the file and then the content is displayed in the editor. If you continue dragging, the file can be dropped in the Projects window, Files window, or Favorites window.
"That's nice, but it would be even better if you could drag an entire folder like that. That's when I'll raise an eyebrow. Not before." Glad you said that, my sceptical friend. Because that functionality is there too. Simply drag an entire folder and drop it wherever you like. For example, drag an entire folder of source files into the Source Package folder... and you have a new package in your application, as I did here with the "org" folder in my filesystem:

Woohoo. Better it doesn't get.
For the other issues mentioned in Temporary in Netbeans land, I totally agree with the gripe about the Library Wrapper Module Project. And many others would agree with my agreement and are arguing for having this aspect fixed. The other points mentioned in that blog entry, about CVS integration and JUnit tests... I don't know about the CVS problem, makes sense and I think that should be fixed, but I'm sure the JUnit test concern is solveable, because JUnit tests run fine in NetBeans module projects.
So, here's hoping that Temporary in Netbeans land will be a longer stay. Whether the stay is longer or not, it is clear that the majority of concerns raised are now part of the past, thanks to all the fantastic work done for NetBeans IDE 6.0.
Feb 19 2007, 07:06:08 AM PST Permalink
The Benefits of Modular Programming: Chapter 2 of "Rich Client Programming"
End of last week, we released chapter 2 of the forthcoming book "Rich Client Programming: Plugging into the NetBeans Platform". The chapter is called "The Benefits of Modular Programming", setting the tone for the rest of the book, which is all about a modular approach to Java programming on the NetBeans Platform.
Want to see it? Go to http://www.netbeans.org/books/rcp.html, which is the official site of the book. Check that site once in a while and you'll see more content being added as we get closer to the release date.
In other news. Things to see in Bangalore... the Bangalore Palace, Tipu Palace, and the Bull Temple, which I visited yesterday and today. All very impressive. Here are some of the pics I took at Bangalore Palace.
Feb 18 2007, 07:19:52 AM PST Permalink
Layer-Based Popup Menus in TopComponents
I've learnt something pretty interesting from Tonny Kohar, the NetBeans module writer, based in Indonesia, who is the project lead of the team that created Sketsa SVG Editor. I've been working on an interview with him and, when it is published, you'll see that he describes a very interesting tip. You can build popup menus in your custom TopComponent by using the NetBeans Lookup API to leverage entries in your layer.xml file. So, here's what the user sees, in my implementation of this approach:

Installed in my toolbar is a TopComponent with a JLabel and JTextField. (Same approach as in the NetBeans Google Toolbar Module Tutorial, except that I'm using a TopComponent instead of a JPanel.) However, you also see a popup. The menu items in the popup come from my layer.xml file. I've added a MouseListener to the JTextField, which triggers the building of the menu items when the popup is invoked. The building of the popup menu items is done through the Lookup API, which Tonny finds absolutely fantastic, as you'll see when you read the interview (once it is published). As a result, it is very easy for external contributors to add their own menu items to my popup, because they can just register their contributions in the same folder structure that I did when I created my module:
<folder name="Web">
<folder name="Search">
<folder name="Engines">
<file name="GoogleAction.shadow">
<attr name="originalFile" stringvalue="Actions/Window/org-mysearch-GoogleAction.instance"/>
</file>
<file name="WebcrawlerAction.shadow">
<attr name="originalFile" stringvalue="Actions/Window/org-mysearch-WebcrawlerAction.instance"/>
</file>
</folder>
</folder>
</folder>
So, if you had a menu item to add to my popup, you'd simply provide a module with your action, with a layer.xml folder structure like the above. Then the popup would be built seamlessly by the code in my module, and all you've done is contribute the action and the registration entries in your layer.xml file. For the code for this scenario, as well as a technical interview and extensive explanation of the usefulness of the above approach, you'll have to wait a few days. The publication of the interview with Tonny should be within the coming week sometime.
In other news. Toni Epple, the guy behind Jarvis, spends some time discussing his project in this brand new interview: Meet a NetBeans Module Writer: Toni Epple. (You also get to see what he looks like!) If nothing else, you should play the Flash demo that he provides in the interview. You'll see that you can already pull data from a database straight into a JasperReport and then generate a PDF document from it. Toni is looking for contributors to his project and lists some open areas that, if you want to help, you might be interested in providing. If it were up to me, then sooner or later this visual designer for JasperReports would become part of the NetBeans code base. It is really really cool.
Feb 17 2007, 01:22:25 AM PST Permalink
TimeZone Calculator Integration in NetBeans IDE
Although this web service is helpful in many ways, so that I now know what time it is in any given timezone... thanks to my NetBeans integration of this module, displayed below:

...I still don't know which timezone India belongs to. So I can't actually use my module for its intended purpose, to work out what time it is in India. Ah well, that's the limits of web service integration. Your integration is ultimately only as good as the web service you're using.
Still, a good way to spend an hour while waiting to catch the plane to India. And it only took that long because of my limited Java skills. I spent more time working with the JList than with the entire web service implementation. Now that's NetBeans IDE for you. Can make wizards fly, but you still got to go to Java programming classes once in a while...
Feb 16 2007, 12:27:35 AM PST Permalink
Putting Some Faces To Names
Ruth Kusterer..? Tinu..? Tori..? "Who are these people?" (As Seinfeld might exclaim in his typical Seinfeldian cry of anguish.) Well, worry no more. Here are two pics taken last night in a pub here in Prague where I hung out with some of my colleagues. Tori is the Managing Editor of www.netbeans.org. She's based in the US, as is David Botterill, who is the evangelist for the Visual Web Pack. David is working on a very interesting project, which will be revealed in the coming weeks. Both Tori and David are in town this week (i.e., in Prague), and I had the honor of hanging out with them and a few others last night. Ruth, the 'web mistress' (is that her official function description, probably not) was there, as well as Tinu (who runs the NetBeans Weekly Newsletter), and Web Jan (who is called "Web Jan" because there are so many other Jans in this building), who develops the technical side of www.netbeans.org, together with Jack. So, in fact, most people there were from the NetBeans Web Team.
To see 'who is who', just click on a pic and it will zoom in and then you'll see the names. (If you are reading this in planetnetbeans.org, you will not see any pics. You need to be inside my blog entry to see them.)
Could this be the first of a very long series of occasional 'putting faces to names' blog entries? Only time will tell...
Feb 15 2007, 02:27:05 AM PST Permalink
Hello OpenOffice.org API
Many many moons ago (which turns out to be June 16, 2006), Wouter van Reeven (from Amis in Holland) and I started writing a tutorial for OpenOffice.org API on the NetBeans Platform. Wouter provided the OpenOffice.org API side of the story and I provided the NetBeans Platform side. That was a pretty cool document we worked on and we intended to try to publish it somewhere externally. However, the story kind of dwindled at some stage, because it became quite difficult to provide a solid bootstrapping story. There were problems with classloading, there were problems with native libraries, and there were problems even understanding what exactly the problems were. So, even though the story was complete and the tutorial written, it never got publicized on netbeans.org or anywhere else.
However, in the meantime we have OpenOffice NetBeans Integration. One of the project templates that this integration provides (i.e., installed via an NBM file in NetBeans IDE) is called "Open Office Client Application Project Type". I used that and, without much problem, worked the original code of Wouter and my tutorial into this Java application project (i.e., not a NetBeans module suite, or rich-client application, or module, but just a plain old Java application). The downside is that you need to specify the OpenOffice SDK and local installation before you even begin working with these project types, and these are registered in a project-level file called project-uno.properties. I wonder what this means for distribution? Does this mean that the end user has to have the SDK installed locally? That's part of the bootstrapping issue we had when working with NetBeans modules and OpenOffice.org API. Anyway, the long and short of it is that the tutorial, slightly reworked for the Java application context (i.e., now I'm using a JFrame instead of a TopComponent and the bootstrapping is slightly different), is that you can produce reports like this one:

When you click the Generate Report button, you get a spreadsheet that has a number of cool features, such as rows that have alternating colors (white/orange), a special color (green) for the row with the highest number of replies, another special color (red) for the row with the lowest number of replies, and additional cells specifying the authors of the highest/lowest replied-to article. Full code for this scenario is in the tutorial worked on by Wouter and myself, which is An Introduction to the OpenOffice.org API.
Feb 14 2007, 01:02:25 AM PST Permalink


