Java Code Examples for org.openide.filesystems.FileEvent

The following examples show how to use org.openide.filesystems.FileEvent. 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 check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   Source File: ProjectProperties.java    License: 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 Project: netbeans   Source File: FolderObjTest.java    License: 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 Project: netbeans   Source File: PhpProject.java    License: 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 4
Source Project: netbeans   Source File: RemotePlatformProvider.java    License: 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 5
Source Project: netbeans   Source File: DefaultDataLoadersBridge.java    License: 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 6
Source Project: netbeans   Source File: AbstractFilesListener.java    License: 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 7
Source Project: editorconfig-netbeans   Source File: FileChangeListener.java    License: 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 8
Source Project: netbeans   Source File: ModuleClassPaths.java    License: 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 9
Source Project: netbeans   Source File: NativeExecutionBaseTestCase.java    License: 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 10
Source Project: netbeans   Source File: WebProject.java    License: 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 11
Source Project: netbeans   Source File: NbMavenProjectImpl.java    License: 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 12
Source Project: netbeans   Source File: LayerUtils.java    License: 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 13
Source Project: netbeans   Source File: CopyResourcesOnSave.java    License: 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 Project: netbeans   Source File: GrailsCommandSupport.java    License: Apache License 2.0 4 votes vote down vote up
public void fileDeleted(FileEvent fe) {
    changed();
}
 
Example 15
Source Project: netbeans   Source File: RunScriptAction.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void fileDataCreated(FileEvent fe) {
    invalidate();
}
 
Example 16
Source Project: netbeans   Source File: POMInheritancePanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void fileChanged(FileEvent fe) {
    showWaitNode();
    RequestProcessor.getDefault().post(POMInheritancePanel.this);
}
 
Example 17
@Override
public void fileFolderCreated(FileEvent fe) {
    fireChange();
}
 
Example 18
Source Project: netbeans   Source File: GraphTopComponent.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void fileDataCreated(FileEvent fe) {
    reset();
}
 
Example 19
Source Project: netbeans   Source File: ProjectClassPathImplementation.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void fileDataCreated(FileEvent fe) {
    fireChange();
}
 
Example 20
Source Project: netbeans   Source File: AntProjectHelper.java    License: Apache License 2.0 4 votes vote down vote up
public void fileDeleted(FileEvent fe) {
    change(fe);
}
 
Example 21
@Override
public void fileChanged(FileEvent fe) {
}
 
Example 22
Source Project: editorconfig-netbeans   Source File: FileChangeListener.java    License: MIT License 4 votes vote down vote up
@Override
public void fileFolderCreated(FileEvent event) {
  super.fileFolderCreated(event);
  LOG.log(Level.FINE, "[EC for {0}] Created folder: {1}", new Object[]{editorConfigFileObject.getPath(), event.getFile().getPath()});
  //TODO search for editor-configs and attach listeners
}
 
Example 23
Source Project: netbeans   Source File: MultiModuleNodeFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void fileDataCreated(FileEvent fe) {
    reset();
}
 
Example 24
@Override
public void fileFolderCreated(FileEvent fe) {
    //Not important
}
 
Example 25
Source Project: netbeans   Source File: TemplatesPanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void fileDeleted(FileEvent fe) {}
 
Example 26
Source Project: netbeans   Source File: ModuleNames.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void fileFolderCreated(FileEvent fe) {
    invalidate();
}
 
Example 27
Source Project: netbeans   Source File: ModuleListTest.java    License: Apache License 2.0 4 votes vote down vote up
public void fileChanged(FileEvent fe) {
    change(fe);
}
 
Example 28
Source Project: netbeans   Source File: MessageDestinationSupportImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void fileChanged(FileEvent fe) {
    assert (fe.getSource() == destinationsFO);
    destinationServiceModel = null;
}
 
Example 29
Source Project: netbeans   Source File: ImportantFilesNodeFactory.java    License: Apache License 2.0 4 votes vote down vote up
public @Override void fileDeleted(FileEvent fe) {
    refreshKeys();
}
 
Example 30
Source Project: netbeans   Source File: DatabaseConnectionConvertorTest.java    License: Apache License 2.0 4 votes vote down vote up
public void testSaveOnPropertyChange() throws Exception {
    DatabaseConnection dbconn = new DatabaseConnection("a", "b", "c", "d", "e", (String) null);
    FileObject fo = DatabaseConnectionConvertor.create(dbconn).getPrimaryFile();
    
    class FCL extends FileChangeAdapter {
        
        private final CountDownLatch latch = new CountDownLatch(1);
        
        @Override
        public void fileChanged(FileEvent fe) {
            latch.countDown();
        }
        
        public void await() throws InterruptedException {
            latch.await();
        }
    }
    
    FCL fcl = new FCL();
    fo.addFileChangeListener(fcl);
    
    dbconn.setDriver("org.bar.BarDriver");
    dbconn.setDriverName("bar_driver");
    dbconn.setDatabase("jdbc:bar:localhost");
    dbconn.setSchema("schema");
    dbconn.setUser("user");
    dbconn.setPassword("password");
    dbconn.setRememberPassword(true);
    
    fcl.await();
    
    ErrorHandlerImpl errHandler = new ErrorHandlerImpl();
    Document doc = null;
    InputStream input = fo.getInputStream();
    try {
        doc = XMLUtil.parse(new InputSource(input), true, true, errHandler, EntityCatalog.getDefault());
    } finally {
        input.close();
    }
    
    assertFalse("Error while parsing XML", errHandler.error);
    errHandler = new ErrorHandlerImpl();
    Document goldenDoc = null;
    input = getClass().getResourceAsStream("bar-connection.xml");
    try {
        goldenDoc = XMLUtil.parse(new InputSource(input), true, true, errHandler, EntityCatalog.getDefault());
    } finally {
        input.close();
    }
    
    assertTrue(DOMCompare.compareDocuments(doc, goldenDoc));
    assertFalse("Error while parsing XML", errHandler.error);
}