Java Code Examples for org.openide.filesystems.FileObject.addFileChangeListener()

The following are Jave code examples for showing how to use addFileChangeListener() of the org.openide.filesystems.FileObject class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: AnnotationTypesFolder.java   Source Code and License Vote up 6 votes
/** Creates new AnnotationTypesFolder */
private AnnotationTypesFolder(FileObject fo, DataFolder fld) {
    super(fld);
    recreate();
    instanceFinished();
    
    // add listener on changes in annotation types folder
    fo.addFileChangeListener(new FileChangeAdapter() {
        public void fileDeleted(FileEvent fe) {
            AnnotationType type;
            for (Iterator it = AnnotationTypes.getTypes().getAnnotationTypeNames(); it.hasNext(); ) {
                type = AnnotationTypes.getTypes().getType((String)it.next());
                if ( type != null && ((FileObject)type.getProp(AnnotationType.PROP_FILE)).equals(fe.getFile()) ) {
                    AnnotationTypes.getTypes().removeType(type.getName());
                    break;
                }
            }
        }
    });
    
}
 
Example 2
Project: incubator-netbeans   File: NbEditorToolBar.java   Source Code and License Vote up 6 votes
/** See issue #57773 for details. Toolbar should be updated with possible changes after
   module install/uninstall */
private void installModulesInstallationListener(){
    moduleRegListener = new FileChangeAdapter() {
        public @Override void fileChanged(FileEvent fe) {
            //some module installed/uninstalled. Refresh toolbar content
            Runnable r = new Runnable() {
                public void run() {
                    if (isToolbarVisible()) {
                        checkPresentersRemoved();
                        checkPresentersAdded();                                
                    }
                }
             };
            Utilities.runInEventDispatchThread(r);
        }
    };

    FileObject moduleRegistry = FileUtil.getConfigFile("Modules"); //NOI18N

    if (moduleRegistry !=null){
        moduleRegistry.addFileChangeListener(
            FileUtil.weakFileChangeListener(moduleRegListener, moduleRegistry));
    }
}
 
Example 3
Project: incubator-netbeans   File: WatcherTest.java   Source Code and License Vote up 6 votes
public void testGarbageCollectListener() throws Exception {
    FileObject root = FileUtil.toFileObject(getWorkDir());
    FileObject folder = root.createFolder("dir");
    
    notify.assertRegistered("No registered paths yet");
    
    root.addFileChangeListener(listener);
    
    notify.assertRegistered("One path is being listened to", root.getPath());
    
    Reference<FileObject> ref = new WeakReference<FileObject>(root);
    root = null;
    folder = null;
    assertGC("Root can be GCed", ref);

    watcher.clearQueue();
    notify.assertRegistered("Path has been cleared", (String)null);
}
 
Example 4
Project: incubator-netbeans   File: TemplatesPanel.java   Source Code and License Vote up 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 5
Project: incubator-netbeans   File: TargetExecutor.java   Source Code and License Vote up 5 votes
public RerunAction(TargetExecutor prototype, boolean withModifications) {
    this.withModifications = withModifications;
    reinit(prototype);
    setEnabledEQ(this, false); // initially, until ready
    FileObject script = pcookie.getFileObject();
    if (script != null) {
        script.addFileChangeListener(FileUtil.weakFileChangeListener(this, script));
    }
}
 
Example 6
Project: incubator-netbeans   File: ProfilingPointsManager.java   Source Code and License Vote up 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 7
Project: incubator-netbeans   File: ImportantFilesNodeFactory.java   Source Code and License Vote up 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
Project: incubator-netbeans   File: EditorSettingsImpl.java   Source Code and License Vote up 5 votes
@Override
public synchronized void fileFolderCreated(FileEvent fe) {
    FileObject f = fe.getFile();
    if (keymapFolder == null && KEYMAPS_FOLDER.equals(f.getNameExt()) && f.getParent() == FileUtil.getConfigRoot()) {
        // keymap folder is created -> start listening on it
        keymapFolder = f;
        f.addFileChangeListener(this);
    }
}
 
Example 9
Project: incubator-netbeans   File: BuildImageWizard.java   Source Code and License Vote up 5 votes
public synchronized void attach(BuildTask buildTask) {
    FileObject fo = buildTask.getDockerfile();

    this.buildTask = buildTask;
    this.listener = new ActionStateListener(this, buildTask.getInstance(), fo);

    fo.addFileChangeListener(listener);
    DockerSupport.getDefault().addChangeListener(listener);

    listener.refresh();
}
 
