Wednesday Dec 31, 2008

Join Free NetBeans Platform Training in Cairo (3 - 5 January)

Start your year with your first steps onto the NetBeans Platform. Ahmed Hashim, the leader of the Egyptian Java User Group, has arranged a time and place for a NetBeans Platform Training in Cairo, as described below:

I got a message from him that 45 registrations have already been received (and there I was hoping for 10 but expecting 5), so hurry because space is limited.

Tuesday Dec 23, 2008

Nice Announcement in Egypt!

I was googling today and came across this announcement:

And everything stated above is 100% true (here are the pics from yesterday), except for the minor detail that there should be a capital "B" in "NetBeans"!

El-Menoufiya and NetBeans IDE

I was at El-Menoufiya University today, which is midway between Cairo and Alexandria, which is where I have been staying for a while (and where I'll be for quite a while longer, scuba diving, learning Arabic, wandering around, etc). The always energetic Hamada Zahera, who is a member of the staff, had set up my presence there via FaceBook contact with Honza Chalupa from NetBeans. That's how it all came about.

Here are the two presentations I did:

  • Productive Web Development with NetBeans IDE (PDF)

  • Productive Desktop Development with NetBeans IDE (PDF)

About 150 students attended, which is a pretty big group. Some general observations: JSF, Struts, Hibernate, and Spring rule there. Wicket and Grails have never been heard of, so I spent a bit of time introducing those. Especially Wicket spoke to the imagination, since no Java developer likes XML, nor JavaScript, and the HTML/Java split is very easy to understand. Also Groovy was unknown, so I showed it in action a bit. My Napkin Look & Feel joky thing worked again ("ah, but now you've created your database Swing app in 3 minutes, so you better make it look bad so your manager doesn't think you're already finished and you can then work on open source projects in the extra time that results"). But the main point of the exercise was to introduce them to JavaFX, which I did (on Linux, thanks to Weiqi Gao), using a simplified version of Gregg Bolinger's space game (well, at least the images), which speaks to the imagination very well. (So, thanks Weiqi and Gregg.)

The day itself was pretty amazing, everything put together. Especially Nader (and Mohannid, who, with Nader, took me on a trip to the Alexandria Library a few days ago) I'd really like to thank for picking me up from my hotel in Alexandria at 7.00 in the morning and accompanying me to El Menoufiya. There I met the local security people as well as some of the professors, before I did my two hours of presentations. Then the trip back by bus during which I met a nice man who is going to help me with my Arabic studies (amazing how many people have offered that help already so far).

I'll put up the many photos that were made soon. They're quite fun, so it's something to look forward to! They look a lot similar to those taken by Hamada and others at a previous event they organized around Fedora that resulted in the cool pics here. Several of the faces in those Fedora pics are now quite familiar to me!

Thanks a lot to all the enthusiastic students who were there, hope you learned something new. Drop me an e-mail anytime (geertjan DOT wielenga AT sun DOT com). And I'm sure I'll be back sometime soon.

Saturday Dec 20, 2008

More Introductory Training Materials for the NetBeans Platform

In January, Jaroslav Tulach, Toni Epple, and Thomas Würthinger will be giving a NetBeans Platform training course at the Institut für Systemsoftware, which is part of the Johannes Kepler Universität in Linz, Austria. That's also where the first official NetBeans Platform training was held (read all about it here).

The course consists of 3 days, the first was an introduction to the NetBeans Platform, which has already been given, by Thomas Würthinger, who is an assistant at the institute and who previously created the Java HotSpot Client Compiler Visualizer , which is a NetBeans Platform application.

His introduction is really interesting, with slides and code provided. So, anyone interested in getting started with the NetBeans Platform should give his materials a look. Click the image below to jump straight to the page:

By the way, a complete list of training materials for the NetBeans Platform (to which a reference to the above will be added too) can be found here.

Monday Dec 15, 2008

Its Super Crazy Nesting Nightmare Might Mean JavaFX's Death...

...unless there are tools like this:

Or is it just me? I don't see myself ever seriously using a shiny PhotoShop-like designer for working with JavaFX (although I am really looking forward to there being that kind of support). I do, however, see myself wanting to get further into JavaFX. But, with all those brackets within brackets, it's a lot like XML hell in other technologies. I reckon that only with tools like the little code generator I built, shown above, can that problem be overcome. By the way, how is everyone else doing it so far? How are you making sure all those brackets are lined up correctly? If there's interest in it (though it's not very smart, e.g., doesn't add any import statements, but simply adds the selected tag around the selected characters, without even reformatting anything), I will put it in the NetBeans Plugin Portal.

Sunday Dec 14, 2008

Little Elly

Little Elly gulped a magnet
thinking that it was a sweet,
ever after she felt drawn to
metal objects in the street.

When her mother lost a bracelet,
when her father dropped a nail,
when they lost a ring or necklace,
Elly found them without fail.

She would fall for boys with braces,
they would smile, and she would swoon,
later they would find her clingy,
and they'd dump her far too soon.

Passing cars became a problem,
sometimes pulling her in tow,
but the locals knew her story:
seeing her, they'd drive real slow.

One day Elly took a plane trip,
quite unplanned, her parents say:
KL-542 flew too low,
taking Elly far away.

Saturday Dec 13, 2008

Animal Meets Person: A JavaFX Drama Unfolds

I wanted to figure out how to make two objects in JavaFX interact with each other. Something like this:

For each of these, I created a new custom node because potentially each object would have many of its own distinct properties. For now, the two are very simplistic:

package demo;

import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.CustomNode;

public class Animal extends CustomNode {

    public var posx = 180;

    public override function create(): Node {
        return Group {
            content: [
                Circle {
                    centerX: bind posx,
                    centerY: 100
                    radius: 40
                    fill: Color.YELLOW
                }
            ]
        };
    }

}
package demo;

import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;

public class Person extends CustomNode {

    public var posx = 40;

    public override function create(): Node {
        return Group {
            content: [
                Circle {
                    centerX: bind posx,
                    centerY: 50
                    radius: 40
                    fill: Color.BLACK
                }
            ]
        };
    }
}

So I created two custom nodes, which can now be treated the same way as all the other JavaFX nodes, i.e., just like circles, arcs, rectangles, texts, and so on.

The only interesting thing is that I exposed the X position of each node to the outside world, such that any changes made to it from the outside would change the property in the node.

Finally, in the main JavaFX file, I imported the two nodes, added them to the scene, and changed their exposed properties in the timeline:

package demo;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.animation.Interpolator;
import java.util.Date;

var animal = Animal{}
var person = Person{}

var date = new Date;

Stage {
    title: "Demo Animation"
    width: 250
    height: 250
    scene: Scene {
        content: [
            person,
            animal
        ]
    }
}

Timeline {
    repeatCount: Timeline.INDEFINITE
    autoReverse:true,
    keyFrames: [
        KeyFrame {
            time: 1s
            canSkip: true
            values: [
                animal.posx => 50
                person.posx => 50
            ]
            action: function() {
                if (animal.posx == person.posx){
                   println("Connected at: {date}")
                }
            }
        }
    ]
}.play();

To make the two nodes move at different speeds... simply create two different keyframes in the same timeline. Or you can add a second timeline and change the "time" property of the timelines so that they are different, then change the "values" property so that in the first case, only one node changes, while in the second case the other node changes. (Different keyframes within the same timeline is more interesting than different timelines, because if they're in different keyframes in the same timeline, one object stops while the other is still moving and then suddenly starts again when the other has finally stopped.)

It was pretty cool to be able to learn from the messages I received during all this:

Finally, the whole application looks as follows:

By the way, Gregg Bolinger's space game is very helpful in understanding some of the key concepts.

Thursday Dec 11, 2008

Linux & JavaFX Tooling in NetBeans IDE

Follow Weiqi Gao's latest instructions (which I found out about thanks to Jim Weaver today) and you too will be able to develop JavaFX applications in NetBeans IDE, even though you're using Linux (in my case, Ubuntu):

Only Media support doesn't work yet, but that's part of the SDK, unrelated to the NetBeans IDE tooling support, which I now have working perfectly on Ubuntu.

And here's my simple code sample for today, note especially the line in bold:

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.paint.Color;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

var color = Color.YELLOW;

Stage {
    title: "Application title"
    width: 250
    height: 250
    scene: Scene {
        content: [
            Circle {
                centerX: 100,
                centerY: 100
                radius: 40
                fill: bind color
            }
        ]
    }
}
Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames: [
        KeyFrame {
            time: 5s
            canSkip: true
            values: [
                color => Color.GREEN
            ]
        }
    ]
}.play()

The "fill" property of the circle is bound to the "color" variable, which is used in the Timeline, changing gradually to green.

So here's how you'd make the circle move as it changes color (only the changes are in bold):

var color = Color.YELLOW;
var posX = 100;

Stage {
    title: "Application title"
    width: 250
    height: 250
    scene: Scene {
        content: [
            Circle {
                centerX: bind posX,
                centerY: 100
                radius: 40
                fill: bind color
            }
        ]
    }
}
Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames: [
        KeyFrame {
            time: 5s
            canSkip: true
            values: [
                color => Color.GREEN
                posX => 200
            ]
        }
    ]
}.play()

