Accessing topcomponent from a XML multiview panel
Friday Apr 13, 2007
Ok, so you have a nice XML multiview for your XML files (refer here, here and here) and thats helping you to edit the file in a visually attractive way. But if you need to access the Top component which has the multiview elements, say for the purpose of displaying properties of a node in properties window, then?
The properties window automatically follows Netbeans selection model as described here. This works, when we set our nodes as activated nodes to the top components, for example. There lies a trick to get the top component access inside the multiview!
Every multiview element (toolbar or treepanel MVElement) has option of providing its own lookup. This loopup will be included in the final top component's lookup when this multiview is constructed to include inside the top component. Ok, so what we can put in this top component's lookup?
org.netbeans.modules.xml.multiview.AbstractMultiViewElement
The above class has a reference to the top component and its called 'callback'. This class is the super class of all XML multiview elements (be it a toolbar or treepanel MVElement). So now let's use this and the lookup to remember the top component.
So in the ToolBar or TreePanel MV element you would do the following:public Lookup getLookup() {
//return Lookup.getDefault();
return new ProxyLookup(new Lookup[] { Lookups.singleton(content),
Lookups.singleton(callback.getTopComponent()),
super.getLookup()});
}
This is essentially putting the top component reference (which is availble only in MVelement ) in lookup.
In any SectionInnerPanel, you can get the top component reference as follows:
TopComponent currentMVComponent =
(TopComponent)Utilities.actionsGlobalContext().lookup(
TopComponent.class);
So cool, right?
Tags: netbeans topcomponent xml-multiview










