Skip to content

Commit

Permalink
Separate logic of showing dialog on workspace stop
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail Kuznyetsov committed Apr 4, 2016
1 parent 4f2bf52 commit 582bc74
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void apply(List<WorkspaceDto> workspaces) throws OperationException {
for (WorkspaceDto workspace : workspaces) {
if (wsNameFromBrowser.equals(workspace.getConfig().getName())) {
Log.info(getClass(), "Starting workspace " + workspace.getConfig().getName());
startWorkspaceById(workspace);
startWorkspaceById(workspace, callback);
return;
}
}
Expand Down Expand Up @@ -138,7 +138,7 @@ private void tryStartRecentWorkspaceIfExist(List<WorkspaceDto> workspaces) {
} else {
for(WorkspaceDto workspace : workspaces) {
if (workspace.getId().equals(recentWorkspaceId)) {
startWorkspaceById(workspace);
startWorkspaceById(workspace, callback);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public class FactoryWorkspaceComponent extends WorkspaceComponent implements Com

@Inject
public FactoryWorkspaceComponent(WorkspaceServiceClient workspaceServiceClient,
FactoryServiceClient factoryServiceClient,
CreateWorkspacePresenter createWorkspacePresenter,
StartWorkspacePresenter startWorkspacePresenter,
FactoryServiceClient factoryServiceClient,
CoreLocalizationConstant locale,
DtoUnmarshallerFactory dtoUnmarshallerFactory,
EventBus eventBus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ public void setCurrentWorkspace(WorkspaceDto workspace) {
*
* @param workspace
* workspace which will be started
* @param callback
* callback to be executed
*/
public void startWorkspaceById(final WorkspaceDto workspace) {
public void startWorkspaceById(final WorkspaceDto workspace, final Callback<Component, Exception> callback) {
this.callback = callback;
loader.show(initialLoadingInfo);
initialLoadingInfo.setOperationStatus(WORKSPACE_BOOTING.getValue(), IN_PROGRESS);

Expand Down Expand Up @@ -304,12 +307,6 @@ protected void onMessageReceived(WorkspaceStatusEvent statusEvent) {
break;

case STOPPED:
workspaceServiceClient.getWorkspaces(SKIP_COUNT, MAX_COUNT).then(new Operation<List<WorkspaceDto>>() {
@Override
public void apply(List<WorkspaceDto> workspaces) throws OperationException {
startWorkspacePresenter.show(workspaces, callback);
}
});
unSubscribeWorkspace(statusEvent.getWorkspaceId(), this);
notificationManager.notify(locale.extServerStopped(), StatusNotification.Status.SUCCESS, true);
eventBus.fireEvent(new WorkspaceStoppedEvent(workspace));
Expand Down Expand Up @@ -369,7 +366,7 @@ protected Operation<WorkspaceDto> startWorkspace() {
return new Operation<WorkspaceDto>() {
@Override
public void apply(WorkspaceDto workspaceToStart) throws OperationException {
startWorkspaceById(workspaceToStart);
startWorkspaceById(workspaceToStart, callback);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ public CreateWorkspacePresenter(CreateWorkspaceView view,
/**
* Shows special dialog window which allows set up workspace which will be created.
*
* @param callback
* callback which is necessary to notify that workspace component started or failed
* @param workspaces
* list of existing workspaces
*/
Expand Down Expand Up @@ -214,7 +212,7 @@ private void createWorkspace() {
@Override
public void apply(WorkspaceDto workspace) throws OperationException {
DefaultWorkspaceComponent component = wsComponentProvider.get();
component.startWorkspaceById(workspace);
component.startWorkspaceById(workspace, callback);
}
}).catchError(new Operation<PromiseError>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void onWorkspaceSelected(WorkspaceDto workspace) {

workspaceComponent.setCurrentWorkspace(workspace);

workspaceComponent.startWorkspaceById(workspace);
workspaceComponent.startWorkspaceById(workspace, callback);

view.hide();
}
Expand All @@ -136,7 +136,7 @@ public void onCreateWorkspaceClicked() {
public void onStartWorkspaceClicked() {
DefaultWorkspaceComponent workspaceComponent = wsComponentProvider.get();

workspaceComponent.startWorkspaceById(selectedWorkspace);
workspaceComponent.startWorkspaceById(selectedWorkspace, callback);

view.hide();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,11 @@ placeholder.find.by.tags=Input tag to find recipe
############# Start Workspace Dialog ##########
start.ws.title=Start Workspace
start.ws.button=Start

start.ws.select.to.start=Workspace to start:
placeholder.select.ws.to.start=Click to select workspace to start
started.ws=Workspace is running
stopped.ws=Workspace is not running
ext.server.started=Workspace agent started
ext.server.stopped=Workspace agent stopped
workspace.start.failed=Failed to start workspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public void workspaceShouldBeCreatedForDevMachine() throws Exception {
callApplyCreateWorkspaceMethod();

verify(wsComponentProvider).get();
verify(workspaceComponent).startWorkspaceById(usersWorkspaceDto);
verify(workspaceComponent).startWorkspaceById(usersWorkspaceDto, componentCallback);
}

private void callApplyCreateWorkspaceMethod() throws Exception {
Expand All @@ -361,7 +361,7 @@ public void workspaceShouldBeCreatedForNotDevMachine() throws Exception {

callApplyCreateWorkspaceMethod();

verify(workspaceComponent).startWorkspaceById(usersWorkspaceDto);
verify(workspaceComponent).startWorkspaceById(usersWorkspaceDto, componentCallback);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void workspaceWithExistingNameShouldBeSelected() {
presenter.onStartWorkspaceClicked();

verify(wsComponentProvider).get();
verify(workspaceComponent).startWorkspaceById(workspaceDto);
verify(workspaceComponent).startWorkspaceById(workspaceDto, callback);
verify(view).hide();
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public void selectedWorkspaceShouldBeStarted() {

verify(wsComponentProvider).get();

verify(workspaceComponent).startWorkspaceById(workspaceDto);
verify(workspaceComponent).startWorkspaceById(workspaceDto, callback);

verify(view).hide();
}
Expand Down
7 changes: 2 additions & 5 deletions plugins/plugin-nodejs/che-plugin-nodejs-lang-shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@
Codenvy, S.A. - initial API and implementation
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>che-plugin-nodejs-parent</artifactId>
<groupId>org.eclipse.che.plugin</groupId>
<version>4.1.0-RC1-SNAPSHOT</version>
</parent>

<artifactId>che-plugin-nodejs-lang-shared</artifactId>
<name>Che Plugin :: NodeJs :: Extension Shared</name>

<build>
<resources>
<resource>
<directory>src/main/java</directory>
</resource>
</resources>
</build>
</project>
</project>
6 changes: 2 additions & 4 deletions plugins/plugin-nodejs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
Codenvy, S.A. - initial API and implementation
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>che-plugin-parent</artifactId>
<groupId>org.eclipse.che.plugin</groupId>
<version>4.1.0-RC1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>che-plugin-nodejs-parent</artifactId>
<packaging>pom</packaging>
<name>Che Plugin :: NodeJs :: Parent</name>
Expand All @@ -29,4 +27,4 @@
<module>che-plugin-nodejs-lang-server</module>
<module>che-plugin-nodejs-lang-shared</module>
</modules>
</project>
</project>
16 changes: 16 additions & 0 deletions plugins/plugin-sdk/che-plugin-sdk-env-local/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-workspace</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-workspace</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-client-gwt-workspace</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-gwt</artifactId>
Expand All @@ -49,6 +61,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-ide-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-ide-app</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-ide-ui</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*******************************************************************************
* Copyright (c) 2012-2016 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.env.local.client;

import com.google.gwt.core.client.Callback;
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.api.workspace.gwt.client.WorkspaceServiceClient;
import org.eclipse.che.api.workspace.gwt.client.event.WorkspaceStoppedEvent;
import org.eclipse.che.api.workspace.gwt.client.event.WorkspaceStoppedHandler;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceDto;
import org.eclipse.che.ide.api.component.Component;
import org.eclipse.che.ide.workspace.start.StartWorkspacePresenter;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;

/**
* Shows dialog after workspace stopped event.
*
* @author Mihail Kuznyetsov
*/
@Singleton
public class CheWorkspaceStoppedHandler implements WorkspaceStoppedHandler {

private final static int SKIP_COUNT = 0;
private final static int MAX_COUNT = 10;
private final StartWorkspacePresenter startWorkspacePresenter;
private final WorkspaceServiceClient workspaceServiceClient;
private final Callback<Component, Exception> callback;

@Inject
public CheWorkspaceStoppedHandler(StartWorkspacePresenter startWorkspacePresenter,
WorkspaceServiceClient workspaceServiceClient,
EventBus eventBus) {
this.startWorkspacePresenter = startWorkspacePresenter;
this.workspaceServiceClient = workspaceServiceClient;

this.callback = new Callback<Component, Exception>() {
@Override
public void onFailure(Exception reason) {
}

@Override
public void onSuccess(Component result) {
}
};
eventBus.addHandler(WorkspaceStoppedEvent.TYPE, this);
}

@Override
public void onWorkspaceStopped(WorkspaceStoppedEvent event) {
workspaceServiceClient.getWorkspace(event.getWorkspace().getId()).then(new Operation<WorkspaceDto>() {
@Override
public void apply(WorkspaceDto workspace) throws OperationException {
workspaceServiceClient.getWorkspaces(SKIP_COUNT, MAX_COUNT)
.then(new Operation<List<WorkspaceDto>>() {
@Override
public void apply(List<WorkspaceDto> workspaces)
throws OperationException {
startWorkspacePresenter.show(workspaces, callback);
}
});
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.eclipse.che.env.local.client.CheConnectionClosedInformer;
import org.eclipse.che.env.local.client.CheProductInfoDataProvider;
import org.eclipse.che.env.local.client.CheWorkspaceStoppedHandler;
import org.eclipse.che.ide.api.ConnectionClosedInformer;
import org.eclipse.che.ide.api.ProductInfoDataProvider;
import org.eclipse.che.ide.api.extension.ExtensionGinModule;
Expand All @@ -28,5 +29,7 @@ public class LocalEnvironmentGinModule extends AbstractGinModule {
protected void configure() {
bind(ProductInfoDataProvider.class).to(CheProductInfoDataProvider.class).in(Singleton.class);
bind(ConnectionClosedInformer.class).to(CheConnectionClosedInformer.class).in(Singleton.class);

bind(CheWorkspaceStoppedHandler.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ public void stop(@ApiParam("The workspace id") @PathParam("id") String id) throw
ConflictException,
BadRequestException {
ensureUserIsWorkspaceOwner(id);
workspaceManager.getWorkspace(id).getAttributes().put("stoppedByTimeout", "true");
workspaceManager.stopWorkspace(id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@EventOrigin("machine")
@DTO
public interface WorkspaceStatusEvent {

enum EventType {
STARTING, RUNNING, STOPPING, STOPPED, ERROR, SNAPSHOT_CREATED, SNAPSHOT_CREATION_ERROR
}
Expand Down

0 comments on commit 582bc74

Please sign in to comment.