Similarly, you can bind the radius to a variable and then change it in the Timeline. This means the circle will become larger which, in turn, creates the impression that it is coming closer and closer to the user of the application.

2009: The Year of Documented Business Scenarios for the NetBeans Platform

The year is drawing to a close and plans for the coming year are being drafted. Personally, my main focus in the coming year in relation to the NetBeans Platform will be—documenting business scenarios for the NetBeans Platform. Up to this point, I've mainly been focused on writing tutorials that cover the main NetBeans APIs and, to a greater or lesser extent, a lot of that is complete, between the NetBeans Platform Tutorials and the NetBeans Developer FAQ, most things have at this stage been covered.

However, what many users are asking for is documentation describing how to optimally connect to a database, how to work with popular frameworks, such as Hibernate and JPA, from a NetBeans Platform application, and similar business scenarios. The issue that describes all these scenarios is this one:

http://www.netbeans.org/issues/show_bug.cgi?id=146402

Creating tutorials that cover those scenarios will be my main focus in the coming year, although this issue would be very helpful to me and to those using the tutorials that come out of it. So, 2009 will be the Year of Documented Business Scenarios for the NetBeans Platform.

If you have any insights to pass on or experiences to share, feel free to do so in that issue or in the comments to this blog entry.

Wednesday Dec 10, 2008

