NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
mone.java
Joined: 12 Jun 2012 Posts: 5
|
Posted: Tue Jun 12, 2012 3:26 pm Post subject: Using Lookup in a not TopComponent class |
|
|
Hi, I have created a wizard module in netbeans... This module after the end of the wizard have to produce an object that will be seen in an OutlineView.. So i wuold do this with lookup: When the Wizard end i put the object in InstanceContent... My InstallWizardAction implements Lookup.Provider, but i can't get the lookup from the module that have the OutlineWiev
| Code: | | Utilities.actionsGlobalContext().lookupResult(ObjectType.class)... |
Because InstallWizardAction is not a TopComponent and not have the method associateLookup()... How can I get the lookup of InstallWizardAction from another component?
this is the class that contains the OutlineView that should contains the object created by wizard..
| Code: |
public final class TreeTopComponent extends TopComponent implements ExplorerManager.Provider, LookupListener {
private ExplorerManager em = new ExplorerManager();
private Lookup.Result<ObjectType> result = null;
public TreeTopComponent() throws Exception {
initComponents();
setName(Bundle.CTL_TreeTopComponent());
setToolTipText(Bundle.HINT_TreeTopComponent());
Children kids = Children.create(new PlatformChildFactory(), true);
//Create a root node:
Node rootNode = new AbstractNode(kids);
em.setRootContext(rootNode);
((OutlineView)jScrollPane1).getOutline().setRootVisible(false);
associateLookup(ExplorerUtils.createLookup(em, getActionMap()));
}
@Override
public void componentOpened() {
result = Utilities.actionsGlobalContext().lookupResult(ObjectType.class);
result.addLookupListener(this);
}
@Override
public void componentClosed() {
result.removeLookupListener(this);
result = null;
}
@Override
public void resultChanged(LookupEvent ev) {
Collection<? extends ObjectType> objects = result.allInstances();
for(ObjectType a : objects)
System.out.println("resultChanged:"+a.getName());
}
eccc....
}
|
this is the class that produce the object...
| Code: |
public final class InstallWizardAction implements ActionListener, Lookup.Provider {
private final InstanceContent content = new InstanceContent();
private final Lookup lookup = new AbstractLookup(content);
public InstallWizardAction() {
ProxyLookup proxy = new ProxyLookup(lookup);
}
@Override
public void actionPerformed(ActionEvent e) {
List<WizardDescriptor.Panel<WizardDescriptor>> panels = new ArrayList<WizardDescriptor.Panel<WizardDescriptor>>();
panels.add(new Panel1(this));
panels.add(new Panel2());
ecc....
String[] steps = new String[panels.size()];
for (int i = 0; i < panels.size(); i++) {
Component c = panels.get(i).getComponent();
// Default step name to component name of panel.
steps[i] = c.getName();
if (c instanceof JComponent) { // assume Swing components
JComponent jc = (JComponent) c;
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i);
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps);
jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true);
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, true);
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true);
}
}
WizardDescriptor wiz = new WizardDescriptor(new WizardDescriptor.ArrayIterator<WizardDescriptor>(panels));
// {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
wiz.setTitleFormat(new MessageFormat("{0}"));
wiz.setTitle("EasyDBLog Wizard");
if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
try {
ObjectType object = (ObjectType) wiz.getProperty(SummingController7.PROPERTY_NAME);
content.set(Collections.singleton(ap), null);
content.add(ap);
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
}
}
@Override
public Lookup getLookup() {
return lookup;
}
}
|
 |
|
| Back to top |
|
 |
skyhook
Joined: 13 Apr 2012 Posts: 22
|
Posted: Thu Jul 12, 2012 8:58 am Post subject: Not nice solution |
|
|
Its without lookup but may be it can help to you...What about another way? Create the object and put it to OutlineView with WindowManager
In wizard create DATA then find TopComponent via WindowManager...
YourTopComponent tc = (YourTopComponent) WindowManager.getDefault().findTopComponent("YourTopComponent");
if (tc != null){
tc.refreshOutlineView(DATA);
}
Marek |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|