Java Code Examples for org.openide.windows.TopComponent#setActivatedNodes()
The following examples show how to use
org.openide.windows.TopComponent#setActivatedNodes() .
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: PaletteSwitchTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testLookupPaletteTakePrecendsOverMimePalette() throws IOException { PaletteController pc = PaletteFactory.createPalette( lookupPaletteRootName, new DummyActions() ); TopComponent tc = createTopComponentWithPalette( pc ); tc.setActivatedNodes( new Node[] { DataObject.find( dummyDocumentFile ).getNodeDelegate() } ); PaletteSwitch paletteSwitch = PaletteSwitch.getDefault(); PaletteController foundPalette = paletteSwitch.getPaletteFromMimeType( MIME_TYPE_NAME ); assertNotNull( foundPalette ); assertEquals( mimePaletteRootName, foundPalette.getModel().getName() ); foundPalette = paletteSwitch.getPaletteFromTopComponent( tc, false, tc.isOpened() ); assertNotNull( foundPalette ); assertEquals( pc.getModel().getName(), foundPalette.getModel().getName() ); }
Example 2
Source File: SyncTable.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } final TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, table); if (tc == null) return; // table is no longer in component hierarchy // this method may be called outside of AWT if a node fires change events from some other thread, see #79174 final Node [] nodeArray = getSelectedNodes(); if (SwingUtilities.isEventDispatchThread()) { tc.setActivatedNodes(nodeArray); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { tc.setActivatedNodes(nodeArray); } }); } }
Example 3
Source File: SyncTable.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } final TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, table); if (tc == null) return; // table is no longer in component hierarchy // this method may be called outside of AWT if a node fires change events from some other thread, see #79174 final Node [] nodeArray = getSelectedNodes(); if (SwingUtilities.isEventDispatchThread()) { tc.setActivatedNodes(nodeArray); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { tc.setActivatedNodes(nodeArray); } }); } }
Example 4
Source File: FileTreeView.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void propertyChange (PropertyChangeEvent evt) { if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName()) && !internalTraverse) { Node[] selectedNodes = em.getSelectedNodes(); final TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, view); if (tc != null) { tc.setActivatedNodes(selectedNodes); } if (selectedNodes.length == 1) { // single selection T node = convertNode(selectedNodes[0]); if (node != null) { nodeSelected(node); return; } } nodeSelected(null); } }
Example 5
Source File: ImageEditorComponent.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void setEditedImage(TopComponent component, BufferedImage image, FileObject file) { this.owner = component; component.setActivatedNodes(new Node[]{saveNode}); if (file == null) { newFile = true; enableSaving(); } else { newFile = false; disableSaving(); } editedFile = file; editedImage = image; resizeDisplay(); }
Example 6
Source File: DiffFileTable.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } ListSelectionModel selectionModel = table.getSelectionModel(); int min = selectionModel.getMinSelectionIndex(); int max = selectionModel.getMaxSelectionIndex(); if (min != -1 && min == max) { // single selection master.nodeSelected(getSelectedNode()); } else { List<DiffNode> selectedNodes = new ArrayList<DiffNode>(); if (min == -1) { master.nodeSelected(null); } else { for (int i = min; i <= max; i++) { if (selectionModel.isSelectedIndex(i)) { int idx = sorter.modelIndex(i); selectedNodes.add(nodes[idx]); } } } final TopComponent tc = (TopComponent) master.getClientProperty(TopComponent.class); if (tc == null) return; // table is no longer in component hierarchy Node [] nodesToActivate = selectedNodes.toArray(new Node[selectedNodes.size()]); tc.setActivatedNodes(nodesToActivate); } }
Example 7
Source File: SearchHistoryPanel.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void propertyChange(PropertyChangeEvent evt) { if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, this); if (tc == null) return; tc.setActivatedNodes((Node[]) evt.getNewValue()); } }
Example 8
Source File: VersioningPanel.java From netbeans with Apache License 2.0 | 5 votes |
public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName() == FileStatusCache.PROP_FILE_STATUS_CHANGED) { FileStatusCache.ChangedEvent changedEvent = (FileStatusCache.ChangedEvent) evt.getNewValue(); Mercurial.LOG.log(Level.FINE, "Status.propertyChange(): {0} file: {1}", new Object [] { parentTopComponent.getContentTitle(), changedEvent.getFile()} ); // NOI18N if (affectsView(evt)) { reScheduleRefresh(1000); } return; } if (evt.getPropertyName() == Mercurial.PROP_CHANGESET_CHANGED) { Object source = evt.getOldValue(); File root = HgUtils.getRootFile(context); Mercurial.LOG.log(Level.FINE, "Mercurial.changesetChanged: source {0} repo {1} ", new Object [] {source, root}); // NOI18N if (root != null && root.equals(source)) { reScheduleRefresh(1000); } return; } if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, this); if (tc != null) { tc.setActivatedNodes((Node[]) evt.getNewValue()); } return; } }
Example 9
Source File: OutlineTable.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void propertyChange (PropertyChangeEvent evt) { String propertyName = evt.getPropertyName (); TopComponent tc = (TopComponent) SwingUtilities. getAncestorOfClass (TopComponent.class, this); if (tc == null) { return; } if (propertyName.equals (TopComponent.Registry.PROP_CURRENT_NODES)) { ExplorerUtils.activateActions(getExplorerManager(), equalNodes()); } else if (propertyName.equals (ExplorerManager.PROP_SELECTED_NODES)) { tc.setActivatedNodes ((Node[]) evt.getNewValue ()); } }
Example 10
Source File: SearchHistoryPanel.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void propertyChange(PropertyChangeEvent evt) { if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, this); if (tc == null) return; tc.setActivatedNodes((Node[]) evt.getNewValue()); } }
Example 11
Source File: DiffFileTable.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } ListSelectionModel selectionModel = table.getSelectionModel(); int min = selectionModel.getMinSelectionIndex(); int max = selectionModel.getMaxSelectionIndex(); if (min != -1 && min == max) { // single selection master.tableRowSelected(table.getSelectedRow()); } else { List<DiffNode> selectedNodes = new ArrayList<DiffNode>(); if (min == -1) { master.tableRowSelected(-1); } else { for (int i = min; i <= max; i++) { if (selectionModel.isSelectedIndex(i)) { int idx = sorter.modelIndex(i); selectedNodes.add(nodes[idx]); } } } final TopComponent tc = (TopComponent) master.getClientProperty(TopComponent.class); if (tc == null) return; // table is no longer in component hierarchy Node [] nodesToActivate = selectedNodes.toArray(new Node[selectedNodes.size()]); tc.setActivatedNodes(nodesToActivate); } }
Example 12
Source File: VersioningPanel.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void propertyChange(PropertyChangeEvent evt) { if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, this); if (tc == null) return; tc.setActivatedNodes((Node[]) evt.getNewValue()); } else if (FileStatusCache.PROP_CACHE_READY.equals(evt.getPropertyName()) && Boolean.TRUE.equals(evt.getNewValue())) { reScheduleRefresh(0); } }
Example 13
Source File: SearchHistoryPanel.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void propertyChange(PropertyChangeEvent evt) { if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, this); if (tc == null) return; tc.setActivatedNodes((Node[]) evt.getNewValue()); } else if (RepositoryInfo.PROPERTY_BRANCHES.equals(evt.getPropertyName())) { refreshBranchFilterModel(); } }
Example 14
Source File: RepositoryBrowserPanel.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void propertyChange (PropertyChangeEvent evt) { if (evt.getPropertyName() == ExplorerManager.PROP_SELECTED_NODES) { TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, this); if (tc != null) { tc.setActivatedNodes(getExplorerManager().getSelectedNodes()); } currRepository = null; Revision oldRevision = currRevision; currRevision = null; if (getExplorerManager().getSelectedNodes().length == 1) { Node selectedNode = getExplorerManager().getSelectedNodes()[0]; currRevision = selectedNode.getLookup().lookup(Revision.class); currRepository = lookupRepository(selectedNode); } if ((currRevision != null || oldRevision != null) && !(currRevision != null && oldRevision != null && currRevision.equals(oldRevision))) { firePropertyChange(PROP_REVISION_CHANGED, oldRevision, currRevision); } if (options.contains(Option.DISPLAY_REVISIONS) && currRevision != null) { revisionsPanel1.updateHistory(currRepository, roots, currRevision); } } else if (options.contains(Option.DISPLAY_REVISIONS) && "focusOwner".equals(evt.getPropertyName())) { Component compNew = (Component) evt.getNewValue(); if (compNew != null) { if (SwingUtilities.getAncestorOfClass(tree.getClass(), compNew) != null) { if (getExplorerManager().getSelectedNodes().length == 1) { propertyChange(new PropertyChangeEvent(tree, ExplorerManager.PROP_SELECTED_NODES, getExplorerManager().getSelectedNodes(), getExplorerManager().getSelectedNodes())); } } else if (revisionsPanel1.lstRevisions == compNew) { int selection = revisionsPanel1.lstRevisions.getSelectedIndex(); if (selection != -1) { valueChanged(new ListSelectionEvent(revisionsPanel1.lstRevisions, selection, selection, false)); } } } } }
Example 15
Source File: PaletteSwitchTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testMimePalette() throws IOException { TopComponent tc = createTopComponentWithPalette( null ); tc.setActivatedNodes( new Node[] { DataObject.find( dummyDocumentFile ).getNodeDelegate() } ); tc.open(); PaletteSwitch paletteSwitch = PaletteSwitch.getDefault(); PaletteController foundPalette = paletteSwitch.getPaletteFromMimeType( MIME_TYPE_NAME ); assertNotNull( foundPalette ); assertEquals( mimePaletteRootName, foundPalette.getModel().getName() ); foundPalette = paletteSwitch.getPaletteFromTopComponent( tc, false, tc.isOpened() ); assertNotNull( foundPalette ); assertEquals( mimePaletteRootName, foundPalette.getModel().getName() ); }
Example 16
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}); }
Example 17
Source File: MultiDiffPanel.java From netbeans with Apache License 2.0 | 4 votes |
private void setDiffIndex(Setup selectedSetup, int location, boolean restartPrepareTask) { currentSetup = selectedSetup; currentSetupDiffLengthChanged = -1; if (currentSetup != null) { if (restartPrepareTask && dpt != null) { dpt.cancel(); dpt.setSelectedSetup(currentSetup); prepareTask.schedule(100); } DiffController view = currentSetup.getView(); TopComponent tc = (TopComponent) getClientProperty(TopComponent.class); if (tc != null) { Node node = currentSetup.getNode(); tc.setActivatedNodes(new Node[] {node == null ? Node.EMPTY : node}); } diffView = null; if (view != null) { currentSetupDiffLengthChanged = view.getDifferenceCount(); if (showingFileComponent()) { fileComponentSetSelectedIndexContext = true; getActiveFileComponent().setSelectedNode(currentSetup.getNode()); fileComponentSetSelectedIndexContext = false; } getDiffViewModeSwitcher().setupMode(view); diffView = view.getJComponent(); diffView.getActionMap().put("jumpNext", nextAction); // NOI18N diffView.getActionMap().put("jumpPrev", prevAction); // NOI18N displayDiffView(); if (location == -1) { location = view.getDifferenceCount() - 1; } if (location >=0 && location < view.getDifferenceCount()) { view.setLocation(DiffController.DiffPane.Modified, DiffController.LocationType.DifferenceIndex, location); } } else { diffView = new NoContentPanel(NbBundle.getMessage(MultiDiffPanel.class, "MSG_DiffPanel_NoContent")); displayDiffView(); } } else { diffView = new NoContentPanel(NbBundle.getMessage(MultiDiffPanel.class, "MSG_DiffPanel_NoFileSelected")); displayDiffView(); } delegatingUndoRedo.setDiffView(diffView); refreshComponents(); }
Example 18
Source File: MoveUpActionTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testBasicUsage() throws Exception { SystemAction mua = SystemAction.get(MoveUpAction.class); SystemAction mda = SystemAction.get(MoveDownAction.class); SystemAction roa = SystemAction.get(ReorderAction.class); ActionsInfraHid.WaitPCL l = null; TopComponent tc = new TopComponent(); tc.requestActive(); try { assertNull(tc.getActivatedNodes()); assertFalse(mua.isEnabled()); assertFalse(mda.isEnabled()); assertFalse(roa.isEnabled()); l = new ActionsInfraHid.WaitPCL(SystemAction.PROP_ENABLED); mua.addPropertyChangeListener(l); assertFalse(mua.isEnabled()); assertFalse(mda.isEnabled()); assertFalse(roa.isEnabled()); tc.setActivatedNodes(new Node[] {n}); if (!l.changed()) { Thread.sleep(1000); } l.gotit = 0; assertFalse(mua.isEnabled()); assertFalse(mda.isEnabled()); assertTrue(roa.isEnabled()); assertEquals(Arrays.asList(new Node[] {n1, n2, n3}), Arrays.asList(n.getChildren().getNodes())); roa.actionPerformed(null); assertEquals(Arrays.asList(new Node[] {n3, n1, n2}), Arrays.asList(n.getChildren().getNodes())); assertTrue(roa.isEnabled()); tc.setActivatedNodes(new Node[] {n1, n2}); if (!l.changed()) { Thread.sleep(1000); } l.gotit = 0; assertFalse(mua.isEnabled()); assertFalse(mda.isEnabled()); assertFalse(roa.isEnabled()); tc.setActivatedNodes(new Node[] {n1}); if (!l.changed()) { Thread.sleep(1000); } l.gotit = 0; assertTrue("MoveUp is enabled on a node in the middle of its parents", mua.isEnabled()); assertTrue(mda.isEnabled()); assertFalse(roa.isEnabled()); mua.actionPerformed(null); assertEquals(Arrays.asList(new Node[] {n1, n3, n2}), Arrays.asList(n.getChildren().getNodes())); if (!l.changed()) { Thread.sleep(1000); } l.gotit = 0; assertTrue("MoveUp is turned off after a node is moved to the very top", !mua.isEnabled()); assertTrue(mda.isEnabled()); assertFalse(roa.isEnabled()); tc.setActivatedNodes(new Node[] {n2}); if (!l.changed()) { Thread.sleep(1000); } l.gotit = 0; assertTrue(mua.isEnabled()); assertFalse(mda.isEnabled()); assertFalse(roa.isEnabled()); tc.setActivatedNodes(new Node[] {n3}); if (!l.changed()) { Thread.sleep(1000); } l.gotit = 0; assertTrue(mua.isEnabled()); assertTrue(mda.isEnabled()); assertFalse(roa.isEnabled()); mda.actionPerformed(null); assertEquals(Arrays.asList(new Node[] {n1, n2, n3}), Arrays.asList(n.getChildren().getNodes())); if (!l.changed()) { Thread.sleep(1000); } l.gotit = 0; assertTrue(mua.isEnabled()); assertFalse(mda.isEnabled()); assertFalse(roa.isEnabled()); } finally { if (l != null) { mua.removePropertyChangeListener(l); mda.removePropertyChangeListener(l); roa.removePropertyChangeListener(l); } tc.setActivatedNodes(new Node[0]); tc.setActivatedNodes(null); } }