org.openide.filesystems.FileEvent Java Examples

The following examples show how to use org.openide.filesystems.FileEvent. 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: ProjectProperties.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void diskChange(FileEvent fe) {
    boolean writing = false;
    if (fe != null) {
        synchronized (saveActions) {
            for (AtomicAction a : saveActions) {
                if (fe.firedFrom(a)) {
                    writing = true;
                    break;
                }
            }
        }
    }
    if (!writing) {
        loaded = false;
        reloadedStackTrace = new Throwable("noticed disk change here");
    }
    fireChange();
    if (!writing) {
        helper.fireExternalChange(path);
    }
}
 
Example #2
Source File: FolderObjTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Test of delete method, of class org.netbeans.modules.masterfs.filebasedfs.fileobjects.FolderObj.
 */
public void testDelete() throws IOException {
    File f = testFile;
    
    FileObject testFo = FileBasedFileSystem.getFileObject(testFile);
    assertNotNull(testFo);
    
    final List<FileEvent> l = new ArrayList<FileEvent>();
    FileChangeListener fcl = new FileChangeAdapter () {
        @Override
        public void fileDeleted(FileEvent fe) {
            l.add(fe);
        }            
    };
    FileObject fo = FileUtil.createData(testFo, "delete/the/whole/structure/in/depth/todelete.txt");
    fo.addFileChangeListener(fcl);
    
    FileObject toDelete = testFo.getFileObject("delete");        
    assertNotNull(toDelete);
    toDelete.addFileChangeListener(fcl);

    FileObject toGC = testFo.getFileObject("delete/the/whole/structure");
    assertNotNull(toGC);
    Reference<FileObject> toGCRef = new WeakReference<FileObject>(toGC);
    toGC.addFileChangeListener(fcl);
    toGC = null;
    
    assertGC("", toGCRef);
    toDelete.delete();
    assertEquals(0,testFo.getChildren().length);
    toDelete = testFo.getFileObject("delete");        
    assertNull(toDelete);        
    assertEquals(2, l.size());
}
 
Example #3
Source File: RemotePlatformProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private RemotePlatformProvider(@NonNull final XMLDataObject store) {
    Parameters.notNull("store", store); //NOI18N
    this.store = store;
    this.store.getPrimaryFile().addFileChangeListener(new FileChangeAdapter(){
        @Override
        public void fileDeleted(@NonNull final FileEvent fe) {
            final String systemName = fe.getFile().getName();
            try {
                ProjectManager.mutex().writeAccess( new Mutex.ExceptionAction<Void> () {
                    @Override
                    public Void run () throws IOException {
                        final String propPrefix =  String.format("platforms.%s.", systemName);   //NOI18N
                        boolean changed = false;
                        final EditableProperties props = PropertyUtils.getGlobalProperties();
                        for (Iterator<String> it = props.keySet().iterator(); it.hasNext(); ) {
                            final String key = it.next ();
                            if (key.startsWith(propPrefix)) {
                                it.remove();
                                changed =true;
                            }
                        }
                        if (changed) {
                            PropertyUtils.putGlobalProperties(props);
                        }
                        return null;
                    }
                });
            } catch (MutexException e) {
                Exceptions.printStackTrace(e);
            }
            ConnectionMethod.Authentification.clear(systemName);
        }
    });
    final InstanceContent c = new InstanceContent();
    c.add(Node.class, this);
    c.add(this);
    this.lkp = new AbstractLookup(c);
    task = RP.create(this);
}
 
Example #4
Source File: FileChangeListener.java    From editorconfig-netbeans with MIT License 5 votes vote down vote up
private boolean isCandidateForProcessing(FileEvent event) {
  FileObject file = event.getFile();

  boolean applyRules = false;
  boolean isntFolder = !file.isFolder();
  boolean isUnexpected = !event.isExpected();
  boolean isntSkipped = !SmartSkip.skipDirectory(file);

  if (isUnexpected && isntFolder && isntSkipped) {
    applyRules = true;
  }

  return applyRules;
}
 
