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

The following are Jave code examples for showing how to use removeFileChangeListener() 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: BuildImageWizard.java   Source Code and License Vote up 6 votes
public synchronized void detach() {
    if (buildTask == null) {
        return;
    }

    FileObject fo = listener.getFileObject();

    fo.removeFileChangeListener(listener);
    DockerSupport.getDefault().removeChangeListener(listener);

    buildTask = null;
    listener = null;
    available = false;

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            setEnabled(false);
        }
    });
}
 
Example 2
Project: incubator-netbeans   File: LayersBridge.java   Source Code and License Vote up 6 votes
private void initActions (String folder, String category) {
    if (loadedFromFolders != null) {
        for (FileObject f : loadedFromFolders) {
            f.removeFileChangeListener(weakFolderL);
        }
    }
    FileObject fo = FileUtil.getConfigFile(folder);
    if (fo == null) return;
    DataFolder root = DataFolder.findFolder (fo);
    if (loadedFromFolders == null) {
        // the root must exist all the time, attach just once:
        root.getPrimaryFile().addFileChangeListener(weakFolderL);
    }
    Enumeration<DataObject> en = root.children ();
    Collection<FileObject> newFolders = new ArrayList<>(7);
    while (en.hasMoreElements ()) {
        DataObject dataObject = en.nextElement ();
        if (dataObject instanceof DataFolder) {
            initActions ((DataFolder) dataObject, null, category, newFolders);
        }
    }
    this.loadedFromFolders = newFolders;
}
 
Example 3
Project: incubator-netbeans   File: WatcherTest.java   Source Code and License Vote up 6 votes
public void testRemoveListenerFromAFileObj() throws Exception {
    File f = new File(new File(getWorkDir(), "dir"), "X.txt");
    final File pf = f.getParentFile();
    pf.mkdirs();
    f.createNewFile();
    
    FileObject fo = FileUtil.toFileObject(f);
    assertTrue("Is data", fo.isData());
    
    f.delete();
    pf.delete();
    FileObject parent = FileUtil.toFileObject(getWorkDir()).createData("dir");
    assertTrue("Also data", parent.isData());
    
    
    fo.removeFileChangeListener(new FileChangeAdapter());
}
 
Example 4
Project: incubator-netbeans   File: GrammarManager.java   Source Code and License Vote up 6 votes
/**
     * Notification from invalidator thread, the grammar need to be reloaded.
     */
    public synchronized void invalidateGrammar() {
        
        // make current loader a zombie
        if (state == VALID) {
            String msg = NbBundle.getMessage(GrammarManager.class, "MSG_loading_cancel");
            StatusDisplayer.getDefault().setStatusText(msg);
        }
        
        doc.removeDocumentListener(this);
        
        //remove FileChangeListeners from the external DTD files
        for(FileObject fo : externalDTDs) {
//            System.out.println("[GrammarManager] removed FileObjectListener from " + fo.getPath());
            fo.removeFileChangeListener(this);
        }
        externalDTDs.clear();
        
        guarded = new Position[0];
        state = INVALID;
    }
 
Example 5
Project: incubator-netbeans   File: ProjectServicesImpl.java   Source Code and License Vote up 5 votes
@Override
public synchronized boolean removeDeleteListener(DeleteListener l) {
    boolean removed = super.removeDeleteListener(l);
    if (removed && getDeleteListeners().isEmpty() && projectDeleteListener != null) {
        Project p = getProject(getURL());
        if (p != null) {
            FileObject projDir = p.getProjectDirectory();
            projDir.removeFileChangeListener(projectDeleteListener);
            projectDeleteListener = null;
        }
    }
    return removed;
}
 
Example 6
Project: incubator-netbeans   File: ProfilingPointsManager.java   Source Code and License Vote up 5 votes
private void removeFileWatch(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) {
            fileWatch.decreaseReferences();
            if (!fileWatch.hasReferences()) fileo.removeFileChangeListener(profilingPointsFiles.remove(file).getListener());
        }
    } else {
        profilingPointsFiles.remove(file);
    }
}
 
