# HG changeset patch # User Vladimir Kvashin # Date 1300815319 -10800 # Node ID 1bd92864c2aa422dd79651b1e725e59171e0a0b9 # Parent 2ef704c3f84cc53e80f214723e0ebc08d0f54a1b fixing events for #196885 - New C source file doesn't show in Project view diff -r 2ef704c3f84c -r 1bd92864c2aa dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteDirectory.java --- a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteDirectory.java Tue Mar 22 20:33:58 2011 +0300 +++ b/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteDirectory.java Tue Mar 22 20:35:19 2011 +0300 @@ -174,7 +174,7 @@ @Override protected void postDeleteChild(FileObject child) { try { - DirectoryStorage ds = refreshDirectoryStorage(); // it will fire events itself + DirectoryStorage ds = refreshDirectoryStorage(null); // it will fire events itself } catch (ConnectException ex) { RemoteLogger.getInstance().log(Level.INFO, "Error post removing child " + child, ex); } catch (IOException ex) { @@ -212,16 +212,11 @@ } if (res.isOK()) { try { - refreshImpl(); - FileObject fo = getFileObject(name); + refreshImpl(name); + RemoteFileObjectBase fo = getFileObject(name); if (fo == null) { throw new FileNotFoundException("Can not create FileObject " + getUrlToReport(path)); //NOI18N } - if (directory) { - fireFileFolderCreatedEvent(getListeners(), new FileEvent(fo)); - } else { - fireFileDataCreatedEvent(getListeners(), new FileEvent(fo)); - } return fo; } catch (ConnectException ex) { throw new IOException("Can not create " + path + ": not connected", ex); // NOI18N @@ -308,8 +303,9 @@ } } - private void fireRemoteFileObjectCreated(RemoteFileObjectBase fo) { - FileEvent e = new FileEvent(fo); + private void fireRemoteFileObjectCreated(RemoteFileObjectBase fo, boolean expected) { + RemoteLogger.assertTrue(fo.getParent() == this, "Wrong parent for " + fo + ": " + fo.getParent() + " expected " + this); //NOI18N + FileEvent e = new FileEvent(this, fo); if (fo instanceof RemoteDirectory) { // fo.isFolder() very slow if it is a link fireFileFolderCreatedEvent(getListeners(), e); } else if (fo instanceof RemotePlainFile) { @@ -392,7 +388,7 @@ ConnectException, IOException, InterruptedException, CancellationException, ExecutionException { long time = System.currentTimeMillis(); try { - return getDirectoryStorageImpl(false); + return getDirectoryStorageImpl(false, null); } finally { if (trace) { trace("getDirectoryStorage for {1} took {0} ms", this, System.currentTimeMillis() - time); // NOI18N @@ -400,11 +396,11 @@ } } - private DirectoryStorage refreshDirectoryStorage() throws + private DirectoryStorage refreshDirectoryStorage(String expectedName) throws ConnectException, IOException, InterruptedException, CancellationException, ExecutionException { long time = System.currentTimeMillis(); try { - return getDirectoryStorageImpl(true); + return getDirectoryStorageImpl(true, expectedName); } finally { if (trace) { trace("refreshDirectoryStorage for {1} took {0} ms", this, System.currentTimeMillis() - time); // NOI18N @@ -412,7 +408,7 @@ } } - private DirectoryStorage getDirectoryStorageImpl(boolean force) throws + private DirectoryStorage getDirectoryStorageImpl(boolean force, String expectedName) throws ConnectException, IOException, InterruptedException, CancellationException, ExecutionException { if (force && ! ConnectionManager.getInstance().isConnectedTo(getExecutionEnvironment())) { @@ -556,7 +552,7 @@ if (oldEntry == null) { changed = true; cacheName = RemoteFileSystemUtils.escapeFileName(newEntry.getName()); - if (loaded) { + if (loaded || newEntry.getName().equals(expectedName)) { entriesToFireCreated.add(newEntry); } } else { @@ -655,16 +651,15 @@ storageFile.setLastModified(System.currentTimeMillis()); if (trace) { trace("set lastModified to {0}", storageFile.lastModified()); } // NOI18N if (changed) { - if (loaded) { - for (DirEntry entry : entriesToFireCreated) { - RemoteFileObjectBase fo = createFileObject(entry); - fireRemoteFileObjectCreated(fo); - } + for (DirEntry entry : entriesToFireCreated) { + RemoteFileObjectBase fo = createFileObject(entry); + fireRemoteFileObjectCreated(fo, fo.getNameExt().equals(expectedName)); } for (DirEntry entry : entriesToFireChanged) { RemoteFileObjectBase fo = getFileSystem().getFactory().getCachedFileObject(getPath() + '/' + entry.getName()); if (fo != null) { - fireFileChangedEvent(getListeners(), new FileEvent(fo)); + fireFileChangedEvent(fo.getListeners(), new FileEvent(fo, fo)); + fireFileChangedEvent(getListeners(), new FileEvent(this, fo)); } } } @@ -760,11 +755,12 @@ } private void invalidate(DirEntry oldEntry) { - FileObject fo = getFileSystem().getFactory().invalidate(getPath() + '/' + oldEntry.getName()); + RemoteFileObjectBase fo = getFileSystem().getFactory().invalidate(getPath() + '/' + oldEntry.getName()); File oldEntryCache = new File(getCache(), oldEntry.getCache()); removeFile(oldEntryCache); if (fo != null) { - fireFileDeletedEvent(getListeners(), new FileEvent(fo)); + fireFileDeletedEvent(fo.getListeners(), new FileEvent(fo)); + fireFileDeletedEvent(getListeners(), new FileEvent(this, fo)); } } @@ -795,12 +791,16 @@ @Override protected void refreshImpl() throws ConnectException, IOException, InterruptedException, CancellationException, ExecutionException { - refreshDirectoryStorage(); + refreshImpl(null); + } + + private void refreshImpl(String expectedName) throws ConnectException, IOException, InterruptedException, CancellationException, ExecutionException { + refreshDirectoryStorage(expectedName); for (RemoteFileObjectBase child : getExistentChildren()) { child.refreshImpl(); } } - + private void trace(String message, Object... args) { if (trace) { message = "SYNC [" + getPath() + "][" + System.identityHashCode(this) + "][" + Thread.currentThread().getId() + "]: " + message; // NOI18N