Skip to content

Commit

Permalink
Proper handle the workspace snapshot creation state (eclipse-che#3851)
Browse files Browse the repository at this point in the history
* Proper handle snapshotting state when user opens ide

* Proper handle snapshotting state when user opens ide
  • Loading branch information
Vladyslav Zhukovskyi authored Feb 2, 2017
1 parent 641cf29 commit 1a38e16
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.List;

import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE;
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;

/**
Expand Down Expand Up @@ -189,6 +190,9 @@ public void onOpen() {

final WorkspaceStatus workspaceStatus = workspace.getStatus();
switch (workspaceStatus) {
case SNAPSHOTTING:
loader.show(CREATING_WORKSPACE_SNAPSHOT);
break;
case STARTING:
eventBus.fireEvent(new WorkspaceStartingEvent(workspace));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.che.api.workspace.shared.dto.WorkspaceDto;
import org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent;
import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.DelayedTask;
import org.eclipse.che.ide.actions.WorkspaceSnapshotCreator;
import org.eclipse.che.ide.api.component.Component;
import org.eclipse.che.ide.api.dialogs.ConfirmCallback;
Expand Down Expand Up @@ -370,6 +371,9 @@ public void accepted() {

@VisibleForTesting
protected class WorkspaceStatusSubscriptionHandler extends SubscriptionHandler<WorkspaceStatusEvent> {

private DelayedTask wsStartedNotification;

private final WorkspaceDto workspace;

public WorkspaceStatusSubscriptionHandler(final WorkspaceDto workspace) {
Expand Down Expand Up @@ -401,6 +405,12 @@ protected void onMessageReceived(WorkspaceStatusEvent statusEvent) {

case STOPPING:
loader.show(LoaderPresenter.Phase.STOPPING_WORKSPACE);

if (wsStartedNotification != null) {
wsStartedNotification.cancel();
wsStartedNotification = null;
}

break;

case STOPPED:
Expand All @@ -417,6 +427,22 @@ protected void onMessageReceived(WorkspaceStatusEvent statusEvent) {
case SNAPSHOT_CREATED:
loader.setSuccess(LoaderPresenter.Phase.CREATING_WORKSPACE_SNAPSHOT);
snapshotCreator.successfullyCreated();

wsStartedNotification = new DelayedTask() {
@Override
public void onExecute() {

/*
Workaround. When ws is in snapshotting state we can get only running state after. But we know that stopping
state may occur after running, so when user is entering ide when the last one is stopping we haven't init
ide then.
*/

onWorkspaceStarted(workspaceId);
}
};
wsStartedNotification.delay(500);

break;

case SNAPSHOT_CREATION_ERROR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.che.ide.workspace;

import com.google.gwt.core.client.Callback;
import com.google.gwtmockito.GwtMockitoTestRunner;
import com.google.inject.Provider;
import com.google.web.bindery.event.shared.EventBus;

Expand Down Expand Up @@ -89,7 +90,7 @@
/**
* @author Roman Nikitenko
*/
@RunWith(MockitoJUnitRunner.class)
@RunWith(GwtMockitoTestRunner.class)
public class WorkspaceEventsHandlerTest {
private static final String MACHINE_NAME = "machineName";
private static final String WORKSPACE_ID = "workspaceId";
Expand Down

0 comments on commit 1a38e16

Please sign in to comment.