本文整理汇总了Java中org.openide.util.lookup.InstanceContent.remove方法的典型用法代码示例。如果您正苦于以下问题:Java InstanceContent.remove方法的具体用法?Java InstanceContent.remove怎么用?Java InstanceContent.remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.util.lookup.InstanceContent
的用法示例。
在下文中一共展示了InstanceContent.remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testOwnContextAction
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
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);
}
示例2: testContextAction
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
public void testContextAction() throws Exception {
Action a = Actions.forID("Tools", "on.int");
assertTrue("It is context aware action", a instanceof ContextAwareAction);
InstanceContent ic = new InstanceContent();
AbstractLookup lkp = new AbstractLookup(ic);
Action clone = ((ContextAwareAction) a).createContextAwareInstance(lkp);
NumberLike ten = new NumberLike(10);
ic.add(ten);
assertEquals("Number lover!", clone.getValue(Action.NAME));
clone.actionPerformed(new ActionEvent(this, 300, ""));
assertEquals("Global Action not called", 10, Context.cnt);
ic.remove(ten);
clone.actionPerformed(new ActionEvent(this, 200, ""));
assertEquals("Global Action stays same", 10, Context.cnt);
}
示例3: checkInstanceInGetLookup
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
private void checkInstanceInGetLookup (Object obj, InstanceContent ic, Node node, boolean shouldBeThere) {
Listener listener = new Listener ();
Lookup.Result res = node.getLookup().lookupResult(obj.getClass());
Collection ignore = res.allItems ();
res.addLookupListener(listener);
ic.add (obj);
if (shouldBeThere) {
listener.assertEvents ("One change in node's lookup", -1, 1);
assertEquals ("Can access object in content via lookup", obj, node.getLookup ().lookup (obj.getClass ()));
} else {
assertNull ("Cannot access object in content via lookup", node.getLookup ().lookup (obj.getClass ()));
}
ic.remove (obj);
if (shouldBeThere) {
listener.assertEvents ("One change in node's lookup", -1, 1);
}
assertNull ("Cookie is removed", node.getLookup ().lookup (obj.getClass ()));
}
示例4: doCheck
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
private void doCheck(TopComponent mvc, InstanceContent ic) {
assertNotNull("MultiViewComponent cloned", mvc);
MultiViewHandler handler = MultiViews.findMultiViewHandler(mvc);
assertNotNull("Handler found", handler);
MultiViewPerspective[] arr = handler.getPerspectives();
assertEquals("Two perspetives found", 2, arr.length);
assertEquals("Contextual", arr[0].getDisplayName());
assertEquals("Contextual", arr[1].getDisplayName());
MultiViewDescription description = Accessor.DEFAULT.extractDescription(arr[0]);
assertTrue(description instanceof ContextAwareDescription);
assertFalse("First one is not for split", ((ContextAwareDescription)description).isSplitDescription());
description = Accessor.DEFAULT.extractDescription(arr[1]);
assertTrue(description instanceof ContextAwareDescription);
assertTrue("Second one is for split", ((ContextAwareDescription)description).isSplitDescription());
assertPersistence("Always", TopComponent.PERSISTENCE_ALWAYS, mvc);
mvc.open();
mvc.requestActive();
mvc.requestVisible();
handler.requestActive(arr[0]);
assertNull("No integer now", mvc.getLookup().lookup(Integer.class));
ic.add(1);
assertEquals("1 now", Integer.valueOf(1), mvc.getLookup().lookup(Integer.class));
((MultiViewCloneableTopComponent)mvc).splitComponent(JSplitPane.HORIZONTAL_SPLIT, -1);
handler.requestActive(arr[0]);
ic.remove(1);
assertNull("No integer now", mvc.getLookup().lookup(Integer.class));
ic.add(2);
assertEquals("2 now", Integer.valueOf(2), mvc.getLookup().lookup(Integer.class));
}
示例5: testCallbackAction
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
public void testCallbackAction() throws Exception {
Callback.cnt = 0;
ContextAwareAction a = (ContextAwareAction) Actions.forID("Tools", "my.action");
class MyAction extends AbstractAction {
int cnt;
@Override
public void actionPerformed(ActionEvent e) {
cnt += e.getID();
}
}
MyAction my = new MyAction();
ActionMap m = new ActionMap();
m.put("klic", my);
InstanceContent ic = new InstanceContent();
AbstractLookup lkp = new AbstractLookup(ic);
Action clone = a.createContextAwareInstance(lkp);
ic.add(m);
assertEquals("I am context", clone.getValue(Action.NAME));
clone.actionPerformed(new ActionEvent(this, 300, ""));
assertEquals("Local Action called", 300, my.cnt);
assertEquals("Global Action not called", 0, Callback.cnt);
ic.remove(m);
clone.actionPerformed(new ActionEvent(this, 200, ""));
assertEquals("Local Action stays", 300, my.cnt);
assertEquals("Global Action ncalled", 200, Callback.cnt);
}
示例6: testLookupInitialized
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
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));
}
示例7: testMultiViewsContextCreate
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
public void testMultiViewsContextCreate() {
InstanceContent ic = new InstanceContent();
Lookup lookup = new AbstractLookup(ic);
TopComponent mvc = MultiViews.createMultiView("text/context", new LP(lookup));
assertNotNull("MultiViewComponent created", mvc);
MultiViewHandler handler = MultiViews.findMultiViewHandler(mvc);
assertNotNull("Handler found", handler);
MultiViewPerspective[] arr = handler.getPerspectives();
assertEquals("Two perspetives found", 2, arr.length);
assertEquals("Contextual", arr[0].getDisplayName());
assertEquals("Contextual", arr[1].getDisplayName());
MultiViewDescription description = Accessor.DEFAULT.extractDescription(arr[0]);
assertTrue(description instanceof ContextAwareDescription);
assertFalse("First one is not for split", ((ContextAwareDescription)description).isSplitDescription());
description = Accessor.DEFAULT.extractDescription(arr[1]);
assertTrue(description instanceof ContextAwareDescription);
assertTrue("Second one is for split", ((ContextAwareDescription)description).isSplitDescription());
mvc.open();
mvc.requestActive();
mvc.requestVisible();
handler.requestActive(arr[0]);
assertNull("No integer now", mvc.getLookup().lookup(Integer.class));
ic.add(1);
assertEquals("1 now", Integer.valueOf(1), mvc.getLookup().lookup(Integer.class));
((MultiViewTopComponent)mvc).splitComponent(JSplitPane.HORIZONTAL_SPLIT, -1);
ic.remove(1);
handler.requestActive(arr[1]);
assertNull("No integer now", mvc.getLookup().lookup(Integer.class));
ic.add(2);
assertEquals("2 now", Integer.valueOf(2), mvc.getLookup().lookup(Integer.class));
}
示例8: testWithFallback
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
public void testWithFallback() throws Exception {
MyAction myAction = new MyAction();
MyAction fallAction = new MyAction();
ActionMap other = new ActionMap();
ActionMap tc = new ActionMap();
tc.put("somekey", myAction);
InstanceContent ic = new InstanceContent();
AbstractLookup al = new AbstractLookup(ic);
ic.add(tc);
ContextAwareAction a = callback("somekey", fallAction, al, false);
CntListener l = new CntListener();
a.addPropertyChangeListener(l);
assertTrue("My action is on", myAction.isEnabled());
assertTrue("Callback is on", a.isEnabled());
l.assertCnt("No change yet", 0);
ic.remove(tc);
assertTrue("fall is on", fallAction.isEnabled());
assertTrue("My is on as well", a.isEnabled());
l.assertCnt("Still enabled, so no change", 0);
fallAction.setEnabled(false);
l.assertCnt("Now there was one change", 1);
assertFalse("fall is off", fallAction.isEnabled());
assertFalse("My is off as well", a.isEnabled());
Action a2 = a.createContextAwareInstance(Lookup.EMPTY);
assertEquals("Both actions are equal", a, a2);
assertEquals("and have the same hash", a.hashCode(), a2.hashCode());
}
示例9: testBugfix104145_DeactivatedNotCalled
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
public void testBugfix104145_DeactivatedNotCalled () throws Exception {
System.out.println("Testing bugfix 104145...");
InstanceContent ic = getInstanceContent();
TestLookupHint ostravskiHint = new TestLookupHint("ostravski/gyzd");
ic.add(ostravskiHint);
NavigatorTC navTC = NavigatorTC.getInstance();
NavigatorTCHandle navTCH = new NavigatorTCHandle(navTC);
try {
navTCH.open();
waitForProviders(navTC);
NavigatorPanel selPanel = navTC.getSelectedPanel();
OstravskiGyzdProvider ostravak = (OstravskiGyzdProvider) selPanel;
ostravak.resetDeactCalls();
navTCH.close();
int deact = ostravak.getPanelDeactivatedCallsCount();
assertEquals("panelDeactivated expected to be called once but called " + deact + " times.",
1, deact);
} finally {
// clean in finally block so that test doesn't affect others
navTCH.close();
ic.remove(ostravskiHint);
}
}
示例10: checkInstanceInGetCookie
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
private void checkInstanceInGetCookie (Node.Cookie obj, InstanceContent ic, Node node) {
assertNull("The node does not contain the object yet", node.getCookie(obj.getClass()));
Listener listener = new Listener ();
node.addNodeListener(listener);
ic.add (obj);
listener.assertEvents ("One change in node", 1, -1);
assertEquals("Can access cookie in the content", obj, node.getCookie(obj.getClass()));
ic.remove (obj);
listener.assertEvents ("One change in node", 1, -1);
}
示例11: testFeature98125_UndoRedo
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
/** Test for IZ feature #98125. It tests ability of NavigatorPanelWithUndo
* implementors to provide UndoRedo support for their view through
* navigator TopComponent.
*/
public void testFeature98125_UndoRedo () throws Exception {
System.out.println("Testing feature #98125, providing UndoRedo...");
InstanceContent ic = getInstanceContent();
TestLookupHint undoHint = new TestLookupHint("undoRedo/tester");
ic.add(undoHint);
NavigatorTC navTC = NavigatorTC.getInstance();
NavigatorTCHandle navTCH = new NavigatorTCHandle(navTC);
try {
navTCH.open();
waitForProviders(navTC);
NavigatorPanel selPanel = navTC.getSelectedPanel();
assertNotNull("Selected panel should not be null", navTC.getSelectedPanel());
assertTrue("Panel class not expected", selPanel instanceof UndoRedoProvider);
UndoRedoProvider provider = (UndoRedoProvider)selPanel;
UndoRedo panelUndo = provider.getUndoRedo();
UndoRedo tcUndo = navTC.getUndoRedo();
assertTrue("Expected undo manager " + panelUndo + ", but got " + tcUndo, panelUndo == tcUndo);
} finally {
// cleanup
navTCH.close();
ic.remove(undoHint);
}
}
示例12: testMultiContextActionLookup
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
public void testMultiContextActionLookup() throws Exception {
FileObject fo = FileUtil.getConfigFile(
"actions/support/test/testInjectContextLookup.instance"
);
assertNotNull("File found", fo);
Object obj = fo.getAttribute("instanceCreate");
assertNotNull("Attribute present", obj);
assertTrue("It is context aware action", obj instanceof ContextAwareAction);
ContextAwareAction a = (ContextAwareAction)obj;
InstanceContent ic = new InstanceContent();
AbstractLookup lkp = new AbstractLookup(ic);
Action clone = a.createContextAwareInstance(lkp);
ic.add(10);
ic.add(3L);
assertEquals("Number lover!", clone.getValue(Action.NAME));
clone.actionPerformed(new ActionEvent(this, 300, ""));
assertEquals("Global Action not called", 13, LookupContext.cnt);
ic.remove(10);
clone.actionPerformed(new ActionEvent(this, 200, ""));
assertEquals("Adds 3", 16, LookupContext.cnt);
ic.remove(3L);
assertFalse("It is disabled", clone.isEnabled());
clone.actionPerformed(new ActionEvent(this, 200, ""));
assertEquals("No change", 16, LookupContext.cnt);
}
示例13: testFeature217091_Toolbar
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
public void testFeature217091_Toolbar () throws Exception {
InstanceContent ic = getInstanceContent();
TestLookupHint toolbarHint = new TestLookupHint("toolbar/tester");
ic.add(toolbarHint);
NavigatorTC navTC = NavigatorTC.getInstance();
NavigatorTCHandle navTCH = new NavigatorTCHandle(navTC);
try {
navTCH.open();
waitForProviders(navTC);
NavigatorPanel selPanel = navTC.getSelectedPanel();
assertNotNull("Selected panel should not be null", navTC.getSelectedPanel());
assertTrue("Panel class not expected", selPanel instanceof ToolbarProvider);
ToolbarProvider provider = (ToolbarProvider)selPanel;
JComponent toolbarProvider = provider.getToolbarComponent();
JComponent toolbarTC = navTC.getToolbar();
assertTrue("Expected toolbar " + toolbarProvider + ", but got " + toolbarTC, toolbarProvider == toolbarTC);
} finally {
// cleanup
navTCH.close();
ic.remove(toolbarHint);
}
}
示例14: doTestRefreshAfterBeingHidden
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
private void doTestRefreshAfterBeingHidden(boolean clone, boolean menu) throws IOException {
InstanceContent ic = new InstanceContent();
Lookup context = new AbstractLookup(ic);
Action instance;
if (clone) {
Action a = create(Lookup.EMPTY);
instance = ((ContextAwareAction)a).createContextAwareInstance(context);
} else {
instance = create(context);
}
if (!(instance instanceof Presenter.Popup)) {
// cannot test, skipping
return;
}
CharSequence log1 = Log.enable("org.netbeans.modules.project.ui.actions", Level.FINER);
assertFalse("Disabled", instance.isEnabled());
if (!log1.toString().contains("Refreshing")) {
fail("Should be refreshing: " + log1);
}
JMenuItem item = item(instance, menu);
JMenu jmenu = new JMenu();
jmenu.addNotify();
assertTrue("Peer created", jmenu.isDisplayable());
jmenu.getPopupMenu().addNotify();
assertTrue("Peer for popup", jmenu.getPopupMenu().isDisplayable());
item.addPropertyChangeListener(this);
jmenu.add(item);
assertEquals("anncessor properly changes, this means the actions framework is activated", 1, ancEvent);
assertFalse("Not enabled", item.isEnabled());
FileObject pfo = TestSupport.createTestProject(FileUtil.createMemoryFileSystem().getRoot(), "yaya");
FileObject pf2 = TestSupport.createTestProject(FileUtil.createMemoryFileSystem().getRoot(), "blabla");
MockServices.setServices(TestSupport.TestProjectFactory.class);
Project p = ProjectManager.getDefault().findProject(pfo);
Project p2 = ProjectManager.getDefault().findProject(pf2);
if (p instanceof TestSupport.TestProject) {
enhanceProject((TestSupport.TestProject)p);
}
if (p2 instanceof TestSupport.TestProject) {
enhanceProject((TestSupport.TestProject)p2);
}
assertNotNull("Project found", p);
assertNotNull("Project2 found", p2);
OpenProjects.getDefault().open(new Project[] { p }, false);
ic.add(p);
assertTrue("enabled", item.isEnabled());
assertEquals("One change", 1, change);
if (menu) {
item.removeNotify();
CharSequence log2 = Log.enable("org.netbeans.modules.project.ui.actions", Level.FINER);
ic.remove(p);
ic.add(p2);
if (log2.length() > 0) {
fail("Nothing shall happen:\n" + log2);
}
} // irrelevant for popups
}
示例15: testStackOverFlow
import org.openide.util.lookup.InstanceContent; //导入方法依赖的package包/类
public void testStackOverFlow() throws IOException {
InstanceContent ic = new InstanceContent();
Lookup context = new AbstractLookup(ic);
boolean clone = false;
Action instance;
if (clone) {
Action a = create(Lookup.EMPTY);
instance = ((ContextAwareAction)a).createContextAwareInstance(context);
} else {
instance = create(context);
}
FileObject pfo = TestSupport.createTestProject(FileUtil.createMemoryFileSystem().getRoot(), "yaya");
FileObject pf2 = TestSupport.createTestProject(FileUtil.createMemoryFileSystem().getRoot(), "blabla");
MockServices.setServices(TestSupport.TestProjectFactory.class);
Project p = ProjectManager.getDefault().findProject(pfo);
Project p2 = ProjectManager.getDefault().findProject(pf2);
if (p instanceof TestSupport.TestProject) {
enhanceProject((TestSupport.TestProject)p);
}
if (p2 instanceof TestSupport.TestProject) {
enhanceProject((TestSupport.TestProject)p2);
}
assertNotNull("Project found", p);
assertNotNull("Project2 found", p2);
OpenProjects.getDefault().open(new Project[] { p }, false);
assertFalse("Disabled1", instance.isEnabled());
instance.addPropertyChangeListener(this);
ic.add(p);
assertTrue("Enabled", instance.isEnabled());
assertEquals("One change", 1, change);
class Q implements PropertyChangeListener {
Action i;
int cnt;
@Override
public void propertyChange(PropertyChangeEvent evt) {
if ("enabled".equals(evt.getPropertyName())) {
cnt++;
/* What is this for? Often fails during unit tests (but tests pass).
assertTrue("enabled in listener", i.isEnabled());
*/
}
}
}
Q q = new Q();
q.i = instance;
ic.remove(p);
instance.removePropertyChangeListener(this);
ic.add(p);
instance.addPropertyChangeListener(q);
assertTrue("Enabled", instance.isEnabled());
assertEquals("One call", 1, q.cnt);
}