Java Code Examples for org.openide.windows.TopComponent

The following examples show how to use org.openide.windows.TopComponent. These examples are extracted from open source projects. 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 Project: netbeans   Source File: RecentFiles.java    License: Apache License 2.0 6 votes vote down vote up
/** Starts to listen for recently closed files */
public static void init() {
    WindowManager.getDefault().invokeWhenUIReady(new Runnable() {

        @Override
        public void run() {
            List<HistoryItem> loaded = load();
            synchronized (HISTORY_LOCK) {
                history.addAll(0, loaded);
                PCH_SUPPORT.firePropertyChange(PROPERTY_RECENT_FILES, null, null);
                if (windowRegistryListener == null) {
                    windowRegistryListener = new WindowRegistryL();
                    TopComponent.getRegistry().addPropertyChangeListener(
                            windowRegistryListener);
                }
            }
        }
    });
}
 
Example 2
Source Project: netbeans   Source File: TopComponentOperator.java    License: Apache License 2.0 6 votes vote down vote up
/** If subchooser is null, return TopComponent.
 * Else if c is instance of MultiViewCloneableTopComponent try to find
 * and return sub component in MVCTC corresponding to sub chooser. Else
 * check TC in sub chooser and return it if matches. MVCTC can host
 * several views, e.g. source and design view in form editor or xml, servlets,
 * overview views in web.xml editor. Then EditorOperator is able to find
 * appropriate CloneableEditor in MVCTC.
 * @param c TopComponent to check
 * @param subchooser ComponentChooser to check if matches
 * @return given TopComponent or appropriate sub component
 */
private static JComponent checkSubchooser(TopComponent c, ComponentChooser subchooser) {
    if (subchooser == null) {
        return c;
    } else {
        boolean isMultiView = false;
        try {
            //isMultiView = c instanceof MultiViewCloneableTopComponent;
            isMultiView = isMultyView(c);
        } catch (Throwable t) {
            // ignore possible NoClassDefFoundError because org.netbeans.core.multiview module is not enabled in IDE
        }
        if (isMultiView) {
            TopComponentOperator tco = new TopComponentOperator((JComponent) c);
            // suppress output when finding sub component
            tco.setOutput(TestOut.getNullOutput());
            return (JComponent) tco.findSubComponent(subchooser);
        } else {
            if (subchooser.checkComponent(c)) {
                return c;
            }
        }
    }
    return null;
}
 
Example 3
Source Project: nb-springboot   Source File: GlobalActionContextProxy.java    License: Apache License 2.0 6 votes vote down vote up
public GlobalActionContextProxy() {
    try {
        this.content = new InstanceContent();
        // The default GlobalContextProvider
        this.globalContextProvider = new GlobalActionContextImpl();
        this.globalContextLookup = this.globalContextProvider.createGlobalContext();
        // Monitor the activation of the Projects Tab TopComponent
        TopComponent.getRegistry().addPropertyChangeListener(this.registryListener);
        // Monitor the existance of a Project in the principle lookup
        this.resultProjects = globalContextLookup.lookupResult(Project.class);
        this.resultProjects.addLookupListener(this.resultListener);
    } catch (Exception e) {
        Exceptions.printStackTrace(e);
    }
    WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
        @Override
        public void run() {
            // Hack to force the current Project selection when the application starts up
            TopComponent tc = WindowManager.getDefault().findTopComponent(PROJECT_LOGICAL_TAB_ID);
            if (tc != null) {
                tc.requestActive();
            }
        }
    });
}
 
Example 4
Source Project: netbeans   Source File: DefaultSeparateContainer.java    License: Apache License 2.0 6 votes vote down vote up
private void snapWindow() {
    Rectangle myBounds = getBounds();

    WindowManagerImpl wm = WindowManagerImpl.getInstance();
    Set<? extends ModeImpl> modes = wm.getModes();
    for( ModeImpl m : modes ) {
        if( m.getState() != Constants.MODE_STATE_SEPARATED )
            continue;
        TopComponent tc = m.getSelectedTopComponent();
        if( null == tc )
            continue;
        Window w = SwingUtilities.getWindowAncestor( tc );
        if( w == ModeDialog.this )
            continue;
        Rectangle targetBounds = w.getBounds();
        if( snapper.snapTo(myBounds, targetBounds) )
            return;
    }

    if( WinSysPrefs.HANDLER.getBoolean(WinSysPrefs.SNAPPING_SCREENEDGES, true) ) {
        snapper.snapToScreenEdges(myBounds);
    }
}
 
