當前位置: 首頁>>代碼示例>>Java>>正文


Java TopComponent.getActivatedNodes方法代碼示例

本文整理匯總了Java中org.openide.windows.TopComponent.getActivatedNodes方法的典型用法代碼示例。如果您正苦於以下問題:Java TopComponent.getActivatedNodes方法的具體用法?Java TopComponent.getActivatedNodes怎麽用?Java TopComponent.getActivatedNodes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openide.windows.TopComponent的用法示例。


在下文中一共展示了TopComponent.getActivatedNodes方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: invokeDefaultAction

import org.openide.windows.TopComponent; //導入方法依賴的package包/類
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 ());
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:DefaultActionTest.java

示例2: getOpenFiles

import org.openide.windows.TopComponent; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:28,代碼來源:Utils.java

示例3: topComponentClosed

import org.openide.windows.TopComponent; //導入方法依賴的package包/類
/** 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);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:RegistryImpl.java

示例4: getSelectedNodes

import org.openide.windows.TopComponent; //導入方法依賴的package包/類
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;
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:UI.java

示例5: topComponentActivated

import org.openide.windows.TopComponent; //導入方法依賴的package包/類
/** 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());
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:36,代碼來源:RegistryImpl.java

示例6: isProperPrevious

import org.openide.windows.TopComponent; //導入方法依賴的package包/類
/** 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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:RegistryImpl.java

示例7: getApplicableFileObject

import org.openide.windows.TopComponent; //導入方法依賴的package包/類
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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:37,代碼來源:GotoOppositeAction.java

示例8: getPaletteFromTopComponent

import org.openide.windows.TopComponent; //導入方法依賴的package包/類
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;
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:42,代碼來源:PaletteSwitch.java

示例9: selectElementsAtOffset

import org.openide.windows.TopComponent; //導入方法依賴的package包/類
/** 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});
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:50,代碼來源:NodeSelector.java


注:本文中的org.openide.windows.TopComponent.getActivatedNodes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。