use of org.eclipse.che.api.promises.client.Function in project che by eclipse.
the class WorkspaceComponent method handleWorkspaceEvents.
/**
* Listens message bus and handles workspace events.
*
* @param workspace
* workspace to listen
* @param callback
* callback
* @param restoreFromSnapshot
* restore or not the workspace from snapshot
*/
public void handleWorkspaceEvents(final WorkspaceDto workspace, final Callback<Component, Exception> callback, final Boolean restoreFromSnapshot) {
this.callback = callback;
if (messageBus != null) {
messageBus.cancelReconnection();
}
messageBus = messageBusProvider.createMessageBus();
messageBus.addOnOpenHandler(new ConnectionOpenedHandler() {
@Override
public void onOpen() {
loader.show(STARTING_WORKSPACE_RUNTIME);
messageBus.removeOnOpenHandler(this);
setCurrentWorkspace(workspace);
workspaceEventsHandler.trackWorkspaceEvents(workspace, callback);
final WorkspaceStatus workspaceStatus = workspace.getStatus();
switch(workspaceStatus) {
case SNAPSHOTTING:
loader.show(CREATING_WORKSPACE_SNAPSHOT);
break;
case STARTING:
eventBus.fireEvent(new WorkspaceStartingEvent(workspace));
break;
case RUNNING:
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
loader.setSuccess(STARTING_WORKSPACE_RUNTIME);
eventBus.fireEvent(new WorkspaceStartedEvent(workspace));
}
});
break;
default:
//
workspaceServiceClient.getSettings().then(new Function<Map<String, String>, Map<String, String>>() {
@Override
public Map<String, String> apply(Map<String, String> settings) throws FunctionException {
if (Boolean.parseBoolean(settings.getOrDefault(CHE_WORKSPACE_AUTO_START, "true"))) {
startWorkspaceById(workspace.getId(), workspace.getConfig().getDefaultEnv(), restoreFromSnapshot);
} else {
loader.show(WORKSPACE_STOPPED);
}
return settings;
}
});
}
}
});
}
use of org.eclipse.che.api.promises.client.Function in project che by eclipse.
the class CopyPasteManager method pasteSuccessively.
private Promise<Void> pasteSuccessively(Promise<Void> promise, Resource[] resources, int position, final Path destination) {
if (position == resources.length) {
return promise;
}
final Resource resource = resources[position];
final Promise<Void> derivedPromise;
if (move) {
derivedPromise = promise.thenPromise(new Function<Void, Promise<Void>>() {
@Override
public Promise<Void> apply(Void ignored) throws FunctionException {
return moveResource(resource, destination.append(resource.getName()));
}
});
} else {
derivedPromise = promise.thenPromise(new Function<Void, Promise<Void>>() {
@Override
public Promise<Void> apply(Void ignored) throws FunctionException {
return copyResource(resource, destination.append(resource.getName()));
}
});
}
return pasteSuccessively(derivedPromise, resources, ++position, destination);
}
Aggregations