Example #5
Source File: NbMavenProjectImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
        public void fileChanged(FileEvent fileEvent) {
                if (lastTime < fileEvent.getTime()) {
                    lastTime = System.currentTimeMillis();
//                    System.out.println("fired based on " + fileEvent.getFile() + fileEvent.getTime());
                    NbMavenProject.fireMavenProjectReload(NbMavenProjectImpl.this);
                }
        }
 
Example #6
Source File: ModuleClassPaths.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void fileDeleted(FileEvent fe) {
    final ClasspathInfo info = ClasspathInfo.create(
        ClassPath.EMPTY,
        ClassPath.EMPTY,
        sources);
    final Set<ElementHandle<ModuleElement>> mods = info.getClassIndex().getDeclaredModules(
            "", //NOI18N
            ClassIndex.NameKind.PREFIX,
            EnumSet.of(ClassIndex.SearchScope.SOURCE));
    if (mods.isEmpty()) {
        resetOutsideWriteAccess(null, PROP_RESOURCES);
    }
}
 
Example #7
Source File: DefaultDataLoadersBridge.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void handleInvalidDataObject(DataObject invalidDO) {
    invalidDO.removePropertyChangeListener(wlistener);
    if (fobj.isValid()) {
        // file object still exists try to find new data object
        try {
            dobj = DataObject.find(fobj);
            dobj.addPropertyChangeListener(wlistener);
            flisten.fileChanged(new FileEvent(fobj));
        } catch (IOException ex) {
            // should not occur
            LOG.log(Level.SEVERE, ex.getMessage(), ex);
        }
    }
}
 
Example #8
Source File: AbstractFilesListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void fileChanged(FileEvent e) {
    FileObject fo = e.getFile();
    if (isTarget(fo)) {
        fo.refresh(true);
        targetChanged(fo);
    }
}
 
Example #9
Source File: PhpProject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void fileChanged(FileEvent fe) {
    FileObject file = fe.getFile();
    if (!isVisible(file)) {
        return;
    }
    browserReload(file);
    processChange(file);
}
 
Example #10
Source File: LayerUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void changed(FileEvent fe) {
    //System.err.println("changed on disk in " + Thread.currentThread().getName() + " for " + this);
    //Thread.dumpStack();
    synchronized (this) {
        if (fe.firedFrom(this)) {
            //System.err.println("(my own change)");
            return;
        }
        problem = null;
        dirty = false;
        root = null;
    }
    pcs.firePropertyChange(PROP_DOCUMENT_ROOT, null, null);
}
 
Example #11
Source File: WebProject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void fileChanged(FileEvent fe) {
    checkPreprocessors(fe.getFile());
    try {
        if (!handleResource(fe)) {
            handleCopyFileToDestDir(fe.getFile());
        }
    } catch (IOException e) {
        LOGGER.log(Level.INFO, null, e);
    }
}
 
Example #12
Source File: NativeExecutionBaseTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void register(String eventKind, FileEvent fe) {
    String src = stripPrefix(((FileObject) fe.getSource()).getPath());
    String obj = stripPrefix(fe.getFile().getPath());
    String exp = checkExpected ? ("exp=" + Boolean.toString(fe.isExpected())) : "";
    String extra = "";
    if (fe instanceof FileRenameEvent) {
        FileRenameEvent fre = (FileRenameEvent) fe;
        extra = "oldName="+fre.getName()+" oldExt="+fre.getExt();
    }
    out.printf("%-20s: %-20s SRC %-20s OBJ %-20s %s %s\n", listenerName, eventKind, src, obj, exp, extra);
}
 
Example #13
Source File: CopyResourcesOnSave.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void fileDeletedImpl(final FileEvent fe) {
    Project owning = getOwningMavenProject(fe.getFile());
    if (owning == null) {
        return;
    }
    try {
        handleDeleteFileInDestDir(fe.getFile(), null, owning);
    } catch (IOException ex) {
        LOG.log(Level.INFO, null, ex);
    }
}
 
Example #14
Source File: CompoundFolderChildren.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void fileFolderCreated(FileEvent fe) {
    fe.runWhenDeliveryOver(rebuildRunnable);
}
 
