Java Code Examples for org.openide.filesystems.FileObject#addFileChangeListener()
The following examples show how to use
org.openide.filesystems.FileObject#addFileChangeListener() .
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: FolderListener.java From netbeans with Apache License 2.0 | 6 votes |
private FolderListener(File key, FileObject folder, J2eeModule.Type type) { configKey = key; if(type == J2eeModule.Type.WAR) { targets = new String [] { "web.xml", "webservices.xml" }; } else if(type == J2eeModule.Type.EJB) { targets = new String [] { "ejb-jar.xml", "webservices.xml" }; } else if(type == J2eeModule.Type.EAR) { targets = new String [] { "application.xml" }; } else if(type == J2eeModule.Type.CAR) { targets = new String [] { "application-client.xml" }; } else { Logger.getLogger("payara-eecommon").log(Level.WARNING, "Unsupported module type: " + type); targets = new String [0]; } folder.addFileChangeListener(this); }
Example 2
Source File: TemplatesPanel.java From netbeans with Apache License 2.0 | 6 votes |
private boolean acceptTemplate (FileObject fo) { if (fo.isFolder() && (TEMPLATES_FOLDER+"/Properties").equals(fo.getPath())) { return false; } boolean attachListener; synchronized (filesWeListenOn) { attachListener = filesWeListenOn.add(fo); } if (attachListener) { FileChangeListener fileChangeListener = FileUtil.weakFileChangeListener(this, fo); fo.addFileChangeListener(fileChangeListener); } if (isTemplate (fo) || fo.isFolder()) { Object o = fo.getAttribute ("simple"); // NOI18N return o == null || Boolean.TRUE.equals (o); } else { return false; } }
Example 3
Source File: ProjectServicesImpl.java From netbeans with Apache License 2.0 | 6 votes |
@Override public synchronized boolean addDeleteListener(DeleteListener l) { boolean added = super.addDeleteListener(l); if (added && projectDeleteListener == null) { Project p = getProject(getURL()); if (p != null) { FileObject projDir = p.getProjectDirectory(); projectDeleteListener = new ProjectDeleteListener(projDir.toURL(), this); projDir.addFileChangeListener(projectDeleteListener); } else { super.removeDeleteListener(l); added = false; } } return added; }
Example 4
Source File: HeapDumpWatch.java From netbeans with Apache License 2.0 | 6 votes |
private void monitor(String path) throws IllegalArgumentException { if ((path == null) || (path.length() == 0)) { throw new IllegalArgumentException("The path \"" + path + "\" can't be null."); // NOI18N } FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(new File(path))); if (fo != null) { if (!fo.isFolder()) { throw new IllegalArgumentException("The given path \"" + path + "\" is invalid. It must be a folder"); // NOI18N } fo.getChildren(); fo.addFileChangeListener(listener); monitoredPath = fo; } }
Example 5
Source File: HtmlDataObject.java From netbeans with Apache License 2.0 | 5 votes |
private Charset cache (final Charset encoding) { if (!listeningOnContentChange.getAndSet(true)) { final FileObject primaryFile = getPrimaryFile(); primaryFile.addFileChangeListener(FileUtil.weakFileChangeListener(new FileChangeAdapter(){ @Override public void fileChanged(FileEvent fe) { cachedEncoding = null; } },primaryFile)); } cachedEncoding = encoding; LOG.log(Level.FINEST, "HtmlDataObject.getFileEncoding noncached {0}", new Object[] {encoding}); //NOI18N return encoding; }
Example 6
Source File: DDProvider.java From netbeans with Apache License 2.0 | 5 votes |
/** * Returns the root of deployment descriptor bean graph for given file object. * The method is useful for clints planning to read only the deployment descriptor * or to listen to the changes. * @param fo FileObject representing the ejb-jar.xml file * @return EjbJar object - root of the deployment descriptor bean graph */ public synchronized EjbJar getDDRoot(FileObject fo) throws java.io.IOException { if (fo == null) { return null; } try { DataObject dataObject = DataObject.find(fo); if(dataObject instanceof DDProviderDataObject){ return getDDRoot0((DDProviderDataObject) dataObject); } } catch (DataObjectNotFoundException e) { return null; // should not occur } EjbJarProxy ejbJarProxy = null; synchronized (ddMap) { ejbJarProxy = getFromCache(fo); if (ejbJarProxy != null) { return ejbJarProxy; } } fo.addFileChangeListener(new DDFileChangeListener()); ejbJarProxy = DDUtils.createEjbJarProxy(fo); synchronized(ddMap){ EjbJarProxy cached = getFromCache(fo); if (cached != null){ return cached; } putToCache(fo, ejbJarProxy); } return ejbJarProxy; }
Example 7
Source File: ImportantFilesNodeFactory.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected Node[] createNodes(String key) { if (LAYER.equals(key)) { Node nd = NodeFactoryUtils.createLayersNode(project); if (nd != null) { DataObject dobj = nd.getLookup().lookup(DataObject.class); if (dobj != null) { FileObject fo = dobj.getPrimaryFile(); fo.addFileChangeListener(FileUtil.weakFileChangeListener(layerfcl, fo)); } return new Node[] {nd }; } return new Node[0]; } else { FileObject file = project.getProjectDirectory().getFileObject(key); if (file != null) { try { Node orig = DataObject.find(file).getNodeDelegate(); return new Node[] {NodeFactoryUtils.createSpecialFileNode(orig, FILES.get(key))}; } catch (DataObjectNotFoundException e) { throw new AssertionError(e); } } return new Node[0]; } }
Example 8
Source File: SingleDiffPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void setListeners () { FileObject baseParent = base.getParent(); FileObject modifiedParent = modified.getParent(); if (baseParent != null) { baseParent.addFileChangeListener(WeakListeners.create(FileChangeListener.class, baseFCL = new DiffFileChangeListener(), baseParent)); } if (baseParent != modifiedParent && modifiedParent != null) { modifiedParent.addFileChangeListener(WeakListeners.create(FileChangeListener.class, modifiedFCL = new DiffFileChangeListener(), modifiedParent)); } }
Example 9
Source File: ProfilingPointsManager.java From netbeans with Apache License 2.0 | 5 votes |
private void addFileWatch(File file) { FileObject fileo = null; if (file.isFile()) fileo = FileUtil.toFileObject(FileUtil.normalizeFile(file)); if (fileo != null) { FileWatch fileWatch = profilingPointsFiles.get(file); if (fileWatch == null) { LocationFileListener listener = new LocationFileListener(file); fileWatch = new FileWatch(listener); fileo.addFileChangeListener(listener); profilingPointsFiles.put(file, fileWatch); } fileWatch.increaseReferences(); } }
Example 10
Source File: ReadOnlyFilesHighlighting.java From netbeans with Apache License 2.0 | 5 votes |
private void checkFileStatus(FileObject fo) { boolean update = false; synchronized (this) { if (lastFile == null || lastFile.get() != fo) { lastFile = new WeakReference<FileObject>(fo); update = true; } } if (update) { fo.addFileChangeListener(WeakListeners.create(FileChangeListener.class, this, fo)); boolean readOnly = !fo.canWrite(); // Access without monitor on this class and document's lock updateFileReadOnly(readOnly); } }
Example 11
Source File: WebModuleImpl.java From netbeans with Apache License 2.0 | 5 votes |
@Override public synchronized MetadataModel<WebAppMetadata> getMetadataModel() { if (webAppMetadataModel == null) { final FileObject ddFO = getDeploymentDescriptor(); final FileObject webInf = getOrCreateWebInf(); if (ddFO == null && webInf != null) { webInf.addFileChangeListener(new FileChangeAdapter() { @Override public void fileDataCreated(FileEvent fe) { if ("web.xml".equals(fe.getFile().getNameExt())) { // NOI18N webInf.removeFileChangeListener(this); resetMetadataModel(); } } }); } File ddFile = ddFO != null ? FileUtil.toFile(ddFO) : null; ProjectSourcesClassPathProvider cpProvider = project.getLookup().lookup(ProjectSourcesClassPathProvider.class); MetadataUnit metadataUnit = MetadataUnit.create( cpProvider.getProjectSourcesClassPath(ClassPath.BOOT), cpProvider.getProjectSourcesClassPath(ClassPath.COMPILE), cpProvider.getProjectSourcesClassPath(ClassPath.SOURCE), ddFile); webAppMetadataModel = WebAppMetadataModelFactory.createMetadataModel(metadataUnit, true); } return webAppMetadataModel; }
Example 12
Source File: ImportantFilesSupport.java From netbeans with Apache License 2.0 | 5 votes |
/** * Creates new support for the given directory and file name(s). * @param directory directory * @param fileNames file name(s) * @return new support */ public static ImportantFilesSupport create(FileObject directory, String... fileNames) { Parameters.notNull("directory", directory); // NOI18N Parameters.notNull("fileNames", fileNames); // NOI18N ImportantFilesSupport support = new ImportantFilesSupport(directory, fileNames); directory.addFileChangeListener(WeakListeners.create(FileChangeListener.class, support.fileChangeListener, directory)); return support; }
Example 13
Source File: JSLineBreakpoint.java From netbeans with Apache License 2.0 | 5 votes |
public void setLineHandler(EditorLineHandler line) { dispose(); EditorLineHandler oldLine = this.line; this.line = line; lineChangesWeak = WeakListeners.propertyChange(lineChangeslistener, line); line.addPropertyChangeListener(lineChangesWeak); FileObject fileObject = line.getFileObject(); if (fileObject != null) { myWeakListener = WeakListeners.create( FileChangeListener.class, myListener, fileObject); fileObject.addFileChangeListener(myWeakListener); } firePropertyChange(PROP_FILE, oldLine.getFileObject(), line.getFileObject()); firePropertyChange(PROP_LINE_NUMBER, oldLine.getLineNumber(), line.getLineNumber()); }
Example 14
Source File: FieldLNCache.java From netbeans with Apache License 2.0 | 5 votes |
void putLine(String url, String className, String fieldName, FileObject fo, int lineNumber) { if (!knownFiles.contains(fo)) { fo.addFileChangeListener(new FileChangeListenerImpl(url)); knownFileRefs.add(new FileKey(fo, url)); } synchronized (fieldLines) { fieldLines.put(new FieldKey(url, className, fieldName), lineNumber); } }
Example 15
Source File: EditorSettingsImpl.java From netbeans with Apache License 2.0 | 5 votes |
public KeymapProfileTracker(FileObject keymapFolder) { this.keymapFolder = keymapFolder; if (keymapFolder != null) { keymapFolder.addFileChangeListener(this); } else { FileUtil.getConfigRoot().addFileChangeListener(this); } }
Example 16
Source File: LineBreakpoint.java From netbeans with Apache License 2.0 | 4 votes |
public LineBreakpoint(Line line) { myLine = line; myListener = new FileRemoveListener(); FileObject fileObject = line.getLookup().lookup(FileObject.class); if (fileObject != null) { myWeakListener = WeakListeners.create(FileChangeListener.class, myListener, fileObject); fileObject.addFileChangeListener(myWeakListener); myFileUrl = fileObject.toURL().toString(); } else { myFileUrl = ""; //NOI18N } isValidFuture = RP.submit(new Callable<Boolean>() { @Override public Boolean call() { final Boolean[] result = new Boolean[1]; DataObject dataObject = DataEditorSupport.findDataObject(myLine); EditorCookie editorCookie = (EditorCookie) dataObject.getLookup().lookup(EditorCookie.class); final StyledDocument styledDocument = editorCookie.getDocument(); if (styledDocument != null && styledDocument instanceof BaseDocument) { try { final BaseDocument baseDocument = (BaseDocument) styledDocument; Source source = Source.create(baseDocument); ParserManager.parse(Collections.singleton(source), new UserTask() { @Override public void run(ResultIterator resultIterator) throws Exception { Parser.Result parserResult = resultIterator.getParserResult(); if (parserResult != null && parserResult instanceof PHPParseResult) { PHPParseResult phpParserResult = (PHPParseResult) parserResult; int rowStart = LineDocumentUtils.getLineStartFromIndex(baseDocument, myLine.getLineNumber()); int contentStart = Utilities.getRowFirstNonWhite(baseDocument, rowStart); int contentEnd = LineDocumentUtils.getLineLastNonWhitespace(baseDocument, rowStart) + 1; StatementVisitor statementVisitor = new StatementVisitor(contentStart, contentEnd); statementVisitor.scan(phpParserResult.getProgram().getStatements()); int properStatementOffset = statementVisitor.getProperStatementOffset(); result[0] = properStatementOffset == contentStart; } } }); } catch (ParseException ex) { LOGGER.log(Level.FINE, null, ex); } } return result[0]; } }); }
Example 17
Source File: LayerUtils.java From netbeans with Apache License 2.0 | 4 votes |
public CookieImpl(FileObject f) { //System.err.println("new CookieImpl for " + f); this.f = f; f.addFileChangeListener(FileUtil.weakFileChangeListener(this, f)); }
Example 18
Source File: AbstractFilesListener.java From netbeans with Apache License 2.0 | 4 votes |
private void addFileListenerTo(FileObject fo) { FileChangeListener l = FileUtil.weakFileChangeListener(listener, fo); fileListeners.put(fo, l); fo.addFileChangeListener(l); }
Example 19
Source File: RulesManager.java From netbeans with Apache License 2.0 | 4 votes |
/** Read rules from system filesystem */ private List<Pair<Rule,FileObject>> readRules( FileObject folder ) { List<Pair<Rule,FileObject>> rules = new LinkedList<Pair<Rule,FileObject>>(); if (folder == null) { return rules; } Queue<FileObject> q = new LinkedList<FileObject>(); q.offer(folder); while(!q.isEmpty()) { FileObject o = q.poll(); o.removeFileChangeListener(this); o.addFileChangeListener(this); if (o.isFolder()) { q.addAll(Arrays.asList(o.getChildren())); continue; } if (!o.isData()) { continue; } String name = o.getNameExt().toLowerCase(); if ( o.canRead() ) { Rule r = null; if ( name.endsWith( INSTANCE_EXT ) ) { r = instantiateRule(o); } if ( r != null ) { rules.add( new Pair<Rule,FileObject>( r, o ) ); } } } return rules; }
Example 20
Source File: RunScriptAction.java From netbeans with Apache License 2.0 | 4 votes |
private RunScriptAction(Lookup context, JTextComponent editor, FileObject scriptOrFolder, String name, String description) { this(); this.context = context; this.editor = editor; this.storage = PersistentSnippetsSupport.create(context); this.scriptFile = scriptOrFolder; putValue(NAME, name); if (scriptFile == null) { putValue(SHORT_DESCRIPTION, Bundle.DESC_RunSavedScript()); putValue(SMALL_ICON, ImageUtilities.loadImageIcon(RESOURCE_ICON, false)); } else { putValue(SHORT_DESCRIPTION, description); } if (storage == null) { setEnabled(false); return; } boolean enabled = true; if (scriptOrFolder == null || scriptOrFolder.isFolder()) { if (scriptOrFolder == null) { popup = new JPopupMenu() { @Override public int getComponentCount() { refresh(); return super.getComponentCount(); } }; } else { subMenu = new JMenu() { @Override public int getMenuComponentCount() { refresh(); return super.getMenuComponentCount(); } }; subMenu.setText(name); subMenu.setToolTipText(description); } if (storage.getSavedClasses(null).isEmpty()) { setEnabled(false); } invalidate(); if (scriptOrFolder != null) { FileChangeListener fcl = WeakListeners.create(FileChangeListener.class, listen, scriptOrFolder); scriptOrFolder.addFileChangeListener(fcl); weakListen = fcl; } else { ChangeListener cl = WeakListeners.change(listen, storage); storage.addChangeListener(cl); weakListen = cl; } } }