Status Whiteboard: "request_for_contribution"

If you're wondering how/where to commit code to the NetBeans project, especially when you're first getting started doing so, go here.

That will bring you to NetBeans Issuezilla, in a query for the whiteboard status "request_for_contribution":

NetBeans engineers use that whiteboard status to indicate that the issue is one that they think would be especially useful for external contributors. So, why not you?

Tuesday Dec 09, 2008

NetBeans Platform CRUD

One thing I'm meant to be working on is writing a tutorial for creating a CRUD application on the NetBeans Platform. The related issue and interesting documentation relating to this point can be found in the issue:

http://www.netbeans.org/issues/show_bug.cgi?id=146402

And here's where things are right now:

It is a prototype that uses the Database Explorer API to display information in a NetBeans Explorer View via the Nodes API. It also prints column names to the Output window when a node is double-clicked. Now the column names need to end up in the columns in the Details view. One way in which this might be done is to add the column names to the global Lookup whenever a table name is selected. The global Lookup would then be available to the Details view, which would then display them as the columns of the table. Seems like a NetBeans-centric approach to me. Any advice from anyone out there on this point?

Monday Dec 08, 2008

AJAX: Can it get better than this...

...if so, I'd like to know:

  1. Go here and download the ZIP file that you find there (updated 5 seconds ago):

    http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=3586

    Use the NetBeans Plugin Manager to install the 3 NBMs that are contained within that ZIP file.

  2. Create a new web application and, in the final panel, click the Wicket checkbox:

    Click Finish and then you'll have a completely new & fresh Wicket application, with all its standard bells & whistles:

  3. The "HomePage" will be open, enticing you to put something there. So make it this:
    public class HomePage extends BasePage {
    
        public HomePage() {
    
            add(field);
    
        }
        
        final AutoCompleteTextField field = new AutoCompleteTextField("countries", new Model("")) {
    
            @Override
            protected Iterator getChoices(String input) {
                if (Strings.isEmpty(input)) {
                    return Collections.EMPTY_LIST.iterator();
                }
                List choices = new ArrayList(10);
                Locale[] locales = Locale.getAvailableLocales();
                for (int i = 0; i < locales.length; i++) {
                    final Locale locale = locales[i];
                    final String country = locale.getDisplayCountry();
                    if (country.toUpperCase().startsWith(input.toUpperCase())) {
                        choices.add(country);
                        if (choices.size() == 10) {
                            break;
                        }
                    }
                }
                return choices.iterator();
            }
        };
        
    }

  4. Add the Java component's HTML counterpart on the other side:

    <input type="text" wicket:id="countries" size="50"/>

  5. Run the application and you're done:

    You now have an autocomplete textfield powered by AJAX.

