Java Code Examples for org.openide.filesystems.FileSystem#removeFileChangeListener()

The following examples show how to use org.openide.filesystems.FileSystem#removeFileChangeListener() . 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: FolderObjTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testRefresh69744() throws Exception {
    File thisTest = new File(getWorkDir(),"thisTest");
    thisTest.createNewFile();
    FileObject testf = FileBasedFileSystem.getFileObject(thisTest);
    assertNotNull(testf);
    assertGC("",new WeakReference<FileObject>(testf.getParent()));
    modifyFileObject(testf, "abc");
    FileSystem fs = testf.getFileSystem();
    final List<FileEvent> l = new ArrayList<FileEvent>();
    FileChangeListener fcl = new FileChangeAdapter() {
        @Override
        public void fileChanged(FileEvent fe) {
            l.add(fe);
        }
    };
    Thread.sleep(1500);
    fs.addFileChangeListener(fcl);
    try {
        modifyFileObject(testf, "def");
        assertFalse(l.isEmpty());
    } finally {
        fs.removeFileChangeListener(fcl);
    }
}
 
Example 2
Source File: PageFlowController.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Unregister any listeners.
 */
public void unregisterListeners() {

    if (pcl != null) {
        if (configModel != null) {
            configModel.removePropertyChangeListener(pcl);
        }
        pcl = null;
    }

    FileObject myWebFolder = getWebFolder();
    if (fcl != null && myWebFolder != null) {
        try {
            FileSystem fileSystem = myWebFolder.getFileSystem();
            fileSystem.removeFileChangeListener(fcl);
            fcl = null;
        } catch (FileStateInvalidException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}
 
Example 3
Source File: FolderObjTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testRefresh109490() throws Exception {
    final File wDir = getWorkDir();
    final FileObject wDirFo = FileBasedFileSystem.getFileObject(wDir);
    final List<FileEvent> fileEvents = new ArrayList<FileEvent>();
    FileSystem fs = wDirFo.getFileSystem();
    FileChangeListener fListener = new FileChangeAdapter() {

        @Override
        public void fileDataCreated(FileEvent fe) {
            super.fileDataCreated(fe);
            fileEvents.add(fe);
        }
    };
    try {
        fs.addFileChangeListener(fListener);

        File file = new File(wDir, "testao.f");
        File file2 = new File(wDir, "testc1.f");
        assertEquals(file.hashCode(), file2.hashCode());
        wDirFo.getChildren();
        assertTrue(file.createNewFile());
        assertTrue(file2.createNewFile());
        assertEquals(0, fileEvents.size());
        fs.refresh(true);
        assertEquals(2, fileEvents.size());
        assertEquals(Arrays.asList(wDirFo.getChildren()).toString(), 2,wDirFo.getChildren().length);
        assertTrue(Arrays.asList(wDirFo.getChildren()).toString().indexOf(file.getName()) != -1);            
        assertTrue(Arrays.asList(wDirFo.getChildren()).toString().indexOf(file2.getName()) != -1);                        
    } finally {
        fs.removeFileChangeListener(fListener);
    }
}
 
Example 4
Source File: BaseFileObjectTestHid.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testRefresh109490() throws Exception {
    final File wDir = new File(getWorkDir(), getName());
    wDir.mkdir();
    final FileObject wDirFo = FileUtil.toFileObject(wDir);
    final List<FileEvent> fileEvents = new ArrayList<FileEvent>();
    FileSystem fs = wDirFo.getFileSystem();
    FileChangeListener fListener = new FileChangeAdapter(){
        @Override
            public void fileDataCreated(FileEvent fe) {
                super.fileDataCreated(fe);
                fileEvents.add(fe);
            }            
        };
    try {
        fs.refresh(true); // catch and skip changes made in VCS metadata, they are not part of this test
        fs.addFileChangeListener(fListener);

        File file = new File(wDir, "testao.f");
        File file2 = new File(wDir, "testc1.f");
        assertEquals(file.hashCode(), file2.hashCode());
        wDirFo.getChildren();
        assertTrue(file.createNewFile());
        assertTrue(file2.createNewFile());
        assertEquals(0, fileEvents.size());
        fs.refresh(true);
        assertEquals(2, fileEvents.size());
        assertEquals(Arrays.asList(wDirFo.getChildren()).toString(), 2,wDirFo.getChildren().length);
        assertTrue(Arrays.asList(wDirFo.getChildren()).toString().indexOf(file.getName()) != -1);            
        assertTrue(Arrays.asList(wDirFo.getChildren()).toString().indexOf(file2.getName()) != -1);                        
        
    } finally {
        fs.removeFileChangeListener(fListener);
    }
}
 
Example 5
Source File: EjbJarMultiViewDataObject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void refreshSourceFolders() {
    SourceGroup[] groups;
    Project project = getProject();
    if (project != null) {
        Sources sources = ProjectUtils.getSources(project);
        groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    } else {
        groups = null;
    }
    if (groups != null) {
        synchronized(srcRoots) {
            srcRoots.clear();
            for (int i = 0; i < groups.length; i++) {
                org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbModule = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(groups[i].getRootFolder());
                if ((ejbModule != null) && (ejbModule.getDeploymentDescriptor() != null)) {
                    try {
                        FileObject fo = groups[i].getRootFolder();
                        srcRoots.add(fo);
                        FileSystem fs = fo.getFileSystem();
                        fs.removeFileChangeListener(this); //avoid being added multiple times
                        fs.addFileChangeListener(this);
                    } catch (FileStateInvalidException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
            }
            initialized = true;
        }
    }
}
 
Example 6
Source File: EarDataObject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void refreshSourceFolders () {
    ArrayList srcRootList = new ArrayList ();
    
    Project project = FileOwnerQuery.getOwner (getPrimaryFile ());
    if (project != null) {
        Sources sources = ProjectUtils.getSources(project);
        sources.removeChangeListener (this);
        sources.addChangeListener (this);
        SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        for (int i = 0; i < groups.length; i++) {
            org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbModule = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(groups[i].getRootFolder());

            if (ejbModule != null && ejbModule.getDeploymentDescriptor() != null) {
                try {
                    FileObject fo = groups[i].getRootFolder();

                    srcRootList.add(groups[i].getRootFolder());
                    FileSystem fs = fo.getFileSystem();

                    fs.removeFileChangeListener(this);
                    fs.addFileChangeListener(this);
                } catch (FileStateInvalidException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        }
    }
    srcRoots = (FileObject []) srcRootList.toArray (new FileObject [srcRootList.size ()]);
}
 
Example 7
Source File: DeleteCreateTestAnnotationProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void reset() {
    Set filesystems = getRootFilesystems();
    for (Iterator i = filesystems.iterator(); i.hasNext();) {
        FileSystem fileSystem = (FileSystem) i.next();
        fileSystem.removeFileChangeListener(interceptor);
    }
    events.clear();
}
 
Example 8
Source File: TestAnnotationProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void reset() {
    Set filesystems = getRootFilesystems();
    for (Iterator i = filesystems.iterator(); i.hasNext();) {
        FileSystem fileSystem = (FileSystem) i.next();
        fileSystem.removeFileChangeListener(interceptor);
    }
    events.clear();
}
 
Example 9
Source File: DeleteCreateTestAnnotationProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void reset() {
    Set filesystems = getRootFilesystems();
    for (Iterator i = filesystems.iterator(); i.hasNext();) {
        FileSystem fileSystem = (FileSystem) i.next();
        fileSystem.removeFileChangeListener(interceptor);
    }
    events.clear();
}
 
Example 10
Source File: FolderObjTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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);
    }
}