private void doTestNodesWithChangesInLookup (Class c) { InstanceContent ic = new InstanceContent(); Node[] arr = new Node[] { new AbstractNode(Children.LEAF, new AbstractLookup(ic)), new AbstractNode(Children.LEAF, Lookup.EMPTY), }; arr[0].setName("cookie-container-node"); arr[1].setName("node-as-cookie"); //doTestNodes(arr, AbstractNode.class); doTestNodes (arr, c, 2); ic.add (arr[1]); /* Huh? There should be both [0] and [1], how can you say which one will be returned? assertEquals ("Now the [1] is in lookup of [0]", arr[1], lookup.lookup (c)); */ Collection all = lookup.lookup(new Lookup.Template(c)).allInstances(); assertEquals("Two nodes are in TC lookup", 2, all.size()); assertEquals("They are the ones we expect", new HashSet(Arrays.asList(arr)), new HashSet(all)); assertTrue("Lookup simple query gives one or the other", new HashSet(Arrays.asList(arr)).contains(lookup.lookup(c))); assertEquals("Have two lookup items", 2, lookup.lookup(new Lookup.Template(c)).allItems().size()); doTestNodes (null, c, 2); }
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>() { @Override public void changed(Filter source) { update(); } }); update(); Lookup.Template<FilterChain> tpl = new Lookup.Template<>(FilterChain.class); result = Utilities.actionsGlobalContext().lookup(tpl); result.addLookupListener(this); FilterTopComponent.findInstance().getFilterSettingsChangedEvent().addListener(this); resultChanged(null); setShortDescription("Double-click to open filter"); }
public void testLookupInitializedForCloneable() { InstanceContent ic = new InstanceContent(); Lookup lookup = new AbstractLookup(ic); ic.add(10); CloneableTopComponent cmv = MultiViews.createCloneableMultiView("text/context", new LP(lookup)); assertEquals("10 now", Integer.valueOf(10), cmv.getLookup().lookup(Integer.class)); assertNotNull("MultiViewComponent created", cmv); TopComponent mvc = cmv.cloneTopComponent(); assertNotNull("MultiViewComponent cloned", mvc); MultiViewHandler handler = MultiViews.findMultiViewHandler(mvc); assertNotNull("Handler found", handler); 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)); }
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 ())); }
@Override public void handleRename(DataFolder folder, String newName) { InstanceContent ic = new InstanceContent(); ic.add(folder.getNodeDelegate()); ExplorerContext d = new ExplorerContext(); d.setNewName(newName); ic.add(d); final Lookup l = new AbstractLookup(ic); if (ActionsImplementationFactory.canRename(l)) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Action a = RefactoringActionsFactory.renameAction().createContextAwareInstance(l); a.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT); } }); } else { FileObject fo = folder.getPrimaryFile(); try { folder.rename(newName); } catch (IOException ioe) { ErrorManager.getDefault().notify(ioe); } } }
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 testChangeOfDefaultLookupAppliedToRPTask() throws Exception { Lookup prev = Lookup.getDefault(); final Lookup my = new AbstractLookup(new InstanceContent()); final Thread myThread = Thread.currentThread(); final RequestProcessor.Task[] task = { null }; final boolean[] ok = { false }; Lookups.executeWith(my, new Runnable() { @Override public void run() { assertSame("Default lookup has been changed", my, Lookup.getDefault()); if (task[0] == null) { assertSame("We are being executed in the same thread", myThread, Thread.currentThread()); // once again in the RP task[0] = RequestProcessor.getDefault().post(this, 500); } else { ok[0] = true; } } }); assertNotNull("In my lookup code executed OK", task[0]); assertEquals("Current lookup back to normal", prev, Lookup.getDefault()); task[0].waitFinished(); assertTrue("Even RP task had the right lookup", ok[0]); }
public void testCopyLikeProblem() throws Exception { FileObject fo = folder.getFileObject("testCopyLike.instance"); Object obj = fo.getAttribute("instanceCreate"); if (!(obj instanceof Action)) { fail("Shall create an action: " + obj); } InstanceContent ic = new InstanceContent(); AbstractLookup l = new AbstractLookup(ic); ActionMap map = new ActionMap(); map.put("copy-to-clipboard", new MyAction()); ic.add(map); CntListener list = new CntListener(); Action clone = ((ContextAwareAction)obj).createContextAwareInstance(l); clone.addPropertyChangeListener(list); assertTrue("Enabled", clone.isEnabled()); ic.remove(map); assertFalse("Disabled", clone.isEnabled()); list.assertCnt("one change", 1); }
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 PhotoNode(String photo, InstanceContent ic) { super(Children.LEAF, new AbstractLookup(ic)); final String name = new File(photo).getName(); setName(name); setDisplayName(name); setShortDescription(photo); ic.add((OpenCookie) () -> { TopComponent tc = findTopComponent(photo); if (tc == null) { tc = new PhotoViewerTopComponent(photo); tc.open(); } tc.requestActive(); }); }
private CompilationNode(final Folder folder, Children children, InstanceContent content) { super(children, new AbstractLookup(content)); this.setDisplayName(folder.getName()); if (folder instanceof Group) { content.add(new OpenCookie() { @Override public void open() { final List<InputGraph> graphs = ((Group) folder).getGraphs(); if (graphs.isEmpty()) { JOptionPane.showMessageDialog(null, "Cannot open compilation, because there was no snapshots recorded!"); } else { Lookup.getDefault().lookup(GraphViewer.class).view(graphs.get(0)); } } }); } content.add(folder); folder.getChangedEvent().addListener(this); }
public void testActionStatusUpdatedOnLookupChange() throws Exception { final InstanceContent content = new InstanceContent(); Lookup lkp = new AbstractLookup( content ); final SaveAsCapable saveAsImpl = new SaveAsCapable() { public void saveAs(FileObject folder, String name) throws IOException { throw new UnsupportedOperationException("Not supported yet."); } }; TopComponent tc = new TopComponent( lkp ); editorMode.dockInto( tc ); tc.open(); tc.requestActive(); assertTrue(Arrays.asList(WindowManager.getDefault().getOpenedTopComponents(editorMode)).contains(tc)); ContextAwareAction action = SaveAsAction.create(); assertFalse( "action is disabled for editor windows without SaveAsCapable in their Lookup", action.isEnabled() ); Action a = action.createContextAwareInstance( tc.getLookup() ); content.add( saveAsImpl ); assertTrue( "action is enabled for editor windows with SaveAsCapable in their Lookup", a.isEnabled() ); content.remove( saveAsImpl ); assertFalse( "action is disabled for editor windows without SaveAsCapable in their Lookup", a.isEnabled() ); }
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 CustomMethodNode(CustomSaasMethod method, InstanceContent content) { super(Children.LEAF, new AbstractLookup(content)); this.method = method; content.add(method); transferable = ExTransferable.create( new SaasTransferable<SaasMethod>(method, SaasTransferable.CUSTOM_METHOD_FLAVORS)); }
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); } }
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); }
protected WsdlMethodNode(WsdlSaasMethod method, InstanceContent content) { super(Children.LEAF, new AbstractLookup(content)); this.method = method; content.add(method); transferable = ExTransferable.create( new SaasTransferable<WsdlSaasMethod>(method, SaasTransferable.WSDL_METHOD_FLAVORS)); }
public void testBugfix80155_NotEmptyOnProperties () throws Exception { System.out.println("Testing bugfix 80155, keeping content on Properties window and similar..."); 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(); assertNotNull("Selected panel is null", selPanel); ic.remove(ostravskiHint); // wait for selected node change to be applied, because changes are // reflected with little delay waitForChange(); // after 80155 fix, previous navigator should keep its content even when // new component was activated, but didn't contain any activated nodes or navigator lookup hint selPanel = navTC.getSelectedPanel(); assertNotNull("Selected panel is null", selPanel); assertTrue("Panel class not expected", selPanel instanceof OstravskiGyzdProvider); } finally { // cleanup navTCH.close(); ic.remove(ostravskiHint); } }
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); }
public final void testPropagatesFlags() throws IOException { InstanceContent ic = new InstanceContent(); Lookup lookup = new AbstractLookup(ic); final URL root1 = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(new File(getWorkDir(),"root1"))); final URL root2 = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(new File(getWorkDir(),"root2"))); ProviderImpl defaultCP = new ProviderImpl(); final MutableCPImpl cpImpl = new MutableCPImpl(root1); defaultCP.paths.put(ClassPath.COMPILE, ClassPathFactory.createClassPath(cpImpl)); ClassPathProviderMerger instance = new ClassPathProviderMerger(defaultCP); ClassPathProvider result = instance.merge(lookup); ClassPath compile = result.findClassPath(null, ClassPath.COMPILE); assertNotNull(compile); assertEquals(0, compile.getFlags().size()); final ProviderImpl additional = new ProviderImpl(); final MutableCPImpl addCpImpl = new MutableCPImpl(root2); addCpImpl.add(ClassPath.Flag.INCOMPLETE); additional.paths.put(ClassPath.COMPILE, ClassPathFactory.createClassPath(addCpImpl)); ic.add(additional); assertEquals(1, compile.getFlags().size()); assertSame(compile, result.findClassPath(null, ClassPath.COMPILE)); addCpImpl.remove(ClassPath.Flag.INCOMPLETE); assertEquals(0, compile.getFlags().size()); addCpImpl.add(ClassPath.Flag.INCOMPLETE); assertEquals(1, compile.getFlags().size()); }
private static Lookup createLookupFor(final Iterator<Element> elementsIterator) { InstanceContent ic = new InstanceContent(); ic.add(new ElementsIteratorHandle() { @Override public Iterator<Element> getIterator() { return elementsIterator; } }); return new AbstractLookup(ic); }
public PoshDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException { super(pf, loader); ic = new InstanceContent(); lookup = new AbstractLookup(ic); ic.add(support = new PoshEditorSupport(this)); ic.add(this); }
/** * getter for refactoring Context * @see Context * @return context in which the refactoring was invoked. */ @NonNull public final Context getContext() { if (this.scope == null) { this.scope=new Context(new InstanceContent()); } return this.scope; }
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); } } return new AbstractLookup(ic); }
private void doFullRename(EditorCookie ec, Node n) { InstanceContent ic = new InstanceContent(); ic.add(ec); ic.add(n); Lookup actionContext = new AbstractLookup(ic); Action a = RefactoringActionsFactory.renameAction().createContextAwareInstance(actionContext); a.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT); }
public void testNoClassCast89329() throws Exception { InstanceContent ic = new InstanceContent(); AbstractLookup lookup = new AbstractLookup(ic); AbstractNode a = new AbstractNode(Children.LEAF, lookup); FilterNode f = new FilterNode(a); ic.add("Kuk"); Class what = String.class; assertNull("Indeed null, string is not a cookie", f.getCookie(what)); assertEquals("Kuk", f.getLookup().lookup(String.class)); }
public void testTextNodes() throws ParseException { // ParseTreeBuilder.setLoggerLevel(Level.ALL); String code = "<html>\n" + "<head>\n" + "<title>hello</title>\n" + "</head>\n" + "<body>\n" + "<div>text1</div>\n" + "<p>text2\n" + "<p>text3\n" + "</body>\n" + "</html>\n"; // 0123456789012 HtmlSource source = new HtmlSource(code); InstanceContent ic = new InstanceContent(); Properties props = new Properties(); props.setProperty("add_text_nodes", "true"); ic.add(props); Lookup l = new AbstractLookup(ic); HtmlParseResult result = new Html5Parser().parse(source, HtmlVersion.HTML5, l); Node root = result.root(); // ElementUtils.dumpTree(root); Node title = ElementUtils.query(root, "html/head/title"); Collection<Element> elements = title.children(ElementType.TEXT); assertNotNull(elements); assertEquals(1, elements.size()); Element text = elements.iterator().next(); assertNotNull(text); assertEquals(ElementType.TEXT, text.type()); assertEquals("hello", text.image().toString()); }
private void doUndoRedoTest(UndoRedo.Manager man, boolean testCounts) { me = new MyEdit(); man.undoableEditHappened(new UndoableEditEvent(this, me)); assertTrue("Can undo", man.canUndo()); this.ur = man; InstanceContent ic = new InstanceContent(); AbstractLookup lkp = new AbstractLookup(ic); Action u = undoAction(lkp); Action r = redoAction(lkp); assertFalse("Not enabled", u.isEnabled()); assertFalse("Not enabledR", r.isEnabled()); MyEdit lu = new MyEdit(); MyEdit lr = new MyEdit(); u.addPropertyChangeListener(lu); r.addPropertyChangeListener(lr); ic.add(this); assertTrue("Action is enabled", u.isEnabled()); assertEquals("One change", 1, lu.cnt); assertEquals("No redo change", 0, lr.cnt); assertEquals("Undo presentation", "&Undo My Undo", u.getValue(Action.NAME)); u.actionPerformed(new ActionEvent(this, 0, "")); if (testCounts) { assertEquals("my edit undone", 1, me.undo); assertFalse("No more undo", man.canUndo()); assertTrue("But redo", man.canRedo()); assertEquals("Another undo change", 2, lu.cnt); assertEquals("New redo change", 1, lr.cnt); assertTrue("Redo action enabled", r.isEnabled()); assertEquals("Redo presentation correct", "&Redo My Redo", r.getValue(Action.NAME)); } r.actionPerformed(new ActionEvent(this, 0, "")); assertFalse("Redo action no longer enabled", r.isEnabled()); }
public BundleNode(Node orig, String bundlepath, String codenamebase, InstanceContent content) { super(orig, new BundleChildren (orig, bundlepath, codenamebase), new AbstractLookup(content)); content.add(this); disableDelegation(DELEGATE_GET_DISPLAY_NAME | DELEGATE_SET_DISPLAY_NAME | DELEGATE_GET_SHORT_DESCRIPTION | DELEGATE_SET_SHORT_DESCRIPTION | DELEGATE_GET_ACTIONS); setDisplayName(bundlepath); setShortDescription(codenamebase); this.bundlepath = bundlepath; this.codenamebase = codenamebase; this.bundleChildren = (BundleChildren) getChildren(); }
public void testGlobalChanges() throws Exception { class MyAction extends AbstractAction { public int cntEnabled; public int cntPerformed; public MyAction() { setEnabled(true); } @Override public boolean isEnabled() { cntEnabled++; return super.isEnabled(); } public void actionPerformed(ActionEvent ev) { cntPerformed++; } } MyAction myAction = new MyAction(); ActionMap tc = new ActionMap(); tc.put(DefaultEditorKit.copyAction, myAction); InstanceContent ic = new InstanceContent(); AbstractLookup al = new AbstractLookup(ic); ContextAwareAction a = CallbackActionTest.callback(DefaultEditorKit.copyAction, null, al, false); ic.add(tc); assertTrue("MyAction is enabled", a.isEnabled()); assertEquals("isEnabled called once", 1, myAction.cntEnabled); myAction.setEnabled(false); assertEquals("An enabled is not called on property change", 1, myAction.cntEnabled); assertFalse("MyAction is disabled", a.isEnabled()); assertEquals("An enabled is currentlly called again", 2, myAction.cntEnabled); }
public void setContext(FileObject file) { InstanceContent ic = new InstanceContent(); if (file != null) { ic.add(file); } ic.add(getRuleEditorController()); providersLookup.updateLookup(new AbstractLookup(ic)); updateToolbar(file); }
/** * Test of createCompositeChildren method, of class org.netbeans.spi.project.ui.support.NodeFactorySupport. */ public void testCreateCompositeChildren() throws InterruptedException, InvocationTargetException { InstanceContent ic = new InstanceContent(); final Children dels = new TestDelegates(new AbstractLookup(ic)); final Node node1 = new AbstractNode(Children.LEAF); final Node node2 = new AbstractNode(Children.LEAF); final Node node3 = new AbstractNode(Children.LEAF); final Node node4 = new AbstractNode(Children.LEAF); node1.setName("node1"); node2.setName("node2"); node3.setName("node3"); node4.setName("node4"); NodeFactory fact1 = new TestNodeFactory(node1); NodeFactory fact2 = new TestNodeFactory(node2); NodeFactory fact3 = new TestNodeFactory(node3); NodeFactory fact4 = new TestNodeFactory(node4); List<NodeFactory> col = new ArrayList<NodeFactory>(); col.add(fact1); col.add(fact2); ic.set(col, null); assertEquals(Arrays.asList(node1, node2), Arrays.asList(dels.getNodes(true))); col.add(0, fact4); col.add(fact3); col.remove(fact2); ic.set(col, null); //#115995, caused by fix for #115128 SwingUtilities.invokeAndWait(new Runnable() { public void run() { Node[] nds = dels.getNodes(); assertEquals(nds[0], node4); assertEquals(nds[1], node1); assertEquals(nds[2], node3); } }); }
private Lookup getInstanceLookup(final Object... instances) { InstanceContent instanceContent = new InstanceContent(); for(Object i : instances) { instanceContent.add(i); } Lookup instanceLookup = new AbstractLookup(instanceContent); return instanceLookup; }
protected void setUp () { ic = new InstanceContent (); CES support = new CES (this, new AbstractLookup(ic)); MockServices.setServices(Redirector.class); red = Lookup.getDefault().lookup(Redirector.class); assertNotNull(red); CloneableEditorSupportRedirectorTest t = new CloneableEditorSupportRedirectorTest(""); red.master = support; InstanceContent slave = new InstanceContent(); red.slave = new CES(t, new AbstractLookup (slave)); slave.add(red.master); }
@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); }
@Override protected void setUp() throws Exception { MockLookup.init(); final InstanceContent ic = new InstanceContent(); lkp = new AbstractLookup(ic); ic.add("", this); }
@NonNull private static Lookup createLookup (@NonNull Description desc) { final InstanceContent ic = new InstanceContent(); ic.add(desc); ic.add(desc, ConvertDescription2TreePathHandle); ic.add(desc, ConvertDescription2FileObject); ic.add(desc, ConvertDescription2DataObject); return new AbstractLookup(ic); }
public ActNodeLookupProvider () { this.node1 = new AbstractNode(Children.LEAF); this.node1.setDisplayName(FIRST_NAME); this.node2 = new AbstractNode(Children.LEAF); this.node2.setDisplayName(SECOND_NAME); ic = new InstanceContent(); ic.add(node1); lookup = new AbstractLookup(ic); }