Example 5
Source Project: netbeans   Source File: BlameAction.java    License: Apache License 2.0 6 votes vote down vote up
public static void showAnnotations(JEditorPane currentPane, File file, SVNRevision revision) {
    final AnnotationBar ab = AnnotationBarManager.showAnnotationBar(currentPane);
    ab.setAnnotationMessage(NbBundle.getMessage(BlameAction.class, "CTL_AnnotationSubstitute")); // NOI18N;

    SVNUrl repository;
    try {
        repository = SvnUtils.getRepositoryRootUrl(file);
    } catch (SVNClientException ex) {
        SvnClientExceptionHandler.notifyException(ex, true, true);
        return;
    }

    if (revision == null) {
        ISVNStatus status = Subversion.getInstance().getStatusCache().getStatus(file).getEntry(file);
        if (status == null || status.getRevision() == null) {
            // status could not be loaded or we have a symlink, do not continnue
            return;
        }
        ab.setSVNClienListener(new SVNClientListener(status.getRevision().getNumber(), repository, file, ab));
    }

    TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, currentPane);
    tc.requestActive();
    computeAnnotations(repository, file, ab, revision);
}
 
Example 6
Source Project: netbeans   Source File: CSSStylesPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Updates the title of the enclosing view.
 */
void updateTitle() {
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            if (active) {
                PageModel page = pageModel;
                String title = null; // NOI18N
                if (page != null) {
                    List<? extends Node> nodes = page.getSelectedNodes();
                    if (nodes.size() == 1) {
                        title = nodes.get(0).getDisplayName();
                    }
                }
                TopComponent tc = WindowManager.getDefault().findTopComponent("CssStylesTC"); // NOI18N
                ((CssStylesTC)tc).setTitle(title);
            }
        }
    });
}
 
Example 7
Source Project: netbeans   Source File: MemoryTest.java    License: Apache License 2.0 6 votes vote down vote up
private static void collectToolbars(final List<JToolBar> toolbars, final EditorCookie oc) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            JEditorPane [] jeps = oc.getOpenedPanes();

            for(JEditorPane jep : jeps) {
                EditorUI editorUI = Utilities.getEditorUI(jep);
                assertNotNull(editorUI);

                JToolBar toolbar = editorUI.getToolBarComponent();
                assertNotNull(toolbar);
                toolbars.add(toolbar);

                TopComponent tc = findTopComponent(jep);
                //System.out.println("tc = " + tc);
                assertNotNull(tc);

                boolean closed = tc.close();
                assertTrue("Can't close TC", closed);
            }
        }
    });
}
 
Example 8
Source Project: netbeans   Source File: SaveAsActionTest.java    License: Apache License 2.0 6 votes vote down vote up
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() );
}
 
