Java Code Examples for org.openide.windows.TopComponent#getLookup()
The following examples show how to use
org.openide.windows.TopComponent#getLookup() .
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: 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 2
Source File: ShowHistoryAction.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void propertyChange(PropertyChangeEvent evt) { if(Registry.PROP_ACTIVATED.equals(evt.getPropertyName())) { try { TopComponent tc =(TopComponent) evt.getNewValue(); Lookup l = tc.getLookup(); DataObject tcDataObject = l.lookup(DataObject.class); if (tcDataObject != null && dataObject.equals(tcDataObject)) { final MultiViewHandler handler = MultiViews.findMultiViewHandler(tc); if (handler == null || !activateHistoryTab(handler, tc)) { // oops, whats this? // lets fallback on LHTC tc.close(); openLocalHistoryTC(files); } } } finally { TopComponent.getRegistry().removePropertyChangeListener(this); } } }
Example 3
Source File: CakePHPTabDecorator.java From cakephp3-netbeans with Apache License 2.0 | 6 votes |
@Override public String getText(TabData tab) { // show a parent directory name if it's a view file // e.g. home.ctp [Pages] String text = tab.getText(); if (text.endsWith(".ctp")) { // NOI18N Component component = tab.getComponent(); if (component instanceof TopComponent) { TopComponent topComponent = (TopComponent) component; Lookup lookup = topComponent.getLookup(); if (lookup != null) { FileObject fileObject = lookup.lookup(FileObject.class); if (fileObject != null) { FileObject parent = fileObject.getParent(); if (parent != null) { String parentName = parent.getName(); return String.format("%s [%s]", text, parentName); // NOI18N } } } } } return super.getText(tab); }
Example 4
Source File: NoMVCLookupTest.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void propertyChange(PropertyChangeEvent evt) { if(TopComponent.Registry.PROP_TC_OPENED.equals(evt.getPropertyName())) { Object obj = evt.getNewValue(); if(obj instanceof TopComponent) { final TopComponent openedTC = (TopComponent) obj; Lookup lookup = openedTC.getLookup(); DataObject openedDataObject = lookup.lookup(DataObject.class); dataObjectFoundInLookup = openedDataObject != null; // if(openedDataObject != null) { // dataObjectOnTCOpen = data == openedDataObject; // } // else { // Result<DataObject> r = lookup.lookupResult(DataObject.class); // r.addLookupListener(new LookupListener() { // @Override // public void resultChanged(LookupEvent ev) { // Lookup lookup = openedTC.getLookup(); // DataObject openedDataObject = lookup.lookup(DataObject.class); // dataObjectAfterTCOpen = data == openedDataObject; // } // }); // } this.tc = openedTC; } opened = true; } }
Example 5
Source File: DocumentsDlg.java From netbeans with Apache License 2.0 | 5 votes |
private void saveDocuments(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveDocuments // Add your handling code here: Node[] selNodes = explorer.getSelectedNodes(); if (selNodes.length == 0) { return; } for (int i = 0; i < selNodes.length; i++) { TopComponent tc = ((TopComponentNode) selNodes[i]).getTopComponent(); Lookup l = tc.getLookup(); SaveCookie sc = (SaveCookie) l.lookup(SaveCookie.class); if (sc != null) { try { sc.save(); } catch (IOException exc) { Logger.getAnonymousLogger().log(Level.WARNING, "[WinSys.DocumentsDlg.saveDocuments]" // NOI18N + " Warning: Cannot save content of TopComponent: [" // NOI18N + WindowManagerImpl.getInstance().getTopComponentDisplayName(tc) + "]" // NOI18N + " [" + tc.getClass().getName() + "]", exc); // NOI18N } //Refresh name of node because TopComponent name is probably changed too //('*' is removed) ((TopComponentNode) selNodes[i]).refresh(); } } jButtonSave.setEnabled(false); }
Example 6
Source File: TabbedHandler.java From netbeans with Apache License 2.0 | 5 votes |
/** Possibly invokes popup menu. */ public static void handlePopupMenuShowing(MouseEvent e, int idx) { Component c = (Component) e.getSource(); while (c != null && !(c instanceof Tabbed.Accessor)) c = c.getParent(); if (c == null) { return; } final Tabbed tab = ((Tabbed.Accessor)c).getTabbed(); final Point p = SwingUtilities.convertPoint((Component) e.getSource(), e.getPoint(), c); final int clickTab = idx; Lookup context = null; Action[] actions = null; if (clickTab >= 0) { TopComponent tc = tab.getTopComponentAt(clickTab); if(tc != null) { // ask also tabbed to possibly alter actions actions = tab.getPopupActions(tc.getActions(), clickTab); if (actions == null) { actions = tc.getActions(); } if (actions == null || actions.length == 0 ) return; context = tc.getLookup(); } } if( null == context ) { actions = tab.getPopupActions(new Action[0], -1); if (actions == null || actions.length == 0 ) return; context = Lookup.getDefault(); } showPopupMenu(Utilities.actionsToPopup(actions, context), p, c); }
Example 7
Source File: ActionUtils.java From netbeans with Apache License 2.0 | 5 votes |
private static SaveCookie getSaveCookie(TopComponent tc) { Lookup lookup = tc.getLookup(); Object obj = lookup.lookup(SaveCookie.class); if(obj instanceof SaveCookie) { return (SaveCookie)obj; } return null; }
Example 8
Source File: GlobalActionContextImpl.java From netbeans with Apache License 2.0 | 5 votes |
/** The current component lookup */ public Lookup getLookup() { Lookup l = temporary; if (l != null) { return l; } TopComponent tc = registry.getActivated(); return tc == null ? Lookup.EMPTY : tc.getLookup(); }
Example 9
Source File: TopComponentGetLookupTest.java From netbeans with Apache License 2.0 | 4 votes |
/** Setup component with lookup. */ protected void setUp () { top = new TopComponent (); get = top; lookup = top.getLookup (); }
Example 10
Source File: EditorBufferSelectorPanel.java From netbeans with Apache License 2.0 | 4 votes |
private void initEditorDocuments() { elementsList = new JList() { @Override public String getToolTipText(MouseEvent event) { int index = locationToIndex(event.getPoint()); if (index != -1) { EditorListElement element = (EditorListElement) elementsList.getModel().getElementAt(index); return element.fileObject.getPath(); } return null; } }; List<EditorListElement> elements = new ArrayList<EditorListElement>(); WindowManager wm = WindowManager.getDefault(); Set<? extends Mode> modes = wm.getModes(); for (Mode mode : modes) { if (wm.isEditorMode(mode)) { TopComponent[] tcs = mode.getTopComponents(); for (TopComponent tc : tcs) { Lookup lukap = tc.getLookup(); FileObject fo = lukap.lookup(FileObject.class); if (fo == null) { DataObject dobj = lukap.lookup(DataObject.class); if (dobj != null) { fo = dobj.getPrimaryFile(); } } if (fo != null && fo != peer) { if (tc.getHtmlDisplayName() != null) { elements.add(new EditorListElement(fo, tc.getHtmlDisplayName(), true)); } else { elements.add(new EditorListElement(fo, tc.getName(), false)); } } } } } elementsList.setListData(elements.toArray(new EditorListElement[elements.size()])); elementsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); elementsList.addListSelectionListener(this); elementsList.setCellRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (isSelected && value instanceof EditorListElement && ((EditorListElement) value).isHtml()) { value = stripHtml(((EditorListElement) value).toString()); } return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } private String stripHtml (String htmlText) { if (null == htmlText) { return null; } String res = htmlText.replaceAll("<[^>]*>", ""); // NOI18N // NOI18N res = res.replaceAll(" ", " "); // NOI18N // NOI18N res = res.trim(); return res; } }); JScrollPane sp = new JScrollPane(elementsList); jPanel1.add(sp); }
Example 11
Source File: ShowHistoryAction.java From netbeans with Apache License 2.0 | 4 votes |
@Override protected void performAction(final Node[] activatedNodes) { VCSContext ctx = VCSContext.forNodes(activatedNodes); final Set<VCSFileProxy> rootSet = ctx.getRootFiles(); final VCSFileProxy[] files = rootSet.toArray(new VCSFileProxy[rootSet.size()]); if(!files[0].isFile()) { return; } VCSFileProxy file = files[0]; FileObject fo = file.toFileObject(); if(fo != null) { DataObject dataObject = null; try { dataObject = DataObject.find(fo); } catch (DataObjectNotFoundException ex) { History.LOG.log(Level.WARNING, null, ex); } if(dataObject != null) { if(!hasHistoryElement(dataObject)) { // there is no history element defined for this data object, so // lets open in a separate TopComponent openLocalHistoryTC(files); return; } // activate the History tab if there is a opened TopComponent // with a History MultiView element Set<TopComponent> tcs = TopComponent.getRegistry().getOpened(); for (final TopComponent tc : tcs) { Lookup l = tc.getLookup(); final DataObject tcDataObject = l.lookup(DataObject.class); if (tcDataObject != null && dataObject.equals(tcDataObject)) { final MultiViewHandler handler = MultiViews.findMultiViewHandler(tc); if(handler != null) { if(activateHistoryTab(handler, tc)) { // done, history tab found and activated. return; } } } } final EditorCookie editorCookie = dataObject.getLookup().lookup(EditorCookie.class); if(editorCookie != null) { Runnable r = new Runnable() { @Override public void run() { JEditorPane pane = NbDocument.findRecentEditorPane(editorCookie); if(pane != null) { // editor is oen, though we havent found a multiview => open the LH top component openLocalHistoryTC(files); } } }; if(SwingUtilities.isEventDispatchThread()) { r.run(); } else { SwingUtilities.invokeLater(r); } } EditCookie editCookie = dataObject.getLookup().lookup(EditCookie.class); if(editCookie != null) { // no editor found, lets open it... // editcookie might return imediately, so listen for the TC // to be opened and activate then TopComponent.getRegistry().addPropertyChangeListener(new TCOpenedListener(dataObject, files)); editCookie.edit(); return; } } } openLocalHistoryTC(files); }