Ask yourself:

  1. How much JavaScript did you need to know? (Thanks, Wicket! Then read all about it here.)

  2. How much Wicket did you need to know? (Thanks, NetBeans IDE! Then read all about it here.)

If you like this stuff, track this issue, which seeks to include the Wicket plugin in the NetBeans Update Center:

http://www.netbeans.org/issues/show_bug.cgi?id=153152

Three issues: you must right-click a package (not the project) when using the Wicket file templates; don't try to use the Project Properties dialog to add/remove Wicket support; the "Login" sample has issues, though the "Pizza" sample doesn't. For the rest, this plugin should work fine.

Saturday Dec 06, 2008

Overriding a CSS Reference from a Different NetBeans Module

Let's say your application incorporates a module's helpset that has CSS references in each of its help topics such as this:

<link rel="stylesheet" href="nbdocs://org.netbeans.modules.usersguide/org/netbeans/modules/usersguide/ide.css" type="text/css">

I believe, but could be wrong, that the above is not very good. Why? Because the CSS reference is to a DIFFERENT module, so that the module that includes the reference above is not self-contained. Instead of that, it depends on another module. What if you want to include the module that includes the reference above, but not the module where the referenced CSS stylesheet is found?

Practical example: you want to include the NetBeans "db" module (because your application includes database functionality). Therefore, you also want to include the "db" helpset. However, the "db" helpset has CSS references exactly as above (in fact, I copied the above from a "db" help topic). However, you're not interested in the "usersguide" module, which is where the referenced CSS stylesheet is found. You have, in fact, excluded that module. So all the references point nowhere.

While you wait for the NetBeans Docs team to make the "db" module self-contained (i.e., they [we] should copy the ide.css into the "db" module and then reference that CSS, which breaks the "single source" concept but at least makes the module self-contained, which is more important than "single source"), you can do the following:

  1. Make sure that your application includes the "usersguide" module, even though your application doesn't need its help topics. Check in the application's platform.properties that "usersguide" has not been excluded!

  2. Hide the "usersguide" help topics (even though you're including the module itself), using the application branding module's Services/JavaHelp folder.

  3. Override the "usersguide" module, in the application's "branding" folder, pasting in your own CSS stylesheet in the place where the original CSS stylesheet used to be.

That's all. Now, when you run the application, your own stylesheet will be used, overriding the one referenced by the help topics in the module (in this case, the "db" module). Big donwside: you're including a module with many help topics, even though you're only interested in overriding one single file: the CSS stylesheet. You're hiding all the help topics in the module... so the module is a complete waste to you and to your users. The upside, though, is that the user won't notice that at all (a few more bits to download/startup doesn't make all that much difference) and, instead, will experience the helpset as one single document, because all of the topics will be styled in exactly the same way, which is especially valuable if the help topics are styled in a very special way, e.g. using a standard color for all headings, etc.

