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

The following examples show how to use org.openide.filesystems.FileObject#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: ServiceModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public synchronized void removeServiceChangeListener(ServiceChangeListener pcl) {
    serviceChangeListeners.remove(pcl);
    if (serviceChangeListeners.size()==0) {
        implementationClass.removeFileChangeListener(fcl);
        if ( getEndpointInterface() != null ){
            String endpoint = getEndpointInterface();
            ClassPath sourceCP = ClassPath.getClassPath(implementationClass, 
                    ClassPath.SOURCE);
            FileObject endpointFo = sourceCP.findResource(
                    endpoint.replace('.', '/')+".java"); //NOI18N
            if ( endpointFo != null ){
                endpointFo.removeFileChangeListener(fcl);
            }
        }
    }
}
 
Example 2
Source File: GrammarManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
     * 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 3
Source File: LayersBridge.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 4
Source File: ListenerAttacher.java    From editorconfig-netbeans with MIT License 6 votes vote down vote up
public static void removeListeners(FileObject file, Project project) {
  if (project.getProjectDirectory().equals(file)) {
    file.removeRecursiveListener(LISTENER_REGISTRY.get(file));
  }

  if (file.isFolder()) {
    if (SmartSkip.skipDirectory(file)) {
      LOG.log(Level.INFO, "\u00ac Skipped directory: {0}", file.getPath());
    } else {
      for (FileObject child : file.getChildren()) {
        removeListeners(child, project);
      }
    }
  } else {
    if (file.getExt().equals(EXTENSION) || file.getName().equals(DEFAULT_FILE_NAME)) {
      file.removeFileChangeListener(LISTENER_REGISTRY.get(file));
      LOG.log(Level.INFO, "\u00ac Found EditorConfig: {0}", file.getPath());
    } else {
      LOG.log(Level.FINE, "\u00ac No EditorConfig Found: {0}", file.getPath());
    }
  }
}
 
Example 5
Source File: InstallOrActivateTask.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void run() {
    FileObject fo = FileUtil.getConfigFile("Modules"); // NOI18N
    try {
        if (fo != null) {
            fo.addFileChangeListener(this);
        }
        if (installer != null) {
            installer.installMissingModules();
        }
        if (activator != null) {
            activator.enableModules();
        }
    } finally {
        if (fo != null) {
            fo.removeFileChangeListener(this);
            FeatureManager.associateFiles(getChangedFiles());
        }
        notifyUpdates();
    }
}
 
Example 6
Source File: BuildImageWizard.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 7
Source File: WatcherTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 8
Source File: OtherRootNodeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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
Source File: GroovySourcesNodeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void checkFileObject(String path) {
    FileObject fo = project.getProjectDirectory().getFileObject(path);
    if (fo != null) {
        fo.removeFileChangeListener(changeListener);
        fo.addFileChangeListener(changeListener);
    }
}
 
Example 10
Source File: ProfilingPointsManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 11
Source File: LineBreakpoint.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void removed() {
    FileObject fileObject = getLine().getLookup().lookup(FileObject.class);
    if (fileObject != null) {
        fileObject.removeFileChangeListener(myWeakListener);
    }
}
 
Example 12
Source File: JSLineBreakpoint.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void dispose() {
    super.dispose();
    line.dispose();
    FileObject fileObject = line.getFileObject();
    if( fileObject != null ){
        fileObject.removeFileChangeListener( myWeakListener );
        myWeakListener = null;
    }
}
 
Example 13
Source File: ProjectHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 14
Source File: BaseFileObjectTestHid.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@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
Source File: WatcherTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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 16
Source File: BadgingSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static String annotateNameGeneral(String name, Set<? extends FileObject> files,
        String suffix, FileChangeListener fileChangeListener, Set<FileObject> toFire) {
    for (FileObject fo : files) {
        // #168446: try <attr name="displayName" bundlevalue="Bundle#key"/> first
        String bundleKey = (String) fo.getAttribute("literal:displayName"); // NOI18N
        String bundleName;
        if (bundleKey != null) {
            String[] arr = bundleKey.split(":", 2); // NOI18N
            if (arr[0].equals("bundle")) { // NOI18N
                // bundlevalue
                arr = arr[1].split("#", 2);    // NOI18N
                bundleName = arr[0];
                bundleKey = arr[1];
            } else {
                // stringvalue
                return bundleKey;
            }
        } else {
            bundleName = (String) fo.getAttribute("SystemFileSystem.localizingBundle"); // NOI18N
            bundleKey = fo.getPath();
        }
        if (bundleName != null) {
            try {
                URL[] u = LayerUtils.currentify(LayerUtils.urlForBundle(bundleName), suffix, classpathForFile(fo));
                for (int i = 0; i < u.length; i++) {
                InputStream is = u[i].openStream();
                try {
                    Properties p = new Properties();
                    p.load(is);
                    String val = p.getProperty(bundleKey);
                    if (fileChangeListener != null) {
                    // Listen to changes in the origin file if any...
                    FileObject ufo = URLMapper.findFileObject(u[i]);
                    if (ufo != null) {
                        ufo.removeFileChangeListener(fileChangeListener);
                        ufo.addFileChangeListener(fileChangeListener);
                        // In case a sibling bundle is added, that may be relevant:
                        ufo.getParent().removeFileChangeListener(fileChangeListener);
                        ufo.getParent().addFileChangeListener(fileChangeListener);
                    }
                    }
                    if (val != null) {
                        if (fo.getPath().matches("(Menu|Toolbars)/.+")) { // NOI18N
                            // Special-case these folders to trim the mnemonics, since they are ugly.
                            return Actions.cutAmpersand(val);
                        } else {
                            return val;
                        }
                    }
                    // if null, fine--normal for key to not be found
                } finally {
                    is.close();
                }
                }
            } catch (IOException ioe) {
                // For debugging; SFS will rather notify a problem separately...
                Util.err.notify(ErrorManager.INFORMATIONAL, ioe);
                return NbBundle.getMessage(BadgingSupport.class, "LBL_no_such_bundle", name, bundleName);
            }
        }
        if (fo.hasExt("instance")) { // NOI18N
            return getInstanceLabel(fo);
        }
        if (fo.hasExt("shadow")) { // NOI18N
            Object originalFile = fo.getAttribute("originalFile"); // NOI18N
            if (originalFile != null && originalFile instanceof String) {
                FileObject orig;
                try {
                    orig = fo.getFileSystem().findResource((String) originalFile);
                } catch (FileStateInvalidException e) {
                    orig = null;
                }
                if (orig != null && orig.hasExt("instance")) { // NOI18N
                    if (toFire != null) {
                        toFire.add(orig);
                    }
                    return annotateNameGeneral((String) originalFile, Collections.singleton(orig), suffix, fileChangeListener, toFire);
                }
            }
        }
    }
    return name;
}
 
Example 17
Source File: PropertiesFileEntry.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void detachListener () {
    FileObject fo = getFile();
    fo.removeFileChangeListener(weakList);
    weakList = null;
}
 
Example 18
Source File: GroovySourcesNodeFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void removeListener(String rootPath) {
    FileObject fo = project.getProjectDirectory().getFileObject(rootPath);
    if (fo != null) {
        fo.removeFileChangeListener(changeListener);
    }
}
 
Example 19
Source File: JspDataObject.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void unregister(FileObject fo) {
    FileChangeListener listener = (FileChangeListener) weakListener.get();
    if (listener != null) {
        fo.removeFileChangeListener(listener);
    }
}
 
Example 20
Source File: WatcherTest.java    From netbeans with Apache License 2.0 3 votes vote down vote up
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);
}