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

The following examples show how to use org.openide.filesystems.FileSystem#addFileStatusListener() . 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: PackageRootNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private PackageRootNode( SourceGroup group, Children ch) {
    super(ch, new ProxyLookup(createLookup(group), Lookups.singleton(
            SearchInfoDefinitionFactory.createSearchInfoBySubnodes(ch))));
    this.group = group;
    file = group.getRootFolder();
    files = Collections.singleton(file);
    try {
        FileSystem fs = file.getFileSystem();
        fileSystemListener = FileUtil.weakFileStatusListener(this, fs);
        fs.addFileStatusListener(fileSystemListener);
    } catch (FileStateInvalidException e) {            
        Exceptions.printStackTrace(Exceptions.attachMessage(e,"Can not get " + file + " filesystem, ignoring...")); //NOI18N
    }
    setName( group.getName() );
    setDisplayName( group.getDisplayName() );        
    // setIconBase("org/netbeans/modules/java/j2seproject/ui/resources/packageRoot");
}
 
Example 2
Source File: MultiModuleNodeFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void updateFileStatusListeners() {
    final Collection<FileSystem> fileSystems = new HashSet<>();
    for (FileObject fo : getFileObjects()) {
        try {
            fileSystems.add(fo.getFileSystem());
        } catch (FileStateInvalidException e) {
            LOG.log(
                    Level.WARNING,
                    "Ignoring invalid file: {0}",   //NOI18N
                    FileUtil.getFileDisplayName(fo));
        }
    }
    synchronized (this) {
        for (Pair<FileSystem,FileStatusListener> p : fsListensOn) {
            p.first().removeFileStatusListener(p.second());
        }
        final List<Pair<FileSystem,FileStatusListener>> newFsListensOn = new ArrayList<>();
        for (FileSystem fs : fileSystems) {
            FileStatusListener l = FileUtil.weakFileStatusListener(this, fs);
            fs.addFileStatusListener(l);
            newFsListensOn.add(Pair.of(fs,l));
        }
        fsListensOn = newFsListensOn;
    }
}
 
Example 3
Source File: BIEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void addStatusListener(FileSystem fs) {
    FileStatusListener fsl = fsToStatusListener.get(fs);
    if (fsl == null) {
        fsl = new FileStatusListener() {
            @Override
            public void annotationChanged(FileStatusEvent ev) {
                synchronized (opened) {
                    Iterator<BIEditorSupport> iter = opened.iterator();
                    while (iter.hasNext()) {
                        BIEditorSupport fes = iter.next();
                        if (ev.hasChanged(fes.getDataObject().getPrimaryFile())) {
                            fes.updateMVTCName();
                        }
                    }
                }
            }
        };
        fs.addFileStatusListener(fsl);
        fsToStatusListener.put(fs, fsl);
    } // else do nothing - the listener is already added
}
 
Example 4
Source File: FormEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void addStatusListener(FileSystem fs) {
    FileStatusListener fsl = fsToStatusListener.get(fs);
    if (fsl == null) {
        fsl = new FileStatusListener() {
            @Override
            public void annotationChanged(FileStatusEvent ev) {
                synchronized (opened) {
                    Iterator<FormEditorSupport> iter = opened.iterator();
                    while (iter.hasNext()) {
                        FormEditorSupport fes = iter.next();
                        if (ev.hasChanged(fes.getFormDataObject().getPrimaryFile())
                                || ev.hasChanged(fes.getFormDataObject().getFormFile())) {
                            fes.updateMVTCDisplayName();
                        }
                    }
                }
            }
        };
        fs.addFileStatusListener(fsl);
        fsToStatusListener.put(fs, fsl);
    } // else do nothing - the listener is already added
}
 
Example 5
Source File: ProjectsRootNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected final void setFiles(Set<FileObject> files) {
    if (fileSystemListeners != null) {
        for (Map.Entry<FileSystem, FileStatusListener> entry : fileSystemListeners.entrySet()) {
            entry.getKey().removeFileStatusListener(entry.getValue());
        }
    }

    fileSystemListeners = new HashMap<FileSystem, FileStatusListener>();
    this.files = files;

    Set<FileSystem> hookedFileSystems = new HashSet<FileSystem>();
    for (FileObject fo : files) {
        try {
            FileSystem fs = fo.getFileSystem();
            if (hookedFileSystems.contains(fs)) {
                continue;
            }
            hookedFileSystems.add(fs);
            FileStatusListener fsl = FileUtil.weakFileStatusListener(this, fs);
            fs.addFileStatusListener(fsl);
            fileSystemListeners.put(fs, fsl);
        } catch (FileStateInvalidException e) {
            LOG.log(Level.INFO, "Cannot get " + fo + " filesystem, ignoring...", e); // NOI18N
        }
    }
}
 
Example 6
Source File: PropertiesEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 */
private void attachStatusListener() {
    if (fsStatusListener != null) {
        return;                 //already attached
    }
    
    FileSystem fs;
    try {
        fs = myEntry.getFile().getFileSystem();
    } catch (FileStateInvalidException ex) {
        ErrorManager.getDefault().notify(ErrorManager.ERROR, ex);
        return;
    }
    
    fsStatusListener = new FsStatusListener();
    fs.addFileStatusListener(
            FileUtil.weakFileStatusListener(fsStatusListener, fs));
}
 
Example 7
Source File: PropertiesLocaleNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates a new PropertiesLocaleNode for the given locale-specific file */
public PropertiesLocaleNode (PropertiesFileEntry fe) {
    super(fe, fe.getChildren());
    setDisplayName(Util.getLocaleLabel(fe));

    setIconBaseWithExtension(LOCALE_ICON_BASE);        
    setShortDescription(messageToolTip());

    // the node uses lookup based on CookieSet from PropertiesFileEntry
    CookieSet cookieSet = fe.getCookieSet();
    cookieSet.add(PropertiesOpen.class, this);
    cookieSet.add(fe);
    cookieSet.add(fe.getDataObject());
    cookieSet.add(this);

    fsStatusListener = new FSListener();
    try {
        FileSystem fs = fe.getFile().getFileSystem();
        fs.addFileStatusListener(FileUtil.weakFileStatusListener(fsStatusListener, fs));
    } catch (FileStateInvalidException ex) {
    }
}
 
Example 8
Source File: AnnotatedNode.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
protected final void setFiles(final Set<FileObject> files) {
    fileSystemListeners = new HashSet<FileStatusListener>();
    this.files = files;
    if (files == null) {
        return;
    }
    Set<FileSystem> hookedFileSystems = new HashSet<FileSystem>();
    for (FileObject fo : files) {
        try {
            FileSystem fs = fo.getFileSystem();
            if (hookedFileSystems.contains(fs)) {
                continue;
            }
            hookedFileSystems.add(fs);
            FileStatusListener fsl = FileUtil.weakFileStatusListener(this, fs);
            fs.addFileStatusListener(fsl);
            fileSystemListeners.add(fsl);
        } catch (FileStateInvalidException e) {
            ErrorManager err = ErrorManager.getDefault();
            err.annotate(e, "Cannot get " + fo + " filesystem, ignoring...");  // NOI18N
            err.notify(ErrorManager.INFORMATIONAL, e);
        }
    }
}