Java Code Examples for org.openide.windows.TopComponent#getActivatedNodes()
The following examples show how to use
org.openide.windows.TopComponent#getActivatedNodes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultActionTest.java From netbeans with Apache License 2.0 | 6 votes |
private void invokeDefaultAction (final TopComponent tc) { performed = false; try { Node[] nodes = tc.getActivatedNodes (); assertNotNull ("View has the active nodes.", nodes); Node n = nodes.length > 0 ? nodes[0] : null; assertNotNull ("View has a active node.", n); final Action action = n.getPreferredAction (); action.actionPerformed (new ActionEvent (n, ActionEvent.ACTION_PERFORMED, "")); // wait to invoke action is propagated Thread.sleep (300); } catch (Exception x) { fail (x.getMessage ()); } }
Example 2
Source File: RegistryImpl.java From netbeans with Apache License 2.0 | 6 votes |
/** Called when a TopComponent is closed. */ public synchronized void topComponentClosed(TopComponent tc) { if (!openSet.contains(tc)) { return; } Set<TopComponent> old = new HashSet<TopComponent>(openSet); openSet.remove(tc); doFirePropertyChange(PROP_TC_CLOSED, null, tc); doFirePropertyChange(PROP_OPENED, old, new HashSet<TopComponent>(openSet)); if (activatedNodes != null) { Node[] closedNodes = tc.getActivatedNodes(); if (closedNodes != null && Arrays.equals(closedNodes, activatedNodes)) { // The component whose nodes were activated has been closed; cancel the selection. activatedNodes = null; doFirePropertyChange(PROP_ACTIVATED_NODES, closedNodes, null); } } }
Example 3
Source File: Utils.java From netbeans with Apache License 2.0 | 6 votes |
/** * Returns files from all opened top components * @return set of opened files */ public static Set<File> getOpenFiles() { TopComponent[] comps = TopComponent.getRegistry().getOpened().toArray(new TopComponent[0]); Set<File> openFiles = new HashSet<File>(comps.length); for (TopComponent tc : comps) { Node[] nodes = tc.getActivatedNodes(); if (nodes == null) { continue; } for (Node node : nodes) { File file = node.getLookup().lookup(File.class); if (file == null) { FileObject fo = node.getLookup().lookup(FileObject.class); if (fo != null && fo.isData()) { file = FileUtil.toFile(fo); } } if (file != null) { openFiles.add(file); } } } return openFiles; }
Example 4
Source File: UI.java From netbeans with Apache License 2.0 | 5 votes |
public static Node[] getSelectedNodes() { //out(); TopComponent top = getActiveTopComponent(); //out("top: " + top); if (top == null) { return null; } Node[] nodes = top.getActivatedNodes(); //out("nodes: " + nodes); if (nodes == null || nodes.length == 0) { return null; } return nodes; }
Example 5
Source File: RegistryImpl.java From netbeans with Apache License 2.0 | 5 votes |
/** Called when a TopComponent is activated. * * @param ev TopComponentChangedEvent */ void topComponentActivated(TopComponent tc) { if(activatedTopComponent.get() == tc && activatedNodes != null) { // When null it means were not inited yet. return; } final TopComponent old = activatedTopComponent.get(); if (old != null && old.getActivatedNodes() != null) { previousActivated = new WeakReference<TopComponent>(old); } activatedTopComponent = new WeakReference<TopComponent>(tc); /** PENDING: Firing the change asynchronously improves perceived responsiveness considerably (toolbars are updated after the component repaints, so it appears to immediately become selected), but means that for one EQ cycle the activated TopComponent will be out of sync with the global node selection. Needs testing. -Tim C.f. issue 42256 - most of the delay may be called by contention in ProxyLookup, but this fix will have some responsiveness benefits even if that is fixed */ final TopComponent tmp = this.activatedTopComponent.get(); SwingUtilities.invokeLater(new Runnable() { public void run() { doFirePropertyChange(PROP_ACTIVATED, old, tmp); } }); selectedNodesChanged(tmp, tmp == null ? null : tmp.getActivatedNodes()); }
Example 6
Source File: RegistryImpl.java From netbeans with Apache License 2.0 | 5 votes |
/** Part of #82319 bugfix. * Returns true if given top component is the one previously selected * and conditions are met to update activated nodes from it. */ private boolean isProperPrevious (TopComponent tc, Node[] newNodes) { if (previousActivated == null || newNodes == null) { return false; } TopComponent previousTC = previousActivated.get(); if (previousTC == null || !previousTC.equals(tc)) { return false; } TopComponent tmp = activatedTopComponent.get(); return tmp != null && tmp.getActivatedNodes() == null; }
Example 7
Source File: GotoOppositeAction.java From netbeans with Apache License 2.0 | 5 votes |
private FileObject getApplicableFileObject(int[] caretPosHolder) { if (!EventQueue.isDispatchThread()) { // Unsafe to ask for an editor pane from a random thread. // E.g. org.netbeans.lib.uihandler.LogRecords.write asking for getName(). Collection<? extends FileObject> dobs = Utilities.actionsGlobalContext().lookupAll(FileObject.class); return dobs.size() == 1 ? dobs.iterator().next() : null; } // TODO: Use the new editor library to compute this: // JTextComponent pane = EditorRegistry.lastFocusedComponent(); TopComponent comp = TopComponent.getRegistry().getActivated(); if(comp == null) { return null; } Node[] nodes = comp.getActivatedNodes(); if (nodes != null && nodes.length == 1) { if (comp instanceof CloneableEditorSupport.Pane) { //OK. We have an editor EditorCookie ec = nodes[0].getLookup().lookup(EditorCookie.class); if (ec != null) { JEditorPane editorPane = NbDocument.findRecentEditorPane(ec); if (editorPane != null) { if (editorPane.getCaret() != null) { caretPosHolder[0] = editorPane.getCaret().getDot(); } Document document = editorPane.getDocument(); return Source.create(document).getFileObject(); } } } else { return UICommonUtils.getFileObjectFromNode(nodes[0]); } } return null; }
Example 8
Source File: PaletteSwitch.java From netbeans with Apache License 2.0 | 4 votes |
PaletteController getPaletteFromTopComponent( TopComponent tc, boolean mustBeShowing, boolean isOpened ) { if( null == tc || (!tc.isShowing() && mustBeShowing) ) return null; PaletteController pc = (PaletteController)tc.getLookup().lookup( PaletteController.class ); //#231997 - TopComponent.getSubComponents() can be called from EDT only //The only drawback of commenting out the code below is that a split view of //a form designer showing source and design hides the palette window //when the source split is the active one and some other TopComponent is activated // if (pc == null && isOpened) { // TopComponent.SubComponent[] subComponents = tc.getSubComponents(); // for (int i = 0; i < subComponents.length; i++) { // TopComponent.SubComponent subComponent = subComponents[i]; // Lookup subComponentLookup = subComponent.getLookup(); // if (subComponentLookup != null) { // pc = (PaletteController) subComponentLookup.lookup(PaletteController.class); // if (pc != null && (subComponent.isActive() || subComponent.isShowing())) { // break; // } // } // } // } if( null == pc && isOpened ) { //check if there's any palette assigned to TopComponent's mime type Node[] activeNodes = tc.getActivatedNodes(); if( null != activeNodes && activeNodes.length > 0 ) { DataObject dob = activeNodes[0].getLookup().lookup( DataObject.class ); if( null != dob ) { while( dob instanceof DataShadow ) { dob = ((DataShadow)dob).getOriginal(); } FileObject fo = dob.getPrimaryFile(); if( !fo.isVirtual() ) { String mimeType = fo.getMIMEType(); pc = getPaletteFromMimeType( mimeType ); } } } } return pc; }
Example 9
Source File: NodeSelector.java From netbeans with Apache License 2.0 | 4 votes |
/** Selects element at the given position. */ synchronized void selectElementsAtOffset(final int offset) { if (syntaxSupport == null) { Document doc = pane.getDocument(); if (doc instanceof BaseDocument) { syntaxSupport = XMLSyntaxSupport.getSyntaxSupport((BaseDocument)doc); } if (syntaxSupport == null) { return; } } Container parent = pane.getParent(); while (parent != null && !(parent instanceof TopComponent)){ parent = parent.getParent(); } if (parent == null) { return; } TopComponent topComp = (TopComponent)parent; Node activeNodes[] = topComp.getActivatedNodes(); if (activeNodes == null || activeNodes.length == 0) { return; // No nodes active } if (originalUINode == null) { originalUINode = activeNodes[0]; } //it must be called from separate thread, it may the block UI thread GrammarQuery grammarQuery = XMLCompletionQuery.getPerformer(pane.getDocument(), syntaxSupport); if (grammarQuery == null) { return; } SyntaxQueryHelper helper = null; try { helper = new SyntaxQueryHelper(syntaxSupport, offset); } catch (BadLocationException e) { topComp.setActivatedNodes(new Node[]{new DelegatingNode(originalUINode, null, null)}); return; } Node newUiNode = new DelegatingNode(originalUINode, grammarQuery, helper.getContext()); topComp.setActivatedNodes(new Node[]{newUiNode}); }