@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); } } }
private void removeOpenedFiles(List<File> files) { if (files == null) { return; } synchronized (openedFiles) { for (File file : files) { LOG.log(Level.FINE, " removing from opened files {0} ", new Object[] {file}); openedFiles.remove(file.getAbsolutePath()); } } }
private List<File> getFiles(DataObject tcDataObject) { List<File> ret = new ArrayList<File>(); LOG.log(Level.FINER, " looking up files in dataobject {0} ", new Object[] {tcDataObject}); Set<FileObject> fos = tcDataObject.files(); if (fos != null) { for (FileObject fo : fos) { LOG.log(Level.FINER, " found file {0}", new Object[] {fo}); File f = FileUtil.toFile(fo); if (f != null && !openedFiles.contains(f.getAbsolutePath()) && !touchedFiles.contains(f.getAbsolutePath())) { ret.add(f); } } } if (LOG.isLoggable(Level.FINER)) { for (File f : ret) { LOG.log(Level.FINER, " returning file {0} ", new Object[] {f}); } } return ret; }
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; }
private void addOpenedFiles(List<File> files) { if (files == null) { return; } synchronized (openedFiles) { for (File file : files) { LOG.log(Level.FINE, " adding to opened files : ", new Object[] {file}); openedFiles.add(file.getAbsolutePath()); } for (File file : files) { if (handleManaged(file)) { break; } } } }