Example 10
Project: incubator-netbeans   File: OtherRootNodeFactory.java   Source Code and License Vote up 5 votes
private void checkFileObject(String path) {
    FileObject fo = project.getProjectDirectory().getFileObject(path);
    if (fo != null) {
        fo.removeFileChangeListener(fcl);
        fo.addFileChangeListener(fcl);
    }
}
 
Example 11
Project: incubator-netbeans   File: FieldLNCache.java   Source Code and License Vote up 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 12
Project: incubator-netbeans   File: EditorSettingsImpl.java   Source Code and License Vote up 5 votes
public KeymapProfileTracker(FileObject keymapFolder) {
    this.keymapFolder = keymapFolder;
    if (keymapFolder != null) {
        keymapFolder.addFileChangeListener(this);
    } else {
        FileUtil.getConfigRoot().addFileChangeListener(this);
    }
}
 
Example 13
Project: incubator-netbeans   File: JSLineBreakpoint.java   Source Code and License Vote up 5 votes
public JSLineBreakpoint(EditorLineHandler 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 );
    }
}
 
Example 14
Project: incubator-netbeans   File: HtmlDataObject.java   Source Code and License Vote up 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 15
Project: incubator-netbeans   File: JSLineBreakpoint.java   Source Code and License Vote up 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 16
Project: incubator-netbeans   File: JPAProblemFinder.java   Source Code and License Vote up 4 votes
private void createPersistenceScopesListener(FileObject file, Document doc){
    if (doc == null){
        return;
    }
    
    LOG.fine("Creating PersistenceScopesListener on " + file.getName());
    Project project = FileOwnerQuery.getOwner(file);
    
    if (project != null){
        ClassPath cp = ClassPath.getClassPath(file, ClassPath.SOURCE);
        PersistenceScopes scopes = PersistenceScopes.getPersistenceScopes(project, cp != null ? cp.findOwnerRoot(file) : null);
        
        if (scopes != null){
            PersistenceScopesListener listener = (PersistenceScopesListener) doc.getProperty(PERSISTENCE_SCOPES_LISTENER);
            
            if (listener == null){
                listener = new PersistenceScopesListener(file);
                PropertyChangeListener weakListener = WeakListeners.create(PropertyChangeListener.class, listener, null);
                scopes.addPropertyChangeListener(weakListener);
                
                // scopes listener should live as long as the document
                doc.putProperty(PERSISTENCE_SCOPES_LISTENER, listener);
            }
            
            ArrayList<PersistenceXMLListener> pxmlListeners = new ArrayList<PersistenceXMLListener>();
            
            for (PersistenceScope scope : scopes.getPersistenceScopes()){
                FileObject persistenceXML = scope.getPersistenceXml();
                if(persistenceXML!=null){//persistence xml may be deleted/renamed
                    PersistenceXMLListener pxmlListener = new PersistenceXMLListener(file);
                    FileChangeListener weakPXMLListener = WeakListeners.create(FileChangeListener.class, pxmlListener, null);
                    persistenceXML.addFileChangeListener(weakPXMLListener);
                    pxmlListeners.add(pxmlListener);
                    LOG.fine("Added PersistenceXMLListener to " + persistenceXML.getName());
                }
            }
            
            // persistence.xml listeners should live as long as the scopes listener
            listener.setPXMLListeners(pxmlListeners);
        }
    }
}
 
Example 17
Project: incubator-netbeans   File: PropertiesEncoding.java   Source Code and License Vote up 4 votes
PropCharset(FileObject file) throws FileStateInvalidException {
    super(PROP_CHARSET_NAME, null);                     //NOI18N
    fileRef = new WeakReference<FileObject>(file);
    file.addFileChangeListener(this);
    updateURL(file);
}
 
