Java Code Examples for org.openide.filesystems.FileUtil#weakFileChangeListener()

The following examples show how to use org.openide.filesystems.FileUtil#weakFileChangeListener() . 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: ProjectHelper.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void addCfgFileChangeListener(Project prj, 
        FileChangeListener l){
    
    FileObject fo = getFOForBindingConfigFile(prj);
    FileChangeListener fcl = null;
    if (fo != null) {
        fcl = FileUtil.weakFileChangeListener(l, fo);
        fo.addFileChangeListener(fcl);
    } else {
        fo = getFOForNBProjectDir(prj);
        if (fo != null) {
            fcl = FileUtil.weakFileChangeListener(l, fo);                
            fo.addFileChangeListener(fcl);
        }
    }
}
 
Example 2
Source File: TemplatesPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean acceptTemplate (FileObject fo) {
    if (fo.isFolder() &&
        (TEMPLATES_FOLDER+"/Properties").equals(fo.getPath())) {
        
        return false;
    }
    boolean attachListener;
    synchronized (filesWeListenOn) {
        attachListener = filesWeListenOn.add(fo);
    }
    if (attachListener) {
        FileChangeListener fileChangeListener = FileUtil.weakFileChangeListener(this, fo);
        fo.addFileChangeListener(fileChangeListener);
    }
    if (isTemplate (fo) || fo.isFolder()) {
        Object o = fo.getAttribute ("simple"); // NOI18N
        return o == null || Boolean.TRUE.equals (o);
    } else {
        return false;
    }
}
 
Example 3
Source File: MobileConfigurationsProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void update(FileEvent ev) {
    LOGGER.log(Level.FINEST, "Received {0}", ev);
    Set<String> oldConfigs = configs != null ? configs.keySet() : Collections.<String>emptySet();
    configDir = p.getProjectDirectory().getFileObject("nbproject/configs"); // NOI18N
    if (configDir != null) {
        if (fclWeakConfig != null) {
            configDir.removeFileChangeListener(fclWeakConfig);
        }
        fclWeakConfig = FileUtil.weakFileChangeListener(fcl, configDir);
        configDir.addFileChangeListener(fclWeakConfig);
        LOGGER.log(Level.FINEST, "(Re-)added listener to {0}", configDir);
    } else {
        LOGGER.log(Level.FINEST, "No nbproject/configs exists");
    }
    calculateConfigs();
    Set<String> newConfigs = configs.keySet();
    if (!oldConfigs.equals(newConfigs)) {
        LOGGER.log(Level.FINER, "Firing " + ProjectConfigurationProvider.PROP_CONFIGURATIONS + ": {0} -> {1}", new Object[]{oldConfigs, newConfigs});
        support.firePropertyChange(ProjectConfigurationProvider.PROP_CONFIGURATIONS, null, null);
    }
}
 
Example 4
Source File: PhpConfigurationProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public PhpConfigurationProvider(PhpProject project) {
    this.project = project;
    fclWeak = FileUtil.weakFileChangeListener(fcl, null);
    nbp = project.getProjectDirectory().getFileObject("nbproject"); // NOI18N

    if (nbp != null) {
        nbp.addFileChangeListener(fclWeak);
        LOGGER.log(Level.FINEST, "Added listener to {0}", nbp);
        configDir = nbp.getFileObject("configs"); // NOI18N

        if (configDir != null) {
            configDir.addFileChangeListener(fclWeak);
            LOGGER.log(Level.FINEST, "Added listener to {0}", configDir);
        }
    }
    project.getEvaluator().addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (PROP_CONFIG.equals(evt.getPropertyName())) {
                LOGGER.log(Level.FINER, "Refiring " + PROP_CONFIG + " -> " + ProjectConfigurationProvider.PROP_CONFIGURATION_ACTIVE);
                pcs.firePropertyChange(ProjectConfigurationProvider.PROP_CONFIGURATION_ACTIVE, null, null);
            }
        }
    });
}
 
Example 5
Source File: PackageViewChildren.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void run() {
    computeKeys();
    refreshKeys();
    try { 
        FileSystem fs = root.getFileSystem();
        wfcl = FileUtil.weakFileChangeListener(this, fs);
        fs.addFileChangeListener( wfcl );
    }
    catch ( FileStateInvalidException e ) {
        Exceptions.printStackTrace(e);
    }
    wvqcl = WeakListeners.change( this, VisibilityQuery.getDefault() );
    VisibilityQuery.getDefault().addChangeListener( wvqcl );
}
 
Example 6
Source File: ModuleNames.java    From netbeans with Apache License 2.0 5 votes vote down vote up
FileObjectCacheLine(
        @NonNull final URL artefact,
        @NullAllowed final String modName,
        @NonNull final FileObject file) {
    super(artefact, modName);
    this.file = file;
    this.wl = FileUtil.weakFileChangeListener(this, this.file);
    this.file.addFileChangeListener(this.wl);
}
 
Example 7
Source File: RecognizeInstanceFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private OverFiles(String path, List<FOItem> items, AbstractLookup lkp, AbstractLookup.Content cnt) {
    super(computeDelegates(path, items, lkp));
    this.path = path;
    this.lkp = lkp;
    this.content = cnt;
    this.content.setPairs(order(items));
    FileSystem fs = null;
    try {
        fs = FileUtil.getSystemConfigRoot().getFileSystem();
    } catch (FileStateInvalidException ex) {
        Exceptions.printStackTrace(ex);
    }
    this.weakL = FileUtil.weakFileChangeListener(this, fs);
    fs.addFileChangeListener(weakL);
}
 
