|
org.netbeans.spi.navigator/1 1.5 | |||||||||
PREV NEXT | FRAMES NO FRAMES |
See:
Description
Navigator API | |
---|---|
org.netbeans.spi.navigator |
Navigator API is good for clients (module writers) that want to show some structure or outline of their document in dedicated window, allowing end user fast navigation and control over the document.
API allows its clients to plug in their Swing based views easily, which then will be automatically shown in specialized Navigator UI.
Client's views are registered through declarative xml layers approach.
org.netbeans.spi.navigator.NavigatorPanel org.netbeans.spi.navigator.NavigatorHandlerNavigatorLookupPanelsPolicy is new SPI interface for SPI clients who want to affect searching mechanism for available NavigatorPanel implementations. Method NavigatorLookupPanelsPolicy.getPanelsPolicy() allows for example to remove active Node/DataObject related NavigatorPanel implementations from Navigator window.
NavigatorPanelWithUndo is new SPI interface which extands NavigatorPanel by support for undoing and redoing changes in navigation views. Method NavigatorPanelWithUndo.getUndoRedo() allows clients to specify UndoRedo support that will be propagated to the Navigator TopComponent when this panel is active in navigation area.
NavigatorHandler is new API class for driving navigator behaviour. Method NavigatorHandler.activatePanel(NavigatorPanel) allows clients to programmatically activate the panel - panel becomes active and visible in navigator area.
first initial release of the Navigator API.
Implementing NavigatorPanel interface is easy, you can copy from template basic implementation BasicNavPanelImpl.java.
Advices on important part of panel implementation:/** JavaDataObject used as example, replace with your own data source */ private static final Lookup.Template MY_DATA = new Lookup.Template(JavaDataObject.class); public void panelActivated (Lookup context) { // lookup context and listen to result to get notified about context changes curResult = context.lookup(MY_DATA); curResult.addLookupListener(/** your LookupListener impl here*/); Collection data = curResult.allInstances(); // ... compute view from data and trigger repaint }Do *not* perform any long computation in panelActivated directly, see below.
Declarative registration of your NavigatorPanel impl connects this implementation with specific content type, which is type of the document, expressed in mime-type syntax, for example 'text/x-java' for java sources. Infrastructure will automatically load and show your NavigatorPanel impl in UI, when currently activated Node is backed by primary FileObject whose FileObject.getMimeType() equals to content type specified in your layer.
Writing layer registration itself is easy, you can again copy from template layer Basic Navigator Registration Layer.
Additional important info:There may be situations where linking between your Navigator view and activated Node's primary FileObject is not enough or not possible at all. This simply happens when the data you want to represent in Navigator are not accessible through primary FileObject or DataObject. Usual example is Multiview environment, where more views of one document exists.
The solution is to bind content of your Navigator view directly to your TopComponent. Then, whenever your TopComponent gets activated in the system, Navigator UI will show th content you connected to it.
Steps to do:class AmazingTypeLookupHint implements NavigatorLookupHint { public String getContentType () { return "text/my-amazing-type"; } }
Node
subclass
instead of directly altering lookup of your TopComponent
.
See Node.getLookup() method.
Then Navigator will show your desired content whenever your Node
subclass will be active in the system.TopComponent.getLookup()
includes also results from
lookup of asociated Node
. So this approach will stop
working if you change default behaviour of TopComponent.getLookup()
method.
Programmatic activation of specific navigator panel activates and shows navigator panel in navigation area, as if user had selected the panel manually. API clients are expected to use programmatic activation to activate/select preferred panel from a set of available panels.
Example: SeveralTopComponents
in multiview arrangement,
TopComponentA
and TopComponentB
.
Both components provide the same
NavigatorLookupHint
impl, which is recognized by two
providers NavigatorPanelA
and NavigatorPanelB
.
Now when TopComponentA
becomes activated (has a focus),
it's desirable to select/show NavigatorPanelA
from
navigator panels. On the other side, when TopComponentB
is activated, NavigatorPanelB
should be activated automatically.
Steps to do to activate panel programmatically:
NavigatorPanel
implementation that
you want to activate/show in navigator area.Sometimes clients need to alter activated Nodes of Navigator window, to better represent Navigator area content within the whole application. See TopComponent.getActivatedNodes() and TopComponent.Registry.html#getActivatedNodes() to find out what activated nodes of TopComponent and whole system mean.
Use Case Example: NavigatorPanel implementation shows list or tree of someNode
s
in Navigator area. When user selects a Node in the list or tree,
it is desirable to show selected Node's properties in Properties
window and enable proper actions in main menu. Exactly this can be done
by presenting Node selected in the list/tree as activated Node of
Navigator window.
Steps to specify activated Nodes of Navigator window:
NavigatorPanel
, implement
method getLookup()
to return Lookup instance filled
with Node(s) that you want to set as activated Nodes of Navigator window.
class MyNavigatorPanel implements NavigatorPanel { /** Dynamic Lookup content */ private final InstanceContent ic; /** Lookup instance */ private final Lookup lookup; public MyNavigatorPanel () { this.ic = new InstanceContent(); this.lookup = new AbstractLookup(ic); } public Lookup getLookup () { return lookup; } /** Call this method when activated Nodes change is needed, * for example when selection changes in your NavigatorPanel's Component */ private void selectionChanged (Node oldSel, Node newSel) { ic.remove(oldSel); ic.add(newSel); } ... impl of rest of your NavigatorPanel }
Some complex navigation views need support for undoing and redoing edit changes done either directly in the view or in document which the view is representing.
Steps to support undo and redo in navigation view:NavigatorPanel
interface with extra method
getUndoRedo().
NavigatorPanel
usage.
UndoRedo
support returned from NavigatorPanelWithUndo.getUndoRedo()
is propagated to the Navigator TopComponent and returned as its
UndoRedo
support. For details see
TopComponent.getUndoRedo()
and UndoRedo interface.
NavigatorPanelWithUndo
implementation:
class MyNavigatorPanelWithUndo implements NavigatorPanelWithUndo { /** UndoRedo support, substitute with your impl */ private final UndoRedo undo = new UndoRedo.Manager(); public UndoRedo getUndoRedo () { return undo; } ... rest of the NavigatorPanelWithUndo impl ... }
In certain situations it's not desired to show NavigatorPanel implementations related to DataObject of active Node in Navigator window. Typically you need to have active Node of some type, so that actions in the system works properly. But you don't want to show NavigatorPanels that "come" with such active Node.
Steps to remove such NavigatorPanels:getPanelsPolicy()
method.
|
The sources for the module are in NetBeans CVS in core/navigator directory.
Nothing.
Read more about the implementation in the answers to architecture questions.
|
org.netbeans.spi.navigator/1 1.5 | |||||||||
PREV NEXT | FRAMES NO FRAMES |