Example 18
Project: incubator-netbeans   File: BinaryCacheManagerTest.java   Source Code and License Vote up 4 votes
public void testFastReplacement() throws Exception {
    clearWorkDir();
    LayerCacheManager m = new BinaryCacheManager();
    // layer2.xml should override layer1.xml where necessary:
    List<URL> urls = new ArrayList<URL>(Arrays.asList(
        loadResource("data/layer2.xml"),
        loadResource("data/layer1.xml")));
    
    FileSystem f = store(m, urls);
    FileSystem base = FileUtil.createMemoryFileSystem();
    FileUtil.createData(base.getRoot(), "baz/thongy");
    final MFS mfs = new MFS(new FileSystem[] {base, f});
    FileObject baz = mfs.findResource("baz");
    assertNotNull(baz);
    assertEquals(2, baz.getChildren().length);
    FileObject thingy = mfs.findResource("baz/thingy");
    assertNotNull(thingy);
    L l = new L();
    baz.addFileChangeListener(l);
    //L l2 = new L();mfs.addFileChangeListener(l2);
    urls.remove(0);
    f = store(m, urls);
    final FileSystem[] fss = {base, f};
    mfs.runAtomicAction(new FileSystem.AtomicAction() {
        public void run() {
            mfs._setDelegates(fss);
        }
    });
    assertEquals(2, baz.getChildren().length);
    assertTrue(thingy.isValid());
    assertEquals(0, l.ac);
    assertEquals(0, l.c);
    assertEquals(0, l.dc);
    assertEquals(0, l.d);
    assertEquals(0, l.fc);
    assertEquals(0, l.r);
    urls.remove(0);
    f = store(m, urls);
    final FileSystem[] fss2 = new FileSystem[] {base, f};
    mfs.runAtomicAction(new FileSystem.AtomicAction() {
        public void run() {
            mfs._setDelegates(fss2);
        }
    });
    assertEquals(1, baz.getChildren().length);
    assertFalse(thingy.isValid());
    assertEquals(0, l.ac);
    assertEquals(0, l.c);
    assertEquals(0, l.dc);
    assertEquals(1, l.d);
    assertEquals(0, l.fc);
    assertEquals(0, l.r);
}
 
Example 19
Project: incubator-netbeans   File: FolderObjTest.java   Source Code and License Vote up 4 votes
public void testRefreshDoesNotMultiplyFileObjects_89059 () throws Exception {
    FileObject fo = FileBasedFileSystem.getFileObject(testFile);
    fo.getChildren();
    FileSystem fs = fo.getFileSystem();
    FileChangeListener fcl = new FileChangeAdapter();
    OutputStream os = null;
    fs.addFileChangeListener(fcl);
    fo.addFileChangeListener(fcl);
    try {
        //no change
        int foInstancesInCache = Statistics.fileObjects();
        fs.refresh(false);
        assertTrue(foInstancesInCache >= Statistics.fileObjects());

        //internal change
        File ff = new File(testFile,"a/b/c/d/aa.txt");//NOI18N
        FileUtil.createData(ff);
        foInstancesInCache = Statistics.fileObjects();
        fs.refresh(false);
        assertTrue(foInstancesInCache >= Statistics.fileObjects());

        //external change
        FileObject ffObject = FileBasedFileSystem.getFileObject(ff);
        foInstancesInCache = Statistics.fileObjects();
        os = new java.io.FileOutputStream(ff);
        os.write("dsdopsdsd".getBytes());//NOI18N
        os.close();
        fs.refresh(false);
        assertTrue(foInstancesInCache >= Statistics.fileObjects());

        assertTrue(new File(testFile,"nfile").createNewFile());//NOI18N
        fs.refresh(false);
        fo.refresh(false);
        assertTrue(foInstancesInCache+1 >= Statistics.fileObjects());

        foInstancesInCache = Statistics.fileObjects();
        assertTrue(new File(testFile,"aa/bb/cc").mkdirs());//NOI18N
        fs.refresh(false);
        fo.refresh(false);
        assertTrue(foInstancesInCache+3 >= Statistics.fileObjects());
    } finally {
        if (os != null) {
            os.close();
        }
        fs.removeFileChangeListener(fcl);
        fo.removeFileChangeListener(fcl);
    }
}
 
Example 20
Project: incubator-netbeans   File: WatcherTest.java   Source Code and License Vote up 3 votes
public void testAddRemoveListener() throws IOException {
    FileObject root = FileUtil.toFileObject(getWorkDir());
    FileObject folder = root.createFolder("dir");
    
    notify.assertRegistered("No registered paths yet");
    
    root.addFileChangeListener(listener);
    
    notify.assertRegistered("One path is being listened to", root.getPath());
    
    root.removeFileChangeListener(listener);
    
    notify.assertRegistered("Path has been cleared", (String)null);
}