Package projectviewer.vpt

Creating custom nodes.

See: Description

Package projectviewer.vpt Description

Creating custom nodes.

It's possible to create new kinds of nodes to be inserted into a project. Although not tested, all the necessary functionality is available. To create a new kind of node, the following steps need to be taken:

These steps should be enough to create a new kind of node and make it be automatically persisted by the ProjectViewer plugin with the corresponding project. You may want to provide other actions to be executed on the given node (by creating more Action subclasses), or implement the open() method of the node to specify an action to be executed when the node receives a double click on the tree. When implementing open(), make sure to make the close(), canOpen() and isOpened() methods consistent with your implementation.

Implementing new nodes should be considered highly experimental, so bear that in mind when going through this path.

Registering a NodeHandler with the ProjectViewer plugin

To register node handlers with ProjectViewer, add an entry to your plugin's services.xml file. The service class is projectviewer.persist.NodeHandler.

Registering custom node handlers has one shortcoming: when your plugin is unloaded, the classes won't be able to be garbage collected. This happens because there's no safe way to remove the custom nodes that have been added to the project and wait for the plugin to be activated again to create a new version of that node with the new instance of the Class. So, the ProjectViewer plugin will keep a reference to the custom node's class and to the node handler's class so that it is possible to persist that node when the project is saved.

If you develop custom nodes, you should keep this in mind to make sure that this does not affect the newly loaded instance of your plugin. Declaring ProjectViewer as an optional dependency for your plugin should fix this issue, since it will make jEdit reload ProjectViewer when your plugin is reloaded, although that may cause data loss (e.g., if PV loads without your plugin being loaded, the data related to your plugin's nodes in a project config file will be lost).