@Override public void resultChanged(LookupEvent ev) { TopComponent tc = ref.get(); if (tc == null) { r.removeLookupListener(this); synchronized (lookupListeners) { lookupListeners.remove(this); } return; } if (LOG.isLoggable(Level.FINER)) { LOG.log(Level.FINER, " looking result changed for {0} ", new Object[] {ref.get()}); } DataObject tcDataObject = tc.getLookup().lookup(DataObject.class); if (tcDataObject != null) { try { if (hasOpenedEditorPanes(tcDataObject)) { addOpenedFiles(getFiles(tcDataObject)); } } catch (InterruptedException ex) { LOG.log(Level.WARNING, null, ex); } catch (InvocationTargetException ex) { LOG.log(Level.WARNING, null, ex); } r.removeLookupListener(this); synchronized (lookupListeners) { lookupListeners.remove(this); } } }
@Override public void componentOpened() { TopComponent projWindow = WindowManager.getDefault().findTopComponent("projectTabLogical_tc"); trainingResultSets = projWindow.getLookup().lookupResult(DataSet.class); trainingResultSets.addLookupListener(this); resultChanged(new LookupEvent(trainingResultSets)); }
private void addLookupListener(TopComponent tc) { Result<DataObject> r = tc.getLookup().lookupResult(DataObject.class); L l = new L(new WeakReference<TopComponent>(tc), r); synchronized (lookupListeners) { lookupListeners.add(l); } r.addLookupListener(l); }
/** * multiview components do not fire events when switching their inner tabs so we have to listen to * changes in lookup contents */ private void switchLookupListener() { TopComponent active = TopComponent.getRegistry().getActivated(); if (null != lookupRes) { lookupRes.removeLookupListener(SatelliteViewSwitch.this); lookupRes = null; } if (null != active) { lookupRes = active.getLookup().lookupResult(LayoutScene.class); lookupRes.addLookupListener(SatelliteViewSwitch.this); lookupRes.allItems(); } }
private String getProjectType() { String ret = ""; TopComponent.Registry registry = TopComponent.getRegistry(); TopComponent tc = registry.getActivated(); if (tc != null) { Lookup lkup = tc.getLookup(); if (lkup != null) { DataObject dObj = lkup.lookup(DataObject.class); if (dObj != null) { FileObject fObj = dObj.getPrimaryFile(); Project project = FileOwnerQuery.getOwner(fObj); if (project != null) { ret = project.getClass().getName(); } } } } return ret; }
private boolean isValidFileOpened() { boolean result = false; TopComponent.Registry registry = TopComponent.getRegistry(); TopComponent tc = registry.getActivated(); if (tc != null) { Lookup lkup = tc.getLookup(); if (lkup != null) { DataObject dObj = lkup.lookup(DataObject.class); if (dObj != null) { String ext = dObj.getPrimaryFile().getExt(); if (ext != null) { ext = ext.toLowerCase(); if (ext.equals("java")) { // NOI18N return true; } } } } } return result; }
private List<File> getFiles(TopComponent tc) { LOG.log(Level.FINER, " looking up files in tc {0} ", new Object[] {tc}); DataObject tcDataObject = tc.getLookup().lookup(DataObject.class); if (tcDataObject == null) { boolean alreadyListening = false; Iterator<L> it = lookupListeners.iterator(); synchronized (lookupListeners) { while (it.hasNext()) { L l = it.next(); if (l.ref.get() == null) { l.r.removeLookupListener(l); it.remove(); } if (l.ref.get() == tc) { alreadyListening = true; break; } } } if (!alreadyListening) { addLookupListener(tc); } return Collections.EMPTY_LIST; } else { try { return hasOpenedEditorPanes(tcDataObject) ? getFiles(tcDataObject) : Collections.EMPTY_LIST; } catch (InterruptedException ex) { LOG.log(Level.WARNING, null, ex); } catch (InvocationTargetException ex) { LOG.log(Level.WARNING, null, ex); } } return Collections.EMPTY_LIST; }
LayoutScene getLayersFromTopComponent(TopComponent tc, boolean mustBeShowing, boolean isOpened) { if (null == tc || (!tc.isShowing() && mustBeShowing)) { return null; } return tc.getLookup().lookup(LayoutScene.class); }