Friday Dec 05, 2008

Changing the Appearance of Windows in NetBeans IDE

I found some code by Tim Boudreau on-line, which changes the tabbed windows in the IDE to toolbars:

It works perfectly. Just click a different toolbar and a different window is opened, in the case of Projects/Files/Services. Compare that to the default, where you have tabs instead:

It's not very easy to do something like this. In this case, the class that did the trick extended AbstractTabDisplayerUI. It would be cool if somehow something like that could be done to add new buttons to the toolbars of TopComponents, though I'm not that far yet. Even better would be if there were different window layouts that the user could select.

Thursday Dec 04, 2008

Dovidenia Bratislava

Slovak Java Day was today in Bratislava. Vaclav Pech from IntelliJ did a presentation and then me on NetBeans IDE. The audience determined who got the bottle of wine and it was a tie, more or less, so we ended up "fighting" over it:

It was a great day, well organized, and my secret agenda of meeting people who could end up getting the NetBeans Platform training injected into them... worked out pretty well.

Tuesday Dec 02, 2008

Creating a NetBeans Platform Toolbar in 6.5

Creating a new toolbar for NetBeans IDE is now easy in 6.5. Just use the New Action wizard, which gives you an "ActionListener", and then replace the "ActionListener" implementation with a "Presenter.Toolbar", as shown here:
package org.demo.toolbar;

import java.awt.Component;
import org.openide.util.actions.Presenter;

public final class SomeAction implements Presenter.Toolbar {

    //Here's where you put your panel into the toolbar area:
    @Override
    public Component getToolbarPresenter() {
        return new DemoJPanel();
    }

}

Finally, delete the "instanceCreate" attribute that the New Action wizard created in the layer.xml. Then install and you're done.

Update. See this tutorial for the complete example, the above is partial and incomplete.

From ActionListener to CallableSystemAction

In 6.5, when you create an "Always Enabled" action, the "New Action" wizard gives you this Java code:
package org.demo.module;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public final class SomeAction implements ActionListener {

    public void actionPerformed(ActionEvent e) {
        // TODO implement action body
    }
}

Very nice... because you're using plain old Java code. The ActionListener is one of the JDK's classes, unlike the Action classes that the NetBeans Platform provides. In previous releases, you would get a CallableSystemAction instead, which is one of those NetBeans Platform classes.

To make it possible for the NetBeans Platform to hook the above class into the NetBeans action system, the following entries are added to the layer.xml file, by the same "New Action" wizard that created the above Java class:



<filesystem>
    <folder name="Actions">
        <folder name="Build">
            <file name="org-demo-module-SomeAction.instance">
                <attr name="SystemFileSystem.localizingBundle" stringvalue="org.demo.module.Bundle"/>
                <attr name="delegate" newvalue="org.demo.module.SomeAction"/>
                <attr name="displayName" bundlevalue="org.demo.module.Bundle#CTL_SomeAction"/>
                <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/>
                <attr name="noIconInMenu" boolvalue="false"/>
            </file>
        </folder>
    </folder>
    <folder name="Menu">
        <folder name="File">
            <file name="org-demo-module-SomeAction.shadow">
                <attr name="originalFile" stringvalue="Actions/Build/org-demo-module-SomeAction.instance"/>
                <attr name="position" intvalue="0"/>
            </file>
        </folder>
    </folder>
</filesystem>

Take careful note of the section that is in bold above! There you can see how the ActionListener implementation is hooked into the NetBeans action system. For example, the "instanceCreate" attribute causes a NetBeans Platform action to be created for your ActionListener! So, even though you're using plain old Java, the entries above (generated automatically by the wizard) cause the ActionListener to be treated as a NetBeans Platform class.