Example 8
Source File: FileStateManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * @param mfo FileObject from default file system
 * @param layer the layer where notifier will be searched on
 * @return true if attached notifier is the delegate FO
 */
private synchronized boolean attachNotifier (FileObject mfo, int layer) {
    FileSystem fsLayer = getLayer (layer);
    String fn = mfo.getPath();
    FileObject fo = null;
    boolean isDelegate = true;

    if (fsLayer == null)
        return false;

    // find new notifier - the FileObject with closest match to getFile ()
    while (fn.length () > 0 && null == (fo = fsLayer.findResource (fn))) {
        int pos = fn.lastIndexOf ('/');
        isDelegate = false;

        if (-1 == pos)
            break;
        
        fn = fn.substring (0, pos);
    }
    
    if (fo == null)
        fo = fsLayer.getRoot ();

    if (fo != notifiers [layer]) {
        // remove listener from existing notifier if any
        if (notifiers [layer] != null)
            notifiers [layer].removeFileChangeListener (weakL [layer]);

        // create new listener and attach it to new notifier
        weakL [layer] = FileUtil.weakFileChangeListener (this, fo);
        fo.addFileChangeListener (weakL [layer]);
        notifiers [layer] = fo;
    }
    
    return isDelegate;
}
 
Example 9
Source File: MobileConfigurationsProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public MobileConfigurationsProvider(Project p) {
    this.p = p;
    this.nbProjectDir = p.getProjectDirectory().getFileObject("nbproject"); // NOI18N
    if (nbProjectDir != null) {
        fclWeakNB = FileUtil.weakFileChangeListener(fcl, nbProjectDir);
        nbProjectDir.addFileChangeListener(fclWeakNB);
        LOGGER.log(Level.FINEST, "Added listener to {0}", nbProjectDir);
        configDir = nbProjectDir.getFileObject("configs"); // NOI18N
        if (configDir != null) {
            fclWeakConfig = FileUtil.weakFileChangeListener(fcl, configDir);
            configDir.addFileChangeListener(fclWeakConfig);
            LOGGER.log(Level.FINEST, "Added listener to {0}", configDir);
        }
    }
}
 
Example 10
Source File: ProjectConfigurations.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public ConfigurationProviderImpl(
        @NonNull final Project p,
        @NonNull final PropertyEvaluator eval,
        @NonNull final UpdateHelper updateHelper,
        @NonNull final Set<String> configurationsAffectActions,
        @NullAllowed final Runnable customizerAction) {
    Parameters.notNull("p", p); //NOI18N
    Parameters.notNull("eval", eval);   //NOI18N
    Parameters.notNull("updateHelper", updateHelper);   //NOI18N
    Parameters.notNull("configurationsAffectActions", configurationsAffectActions); //NOI18N
    this.p = p;
    this.eval = eval;
    this.updateHelper = updateHelper;
    this.configurationsAffectActions = configurationsAffectActions;
    this.customizerAction = customizerAction;
    fclWeak = FileUtil.weakFileChangeListener(fcl, null);
    nbp = p.getProjectDirectory().getFileObject("nbproject"); // NOI18N
    if (nbp != null) {
        nbp.addFileChangeListener(fclWeak);
        LOGGER.log(Level.FINEST, "Added listener to {0}", nbp);
        configDir = nbp.getFileObject("configs"); // NOI18N
        if (configDir != null) {
            configDir.addFileChangeListener(fclWeak);
            LOGGER.log(Level.FINEST, "Added listener to {0}", configDir);
        }
    }
    eval.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(@NonNull final PropertyChangeEvent evt) {
            if (ProjectProperties.PROP_PROJECT_CONFIGURATION_CONFIG.equals(evt.getPropertyName())) {
                LOGGER.log(Level.FINER, "Refiring " + ProjectProperties.PROP_PROJECT_CONFIGURATION_CONFIG + " -> " + ProjectConfigurationProvider.PROP_CONFIGURATION_ACTIVE);
                Set<String> oldConfigs = configs != null ? configs.keySet() : Collections.<String>emptySet();
                calculateConfigs();
                Set<String> newConfigs = configs.keySet();
                if (!oldConfigs.equals(newConfigs)) {
                    LOGGER.log(Level.FINER, "Firing " + ProjectConfigurationProvider.PROP_CONFIGURATIONS + ": {0} -> {1}", new Object[] {oldConfigs, newConfigs});
                    pcs.firePropertyChange(ProjectConfigurationProvider.PROP_CONFIGURATIONS, null, null);
                }
                pcs.firePropertyChange(ProjectConfigurationProvider.PROP_CONFIGURATION_ACTIVE, null, null);
            }
        }
    });
}
 
Example 11
Source File: ModuleList.java    From netbeans with Apache License 2.0 4 votes vote down vote up
final void init() {
    weakListener = FileUtil.weakFileChangeListener(listener, folder);
    folder.getChildren();
    folder.addFileChangeListener(weakListener);
}
 
Example 12
Source File: BadgingSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public BadgingSupport(FileSystem fs) {
    this.fs = fs;
    fileChangeListener = FileUtil.weakFileChangeListener(this, null);
    fs.addFileChangeListener(fileChangeListener);
}
 
Example 13
Source File: AbstractFilesListener.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void addFileListenerTo(FileObject fo) {
    FileChangeListener l = FileUtil.weakFileChangeListener(listener, fo);
    fileListeners.put(fo, l);
    fo.addFileChangeListener(l);
    
}