当前位置: 首页>>代码示例>>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;未经允许,请勿转载。