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);
}
}
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;
}
}
}
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));
}
}
});
}
}
Aggregations