Example #1
0
 private VirtualFileSystemEntry applyEvent(@NotNull VFileEvent event) {
   try {
     if (event instanceof VFileCreateEvent) {
       final VFileCreateEvent createEvent = (VFileCreateEvent) event;
       return executeCreateChild(createEvent.getParent(), createEvent.getChildName());
     } else if (event instanceof VFileDeleteEvent) {
       final VFileDeleteEvent deleteEvent = (VFileDeleteEvent) event;
       executeDelete(deleteEvent.getFile());
     } else if (event instanceof VFileContentChangeEvent) {
       final VFileContentChangeEvent contentUpdateEvent = (VFileContentChangeEvent) event;
       executeTouch(
           contentUpdateEvent.getFile(),
           contentUpdateEvent.isFromRefresh(),
           contentUpdateEvent.getModificationStamp());
     } else if (event instanceof VFileCopyEvent) {
       final VFileCopyEvent copyEvent = (VFileCopyEvent) event;
       return executeCreateChild(copyEvent.getNewParent(), copyEvent.getNewChildName());
     } else if (event instanceof VFileMoveEvent) {
       final VFileMoveEvent moveEvent = (VFileMoveEvent) event;
       executeMove(moveEvent.getFile(), moveEvent.getNewParent());
     } else if (event instanceof VFilePropertyChangeEvent) {
       final VFilePropertyChangeEvent propertyChangeEvent = (VFilePropertyChangeEvent) event;
       if (VirtualFile.PROP_NAME.equals(propertyChangeEvent.getPropertyName())) {
         executeRename(propertyChangeEvent.getFile(), (String) propertyChangeEvent.getNewValue());
       } else if (VirtualFile.PROP_WRITABLE.equals(propertyChangeEvent.getPropertyName())) {
         executeSetWritable(
             propertyChangeEvent.getFile(),
             ((Boolean) propertyChangeEvent.getNewValue()).booleanValue());
       } else if (VirtualFile.PROP_HIDDEN.equals(propertyChangeEvent.getPropertyName())) {
         executeSetHidden(
             propertyChangeEvent.getFile(),
             ((Boolean) propertyChangeEvent.getNewValue()).booleanValue());
       } else if (VirtualFile.PROP_SYMLINK_TARGET.equals(propertyChangeEvent.getPropertyName())) {
         executeSetTarget(
             propertyChangeEvent.getFile(), (String) propertyChangeEvent.getNewValue());
       }
     }
   } catch (Exception e) {
     // Exception applying single event should not prevent other events from applying.
     LOG.error(e);
   }
   return null;
 }
Example #2
0
  @RequiredWriteAction
  @Override
  public void processEvents(@NotNull List<VFileEvent> events) {
    ApplicationManager.getApplication().assertWriteAccessAllowed();

    List<VFileEvent> validated = validateEvents(events);

    BulkFileListener publisher = myEventBus.syncPublisher(VirtualFileManager.VFS_CHANGES);
    publisher.before(validated);

    THashMap<VirtualFile, List<VFileEvent>> parentToChildrenEventsChanges = null;
    for (VFileEvent event : validated) {
      VirtualFile changedParent = null;
      if (event instanceof VFileCreateEvent) {
        changedParent = ((VFileCreateEvent) event).getParent();
        ((VFileCreateEvent) event).resetCache();
      } else if (event instanceof VFileDeleteEvent) {
        changedParent = ((VFileDeleteEvent) event).getFile().getParent();
      }

      if (changedParent != null) {
        if (parentToChildrenEventsChanges == null)
          parentToChildrenEventsChanges = new THashMap<VirtualFile, List<VFileEvent>>();
        List<VFileEvent> parentChildrenChanges = parentToChildrenEventsChanges.get(changedParent);
        if (parentChildrenChanges == null) {
          parentToChildrenEventsChanges.put(
              changedParent, parentChildrenChanges = new SmartList<VFileEvent>());
        }
        parentChildrenChanges.add(event);
      } else {
        applyEvent(event);
      }
    }

    if (parentToChildrenEventsChanges != null) {
      parentToChildrenEventsChanges.forEachEntry(
          new TObjectObjectProcedure<VirtualFile, List<VFileEvent>>() {
            @Override
            public boolean execute(VirtualFile parent, List<VFileEvent> childrenEvents) {
              applyChildrenChangeEvents(parent, childrenEvents);
              return true;
            }
          });
      parentToChildrenEventsChanges.clear();
    }

    publisher.after(validated);
  }