diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/bootstrap/CurrentWorkspaceManager.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/bootstrap/CurrentWorkspaceManager.java index 33259c807ec..b4fd9135e32 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/bootstrap/CurrentWorkspaceManager.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/bootstrap/CurrentWorkspaceManager.java @@ -27,7 +27,7 @@ import org.eclipse.che.ide.ui.loaders.LoaderPresenter; import org.eclipse.che.ide.util.loging.Log; import org.eclipse.che.ide.workspace.WorkspaceServiceClient; -import org.eclipse.che.ide.workspace.events.WorkspaceStatusEventHandler; +import org.eclipse.che.ide.workspace.WorkspaceStatusHandler; import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.RUNNING; import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED; @@ -53,7 +53,7 @@ public class CurrentWorkspaceManager { private final Provider notificationManagerProvider; private final IdeInitializer ideInitializer; private final CoreLocalizationConstant messages; - private final WorkspaceStatusEventHandler wsStatusEventHandler; + private final WorkspaceStatusHandler wsStatusHandler; private final AppContext appContext; @Inject @@ -64,7 +64,7 @@ public class CurrentWorkspaceManager { Provider notificationManagerProvider, IdeInitializer ideInitializer, CoreLocalizationConstant messages, - WorkspaceStatusEventHandler wsStatusEventHandler, + WorkspaceStatusHandler wsStatusHandler, AppContext appContext) { this.workspaceServiceClient = workspaceServiceClient; this.browserAddress = browserAddress; @@ -73,7 +73,7 @@ public class CurrentWorkspaceManager { this.notificationManagerProvider = notificationManagerProvider; this.ideInitializer = ideInitializer; this.messages = messages; - this.wsStatusEventHandler = wsStatusEventHandler; + this.wsStatusHandler = wsStatusHandler; this.appContext = appContext; } @@ -115,7 +115,7 @@ private void startWorkspace(Workspace workspace, boolean restoreFromSnapshot) { final WorkspaceStatus workspaceStatus = workspace.getStatus(); if (workspaceStatus == RUNNING) { - wsStatusEventHandler.handleWorkspaceStatusChanged(); + wsStatusHandler.handleWorkspaceStatusChanged(); } else if (workspaceStatus == STOPPED || workspaceStatus == STOPPING) { wsStatusNotification.show(STARTING_WORKSPACE_RUNTIME); diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/machine/EnvironmentStatusHandler.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/machine/EnvironmentStatusHandler.java new file mode 100644 index 00000000000..10ebdcba26c --- /dev/null +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/machine/EnvironmentStatusHandler.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.ide.machine; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.web.bindery.event.shared.EventBus; + +import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter; +import org.eclipse.che.api.machine.shared.dto.event.MachineStatusEvent; +import org.eclipse.che.api.workspace.shared.dto.RuntimeDto; +import org.eclipse.che.ide.api.app.AppContext; +import org.eclipse.che.ide.api.machine.ActiveRuntime; +import org.eclipse.che.ide.api.machine.MachineEntity; +import org.eclipse.che.ide.api.machine.events.MachineStateEvent; +import org.eclipse.che.ide.api.notification.NotificationManager; +import org.eclipse.che.ide.context.AppContextImpl; +import org.eclipse.che.ide.workspace.WorkspaceServiceClient; + +import java.util.Optional; + +import static com.google.common.base.Strings.isNullOrEmpty; +import static org.eclipse.che.ide.api.machine.events.MachineStateEvent.MachineAction.CREATING; +import static org.eclipse.che.ide.api.machine.events.MachineStateEvent.MachineAction.RUNNING; +import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.EMERGE_MODE; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; + +/** + * Handles changes in the workspace's environment and fires + * the corresponded events to notify all interested subscribers. + */ +@Singleton +public class EnvironmentStatusHandler { + + private EventBus eventBus; + private AppContext appContext; + private WorkspaceServiceClient workspaceServiceClient; + private NotificationManager notificationManager; + private RequestTransmitter transmitter; + + @Inject + EnvironmentStatusHandler(EventBus eventBus, + AppContext appContext, + WorkspaceServiceClient workspaceServiceClient, + NotificationManager notificationManager, + RequestTransmitter transmitter) { + this.eventBus = eventBus; + this.appContext = appContext; + this.workspaceServiceClient = workspaceServiceClient; + this.notificationManager = notificationManager; + this.transmitter = transmitter; + } + + public void handleEnvironmentStatusChanged(MachineStatusEvent event) { + final String machineId = event.getMachineId(); + final String workspaceId = event.getWorkspaceId(); + + workspaceServiceClient.getWorkspace(workspaceId).then(workspace -> { + RuntimeDto workspaceRuntime = workspace.getRuntime(); + if (workspaceRuntime == null) { + return; + } + + ((AppContextImpl)appContext).setWorkspace(workspace); + + switch (event.getEventType()) { + case CREATING: + handleMachineCreating(machineId); + break; + case RUNNING: + handleMachineRunning(machineId); + break; + case ERROR: + handleMachineError(event); + break; + } + }); + } + + private void handleMachineCreating(String machineName) { + final ActiveRuntime activeRuntime = appContext.getActiveRuntime(); + final Optional machine = activeRuntime.getMachineByName(machineName); + + if (machine.isPresent()) { + subscribeToMachineOutput(machineName); + + eventBus.fireEvent(new MachineStateEvent(machine.get(), CREATING)); + } + } + + private void subscribeToMachineOutput(String machineName) { + final String endpointId = "ws-master"; + final String subscribeByName = "event:environment-output:subscribe-by-machine-name"; + final String workspaceIdPlusMachineName = appContext.getWorkspaceId() + "::" + machineName; + + transmitter.newRequest() + .endpointId(endpointId) + .methodName(subscribeByName) + .paramsAsString(workspaceIdPlusMachineName) + .sendAndSkipResult(); + } + + private void handleMachineRunning(String machineName) { + final ActiveRuntime activeRuntime = appContext.getActiveRuntime(); + final Optional machine = activeRuntime.getMachineByName(machineName); + + machine.ifPresent(machineEntity -> eventBus.fireEvent(new MachineStateEvent(machineEntity, RUNNING))); + } + + private void handleMachineError(MachineStatusEvent event) { + if (!isNullOrEmpty(event.getError())) { + notificationManager.notify(event.getError(), FAIL, EMERGE_MODE); + } + } +} \ No newline at end of file diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspaceStatusHandler.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspaceStatusHandler.java new file mode 100644 index 00000000000..1a1579e93bd --- /dev/null +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspaceStatusHandler.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.ide.workspace; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.web.bindery.event.shared.EventBus; + +import org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent; +import org.eclipse.che.commons.annotation.Nullable; +import org.eclipse.che.ide.CoreLocalizationConstant; +import org.eclipse.che.ide.actions.WorkspaceSnapshotNotifier; +import org.eclipse.che.ide.api.app.AppContext; +import org.eclipse.che.ide.api.machine.WsAgentStateController; +import org.eclipse.che.ide.api.machine.WsAgentURLModifier; +import org.eclipse.che.ide.api.notification.NotificationManager; +import org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent; +import org.eclipse.che.ide.api.workspace.event.WorkspaceStartingEvent; +import org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent; +import org.eclipse.che.ide.context.AppContextImpl; +import org.eclipse.che.ide.resource.Path; +import org.eclipse.che.ide.ui.loaders.LoaderPresenter; +import org.eclipse.che.ide.workspace.start.StartWorkspaceNotification; + +import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.RUNNING; +import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STARTING; +import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED; +import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; +import static org.eclipse.che.ide.ui.loaders.LoaderPresenter.Phase.CREATING_WORKSPACE_SNAPSHOT; +import static org.eclipse.che.ide.ui.loaders.LoaderPresenter.Phase.STARTING_WORKSPACE_RUNTIME; +import static org.eclipse.che.ide.ui.loaders.LoaderPresenter.Phase.STOPPING_WORKSPACE; + +/** + * Handles changes of the workspace status and fires + * the corresponded events to notify all interested subscribers. + */ +@Singleton +public class WorkspaceStatusHandler { + + private final WorkspaceServiceClient workspaceServiceClient; + private final AppContext appContext; + private final StartWorkspaceNotification startWorkspaceNotificationProvider; + private final NotificationManager notificationManagerProvider; + private final WorkspaceSnapshotNotifier snapshotNotifierProvider; + private final LoaderPresenter wsStatusNotification; + private final WsAgentStateController wsAgentStateController; + private final WsAgentURLModifier wsAgentURLModifier; + private final EventBus eventBus; + private final CoreLocalizationConstant messages; + + @Inject + WorkspaceStatusHandler(WorkspaceServiceClient workspaceServiceClient, + AppContext appContext, + StartWorkspaceNotification startWorkspaceNotification, + NotificationManager notificationManager, + WorkspaceSnapshotNotifier snapshotNotifier, + LoaderPresenter wsStatusNotification, + WsAgentStateController wsAgentStateController, + WsAgentURLModifier wsAgentURLModifier, + EventBus eventBus, + CoreLocalizationConstant messages) { + this.workspaceServiceClient = workspaceServiceClient; + this.appContext = appContext; + this.startWorkspaceNotificationProvider = startWorkspaceNotification; + this.notificationManagerProvider = notificationManager; + this.snapshotNotifierProvider = snapshotNotifier; + this.wsStatusNotification = wsStatusNotification; + this.wsAgentStateController = wsAgentStateController; + this.wsAgentURLModifier = wsAgentURLModifier; + this.eventBus = eventBus; + this.messages = messages; + } + + public void handleWorkspaceStatusChanged() { + handleWorkspaceStatusChanged(null); + } + + public void handleWorkspaceStatusChanged(@Nullable WorkspaceStatusEvent serverEvent) { + workspaceServiceClient.getWorkspace(appContext.getWorkspaceId()).then(workspace -> { + ((AppContextImpl)appContext).setWorkspace(workspace); + + // FIXME: spi + // should be set on server `ws-agent` has been started + ((AppContextImpl)appContext).setProjectsRoot(Path.valueOf("/projects")); + + if (workspace.getStatus() == RUNNING) { + wsStatusNotification.setSuccess(STARTING_WORKSPACE_RUNTIME); + wsAgentStateController.initialize(appContext.getDevMachine()); + wsAgentURLModifier.initialize(appContext.getDevMachine()); + + eventBus.fireEvent(new WorkspaceStartedEvent(workspace)); + } else if (workspace.getStatus() == STARTING) { + eventBus.fireEvent(new WorkspaceStartingEvent(workspace)); + } else if (workspace.getStatus() == STOPPED) { + eventBus.fireEvent(new WorkspaceStoppedEvent(workspace)); + } + + if (serverEvent != null) { + notify(serverEvent); + } + }); + } + + // TODO: move to the separate component that should listen appropriate events + private void notify(WorkspaceStatusEvent event) { + switch (event.getEventType()) { + case STARTING: + wsStatusNotification.setSuccess(STARTING_WORKSPACE_RUNTIME); + break; + case RUNNING: + startWorkspaceNotificationProvider.hide(); + wsStatusNotification.setSuccess(STARTING_WORKSPACE_RUNTIME); + break; + case STOPPING: + wsStatusNotification.show(STOPPING_WORKSPACE); + break; + case STOPPED: + wsStatusNotification.setSuccess(STOPPING_WORKSPACE); + startWorkspaceNotificationProvider.show(); + break; + case ERROR: + notificationManagerProvider.notify(messages.workspaceStartFailed(), FAIL, FLOAT_MODE); + startWorkspaceNotificationProvider.show(); + break; + case SNAPSHOT_CREATING: + wsStatusNotification.show(CREATING_WORKSPACE_SNAPSHOT); + snapshotNotifierProvider.creationStarted(); + break; + case SNAPSHOT_CREATED: + wsStatusNotification.setSuccess(CREATING_WORKSPACE_SNAPSHOT); + snapshotNotifierProvider.successfullyCreated(); + break; + case SNAPSHOT_CREATION_ERROR: + wsStatusNotification.setError(CREATING_WORKSPACE_SNAPSHOT); + snapshotNotifierProvider.creationError("Snapshot creation error: " + event.getError()); + break; + default: + break; + } + } +} diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/events/EnvironmentStatusEventHandler.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/events/EnvironmentStatusEventHandler.java index 2652d59ad35..9659ecdbe61 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/events/EnvironmentStatusEventHandler.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/events/EnvironmentStatusEventHandler.java @@ -13,34 +13,17 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; -import com.google.web.bindery.event.shared.EventBus; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator; -import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter; import org.eclipse.che.api.machine.shared.dto.event.MachineStatusEvent; -import org.eclipse.che.api.workspace.shared.dto.RuntimeDto; -import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.machine.ActiveRuntime; -import org.eclipse.che.ide.api.machine.MachineEntity; -import org.eclipse.che.ide.api.machine.events.MachineStateEvent; -import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.context.AppContextImpl; +import org.eclipse.che.ide.machine.EnvironmentStatusHandler; import org.eclipse.che.ide.util.loging.Log; -import org.eclipse.che.ide.workspace.WorkspaceServiceClient; - -import java.util.Optional; - -import static com.google.common.base.Strings.isNullOrEmpty; -import static org.eclipse.che.ide.api.machine.events.MachineStateEvent.MachineAction.CREATING; -import static org.eclipse.che.ide.api.machine.events.MachineStateEvent.MachineAction.RUNNING; -import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.EMERGE_MODE; -import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; @Singleton class EnvironmentStatusEventHandler { @Inject - void configureEnvironmentStatusHandler(RequestHandlerConfigurator configurator, Provider handlerProvider) { + void configureEnvironmentStatusHandler(RequestHandlerConfigurator configurator, Provider handlerProvider) { configurator.newConfiguration() .methodName("event:environment-status:changed") .paramsAsDto(MachineStatusEvent.class) @@ -49,94 +32,9 @@ void configureEnvironmentStatusHandler(RequestHandlerConfigurator configurator, Log.debug(getClass(), "Received notification from endpoint: " + endpointId); // Since EnvironmentStatusEventHandler instantiated by GIN eagerly, - // it may be really expensive to instantiate nested Handler with all it's dependencies. - // So defer that work with Provider. + // it may be really expensive to instantiate EnvironmentStatusHandler with all it's dependencies. + // So defer that work. handlerProvider.get().handleEnvironmentStatusChanged(event); }); } - - @Singleton - static class Handler { - - private EventBus eventBus; - private AppContext appContext; - private WorkspaceServiceClient workspaceServiceClient; - private NotificationManager notificationManager; - private RequestTransmitter transmitter; - - @Inject - Handler(EventBus eventBus, - AppContext appContext, - WorkspaceServiceClient workspaceServiceClient, - NotificationManager notificationManager, - RequestTransmitter transmitter) { - this.eventBus = eventBus; - this.appContext = appContext; - this.workspaceServiceClient = workspaceServiceClient; - this.notificationManager = notificationManager; - this.transmitter = transmitter; - } - - private void handleEnvironmentStatusChanged(MachineStatusEvent event) { - final String machineId = event.getMachineId(); - final String workspaceId = event.getWorkspaceId(); - - workspaceServiceClient.getWorkspace(workspaceId).then(workspace -> { - RuntimeDto workspaceRuntime = workspace.getRuntime(); - if (workspaceRuntime == null) { - return; - } - - ((AppContextImpl)appContext).setWorkspace(workspace); - - switch (event.getEventType()) { - case CREATING: - handleMachineCreating(machineId); - break; - case RUNNING: - handleMachineRunning(machineId); - break; - case ERROR: - handleMachineError(event); - break; - } - }); - } - - private void handleMachineCreating(String machineName) { - final ActiveRuntime activeRuntime = appContext.getActiveRuntime(); - final Optional machine = activeRuntime.getMachineByName(machineName); - - if (machine.isPresent()) { - subscribeToMachineOutput(machineName); - - eventBus.fireEvent(new MachineStateEvent(machine.get(), CREATING)); - } - } - - private void subscribeToMachineOutput(String machineName) { - final String endpointId = "ws-master"; - final String subscribeByName = "event:environment-output:subscribe-by-machine-name"; - final String workspaceIdPlusMachineName = appContext.getWorkspaceId() + "::" + machineName; - - transmitter.newRequest() - .endpointId(endpointId) - .methodName(subscribeByName) - .paramsAsString(workspaceIdPlusMachineName) - .sendAndSkipResult(); - } - - private void handleMachineRunning(String machineName) { - final ActiveRuntime activeRuntime = appContext.getActiveRuntime(); - final Optional machine = activeRuntime.getMachineByName(machineName); - - machine.ifPresent(machineEntity -> eventBus.fireEvent(new MachineStateEvent(machineEntity, RUNNING))); - } - - private void handleMachineError(MachineStatusEvent event) { - if (!isNullOrEmpty(event.getError())) { - notificationManager.notify(event.getError(), FAIL, EMERGE_MODE); - } - } - } } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/events/WorkspaceStatusEventHandler.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/events/WorkspaceStatusEventHandler.java index 9edf50a94b4..7a9d9d0f0d9 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/events/WorkspaceStatusEventHandler.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/events/WorkspaceStatusEventHandler.java @@ -13,45 +13,17 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; -import com.google.web.bindery.event.shared.EventBus; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator; import org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent; -import org.eclipse.che.commons.annotation.Nullable; -import org.eclipse.che.ide.CoreLocalizationConstant; -import org.eclipse.che.ide.actions.WorkspaceSnapshotNotifier; -import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.machine.WsAgentStateController; -import org.eclipse.che.ide.api.machine.WsAgentURLModifier; -import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent; -import org.eclipse.che.ide.api.workspace.event.WorkspaceStartingEvent; -import org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent; -import org.eclipse.che.ide.context.AppContextImpl; -import org.eclipse.che.ide.resource.Path; -import org.eclipse.che.ide.ui.loaders.LoaderPresenter; import org.eclipse.che.ide.util.loging.Log; -import org.eclipse.che.ide.workspace.WorkspaceServiceClient; -import org.eclipse.che.ide.workspace.start.StartWorkspaceNotification; - -import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.RUNNING; -import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STARTING; -import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED; -import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; -import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; -import static org.eclipse.che.ide.ui.loaders.LoaderPresenter.Phase.CREATING_WORKSPACE_SNAPSHOT; -import static org.eclipse.che.ide.ui.loaders.LoaderPresenter.Phase.STARTING_WORKSPACE_RUNTIME; -import static org.eclipse.che.ide.ui.loaders.LoaderPresenter.Phase.STOPPING_WORKSPACE; +import org.eclipse.che.ide.workspace.WorkspaceStatusHandler; @Singleton -public class WorkspaceStatusEventHandler { - - private final Provider handlerProvider; +class WorkspaceStatusEventHandler { @Inject - WorkspaceStatusEventHandler(RequestHandlerConfigurator configurator, Provider handlerProvider) { - this.handlerProvider = handlerProvider; - + WorkspaceStatusEventHandler(RequestHandlerConfigurator configurator, Provider handlerProvider) { configurator.newConfiguration() .methodName("event:workspace-status:changed") .paramsAsDto(WorkspaceStatusEvent.class) @@ -60,115 +32,9 @@ public class WorkspaceStatusEventHandler { Log.debug(getClass(), "Received notification from endpoint: " + endpointId); // Since WorkspaceStatusEventHandler instantiated by GIN eagerly, - // it may be really expensive to instantiate nested Handler with all it's dependencies. - // So defer that work with Provider. + // it may be really expensive to instantiate WorkspaceStatusHandler with all it's dependencies. + // So defer that work. handlerProvider.get().handleWorkspaceStatusChanged(event); }); } - - /** Handles workspace status changes. */ - public void handleWorkspaceStatusChanged() { - handlerProvider.get().handleWorkspaceStatusChanged(null); - } - - @Singleton - static class Handler { - - private final WorkspaceServiceClient workspaceServiceClient; - private final AppContext appContext; - private final StartWorkspaceNotification startWorkspaceNotificationProvider; - private final NotificationManager notificationManagerProvider; - private final WorkspaceSnapshotNotifier snapshotNotifierProvider; - private final LoaderPresenter wsStatusNotification; - private final WsAgentStateController wsAgentStateController; - private final WsAgentURLModifier wsAgentURLModifier; - private final EventBus eventBus; - private final CoreLocalizationConstant messages; - - @Inject - Handler(WorkspaceServiceClient workspaceServiceClient, - AppContext appContext, - StartWorkspaceNotification startWorkspaceNotification, - NotificationManager notificationManager, - WorkspaceSnapshotNotifier snapshotNotifier, - LoaderPresenter wsStatusNotification, - WsAgentStateController wsAgentStateController, - WsAgentURLModifier wsAgentURLModifier, - EventBus eventBus, - CoreLocalizationConstant messages) { - this.workspaceServiceClient = workspaceServiceClient; - this.appContext = appContext; - this.startWorkspaceNotificationProvider = startWorkspaceNotification; - this.notificationManagerProvider = notificationManager; - this.snapshotNotifierProvider = snapshotNotifier; - this.wsStatusNotification = wsStatusNotification; - this.wsAgentStateController = wsAgentStateController; - this.wsAgentURLModifier = wsAgentURLModifier; - this.eventBus = eventBus; - this.messages = messages; - } - - void handleWorkspaceStatusChanged(@Nullable WorkspaceStatusEvent serverEvent) { - workspaceServiceClient.getWorkspace(appContext.getWorkspaceId()).then(workspace -> { - ((AppContextImpl)appContext).setWorkspace(workspace); - - // FIXME: spi - ((AppContextImpl)appContext).setProjectsRoot(Path.valueOf("/projects")); - - if (workspace.getStatus() == RUNNING) { - wsStatusNotification.setSuccess(STARTING_WORKSPACE_RUNTIME); - wsAgentStateController.initialize(appContext.getDevMachine()); - wsAgentURLModifier.initialize(appContext.getDevMachine()); - - eventBus.fireEvent(new WorkspaceStartedEvent(workspace)); - } else if (workspace.getStatus() == STARTING) { - eventBus.fireEvent(new WorkspaceStartingEvent(workspace)); - } else if (workspace.getStatus() == STOPPED) { - eventBus.fireEvent(new WorkspaceStoppedEvent(workspace)); - } - - if (serverEvent != null) { - notify(serverEvent); - } - }); - } - - // TODO: move to the separate component that should listen appropriate events - private void notify(WorkspaceStatusEvent event) { - switch (event.getEventType()) { - case STARTING: - wsStatusNotification.setSuccess(STARTING_WORKSPACE_RUNTIME); - break; - case RUNNING: - startWorkspaceNotificationProvider.hide(); - wsStatusNotification.setSuccess(STARTING_WORKSPACE_RUNTIME); - break; - case STOPPING: - wsStatusNotification.show(STOPPING_WORKSPACE); - break; - case STOPPED: - wsStatusNotification.setSuccess(STOPPING_WORKSPACE); - startWorkspaceNotificationProvider.show(); - break; - case ERROR: - notificationManagerProvider.notify(messages.workspaceStartFailed(), FAIL, FLOAT_MODE); - startWorkspaceNotificationProvider.show(); - break; - case SNAPSHOT_CREATING: - wsStatusNotification.show(CREATING_WORKSPACE_SNAPSHOT); - snapshotNotifierProvider.creationStarted(); - break; - case SNAPSHOT_CREATED: - wsStatusNotification.setSuccess(CREATING_WORKSPACE_SNAPSHOT); - snapshotNotifierProvider.successfullyCreated(); - break; - case SNAPSHOT_CREATION_ERROR: - wsStatusNotification.setError(CREATING_WORKSPACE_SNAPSHOT); - snapshotNotifierProvider.creationError("Snapshot creation error: " + event.getError()); - break; - default: - break; - } - } - } } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/start/StartWorkspaceNotification.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/start/StartWorkspaceNotification.java index 8633794646f..98026acd429 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/start/StartWorkspaceNotification.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/start/StartWorkspaceNotification.java @@ -18,6 +18,7 @@ import com.google.gwt.user.client.ui.CheckBox; import com.google.gwt.user.client.ui.Widget; import com.google.inject.Inject; +import com.google.inject.Provider; import com.google.inject.Singleton; import org.eclipse.che.ide.bootstrap.CurrentWorkspaceManager; @@ -32,9 +33,9 @@ @Singleton public class StartWorkspaceNotification { - private final WorkspaceStarterUiBinder uiBinder; - private final LoaderPresenter loader; - private final CurrentWorkspaceManager currentWorkspaceManager; + private final WorkspaceStarterUiBinder uiBinder; + private final LoaderPresenter loader; + private final Provider currentWorkspaceManagerProvider; @UiField Button button; @@ -44,10 +45,10 @@ public class StartWorkspaceNotification { @Inject public StartWorkspaceNotification(LoaderPresenter loader, WorkspaceStarterUiBinder uiBinder, - CurrentWorkspaceManager currentWorkspaceManager) { + Provider currentWorkspaceManagerProvider) { this.loader = loader; this.uiBinder = uiBinder; - this.currentWorkspaceManager = currentWorkspaceManager; + this.currentWorkspaceManagerProvider = currentWorkspaceManagerProvider; } /** Displays a notification with a proposal to start current workspace. */ @@ -66,7 +67,7 @@ public void hide() { @UiHandler("button") void startClicked(ClickEvent e) { loader.setSuccess(LoaderPresenter.Phase.WORKSPACE_STOPPED); - currentWorkspaceManager.startWorkspace(restore.getValue()); + currentWorkspaceManagerProvider.get().startWorkspace(restore.getValue()); } interface WorkspaceStarterUiBinder extends UiBinder {