Example 7
Project: incubator-netbeans   File: ProjectHelper.java   Source Code and License Vote up 5 votes
public static void removeModelListner(Project prj, FileChangeListener l){
    // WeakChangeListener will return true for its proxy.
    FileObject fo = getFOForBindingConfigFile(prj);
    if (fo != null) {
        fo.removeFileChangeListener(l);
    }

    fo = getFOForNBProjectDir(prj);
    if (fo != null) {
        fo.removeFileChangeListener(l);
    }
}
 
Example 8
Project: incubator-netbeans   File: OtherRootNodeFactory.java   Source Code and License Vote up 5 votes
@Override
public void removeNotify() {
    NbMavenProject watch = project.getLookup().lookup(NbMavenProject.class);
    watch.removePropertyChangeListener(this);
    watch.removeWatchedPath(MAIN); //NOI18N
    watch.removeWatchedPath(TEST); //NOI18N            
    FileObject fo = project.getProjectDirectory().getFileObject(MAIN);
    if (fo != null) {
        fo.removeFileChangeListener(fcl);
    }
    fo = project.getProjectDirectory().getFileObject(TEST);
    if (fo != null) {
        fo.removeFileChangeListener(fcl);
    }
}
 
Example 9
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 10
Project: incubator-netbeans   File: FolderObjTest.java   Source Code and License Vote up 5 votes
public void testAsyncCall() throws Exception {
    final FileObject workDirFo = FileBasedFileSystem.getFileObject(getWorkDir());
    File f = new File(getWorkDir(), "a");
    assertNull(workDirFo.getFileObject("a"));
    assertTrue(f.createNewFile());
    final Thread t = Thread.currentThread();
    class FileChange extends FileChangeAdapter {
        private boolean called = false;
        @Override
        public void fileDataCreated(FileEvent fe) {
            assertNotSame(t, Thread.currentThread());
            called = true;
            synchronized (workDirFo) {
                workDirFo.notifyAll();
            }
        }
        public boolean isCalled() {
            return called;
        }            
    } 
    FileChange fcl = new FileChange();
    workDirFo.addFileChangeListener(fcl);
    try {
        assertNotNull(FileUtil.toFileObject(f));
        synchronized(workDirFo) {
            workDirFo.wait();
        }
        assertNotNull(workDirFo.getFileObject("a"));                
        assertTrue(fcl.isCalled());
    } finally {
        workDirFo.removeFileChangeListener(fcl);
    }
}
 
Example 11
Project: incubator-netbeans   File: JSLineBreakpoint.java   Source Code and License Vote up 5 votes
@Override
protected void dispose() {
    super.dispose();
    line.dispose();
    FileObject fileObject = line.getFileObject();
    if( fileObject != null ){
        fileObject.removeFileChangeListener( myWeakListener );
        myWeakListener = null;
    }
}
 
Example 12
Project: incubator-netbeans   File: MatchingObject.java   Source Code and License Vote up 4 votes
/**
 * Refresh the node, use information from a {@link Def} instance.
 */
public void refresh(Def def) {
    refreshed = true; // ignore result set timestamp
    this.charset = def.getCharset();
    FileObject origFileObject = fileObject;
    this.fileObject = def.getFileObject();
    this.textDetails = def.getTextDetails();

    dataObject = dataObject();
    timestamp = fileObject.lastModified().getTime();
    valid = (timestamp != 0L);

    if (dataObject == null) {
        return;
    }
    if (fileObject != origFileObject) {
        if (fileListener != null) {
            origFileObject.removeFileChangeListener(fileListener);
        }
        setUpDataObjValidityChecking();
    }
    nodeDelegate = dataObject.getNodeDelegate();

    Mutex.EVENT.writeAccess(new Runnable() {

        @Override
        public void run() {
            int origSelectedMatches = selectedMatchesCount;
            selectedMatchesCount = 0;
            if (textDetails != null && !textDetails.isEmpty()) {
                adjustTextDetails();
            }

            changeSupport.firePropertyChange(PROP_MATCHES_SELECTED,
                    origSelectedMatches, selectedMatchesCount);
            if (matchesCount > 0) {
                setSelected(true);
            }
            InvalidityStatus origInvStat = invalidityStatus;
            invalidityStatus = null;
            changeSupport.firePropertyChange(PROP_INVALIDITY_STATUS,
                    origInvStat,
                    invalidityStatus);
        }
    });
}
 
