Search in sources :

Example 1 with FileWatcherEventType

use of org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType in project che by eclipse.

the class ProjectManager method initWatcher.

void initWatcher() throws IOException {
    FileWatcherNotificationListener defaultListener = new FileWatcherNotificationListener(file -> !(file.getPath().toString().contains(".che") || file.getPath().toString().contains(".#"))) {

        @Override
        public void onFileWatcherEvent(VirtualFile virtualFile, FileWatcherEventType eventType) {
            LOG.debug("FS event detected: " + eventType + " " + virtualFile.getPath().toString() + " " + virtualFile.isFile());
        }
    };
    fileWatchNotifier.addNotificationListener(defaultListener);
    try {
        fileWatcher.startup();
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
        fileWatchNotifier.removeNotificationListener(defaultListener);
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) FileWatcherNotificationListener(org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationListener) FileWatcherEventType(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType) IOException(java.io.IOException)

Example 2 with FileWatcherEventType

use of org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType in project che by eclipse.

the class EditorFileStatusNotificationOperation method apply.

public void apply(String endpointId, FileStateUpdateDto params) {
    final FileWatcherEventType status = params.getType();
    final String stringPath = params.getPath();
    final String name = stringPath.substring(stringPath.lastIndexOf("/") + 1);
    switch(status) {
        case MODIFIED:
            {
                Log.debug(getClass(), "Received updated file event status: " + stringPath);
                eventBus.fireEvent(new FileContentUpdateEvent(stringPath, params.getHashCode()));
                break;
            }
        case DELETED:
            {
                Log.debug(getClass(), "Received removed file event status: " + stringPath);
                final Path path = Path.valueOf(stringPath);
                appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(path, path, REMOVED));
                if (notificationManager != null && !deletedFilesController.remove(stringPath)) {
                    notificationManager.notify("External operation", "File '" + name + "' is removed", SUCCESS, EMERGE_MODE);
                }
                break;
            }
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) ExternalResourceDelta(org.eclipse.che.ide.api.resources.ExternalResourceDelta) FileContentUpdateEvent(org.eclipse.che.ide.api.event.FileContentUpdateEvent) FileWatcherEventType(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType)

Example 3 with FileWatcherEventType

use of org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType in project che by eclipse.

the class ProjectTreeStateNotificationOperation method apply.

@Override
public void apply(String endpointId, ProjectTreeStateUpdateDto params) throws JsonRpcException {
    final String path = params.getPath();
    final FileWatcherEventType type = params.getType();
    final int status;
    switch(type) {
        case CREATED:
            {
                status = ADDED;
                break;
            }
        case DELETED:
            {
                status = REMOVED;
                break;
            }
        case MODIFIED:
            {
                status = UPDATED;
                break;
            }
        default:
            {
                status = UPDATED;
                break;
            }
    }
    Log.debug(getClass(), "Received request\npath: " + path + "\ntype:" + type + "\nstatus:" + status);
    if (path == null || path.isEmpty()) {
        appContext.getWorkspaceRoot().synchronize();
    } else {
        appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(Path.valueOf(path), Path.valueOf(path), status));
    }
    if (status == ADDED) {
        appContext.getWorkspaceRoot().getFile(Path.valueOf(path)).then(new Operation<Optional<File>>() {

            @Override
            public void apply(Optional<File> arg) throws OperationException {
                if (arg.isPresent()) {
                    appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(Path.valueOf(path), Path.valueOf(path), UPDATED));
                }
            }
        });
    }
}
Also used : ExternalResourceDelta(org.eclipse.che.ide.api.resources.ExternalResourceDelta) Optional(com.google.common.base.Optional) FileWatcherEventType(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType) File(org.eclipse.che.ide.api.resources.File) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

FileWatcherEventType (org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType)3 ExternalResourceDelta (org.eclipse.che.ide.api.resources.ExternalResourceDelta)2 Optional (com.google.common.base.Optional)1 IOException (java.io.IOException)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)1 FileWatcherNotificationListener (org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationListener)1 FileContentUpdateEvent (org.eclipse.che.ide.api.event.FileContentUpdateEvent)1 File (org.eclipse.che.ide.api.resources.File)1 Path (org.eclipse.che.ide.resource.Path)1