0

I am listening on changes in EditorRegistry where I can get which JTextComponent is currently selected. Anyone knows how can I get an EditorCookie or a DataObject for it?

JTextComponent jTextComponent = EditorRegistry.focusedComponent();
Document document = jTextComponent.getDocument();

And how can I get to which project does it belong?

Milan Nosáľ
  • 19,169
  • 4
  • 55
  • 90

1 Answers1

1

DataObject is easy one:

JTextComponent jTextComponent = EditorRegistry.focusedComponent();
Document document = jTextComponent.getDocument();
DataObject dobj = NbEditorUtilities.getDataObject(document);

Than the EditorCookie is easily obtainable through getCookie() method of the data object.

The Project object can be retrieved for the data object by following:

Project owner = FileOwnerQuery.getOwner(dobj.getPrimaryFile());
Milan Nosáľ
  • 19,169
  • 4
  • 55
  • 90