X

Geertjan's Blog

  • January 21, 2016

ProjectCustomizer/NodeFactory Combination

Geertjan Wielenga
Product Manager

Here's a handy NetBeans API sample, useful for NetBeans plugin developers, as well as anyone working with node hierarchies on the NetBeans Platform:

https://github.com/GeertjanWielenga/PeterProjectCustomizerNodeFactory

When you check out the repository above and run the module into NetBeans IDE... and you then create a Java SE application, for example this:

...and you then go to the Project Properties dialog of the project, you will see usage of the ProjectCustomizer.CompositeCategoryProvider class, a simple panel with a checkbox:

When you click "Show my node" and then OK, you will see you have a new node created in your node hierarchy, thanks to an implementation of the NodeFactory class:

When you go back to the Project Properties dialog and uncheck the checkbox, and you then click OK, you will find that the "Special" node is removed.

In the ProjectCustomizer, a project preference is set to a key/value combination, to which the NodeFactory is listening for changes. When a change is detected, the Node hierarchy recreates itself with/without the special Node.

The above scenario is a bit tricky and can be useful in many situations, such as when you're extending NetBeans IDE with a plugin for some technology that needs to be configured per project, after which the project logical view needs to be updated with data relating to the configured technology.

Thanks to Peter Nabbefeld for requesting code for this scenario and to Neil C. Smith for making an important suggestion relating to the ChangeListener of the NodeList.

Join the discussion

Comments ( 1 )
  • guest Friday, November 18, 2016

    Hi Geertjan

    Sorry to contact you directly

    Searching through the netbeans platform forum post lead me here, but not a possibly solution for the issue I am wondering about:

    Is it possible to gain programmatic access to the projects explorer and the underlying Nodes?

    Previously I was using:

    Node cage = Utilities.actionsGlobalContext().lookup(Node.class);

    This gave me a node that had parents and children in the hierarchy.

    But I no longer have a context (selection) so I cannot do that?

    How can I gain access to the nodes from so I can call the remove method when there is no selection?

    The logical view in the project lookup contains new references so are not the same instances?

    I can't find an answer are we not meant to be doing this?

    I have a work around using listeners to close TopComponents and deleting FileObjects but I think it would be neater to implement this in destroy method in associated DataNode?

    Kind regards

    Trevor

    P.s your post are very useful.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.