下面列出了java.awt.event.HierarchyBoundsListener#org.openide.util.lookup.InstanceContent 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void testSurviveFocusChange() throws Exception {
InstanceContent ic = new InstanceContent();
Lookup lkp = new AbstractLookup(ic);
Action clone = ((ContextAwareAction) Actions.forID("cat", "survive")).createContextAwareInstance(lkp);
L listener = new L();
clone.addPropertyChangeListener(listener);
assertFalse("Disabled", clone.isEnabled());
Object val = Integer.valueOf(1);
ic.add(val);
assertTrue("Enabled now", clone.isEnabled());
assertEquals("One change", 1, listener.cnt);
ic.remove(val);
assertTrue("Still Enabled", clone.isEnabled());
Survival.value = 0;
clone.actionPerformed(new ActionEvent(this, 0, ""));
assertEquals("Added one", 1, Survival.value);
}
public void testOwnContextAction() throws Exception {
MultiContext.cnt = 0;
FileObject fo = FileUtil.getConfigFile(
"actions/support/test/testOwnContext.instance"
);
assertNotNull("File found", fo);
Object obj = fo.getAttribute("instanceCreate");
assertNotNull("Attribute present", obj);
assertTrue("It is action", obj instanceof Action);
assertFalse("It is not context aware action: " + obj, obj instanceof ContextAwareAction);
Action a = (Action)obj;
InstanceContent ic = contextI;
ic.add(10);
assertEquals("Number lover!", a.getValue(Action.NAME));
a.actionPerformed(new ActionEvent(this, 300, ""));
assertEquals("Global Action not called", 10, MultiContext.cnt);
ic.remove(10);
a.actionPerformed(new ActionEvent(this, 200, ""));
assertEquals("Global Action stays same", 10, MultiContext.cnt);
}
private FilterNode(Filter filter, InstanceContent content) {
super(Children.LEAF, new AbstractLookup(content));
content.add(filter);
content.add(filter.getEditor());
this.filter = filter;
filter.getChangedEvent().addListener(new ChangedListener<Filter>() {
public void changed(Filter source) {
update();
}
});
update();
Lookup.Template<FilterChain> tpl = new Lookup.Template<FilterChain>(FilterChain.class);
result = Utilities.actionsGlobalContext().lookup(tpl);
result.addLookupListener(this);
FilterTopComponent.findInstance().getFilterSettingsChangedEvent().addListener(this);
resultChanged(null);
}
private FolderNode(String name, GroupOrganizer organizer, List<String> oldSubFolders, final List<Group> groups, FolderChildren children, InstanceContent content) {
super(children, new AbstractLookup(content));
children.setParent(this);
this.content = content;
this.children = children;
content.add(new RemoveCookie() {
public void remove() {
for (Group g : groups) {
if (g.getDocument() != null) {
g.getDocument().removeGroup(g);
}
}
}
});
init(name, organizer, oldSubFolders, groups);
}
public void testMoveAction() throws InterruptedException, InvocationTargetException, DataObjectNotFoundException, IOException {
DataObject testdo = DataObject.find(f);
final Node node = testdo.getNodeDelegate();
InstanceContent ic = new InstanceContent();
Lookup lookup = new AbstractLookup(ic);
ic.add(node);
final Action move = RefactoringActionsFactory.moveAction().createContextAwareInstance(lookup);
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
if (move.isEnabled()) {
move.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT);
if (!((MoveRefactoring) DD.rui.getRefactoring()).getRefactoringSource().lookup(FileObject.class).equals(f))
fail("MoveClass was opened with wrong data");
} else {
fail("Action is not enabled.");
}
}
});
}
private FolderNode(String name, GroupOrganizer organizer, List<String> oldSubFolders, final List<Group> groups, FolderChildren children, InstanceContent content) {
super(children, new AbstractLookup(content));
children.setParent(this);
this.content = content;
this.children = children;
content.add(new RemoveCookie() {
public void remove() {
for (Group g : groups) {
if (g.getDocument() != null) {
g.getDocument().removeGroup(g);
}
}
}
});
init(name, organizer, oldSubFolders, groups);
}
private FilterNode(Filter filter, InstanceContent content) {
super(Children.LEAF, new AbstractLookup(content));
content.add(filter);
content.add(filter.getEditor());
this.filter = filter;
filter.getChangedEvent().addListener(new ChangedListener<Filter>() {
public void changed(Filter source) {
update();
}
});
update();
Lookup.Template<FilterChain> tpl = new Lookup.Template<FilterChain>(FilterChain.class);
result = Utilities.actionsGlobalContext().lookup(tpl);
result.addLookupListener(this);
FilterTopComponent.findInstance().getFilterSettingsChangedEvent().addListener(this);
resultChanged(null);
}
private CMPFieldNode(CmpField field, EntityMethodController controller, FileObject ddFile, InstanceContent instanceContent) {
super(Children.LEAF, new AbstractLookup(instanceContent));
instanceContent.add(this); // for enabling Open action
//TODO: RETOUCHE
// try {
// ic.add(DataObject.find(JavaModel.getFileObject(controller.getBeanClass().getResource()))); // for enabling SafeDelete action
// } catch (DataObjectNotFoundException ex) {
// // ignore
// }
// Method getterMethod = controller.getGetterMethod(controller.getBeanClass(), field.getFieldName());
// if (getterMethod != null) {
// ic.add(getterMethod); // for SafeDelete refactoring to find Method element
// }
this.field = field;
this.ddFile = ddFile;
this.controller = controller;
field.addPropertyChangeListener(WeakListeners.propertyChange(this, field));
}
protected void setUp () {
ic = new InstanceContent ();
CES support = new CES (this, new AbstractLookup(ic));
MockServices.setServices(Redirector.class, DD.class);
red = Lookup.getDefault().lookup(Redirector.class);
assertNotNull(red);
dd = Lookup.getDefault().lookup(DD.class);
assertNotNull(dd);
CloneableEditorSupportCOSRedirectorTest t = new CloneableEditorSupportCOSRedirectorTest(this.content);
red.master = support;
InstanceContent slave = new InstanceContent();
red.slave = new CES(t, new AbstractLookup (slave));
slave.add(red.master);
}
@Override
protected void setUp () throws Exception {
MockServices.setServices(DD.class);
clearWorkDir();
LocalFileSystem fs = new LocalFileSystem();
fs.setRootDirectory(getWorkDir());
FileObject fo = fs.getRoot().createData("Ahoj", "txt");
ic = new InstanceContent();
support = new CES(this, new AbstractLookup(ic));
edit = support;
assertNotNull("we have editor", edit);
DD.type = -1;
DD.toReturn = new Stack<Object>();
}
public void testCustomContextAwareInstance() {
Action a = Actions.forID("Foo", "test.ListAction");
DefaultListSelectionModel model = new DefaultListSelectionModel();
InstanceContent localContent1 = new InstanceContent();
AbstractLookup localLookup1 = new AbstractLookup(localContent1);
Action la = ((ContextAwareAction)a).createContextAwareInstance(localLookup1);
assertFalse(a.isEnabled());
assertFalse(la.isEnabled());
localContent1.add(model);
assertFalse(a.isEnabled());
assertTrue(la.isEnabled());
assertFalse((Boolean)la.getValue(Action.SELECTED_KEY));
// checks that the context-bound instance changes its selected state
// if the model changes (relevant property change event is fired)
model.setSelectionInterval(1, 2);
assertTrue((Boolean)la.getValue(Action.SELECTED_KEY));
}
@Override
protected void setUp() throws Exception {
MockServices.setServices(DD.class);
clearWorkDir();
LocalFileSystem fs = new LocalFileSystem();
fs.setRootDirectory(getWorkDir());
FileObject fo = fs.getRoot().createData("Ahoj", "txt");
ic = new InstanceContent();
support = new CES(this, new AbstractLookup(ic));
edit = support;
assertNotNull("we have editor", edit);
DD.type = -1;
DD.toReturn = new Stack<Object>();
}
/** Fills the lookup with instances */
protected void setUp () {
Integer integer = (Integer)getArgument ();
int cnt = integer.intValue ();
boolean reverse = cnt < 0;
if (reverse) cnt = -cnt;
InstanceContent iContent = new InstanceContent();
lookup = new AbstractLookup(iContent);
while (cnt-- > 0) {
for (int i = 0; i < INSTANCES.length; i++) {
if (reverse) {
iContent.add (INSTANCES[INSTANCES.length - i - 1]);
} else {
iContent.add (INSTANCES[i]);
}
}
}
}
public GlobalActionContextProxy() {
try {
this.content = new InstanceContent();
// The default GlobalContextProvider
this.globalContextProvider = new GlobalActionContextImpl();
this.globalContextLookup = this.globalContextProvider.createGlobalContext();
// Monitor the activation of the Projects Tab TopComponent
TopComponent.getRegistry().addPropertyChangeListener(this.registryListener);
// Monitor the existance of a Project in the principle lookup
this.resultProjects = globalContextLookup.lookupResult(Project.class);
this.resultProjects.addLookupListener(this.resultListener);
} catch (Exception e) {
Exceptions.printStackTrace(e);
}
WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
@Override
public void run() {
// Hack to force the current Project selection when the application starts up
TopComponent tc = WindowManager.getDefault().findTopComponent(PROJECT_LOGICAL_TAB_ID);
if (tc != null) {
tc.requestActive();
}
}
});
}
public TestProject(FileObject dir, ProjectState state, ClassPathProvider classpathProvider, Sources sources) {
this.dir = dir;
this.state = state;
InstanceContent ic = new InstanceContent();
ic.add(classpathProvider);
ic.add(sources);
this.lookup = new AbstractLookup(ic);
}
private FolderNode(final Folder folder, FolderChildren children, InstanceContent content) {
super(children, new AbstractLookup(content));
this.content = content;
this.children = children;
if (folder instanceof FolderElement) {
final FolderElement folderElement = (FolderElement) folder;
this.setDisplayName(folderElement.getName());
content.add(new RemoveCookie() {
@Override
public void remove() {
folderElement.getParent().removeElement(folderElement);
}
});
}
}
public TestProject(FileObject dir, ProjectState state, ClassPathProvider classpathProvider, Sources sources) {
this.dir = dir;
this.state = state;
InstanceContent ic = new InstanceContent();
ic.add(classpathProvider);
ic.add(sources);
this.lookup = new AbstractLookup(ic);
}
@Override
public Lookup getLookup() {
if (lookup == null) {
InstanceContent lookupContent = new InstanceContent();
lookupContent.add(new SQLExecutionImpl(modelerFile));
Lookup[] content = {new AbstractLookup(lookupContent)};
lookup = new ProxyLookup(content);
}
return lookup;
}
private Lookup getInstanceLookup() {
InstanceContent instanceContent = new InstanceContent();
instanceContent.add(sq);
instanceContent.add(vq);
Lookup instanceLookup = new AbstractLookup(instanceContent);
return instanceLookup;
}
public DependenciesEditorTopComponent() {
setName(Bundle.CTL_DependenciesEditorTopComponent());
setToolTipText(Bundle.HINT_DependenciesEditorTopComponent());
setLayout(new BorderLayout());
init();
content = new InstanceContent();
lookup = new AbstractLookup(content);
associateLookup(lookup);
}
private JAXBWizardRootNode(Project prj, InstanceContent content) {
super(new JAXBWizardRootNodeChildren(prj),
new AbstractLookup(content));
// adds the node to our own lookup
content.add (this);
// adds additional items to the lookup
content.add (prj);
}
private PlatformNode(PlatformProvider pp, ClassPathSupport cs) {
super (new PlatformContentChildren (cs), new ProxyLookup(new Lookup[]{
Lookups.fixed(new PlatformEditable(pp), new JavadocProvider(pp), new PathFinder()),
new PlatformFolderLookup(new InstanceContent(), pp)
}));
this.pp = pp;
this.pp.addChangeListener(this);
setIconBaseWithExtension(PLATFORM_ICON);
}
private static synchronized Lookup featureTypesLookup() {
if (featureTypesLookup != null) {
return featureTypesLookup;
}
String clusters = System.getProperty("netbeans.dirs");
if (clusters == null) {
featureTypesLookup = Lookup.EMPTY;
} else {
InstanceContent ic = new InstanceContent();
AbstractLookup l = new AbstractLookup(ic);
String[] paths = clusters.split(File.pathSeparator);
for (String c : paths) {
int last = c.lastIndexOf(File.separatorChar);
String clusterName = c.substring(last + 1).replaceFirst("[0-9\\.]*$", "");
String basename = "/org/netbeans/modules/ide/ergonomics/" + clusterName;
String layerName = basename + "/layer.xml";
String bundleName = basename + "/Bundle.properties";
URL layer = FeatureManager.class.getResource(layerName);
URL bundle = FeatureManager.class.getResource(bundleName);
if (layer != null && bundle != null) {
FeatureInfo info;
try {
info = FeatureInfo.create(clusterName, layer, bundle);
ic.add(info);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
featureTypesLookup = l;
}
return featureTypesLookup;
}
protected Lookup getLookup(Node[] n) {
InstanceContent ic = new InstanceContent();
for (Node node:n) {
ic.add(node);
}
if (n.length>0) {
EditorCookie tc = getTextComponent(n[0]);
if (tc != null) {
ic.add(tc);
}
}
ic.add(new Hashtable(0));
return new AbstractLookup(ic);
}
public void testLookupInitialized() {
InstanceContent ic = new InstanceContent();
Lookup lookup = new AbstractLookup(ic);
ic.add(10);
TopComponent mvc = MultiViews.createMultiView("text/context", new LP(lookup));
assertEquals("10 now", Integer.valueOf(10), mvc.getLookup().lookup(Integer.class));
ic.remove(10);
ic.add(1);
assertEquals("1 now", Integer.valueOf(1), mvc.getLookup().lookup(Integer.class));
}
@NonNull
private static Lookup prepareLookup(@NonNull final Description d) {
final InstanceContent ic = new InstanceContent();
ic.add(d, ConvertDescription2FileObject);
ic.add(d, ConvertDescription2DataObject);
if (d.handle != null) {
ic.add(d, ConvertDescription2TreePathHandle);
}
return new AbstractLookup(ic);
}
private static void doFullChangeMethodParameters(TreePathHandle tph, ParameterInfo[] newParameterInfo) {
InstanceContent ic = new InstanceContent();
ic.add(tph);
ic.add(new AbstractNode(Children.LEAF, Lookups.singleton(tph)));
for (ParameterInfo parameterInfo : newParameterInfo) {
ic.add(parameterInfo);
}
Lookup actionContext = new AbstractLookup(ic);
final Action a = JavaRefactoringActionsFactory.changeParametersAction().createContextAwareInstance(actionContext);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
a.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT);
}
});
}
private MyLookup(MimePath mimePath, InstanceContent ic) {
super(ic);
this.mimePath = mimePath;
this.ic = ic;
// Start listening
List<MimePath> allPaths = mimePath.getIncludedPaths();
this.allCtsi = new CodeTemplateSettingsImpl[allPaths.size()];
for(int i = 0; i < allPaths.size(); i++) {
this.allCtsi[i] = CodeTemplateSettingsImpl.get(allPaths.get(i));
this.allCtsi[i].addPropertyChangeListener(WeakListeners.propertyChange(this, this.allCtsi[i]));
}
}
public HistoryComponent() {
activatedNodesContent = new InstanceContent();
lookup = new ProxyLookup(new Lookup[] {
new AbstractLookup(activatedNodesContent)
});
init();
}
public void testContextInstancesAreIndependent() throws Exception {
System.out.println("testContextInstancesAreIndependent");
A a = new A();
assertNull(Utilities.actionsGlobalContext().lookup(String.class)); //sanity check
InstanceContent ic = new InstanceContent();
Lookup l = new AbstractLookup(ic);
Action a3 = a.createContextAwareInstance(l);
assertFalse(a3.isEnabled());
PCL pcl = new PCL();
a3.addPropertyChangeListener(pcl);
setContent("fuddle");
a.assertNotPerformed();
assertTrue(a.isEnabled());
assertFalse(a3.isEnabled());
synchronized (a3) {
//should time out if test is going to pass
a3.wait(TIMEOUT);
}
synchronized (pcl) {
pcl.wait(TIMEOUT);
}
pcl.assertNotFired();
ic.set(Collections.singleton("boo"), null);
synchronized (a3) {
a3.wait(TIMEOUT);
}
synchronized (pcl) {
pcl.wait(TIMEOUT);
}
pcl.assertEnabledChangedTo(true);
clearContent();
assertTrue(a3.isEnabled());
assertFalse(a.isEnabled());
}