Example #15
Source File: ConfigurationFiles.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void fileDeleted(FileEvent fe) {
    fireChange();
}
 
Example #16
Source File: GraphTopComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void fileDeleted(FileEvent fe) {
    reset();
}
 
Example #17
Source File: GrailsCommandSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void fileFolderCreated(FileEvent fe) {
    changed();
}
 
Example #18
Source File: SystemFileSystem.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void fileChanged(FileEvent fe) {
    log("fileChanged", fe); // NOI18N
}
 
Example #19
Source File: RecognizeInstanceObjects.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void fileDataCreated(FileEvent fe) {
    ch(fe);
}
 
Example #20
Source File: SystemFileSystemTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void fileDataCreated(FileEvent fe) {
    events.add(fe);
}
 
Example #21
Source File: FileUtilAddRecursiveListenerStopTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void fileDeleted(FileEvent fe) {
    LOG.log(Level.INFO, "fileDeleted: {0}", fe.getFile());
    LOG.log(Level.INFO, "Thread dump", new Exception());
    events.add(fe);
}
 
Example #22
Source File: AutomaticModuleNameCompilerOptionsQueryImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void fileDeleted(FileEvent fe) {
    if (filter.contains(Op.FILE_DELETED)) {
        action.run();
    }
}
 
Example #23
Source File: UnitTestsCompilerOptionsQueryImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void fileDataCreated(FileEvent fe) {
    reset();
}
 
Example #24
Source File: WarDeploymentConfiguration.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void fileDeleted(FileEvent fe) {
    fireChange();
}
 
Example #25
Source File: ModuleClassPaths.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void fileFolderCreated(FileEvent fe) {
}
 
Example #26
Source File: ExternalTouchTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testChangeInChildrenNoticed() throws Exception {
    long lm = System.currentTimeMillis();
    FileObject fileObject1 = testFolder.createData("fileObject1");
    assertNotNull("Just to initialize the stamp", lm);
    FileObject[] arr = testFolder.getChildren();
    assertEquals("One child", 1, arr.length);
    assertEquals("Right child", fileObject1, arr[0]);

    File file = FileUtil.toFile(fileObject1);
    assertNotNull("File found", file);
    Reference<FileObject> ref = new WeakReference<FileObject>(fileObject1);
    arr = null;
    fileObject1 = null;
    assertGC("File Object can disappear", ref);


    class L extends FileChangeAdapter {
        int cnt;
        FileEvent event;
        
        @Override
        public void fileChanged(FileEvent fe) {
            LOG.info("file change " + fe.getFile());
            cnt++;
            event = fe;
        }
    }
    L listener = new L();
    testFolder.addRecursiveListener(listener);

    Thread.sleep(1000);

    FileOutputStream os = new FileOutputStream(file);
    os.write(10);
    os.close();

    if (lm > file.lastModified() - 50) {
        fail("New modification time shall be at last 50ms after the original one: " + (file.lastModified() - lm));
    }

    testFolder.refresh();

    assertEquals("Change notified", 1, listener.cnt);
    assertEquals("Right file", file, FileUtil.toFile(listener.event.getFile()));
    assertEquals("Right source", file.getParentFile(), FileUtil.toFile((FileObject)listener.event.getSource()));
}
 
Example #27
Source File: CopySupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void fileDeleted(FileEvent fe) {
    copySupport.fileDeleted(fe);
}
 
Example #28
Source File: JAXBWizModelImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void fileDeleted(FileEvent fe) {
    refreshNodes();
}
 
Example #29
Source File: ProjectChangeListener.java    From editorconfig-netbeans with MIT License 4 votes vote down vote up
@Override
public void fileFolderCreated(FileEvent event) {
  super.fileFolderCreated(event);
  LOG.log(Level.INFO, "Created folder: {0}", event.getFile().getPath());
  ListenerAttacher.attachListeners(event.getFile(), project);
}
 
Example #30
Source File: ModuleInfoAccessibilityQueryImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void fileFolderCreated(FileEvent fe) {
    //Not important
}