Example 13
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 14
Project: incubator-netbeans   File: BaseFileObjectTestHid.java   Source Code and License Vote up 4 votes
@RandomlyFails // NB-Core-Build #7927 (from FileBasedFileSystemWithUninitializedExtensionsTest): Didn't receive a FileEvent on the parent.
public void testEventsAfterCreatedFiles55550() throws Exception {
    FileObject parent = root.getFileObject("testdir/mountdir8");  
    assertNotNull(parent);
    assertTrue(parent.isFolder());
    parent.getChildren();
    
    File parentFile = FileUtil.toFile(parent);
    assertNotNull(parentFile);
    assertTrue(parentFile.getAbsolutePath(),parentFile.exists());
    File newFile = new File(parentFile, "sun-web.xml");
    assertFalse(newFile.getAbsolutePath(),newFile.exists());
                    
    class FCLImpl extends FileChangeAdapter {
        boolean created;
        @Override
        public void fileDataCreated(FileEvent e) {
            created = true;
            synchronized(BaseFileObjectTestHid.this) {
                BaseFileObjectTestHid.this.notifyAll();
            }
        }
    }        
    FCLImpl fl = new FCLImpl();        
    parent.addFileChangeListener(fl);
    
    assertTrue(newFile.getAbsolutePath(), newFile.createNewFile());
    assertTrue(newFile.exists());
    
    // !!!! This is the source of the problem !!!
    // ask for the new file
    // remove this line ans the test passes
    FileUtil.toFileObject(newFile);
    
    
    parent.refresh();
    synchronized(this) {
        wait(1000);
    }
    parent.removeFileChangeListener(fl);
    assertTrue("Didn't receive a FileEvent on the parent.", fl.created);
}
 
Example 15
Project: incubator-netbeans   File: WatcherTest.java   Source Code and License Vote up 4 votes
public void testAddRemoveOnData() throws IOException {
    FileObject root = FileUtil.toFileObject(getWorkDir());
    FileObject folder = root.createFolder("dir");
    FileObject data = root.createData("data.txt");
    
    notify.assertRegistered("No registered paths yet");
    
    data.addFileChangeListener(listener);
    root.addFileChangeListener(listener);
    
    notify.assertRegistered("One path is being listened to", root.getPath());
    
    data.removeFileChangeListener(listener);

    notify.assertRegistered("Still one path is being listened to", root.getPath());
    
    root.removeFileChangeListener(listener);
    
    notify.assertRegistered("Path has been cleared", (String)null);
}
 
Example 16
Project: incubator-netbeans   File: WatcherTest.java   Source Code and License Vote up 4 votes
public void testAddRemoveOnData2() throws IOException {
    FileObject root = FileUtil.toFileObject(getWorkDir());
    FileObject folder = root.createFolder("dir");
    FileObject data = root.createData("data.txt");
    
    notify.assertRegistered("No registered paths yet");
    
    data.addFileChangeListener(listener);
    root.addFileChangeListener(listener);
    
    notify.assertRegistered("One path is being listened to", root.getPath());
    
    root.removeFileChangeListener(listener);

    notify.assertRegistered("Still one path is being listened to", root.getPath());
    
    data.removeFileChangeListener(listener);
    
    notify.assertRegistered("Path has been cleared", (String)null);
}
 
Example 17
Project: incubator-netbeans   File: PropertiesFileEntry.java   Source Code and License Vote up 4 votes
private void detachListener () {
    FileObject fo = getFile();
    fo.removeFileChangeListener(weakList);
    weakList = null;
}
 
Example 18
Project: incubator-netbeans   File: RulesManager.java   Source Code and License Vote up 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 19
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);
}