use of org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent in project che by eclipse.
the class MachinePanelPresenterTest method shouldSubscribeToMachineStateEvent.
@Test
public void shouldSubscribeToMachineStateEvent() {
WorkspaceStartedEvent event = mock(WorkspaceStartedEvent.class);
when(event.getWorkspace()).thenReturn(usersWorkspace);
presenter.onWorkspaceStarted(event);
verify(eventBus).addHandler(MachineStateEvent.TYPE, presenter);
}
use of org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent in project che by eclipse.
the class BootstrapController method startWsAgentComponents.
@Inject
private void startWsAgentComponents(EventBus eventBus, final Map<String, Provider<WsAgentComponent>> components) {
eventBus.addHandler(WorkspaceStartedEvent.TYPE, new WorkspaceStartedEvent.Handler() {
@Override
public void onWorkspaceStarted(WorkspaceStartedEvent event) {
workspaceService.getWorkspace(event.getWorkspace().getId()).then(new Operation<WorkspaceDto>() {
@Override
public void apply(WorkspaceDto ws) throws OperationException {
MachineDto devMachineDto = ws.getRuntime().getDevMachine();
DevMachine devMachine = new DevMachine(devMachineDto);
if (appContext instanceof AppContextImpl) {
((AppContextImpl) appContext).setProjectsRoot(Path.valueOf(devMachineDto.getRuntime().projectsRoot()));
}
wsAgentStateControllerProvider.get().initialize(devMachine);
wsAgentURLModifier.initialize(devMachine);
SortedMap<String, Provider<WsAgentComponent>> sortedComponents = new TreeMap<>();
sortedComponents.putAll(components);
startWsAgentComponents(sortedComponents.values().iterator());
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError err) throws OperationException {
Log.error(getClass(), err.getCause());
initializationFailed(err.getMessage());
}
});
}
});
}
use of org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent 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;
}
});
}
}
});
}
Aggregations