Example 9
Source Project: NBANDROID-V2   Source File: LogTopComponent.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Obtain the LogTopComponent instance. Never call {@link #getDefault}
 * directly!
 */
public static synchronized LogTopComponent findInstance() {
    TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
    if (win == null) {
        Logger.getLogger(LogTopComponent.class.getName()).warning(
                "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
        return getDefault();
    }
    if (win instanceof LogTopComponent) {
        return (LogTopComponent) win;
    }
    Logger.getLogger(LogTopComponent.class.getName()).warning(
            "There seem to be multiple components with the '" + PREFERRED_ID
            + "' ID. That is a potential source of errors and unexpected behavior.");
    return getDefault();
}
 
Example 10
Source Project: netbeans   Source File: CallHierarchyTopComponent.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Obtain the CallHierarchyTopComponent instance. Never call {@link #getDefault} directly!
 */
public static synchronized CallHierarchyTopComponent findInstance() {
    TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
    if (win == null) {
        Logger.getLogger(CallHierarchyTopComponent.class.getName()).warning(
                "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
        return getDefault();
    }
    if (win instanceof CallHierarchyTopComponent) {
        return (CallHierarchyTopComponent) win;
    }
    Logger.getLogger(CallHierarchyTopComponent.class.getName()).warning(
            "There seem to be multiple components with the '" + PREFERRED_ID +
            "' ID. That is a potential source of errors and unexpected behavior.");
    return getDefault();
}
 
Example 11
Source Project: netbeans   Source File: MVInnerComponentGetLookupTest.java    License: Apache License 2.0 6 votes vote down vote up
/** Setup component with lookup.
 */
@Override
protected void setUp () {
    final MVElemTopComponent elem1 = new MVElemTopComponent();
    final MVElemTopComponent elem2 = new MVElemTopComponent();
    final MVElemTopComponent elem3 = new MVElemTopComponent();
    desc1 = new MVDesc("desc1", null, 0, elem1);
    desc2 = new MVDesc("desc2", null, 0, elem2);
    desc3 = new MVDesc("desc3", null, 0, elem3);
    MultiViewDescription[] descs = new MultiViewDescription[] { desc1, desc2, desc3 };
    TopComponent mvtop = MultiViewFactory.createMultiView(descs, desc1);
    top = (TopComponent)elem1;
    get = top;
    top2 = (TopComponent)elem2;
    top3 = (TopComponent)elem3;
    lookup = mvtop.getLookup();
    mvtop.open();
    mvtop.requestActive();
    mvtc = mvtop;
}
 
Example 12
Source Project: netbeans   Source File: PhpHierarchyTopComponent.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Obtain the HierarchyTopComponent instance. Never call {@link #getDefault} directly!
 */
public static synchronized PhpHierarchyTopComponent findInstance() {
    TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
    if (win == null) {
        Logger.getLogger(PhpHierarchyTopComponent.class.getName()).warning(
                "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system."); // NOI18N
        return getDefault();
    }
    if (win instanceof PhpHierarchyTopComponent) {
        return (PhpHierarchyTopComponent) win;
    }
    Logger.getLogger(PhpHierarchyTopComponent.class.getName()).warning(
            "There seem to be multiple components with the '" + PREFERRED_ID + // NOI18N
            "' ID. That is a potential source of errors and unexpected behavior."); // NOI18N
    return getDefault();
}
 
Example 13
Source Project: constellation   Source File: DataAccessUtilities.java    License: Apache License 2.0 5 votes vote down vote up
private static DataAccessPane getInternalDataAccessPane() {
    final TopComponent tc = WindowManager.getDefault().findTopComponent(DataAccessViewTopComponent.class.getSimpleName());
    if (tc != null) {
        if (!tc.isOpened()) {
            tc.open();
        }
        tc.requestVisible();
        return ((DataAccessViewTopComponent) tc).getDataAccessPane();
    } else {
        return null;
    }
}
 
Example 14
Source Project: netbeans   Source File: RegistryImpl.java    License: Apache License 2.0 5 votes vote down vote up
/** Called when a TopComponent is opened. */
public synchronized void topComponentOpened(TopComponent tc) {
    assert null != tc;
    if (openSet.contains(tc)) {
        return;
    }
    Set<TopComponent> old = new HashSet<TopComponent>(openSet);
    openSet.add(tc);
    doFirePropertyChange(PROP_TC_OPENED, null, tc);
    doFirePropertyChange(PROP_OPENED, old, new HashSet<TopComponent>(openSet));
}
 
Example 15
@Override
public void actionPerformed(ActionEvent e) {
    TabData tab = tabbedContainer.getModel().getTab(tabIndex);
    JInternalFrame internalFrame = tabToFrameMap.get(tab);
    TopComponent topComponent = dockInternalFrame(internalFrame);
    if (topComponent != null) {
        topComponent.requestActive();
    }
}
 
Example 16
Source Project: netbeans   Source File: EjbJarMultiViewDataObject.java    License: Apache License 2.0 5 votes vote down vote up
@MultiViewElement.Registration(
    mimeType="text/x-dd-ejbjar",
    iconBase="org/netbeans/modules/j2ee/ddloaders/client/DDDataIcon.gif",
    persistenceType=TopComponent.PERSISTENCE_ONLY_OPENED,
    preferredID="multiview_xml",
    displayName="#CTL_SourceTabCaption",
    position=1
)
public static XmlMultiViewElement createXmlMultiViewElement(Lookup lookup) {
    return new XmlMultiViewElement(lookup.lookup(XmlMultiViewDataObject.class));
}
 
Example 17
Source Project: netbeans   Source File: EjbJarMultiViewDataObject.java    License: Apache License 2.0 5 votes vote down vote up
@MultiViewElement.Registration(
    displayName="#LBL_" + CMP_RELATIONSHIPS,
    iconBase=Utils.ICON_BASE_DD_VALID + ".gif",
    persistenceType=TopComponent.PERSISTENCE_NEVER,
    preferredID="dd_multiview_" + CMP_RELATIONSHIPS,
    mimeType="text/x-dd-ejbjar",
    position=1000
)
public static MultiViewElement getCmpRelationShips(Lookup context) {
    DataObject dObj = context.lookup(DataObject.class);
    assert dObj != null;
    return new CmpRelationshipsMultiViewElement((EjbJarMultiViewDataObject) dObj);
}
 
Example 18
/**
 * Gets extra actions, e.g. for floating a docked window or group into a workspace.
 *
 * @param topComponent The document window.
 * @return The extra actions.
 */
public static Action[] getExtraActions(TopComponent topComponent) {
    return new Action[]{
            new FloatIntoWorkspaceAction(topComponent),
            new FloatGroupIntoWorkspaceAction(topComponent)
    };
}
 
Example 19
Source Project: netbeans   Source File: TopComponentOperator.java    License: Apache License 2.0 5 votes vote down vote up
/** Finds DataObject for the content of this TopComponent and set it
 * unmodified. Used in closeDiscard method.
 */
public void setUnmodified() {
    DataObject dob = ((TopComponent) getSource()).getLookup().lookup(DataObject.class);
    if (dob == null) {
        // try to find possible enclosing MultiviewTopComponent
        TopComponentOperator parentTco = findParentTopComponent();
        if (parentTco != null) {
            parentTco.setUnmodified();
        }
    } else {
        dob.setModified(false);
    }
}
 
Example 20
Source Project: netbeans   Source File: DefaultModel.java    License: Apache License 2.0 5 votes vote down vote up
/** */
@Override
public void removeModeTopComponent(ModeImpl mode, TopComponent tc, TopComponent recentTc) {
    ModeModel modeModel = getModelForMode(mode);
    if(modeModel != null) {
        modeModel.removeTopComponent(tc, recentTc);
    }
}
 
Example 21
Source Project: netbeans   Source File: ASTViewManager.java    License: Apache License 2.0 5 votes vote down vote up
private void openIfCan() {
    if (shouldOpenView && isAtTruffleLocation) {
        SwingUtilities.invokeLater(() -> {
            TopComponent tc = WindowManager.getDefault().findTopComponent(ASTView.AST_VIEW_NAME);
            tc.open();
            tc.requestVisible();
        });
        shouldOpenView = false;
    }
}
 
Example 22
Source Project: netbeans   Source File: SplitAction.java    License: Apache License 2.0 5 votes vote down vote up
static void clearSplit(TopComponent tc, int elementToActivate) {
if (tc instanceof Splitable) {
    TopComponent original = ((Splitable) tc).clearSplit(elementToActivate);
    original.open();
    original.requestActive();
           original.invalidate();
           original.revalidate();
           original.repaint();
           original.requestFocusInWindow();
}
   }
 
Example 23
Source Project: visualvm   Source File: SnapshotsWindow.java    License: GNU General Public License v2.0 5 votes vote down vote up
private SnapshotsWindow() {
    snapshotsListener = Lookup.getDefault().lookup(SnapshotsWindowHelper.class);
    
    TopComponent.getRegistry().addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (TopComponent.Registry.PROP_TC_CLOSED.equals(evt.getPropertyName()))
                if (ui != null && evt.getNewValue() == ui) ui = null;
        }
    });
}
 
Example 24
Source Project: netbeans   Source File: DocumentsDlg.java    License: Apache License 2.0 5 votes vote down vote up
private void updateNodes() {
    //Create nodes for TopComponents, sort them using their own comparator
    List<TopComponent> tcList = getOpenedDocuments();
    TopComponent activeTC = TopComponent.getRegistry().getActivated();
    TopComponentNode[] tcNodes = new TopComponentNode[tcList.size()];
    TopComponentNode toSelect = null;
    for (int i = 0; i < tcNodes.length; i++) {
        TopComponent tc = tcList.get(i);
        tcNodes[i] = new TopComponentNode(tc);
        if( tc == activeTC ) {
            toSelect = tcNodes[i];
        }
    }
    if( radioOrderByName.isSelected() ) {
        Arrays.sort(tcNodes);
    }
    
    Children.Array nodeArray = new Children.Array();
    nodeArray.add(tcNodes);
    Node root = new AbstractNode(nodeArray);
    explorer.setRootContext(root);
    // set focus to documents list
    listView.requestFocus();
    // select the active editor tab or the first item if possible
    if (tcNodes.length > 0) {
        try {
            if( null == toSelect ) 
                toSelect = tcNodes[0];
            explorer.setSelectedNodes(new Node[] {toSelect} );
        } catch (PropertyVetoException exc) {
            // do nothing, what should I do?
        }
    }
}
 
Example 25
Source Project: Llunatic   Source File: ViewManager.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public TopComponent show(String name) {
    TopComponent tc = wm.findTopComponent(name);
    if (tc != null) {
        tc.open();
        tc.requestActive();
    }
    return tc;
}
 
Example 26
@Override
public void selectItem(String item, Graph graph, GraphElementType elementType, int elementId, Vector3f unprojected) {
    SwingUtilities.invokeLater(() -> {
        final TopComponent tc = WindowManager.getDefault().findTopComponent("TableView2TopComponent");
        if (tc != null) {
            if (!tc.isOpened()) {
                tc.open();
            }
            tc.requestActive();
            ((au.gov.asd.tac.constellation.views.tableview2.TableViewTopComponent) tc).showSelected(elementType, elementId);
        }
    });
}
 
Example 27
Source Project: NBANDROID-V2   Source File: StylesDataObject.java    License: Apache License 2.0 5 votes vote down vote up
@MultiViewElement.Registration(
        displayName = "#Source",
        iconBase = "org/nbandroid/netbeans/gradle/v2/layout/icons-styles-16.png",
        mimeType = "text/x-android-styles+xml",
        persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
        preferredID = "source",
        position = 1
)
public static MultiViewEditorElement createEditor(Lookup lkp) {
    return new MultiViewEditorElement(lkp);
}
 
Example 28
Source Project: netbeans   Source File: TopComponentOperator.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isMultyView(TopComponent c) {
    Class clz = c.getClass();
    do {
        if (clz.getName().equals("org.netbeans.core.multiview.MultiViewCloneableTopComponent")) {
            return true;
        }
    } while ((clz = clz.getSuperclass()) != null);
    return false;
}
 
Example 29
private Object getInternalFrameID(TopComponent topComponent) {
    Object internalFrameID = topComponent.getClientProperty("internalFrameID");
    if (internalFrameID == null) {
        internalFrameID = "IF" + Long.toHexString(new Random().nextLong());
        topComponent.putClientProperty("internalFrameID", internalFrameID);
    }
    return internalFrameID;
}
 
Example 30
Source Project: netbeans   Source File: UtilTestCase.java    License: Apache License 2.0 5 votes vote down vote up
public void testCreateNewQuery() {
    Repository repo = getRepo();
    APITestRepository apiRepo = getApiRepo();
    
    assertNull(apiRepo.newQuery);
    Util.createNewQuery(repo);
    
    long t = System.currentTimeMillis();
    TopComponent openedTC = null;
    while(openedTC == null) {
        Set<TopComponent> openedTCs = WindowManager.getDefault().getRegistry().getOpened();
        for (TopComponent tc : openedTCs) {
            if(tc instanceof QueryTopComponent) {
                QueryTopComponent itc = (QueryTopComponent)tc;
                QueryImpl queryImpl = itc.getQuery();
                if(queryImpl != null && queryImpl.isData(apiRepo.newQuery)) {
                    openedTC = tc;
                    break;
                }
            }
        }
        if(System.currentTimeMillis() - t > 50000) {
            break;
        }
    }
    
    assertNotNull(apiRepo.newQuery);
    if(openedTC == null) {
        fail("TopComponent with new query wasn't opened");
    }
    openedTC.close();
}