However... the NetBeans Platform classes are much more powerful than the ActionListener class. For example, if you use the CallableSystemAction class, you can (in bad pseudo code, any way) do something like this:

@Override
public void setEnabled(boolean enabled) {
    if (hell freezes over){
        enable this menu item
    } else {
        not
    }
}

In other words, the NetBeans Platform action classes provide built-in support for enabling/disabling themselves. Therefore, you're quite likely to want to 'upgrade' your ActionListener to a CallableSystemAction. So, what must one do to transform one's ActionListener into a CallableSystemAction? First, change the class signature so that you're extending "CallableSystemAction", instead of implementing "ActionListener". The Utilities API, which provides the "CallableSystemAction" class, is already set as one of the module's dependencies when you complete the "New Action" wizard, so there are no additional dependencies you need to set. You'll find you need to do something with a bunch of methods that come from the CallableSystemAction class and/or its ancestors.

Next... you need to tweak the layer.xml file so that the bits in bold above are removed. You'll be left with this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
<filesystem>
    <folder name="Actions">
        <folder name="Build">
            <file name="org-demo-module-SomeAction.instance"/>
        </folder>
    </folder>
    <folder name="Menu">
        <folder name="File">
            <file name="org-demo-module-SomeAction.shadow">
                <attr name="originalFile" stringvalue="Actions/Build/org-demo-module-SomeAction.instance"/>
                <attr name="position" intvalue="0"/>
            </file>
        </folder>
    </folder>
</filesystem>

Or, if you have the display name in the localizing bundle, you might have this instead:

    <folder name="Actions">
        <folder name="Build">
            <file name="org-demo-module-SomeAction.instance">
                <attr name="SystemFileSystem.localizingBundle" stringvalue="org.demo.module.Bundle"/>
                <attr name="displayName" bundlevalue="org.demo.module.Bundle#CTL_SomeAction"/>
            </file>
        </folder>
    </folder>

And now install your module. Your ActionListener is now a CallableSystemAction.

Monday Dec 01, 2008

Goodbye DataLoader, Goodbye DataNode

In most cases, you don't need a separate class to define a DataLoader and another separate class to define a DataNode. So in 6.5, the DataLoader is registered (by the New File Type wizard) in the layer, without being created as a Java class, while the DataNode isn't created by the New File Type wizard either. I applied these principles to the old Book Multiview Sample, which is all I needed to do to updgrade it to 6.5—I deleted the BookDataNode class and the BookDataLoader class. Then I added the following to the layer, within Loaders/text/x-book:
<folder name="Factories">
    <file name="BookDataLoader.instance">
        <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/bookmultiview/Datasource.gif"/>
        <attr name="dataObjectClass" stringvalue="org.netbeans.modules.bookmultiview.BookDataObject"/>
        <attr name="instanceCreate" methodvalue="org.openide.loaders.DataLoaderPool.factory"/>
        <attr name="mimeType" stringvalue="text/x-book"/>
    </file>
</folder>

Next, I rewrote BookDataObject.createNodeDelegate to the following, which is all that was needed in the first place anyway:

@Override
protected Node createNodeDelegate() {
    return new DataNode(this, Children.LEAF);
}

And then I was done. Two less Java classes means two less classes to debug, test, maintain, etc.

Here's how the sample looks now, which will be used as the basis of a highly simplied tutorial on this topic, because several people I've met recently on NetBeans Platform Certified Training courses are very interested in synchronization between the two views in a multiview editor:

So, my plan is to strip this sample down to its absolute basics, so that only one field is left on the visual side, with one tag on the XML side, then add a Visual Library view, and show how the three can be synchronized. I believe this material would be very useful to several NetBeans Platform users out there.

About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« December 2008 »
SunMonTueWedThuFriSat
 
3
7
12
16
17
18
19
21
22
25
26
27
28
29
30
   
       
Today