Removed
Link Here
|
1 |
/* |
2 |
* Sun Public License Notice |
3 |
* |
4 |
* The contents of this file are subject to the Sun Public License |
5 |
* Version 1.0 (the "License"). You may not use this file except in |
6 |
* compliance with the License. A copy of the License is available at |
7 |
* http://www.sun.com/ |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
13 |
|
14 |
import java.util.Collection; |
15 |
import javax.swing.JComponent; |
16 |
import javax.swing.JLabel; |
17 |
import org.netbeans.spi.navigator.NavigatorPanel; |
18 |
import org.openide.util.Lookup; |
19 |
import org.openide.util.LookupEvent; |
20 |
import org.openide.util.LookupListener; |
21 |
|
22 |
/** |
23 |
* Basic dummy implementation of NavigatorPanel interface. |
24 |
*/ |
25 |
public class BasicNavPanelImpl implements NavigatorPanel { |
26 |
|
27 |
/** holds UI of this panel */ |
28 |
private JComponent panelUI; |
29 |
/** template for finding data in given context. |
30 |
* Object used as example, replace with your own data source, for example JavaDataObject etc */ |
31 |
private static final Lookup.Template MY_DATA = new Lookup.Template(Object.class); |
32 |
/** current context to work on */ |
33 |
private Lookup.Result curContext; |
34 |
/** listener to context changes */ |
35 |
private LookupListener contextL; |
36 |
|
37 |
/** public no arg constructor needed for system to instantiate provider well */ |
38 |
public BasicNavPanelImpl() { |
39 |
} |
40 |
|
41 |
public String getDisplayHint() { |
42 |
return "Basic dummy implementation of NavigatorPanel interface"; |
43 |
} |
44 |
|
45 |
public String getDisplayName() { |
46 |
return "Dummy View"; |
47 |
} |
48 |
|
49 |
public JComponent getComponent() { |
50 |
if (panelUI == null) { |
51 |
panelUI = new JLabel("Dummy label"); |
52 |
// You can override requestFocusInWindow() on the component if desired. |
53 |
} |
54 |
return panelUI; |
55 |
} |
56 |
|
57 |
public void panelActivated(Lookup context) { |
58 |
// lookup context and listen to result to get notified about context changes |
59 |
curContext = context.lookup(MY_DATA); |
60 |
curContext.addLookupListener(getContextListener()); |
61 |
// get actual data and recompute content |
62 |
Collection data = curContext.allInstances(); |
63 |
setNewContent(data); |
64 |
} |
65 |
|
66 |
public void panelDeactivated() { |
67 |
curContext.removeLookupListener(getContextListener()); |
68 |
curContext = null; |
69 |
} |
70 |
|
71 |
public Lookup getLookup () { |
72 |
// go with default activated Node strategy |
73 |
return null; |
74 |
} |
75 |
|
76 |
/************* non - public part ************/ |
77 |
|
78 |
private void setNewContent (Collection newData) { |
79 |
// put your code here that grabs information you need from given |
80 |
// collection of data, recompute UI of your panel and show it. |
81 |
// Note - be sure to compute the content OUTSIDE event dispatch thread, |
82 |
// just final repainting of UI should be done in event dispatch thread. |
83 |
// Please use RequestProcessor and Swing.invokeLater to achieve this. |
84 |
} |
85 |
|
86 |
/** Accessor for listener to context */ |
87 |
private LookupListener getContextListener () { |
88 |
if (contextL == null) { |
89 |
contextL = new ContextListener(); |
90 |
} |
91 |
return contextL; |
92 |
} |
93 |
|
94 |
/** Listens to changes of context and triggers proper action */ |
95 |
private class ContextListener implements LookupListener { |
96 |
|
97 |
public void resultChanged(LookupEvent ev) { |
98 |
Collection data = ((Lookup.Result)ev.getSource()).allInstances(); |
99 |
setNewContent(data); |
100 |
} |
101 |
|
102 |
} // end of ContextListener |
103 |
|
104 |
} |