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

The following examples show how to use org.openide.filesystems.FileObject#removeFileChangeListener() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   File: GrammarManager.java    License: 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 2
Source Project: netbeans   File: LayersBridge.java    License: 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 3
Source Project: editorconfig-netbeans   File: ListenerAttacher.java    License: 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 4
Source Project: netbeans   File: WatcherTest.java    License: 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 5
Source Project: netbeans   File: BuildImageWizard.java    License: 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 6
Source Project: netbeans   File: InstallOrActivateTask.java    License: 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 7
Source Project: netbeans   File: ServiceModel.java    License: 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 8
Source Project: netbeans   File: ProjectHelper.java    License: 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 9
Source Project: netbeans   File: OtherRootNodeFactory.java    License: 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 10
Source Project: netbeans   File: JSLineBreakpoint.java    License: 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 11
Source Project: netbeans   File: LineBreakpoint.java    License: 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 Project: netbeans   File: ProfilingPointsManager.java    License: 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 13
private void checkFileObject(String path) {
    FileObject fo = project.getProjectDirectory().getFileObject(path);
    if (fo != null) {
        fo.removeFileChangeListener(changeListener);
        fo.addFileChangeListener(changeListener);
    }
}
 
Example 14
Source Project: netbeans   File: PropertiesFileEntry.java    License: Apache License 2.0 4 votes vote down vote up
private void detachListener () {
    FileObject fo = getFile();
    fo.removeFileChangeListener(weakList);
    weakList = null;
}
 
Example 15
Source Project: netbeans   File: BaseFileObjectTestHid.java    License: 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 16
Source Project: netbeans   File: WatcherTest.java    License: 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 17
Source Project: netbeans   File: BadgingSupport.java    License: 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 18
private void removeListener(String rootPath) {
    FileObject fo = project.getProjectDirectory().getFileObject(rootPath);
    if (fo != null) {
        fo.removeFileChangeListener(changeListener);
    }
}
 
Example 19
Source Project: netbeans   File: JspDataObject.java    License: 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 Project: netbeans   File: WatcherTest.java    License: 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);
}