当前位置: 首页>>代码示例>>Java>>正文


Java FileUtil.addFileChangeListener方法代码示例

本文整理汇总了Java中org.openide.filesystems.FileUtil.addFileChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.addFileChangeListener方法的具体用法?Java FileUtil.addFileChangeListener怎么用?Java FileUtil.addFileChangeListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openide.filesystems.FileUtil的用法示例。


在下文中一共展示了FileUtil.addFileChangeListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: CachingArchive

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public CachingArchive(
        @NonNull final File archiveFile,
        @NullAllowed final String pathToRootInArchive,
        final boolean keepOpened) {
    Parameters.notNull("archiveFile", archiveFile); //NOI18N
    if (pathToRootInArchive != null) {
        if (!keepOpened) {
            throw new UnsupportedOperationException(String.format(
                "FastJar not supported for relocated root of archive %s, relocation %s",    //NOI18N
                archiveFile.getAbsolutePath(),
                pathToRootInArchive));
        }
        if (pathToRootInArchive.charAt(pathToRootInArchive.length()-1) != FileObjects.NBFS_SEPARATOR_CHAR) {
            throw new IllegalArgumentException(String.format(
                "Path to root: %s has to end with /",   //NOI18N
                pathToRootInArchive));
        }
    }
    this.archiveFile = archiveFile;
    this.pathToRootInArchive = pathToRootInArchive;
    this.keepOpened = keepOpened;

    FileUtil.addFileChangeListener(this, FileUtil.normalizeFile(archiveFile));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:CachingArchive.java

示例2: getJarMetadataCoordinatesIntern

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private List<Coordinates> getJarMetadataCoordinatesIntern(File binaryFile) {        
    if (binaryFile == null || !binaryFile.exists() || !binaryFile.isFile()) {
        return null;
    }        
    synchronized (coorCache) {
        List<Coordinates> toRet = coorCache.get(binaryFile);
        if(toRet == null) {
            toRet = getJarMetadataCoordinates(binaryFile);         
            if(toRet != null) {
                FileUtil.addFileChangeListener(binaryChangeListener, binaryFile);
                coorCache.put(binaryFile, toRet);
            }                
        } 
        return toRet;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:RepositoryForBinaryQueryImpl.java

示例3: DualLayers

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
DualLayers(FileSystem explicit) {
    this.explicit = explicit;
    NbModuleProvider nbmp = project.getLookup().lookup(NbModuleProvider.class);
    File clazz = nbmp != null ? nbmp.getClassesDirectory() : null;
    if (clazz != null) {
        generated = new File(clazz, ManifestManager.GENERATED_LAYER_PATH);
        FileUtil.addFileChangeListener(this, generated);
    } else {
        generated = null;
    }
    configure();
    setPropagateMasks(true);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:LayerHandle.java

示例4: computeModuleIfAbsent

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
@CheckForNull
private String computeModuleIfAbsent(
        @NonNull FileObject root,
        @NonNull final Function<FileObject,String> provider) {
    final Pair<Pair<Reference<FileObject>,File>,String> entry = modNameCache.get();
    FileObject owner;
    String modName;
    if (entry == null ||
            (owner = entry.first().first().get()) == null ||
            !owner.equals(root)) {
        modName = provider.apply(root);
        final File modInfo = Optional.ofNullable(FileUtil.toFile(root))
                .map((rf) -> new File(rf, String.format("%s.%s", FileObjects.MODULE_INFO, FileObjects.JAVA)))   //NOI18N
                .orElse(null);
        final Pair<Pair<Reference<FileObject>,File>,String> newEntry = Pair.of(
                Pair.of(new WeakReference<>(root), modInfo),
                modName);
        if (modNameCache.compareAndSet(entry, newEntry)) {
            if (entry != null && entry.first().second() != null) {
                FileUtil.removeFileChangeListener(this, entry.first().second());
            }
            if (newEntry.first().second() != null) {
                FileUtil.addFileChangeListener(this, newEntry.first().second());
            }
        }
        LOG.log(Level.FINE, "modNameCache updated: {0}", modName);  //NOI18N
    } else {
        modName = entry.second();
    }
    return modName;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:ModuleOraculum.java

示例5: changePersistenceScope

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
/**
 * Call this method in order to change the persistence scope returned by the
 * <code>PersistenceScopes</code> instance returned by {@link #getPersistenceScopes}
 * or the corresponding persistence.xml file.
 *
 * @param  newPersistenceScope the new persistence scope; can be null, but in this case
 *         the <code>newPersistenceXml</code> parameter must be null too.
 * @param  newPersistenceXml the new persistence.xml file; can be null.
 *
 * @throws IllegalArgumentException if <code>newPersistenceScope</code> is null
 *         and <code>newPersistenceXml</code> is not.
 */
public void changePersistenceScope(PersistenceScope newPersistenceScope, File newPersistenceXml) {
    if (newPersistenceScope == null && newPersistenceXml != null) {
        throw new IllegalArgumentException("The persistenceScope parameter cannot be null when newPersistenceXml is non-null"); // NOI18N
    }

    boolean oldPersistenceExists, newPersistenceExists;
    PersistenceScope oldPersistenceScope;

    synchronized (this) {
        oldPersistenceExists = persistenceExists;
        oldPersistenceScope = persistenceScope;

        LOG.fine("changePersistenceScope: newPersistenceXml=" + newPersistenceXml); // NOI18N

        if (persistenceXml != null) {
            FileUtil.removeFileChangeListener(fileChangeListener, persistenceXml);
        }
        if (newPersistenceXml != null) {
            persistenceXml = newPersistenceXml;
            FileUtil.addFileChangeListener(fileChangeListener, persistenceXml);
        } else {
            persistenceXml = null;
        }

        persistenceScope = newPersistenceScope;
        persistenceXml = newPersistenceXml;

        change();

        newPersistenceExists = persistenceExists;

        LOG.fine("changePersistenceScope: oldPersistenceExists=" + oldPersistenceExists + ", newPersistenceExists=" + newPersistenceExists); // NOI18N
    }

    if (oldPersistenceExists != newPersistenceExists || (oldPersistenceScope != newPersistenceScope && newPersistenceExists)) {
        LOG.fine("changePersistenceScope: firing PROP_PERSISTENCE_SCOPES change"); // NOI18N
        propChangeSupport.firePropertyChange(PersistenceScopes.PROP_PERSISTENCE_SCOPES, null, null);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:52,代码来源:PersistenceScopesHelper.java

示例6: ModuleInfoSupport

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public ModuleInfoSupport(NbMavenProjectImpl project, DependencyType type) {
    this.project = project;
    this.type = type;        
    
    Collection<String> roots = getRoots(project.getOriginalMavenProject(), type);
    for (String root : roots) {
        FileUtil.addFileChangeListener(moduleInfoListener, new File(root));
    }        
    moduleInfo = getModuleInfo(roots);
    if(moduleInfo != null) {
        populateDeclaredModules(moduleInfo);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:ModuleInfoSupport.java

示例7: addMissingArtifact

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
/**
 * Note an artifact whose absence in the local repository is implicated among the problems.
 * Note that some problems are not caused by missing artifacts,
 * and some problems encapsulate several missing artifacts.
 * @param a an artifact (scope permitted but ignored)
 */
void addMissingArtifact(Artifact a) {
    synchronized (reports) {
        a = EmbedderFactory.getProjectEmbedder().getLocalRepository().find(a);
        //a.getFile should be already normalized but the find() method can pull tricks on us.
        //#225008
        File f = FileUtil.normalizeFile(a.getFile());
        if (missingArtifacts.add(f)) {                
            LOG.log(Level.FINE, "listening to {0} from {1}", new Object[] {f, projectPOMFile});                
            FileUtil.addFileChangeListener(fcl, f);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ProblemReporterImpl.java

示例8: LP

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
LP(ProjectLibraryArea area) {
    this.area = area;
    libraries = calculate(area);
    Definitions defs = new Definitions(area.mainPropertiesFile);
    FileUtil.addFileChangeListener(this, defs.mainPropertiesFile);
    FileUtil.addFileChangeListener(this, defs.privatePropertiesFile);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:ProjectLibraryProvider.java

示例9: safeAddFileChangeListener

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private void safeAddFileChangeListener(@NonNull final File file) {
    try {
        FileUtil.addFileChangeListener(this, file);
    } catch (IllegalArgumentException iae) {
        LOG.log(Level.FINE, iae.getMessage());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:ClassPath.java

示例10: initListeners

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private void initListeners() {
    if (listens.compareAndSet(false, true)) {
        final JavaPlatformManager jpm = JavaPlatformManager.getDefault();
        jpm.addPropertyChangeListener(WeakListeners.propertyChange(
            this,
            jpm));
        J2SEProject j2sePrj = project.getLookup().lookup(J2SEProject.class);
        if (j2sePrj != null) {
            j2sePrj.evaluator().addPropertyChangeListener(this);
        } else {
            LOG.log(
               Level.WARNING,
               "No property evaluator provider in project {0}({1})", //NOI18N
               new Object[]{
                   ProjectUtils.getInformation(project).getDisplayName(),
                   FileUtil.getFileDisplayName(project.getProjectDirectory())
               });
        }

        final FileObject projectFolder = project.getProjectDirectory();
        if (projectFolder != null) {
            final File projectDir = FileUtil.toFile(projectFolder);
            if (projectDir != null) {
                final File cfgDir = new File(projectDir, CFG_PATH);   //NOI18N
                FileUtil.addFileChangeListener(this, cfgDir);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:RuntimePlatformProblemsProvider.java

示例11: addPropertyChangeListener

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public void addPropertyChangeListener(@NonNull final PropertyChangeListener listener) {
    Parameters.notNull("listener", listener);   //NOI18N
    if (!state.compareAndSet(0, 1)) {
        throw new IllegalStateException("Already in state: " + state.get());    //NOI18N
    }
    support.addPropertyChangeListener(listener);
    for (File f : listensOn) {
        FileUtil.addFileChangeListener(this, f);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:LibrariesNode.java

示例12: add

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public void add(File f, boolean moduleRoot) {
    if (moduleRoot) {
        if (!moduleRoots.contains(f)) {
            moduleRoots.add(f);
            FileUtil.addFileChangeListener(this, f);
        }
    } else {
        if (!files.contains(f)) {
            files.add(f);
            FileUtil.addFileChangeListener(this, f);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:SourceRoots.java

示例13: safeAddFileListener

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private static void safeAddFileListener(
        @NonNull final File file,
        @NonNull final FileChangeListener listener) {
    try {
        FileUtil.addFileChangeListener(listener, file);
    } catch (IllegalArgumentException e) {
        LOG.log(
                Level.WARNING,
                "Cannot add listener to: {0}",      //NOI18N
                file);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:MultiModuleUnitTestsCompilerOptionsQueryImpl.java

示例14: isModular

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private boolean isModular(final FileObject javaFile) {
    //Module-info always modular
    if (MODULE_INFO.equals(javaFile.getName())) {
        return true;
    }
    //Try to find module-info
    final Pair<Reference<FileObject>,Reference<FileObject>> entry = rootCache.get();
    FileObject file, root;
    if (entry == null ||
            (file = entry.first().get()) == null || !file.equals(javaFile) ||
            (root = entry.second().get()) == null) {
        root = Optional.ofNullable(ClassPath.getClassPath(javaFile, ClassPath.SOURCE))
                .map((scp) -> scp.findOwnerRoot(javaFile))
                .orElseGet(() -> {
                    final String pkg = parsePackage(javaFile);
                    final String[] pkgElements = pkg.isEmpty() ?
                            new String[0] :
                            pkg.split("\\.");   //NOI18N
                    FileObject owner = javaFile.getParent();
                    for (int i = 0; owner != null && i < pkgElements.length; i++) {
                        owner = owner.getParent();
                    }
                    return owner;
                });
        rootCache.set(Pair.of(
                new WeakReference<>(javaFile),
                new WeakReference<>(root)));
        LOG.log(Level.FINE, "rootCache updated: {0}", root);  //NOI18N
    }
    if (root == null) {
        return false;
    }
    final Pair<Pair<Reference<FileObject>,File>,Boolean> modEntry = modCache.get();
    FileObject meKye;
    if (modEntry == null ||
            (meKye = modEntry.first().first().get()) == null || !meKye.equals(root)) {
        final FileObject modInfo = root.getFileObject(MODULE_INFO, JAVA_EXT);
        final boolean res =  modInfo != null && modInfo.isData();
        final Pair<Pair<Reference<FileObject>,File>,Boolean> newModEntry = Pair.of(
                Pair.of(new WeakReference<>(root), FileUtil.toFile(root)),
                res);
        if (modCache.compareAndSet(modEntry, newModEntry)) {
            if (modEntry != null && modEntry.first().second() != null) {
                FileUtil.removeFileChangeListener(this, modEntry.first().second());
            }
            if (newModEntry != null && newModEntry.first().second() != null) {
                FileUtil.addFileChangeListener(this, newModEntry.first().second());
            }
            LOG.log(Level.FINE, "modCache updated: {0}", res);  //NOI18N
        }
        return res;
    } else {
        return modEntry.second();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:56,代码来源:DefaultSourceLevelQueryImpl.java

示例15: testAddFileChangeListenerFolder

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
/** Tests FileChangeListener on folder. As declared in
 * {@link FileUtil#addFileChangeListener(org.openide.filesystems.FileChangeListener, java.io.File) }
 * - fileFolderCreated event is fired when the folder is created or a child folder created
 * - fileDataCreated event is fired when a child file is created
 * - fileDeleted event is fired when the folder is deleted or a child file/folder removed
 * - fileChanged event is fired when a child file is modified
 * - fileRenamed event is fired when the folder is renamed or a child file/folder is renamed
 * - fileAttributeChanged is fired when FileObject's attribute is changed
 */
public void testAddFileChangeListenerFolder() throws IOException {
    clearWorkDir();
    // test files: dir/file1, dir/subdir/subfile
    File rootF = getWorkDir();
    File dirF = new File(rootF, "dir");
    TestFileChangeListener fcl = new TestFileChangeListener();
    FileUtil.addFileChangeListener(fcl, dirF);
    // create dir
    FileObject dirFO = FileUtil.createFolder(dirF);
    assertEquals("Event not fired when folder created.", 1, fcl.check(EventType.FOLDER_CREATED));
    FileObject subdirFO = dirFO.createFolder("subdir");
    assertEquals("Event not fired when sub folder created.", 1, fcl.check(EventType.FOLDER_CREATED));

    // create file
    FileObject file1FO = dirFO.createData("file1");
    assertEquals("Event not fired when data created.", 1, fcl.check(EventType.DATA_CREATED));
    FileObject subfileFO = subdirFO.createData("subfile");
    assertEquals("Event fired when data in sub folder created.", 0, fcl.checkAll());

    // modify
    file1FO.getOutputStream().close();
    assertEquals("fileChanged event not fired.", 1, fcl.check(EventType.CHANGED));
    subfileFO.getOutputStream().close();
    assertEquals("Event fired when file sub folder modified.", 0, fcl.checkAll());

    // delete
    file1FO.delete();
    assertEquals("Event not fired when child file deleted.", 1, fcl.check(EventType.DELETED));
    subfileFO.delete();
    assertEquals("Event fired when child file in sub folder deleted.", 0, fcl.checkAll());
    subdirFO.delete();
    assertEquals("Event not fired when sub folder deleted.", 1, fcl.check(EventType.DELETED));
    dirFO.delete();
    assertEquals("Event not fired when folder deleted.", 1, fcl.check(EventType.DELETED));

    // rename
    dirFO = FileUtil.createFolder(dirF);
    file1FO = dirFO.createData("file1");
    subdirFO = dirFO.createFolder("subdir");
    subfileFO = subdirFO.createData("subfile");
    fcl.checkAll();
    FileLock lock = file1FO.lock();
    file1FO.rename(lock, "file1Renamed", null);
    lock.releaseLock();
    assertEquals("Event not fired when child file renamed.", 1, fcl.check(EventType.RENAMED));
    lock = subfileFO.lock();
    subfileFO.rename(lock, "subfileRenamed", null);
    lock.releaseLock();
    assertEquals("Event fired when child file in sub folder renamed.", 0, fcl.check(EventType.RENAMED));
    lock = subdirFO.lock();
    subdirFO.rename(lock, "subdirRenamed", null);
    lock.releaseLock();
    assertEquals("Event not fired when sub folder renamed.", 1, fcl.check(EventType.RENAMED));
    lock = dirFO.lock();
    dirFO.rename(lock, "dirRenamed", null);
    lock.releaseLock();
    assertEquals("Event not fired when sub folder renamed.", 1, fcl.check(EventType.RENAMED));
    fcl.printAll();
    assertEquals("No other events should be fired.", 0, fcl.checkAll());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:70,代码来源:FileUtilTest.java


注:本文中的org.openide.filesystems.FileUtil.addFileChangeListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。