org.openide.windows.TopComponent Java Examples
The following examples show how to use
org.openide.windows.TopComponent.
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: RecentFiles.java From netbeans with Apache License 2.0 | 6 votes |
/** 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 File: CSSStylesPanel.java From netbeans with Apache License 2.0 | 6 votes |
/** * 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 #3
Source File: BlameAction.java From netbeans with Apache License 2.0 | 6 votes |
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 #4
Source File: PhpHierarchyTopComponent.java From netbeans with Apache License 2.0 | 6 votes |
/** * 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 #5
Source File: DefaultSeparateContainer.java From netbeans with Apache License 2.0 | 6 votes |
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 #6
Source File: MemoryTest.java From netbeans with Apache License 2.0 | 6 votes |
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 #7
Source File: GlobalActionContextProxy.java From nb-springboot with Apache License 2.0 | 6 votes |
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 #8
Source File: SaveAsActionTest.java From netbeans with Apache License 2.0 | 6 votes |
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 File: LogTopComponent.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
/** * 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 File: CallHierarchyTopComponent.java From netbeans with Apache License 2.0 | 6 votes |
/** * 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 File: MVInnerComponentGetLookupTest.java From netbeans with Apache License 2.0 | 6 votes |
/** 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 File: TopComponentOperator.java From netbeans with Apache License 2.0 | 6 votes |
/** 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 #13
Source File: RegistryImpl.java From netbeans with Apache License 2.0 | 5 votes |
/** 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 #14
Source File: DefaultView.java From netbeans with Apache License 2.0 | 5 votes |
@Override public String guessSlideSide (TopComponent comp) { String toReturn = Constants.LEFT; if (hierarchy.getMaximizedModeView() != null) { //issue #58562 toReturn = (String)comp.getClientProperty("lastSlideSide"); if (toReturn == null) { //TODO? now how does one figure on startup with maximazed mode where the editor is? toReturn = Constants.LEFT; } } else { Rectangle editorb = hierarchy.getPureEditorAreaBounds(); Point leftTop = new Point(0, 0); SwingUtilities.convertPointToScreen(leftTop, comp); if (editorb.x > leftTop.x) { toReturn = Constants.LEFT; comp.putClientProperty("lastSlideSide", toReturn); } if ((editorb.x + editorb.width) < leftTop.x) { toReturn = Constants.RIGHT; comp.putClientProperty("lastSlideSide", toReturn); } if ((editorb.y + editorb.height) < leftTop.y) { toReturn = Constants.BOTTOM; comp.putClientProperty("lastSlideSide", toReturn); } } return toReturn; }
Example #15
Source File: PerfWatchProjects.java From netbeans with Apache License 2.0 | 5 votes |
private static void closeTopComponents() { for (TopComponent tc : new ArrayList<TopComponent>(TopComponent.getRegistry().getOpened())) { final EditorCookie ec = tc.getLookup().lookup(EditorCookie.class); if (ec != null) { ec.close(); } } System.out.println("closed all ... hopefully"); }
Example #16
Source File: WorkspaceTopComponent.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@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 #17
Source File: ControlFlowTopComponent.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Obtain the ControlFlowTopComponent instance. Never call {@link #getDefault} directly! */ public static synchronized ControlFlowTopComponent findInstance() { TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID); if (win == null) { ErrorManager.getDefault().log(ErrorManager.WARNING, "Cannot find ControlFlow component. It will not be located properly in the window system."); return getDefault(); } if (win instanceof ControlFlowTopComponent) { return (ControlFlowTopComponent) win; } ErrorManager.getDefault().log(ErrorManager.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 #18
Source File: MaximizeWindowAction.java From netbeans with Apache License 2.0 | 5 votes |
/** * Alternate constructor to maximize given specific TopComponent. * For use in the context menu and maximization on demand, * invoked from ActionUtils and TabbedHandler. * * see #38801 for details */ public MaximizeWindowAction (TopComponent tc) { String label = NbBundle.getMessage(MaximizeWindowAction.class, "CTL_MaximizeWindowAction"); //NOI18N putValue(Action.NAME, label); topComponent = new WeakReference<TopComponent>(tc); propListener = null; updateState(); }
Example #19
Source File: UtilTestCase.java From netbeans with Apache License 2.0 | 5 votes |
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(); }
Example #20
Source File: TopComponentSubModel.java From netbeans with Apache License 2.0 | 5 votes |
/** * Remove the given TopComponent from this Mode. * @param tc TopComponent to be removed * @param recentTc TopComponent to select if the removed one was selected. * If null then the TopComponent nearest to the removed one will be selected. */ public boolean removeTopComponent(TopComponent tc, TopComponent recentTc) { boolean res; String tcID = getID(tc); if(openedTopComponents.contains(tc)) { if(selectedTopComponentID != null && selectedTopComponentID.equals(tcID)) { int index = openedTopComponents.indexOf(getTopComponent(selectedTopComponentID)); openedTopComponents.remove(tc); adjustSelectedTopComponent(index, recentTc); } else { openedTopComponents.remove(tc); } tcIDs.remove(tcID); res = true; } else if(tcIDs.contains(tcID)) { tcIDs.remove(tcID); res = true; } else { res = false; } // XXX - should be deleted after TopComponent.isSliding is introduced clearSlidingProperty(tc); return res; }
Example #21
Source File: SnapshotsWindow.java From visualvm with GNU General Public License v2.0 | 5 votes |
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 #22
Source File: DocumentsDlg.java From netbeans with Apache License 2.0 | 5 votes |
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 #23
Source File: ViewManager.java From Llunatic with GNU General Public License v3.0 | 5 votes |
@Override public TopComponent show(String name) { TopComponent tc = wm.findTopComponent(name); if (tc != null) { tc.open(); tc.requestActive(); } return tc; }
Example #24
Source File: ControlFlowTopComponent.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Obtain the ControlFlowTopComponent instance. Never call {@link #getDefault} directly! */ public static synchronized ControlFlowTopComponent findInstance() { TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID); if (win == null) { ErrorManager.getDefault().log(ErrorManager.WARNING, "Cannot find ControlFlow component. It will not be located properly in the window system."); return getDefault(); } if (win instanceof ControlFlowTopComponent) { return (ControlFlowTopComponent) win; } ErrorManager.getDefault().log(ErrorManager.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 #25
Source File: ShowInTableViewContextMenuProvider.java From constellation with Apache License 2.0 | 5 votes |
@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 #26
Source File: WorkspaceTopComponent.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
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 #27
Source File: StylesDataObject.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
@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 File: DefaultModel.java From netbeans with Apache License 2.0 | 5 votes |
@Override public boolean addGroupOpeningTopComponent(TopComponentGroupImpl tcGroup, TopComponent tc) { TopComponentGroupModel groupModel = getModelForGroup(tcGroup); if(groupModel != null) { return groupModel.addOpeningTopComponent(tc); } else { return false; } }
Example #29
Source File: TopComponentListener.java From Llunatic with GNU General Public License v3.0 | 5 votes |
public void register(TopComponent slaveComponent, String masterComponentName) { this.tc = slaveComponent; this.mainComponent = masterComponentName; TopComponent.getRegistry().addPropertyChangeListener(this); TopComponent main = view.findWindowByName(masterComponentName); if (main == null || !main.isOpened()) { slaveComponent.close(); } }
Example #30
Source File: TopComponentOperator.java From netbeans with Apache License 2.0 | 5 votes |
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; }