Monday Apr 14, 2008

Step Onto the NetBeans Platform... in Japanese!

The 4-part NetBeans Platform "Selection Management Series", by Tim Boudreau, is now available in Japanese:

Here's the intro:

Note: The ultimate NetBeans plugin quick start is also available in Japanese:

http://platform.netbeans.org/tutorials/60/nbm-google_ja.html

Thanks very much to Masaki Katakai and the community member who worked on this translation!

org.openide.util.ChangeSupport

I'm learning about org.openide.util.ChangeSupport. Some notes below.

In the visual panel:

private final ChangeSupport changeSupport = new ChangeSupport(this);

private final DocumentListener docListener = new DocumentListener() {
    public void insertUpdate(DocumentEvent e) {
        fireChange();
    }

    public void removeUpdate(DocumentEvent e) {
        fireChange();
    }

    public void changedUpdate(DocumentEvent e) {
        fireChange();
    }
    private void fireChange() {
        changeSupport.fireChange();
    }
};

In the visual panel constructor:

field1.getDocument().addDocumentListener(docListener);
field2.getDocument().addDocumentListener(docListener);
changeSupport.addChangeListener(panel);

In the wizard panel, implement ChangeListener and then:

private ChangeSupport changeSupport = new ChangeSupport(this);

@Override
public final void addChangeListener(ChangeListener l) {
    changeSupport.addChangeListener(l);
}

@Override
public final void removeChangeListener(ChangeListener l) {
    changeSupport.removeChangeListener(l);
}

public void stateChanged(ChangeEvent e) {
    changeSupport.fireChange();
}

Then an experiment with DataObject and a DataNode. This in the DataObject:

private final ChangeSupport changeSupport = new ChangeSupport(this);

private final FileChangeListener fileListener = new FileChangeListener() {

    public void fileFolderCreated(FileEvent arg0) {
    }

    public void fileDataCreated(FileEvent arg0) {
    }

    public void fileChanged(FileEvent arg0) {
        changeSupport.fireChange();
    }

    public void fileDeleted(FileEvent arg0) {
    }

    public void fileRenamed(FileRenameEvent arg0) {
    }

    public void fileAttributeChanged(FileAttributeEvent arg0) {
    }
};

And in the constructor of the DataObject:

getPrimaryFile().addFileChangeListener(fileListener);
changeSupport.addChangeListener(createNodeDelegate());

This in the DataNode:

public class DemoDataNode extends DataNode implements ChangeListener {

    private ChangeSupport changeSupport = new ChangeSupport(this);
    DemoDataObject obj;
    Date date;

    public DemoDataNode(DemoDataObject obj) {
        super(obj, Children.LEAF);
        this.obj = obj;
        date = new Date();
        changeSupport.addChangeListener(this);
    }

    DemoDataNode(DemoDataObject obj, Lookup lookup) {
        super(obj, Children.LEAF, lookup);
        setName(obj.getPrimaryFile().getName());
    }

    public void stateChanged(ChangeEvent e) {
        long mills = System.currentTimeMillis();
        DateFormat dateFormatter = DateFormat.getDateTimeInstance(
                DateFormat.LONG,
                DateFormat.LONG);
        String formatted = dateFormatter.format(mills);
        setName("Changed: " + formatted);
        changeSupport.fireChange();
    }

}

Something is wrong because I can only change the name, not the display name or the icon. Probably need to do something with fireIconChange and fireDisplayNameChange on the Node.

Update. Fixed the problem. Some of the code above is wrong. Will blog about this soon.

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
« April 2008 »
SunMonTueWedThuFriSat
  
2
4
5
13
18
19
23
30
   
       
Today