Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to reload page after lose connection with ws agent #3651

Merged
merged 1 commit into from
Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.che.ide.rest.RestServiceInfo;
import org.eclipse.che.ide.rest.StringUnmarshaller;
import org.eclipse.che.ide.ui.loaders.LoaderPresenter;
import org.eclipse.che.ide.util.browser.BrowserUtils;
import org.eclipse.che.ide.util.loging.Log;
import org.eclipse.che.ide.websocket.MessageBus;
import org.eclipse.che.ide.websocket.MessageBusProvider;
Expand Down Expand Up @@ -203,24 +204,45 @@ private void started() {
private void checkStateOfWsAgent(WsAgentHealthStateDto agentHealthStateDto) {
final int statusCode = agentHealthStateDto.getCode();
final String infoWindowTitle = "Workspace Agent Not Responding";
final ConfirmCallback stopCallback = new StopCallback();
final ConfirmCallback stopCallback = new StopCallback(false);
final ConfirmCallback stopAndReloadCallback = new StopCallback(true);

if (statusCode == 200) {
dialogFactory.createMessageDialog(infoWindowTitle,
"Workspace agent is no longer responding. To fix the problem, verify you have a" +
" good network connection and restart the workspace.",
stopCallback).show();
dialogFactory.createChoiceDialog(infoWindowTitle,
"Workspace agent is no longer responding. To fix the problem, verify you have a" +
" good network connection and restart the workspace.",
"Restart",
"Close",
stopAndReloadCallback,
stopCallback).show();
} else {
dialogFactory.createMessageDialog(infoWindowTitle,
"Workspace agent is no longer responding. To fix the problem, restart the workspace.",
stopCallback).show();
dialogFactory.createChoiceDialog(infoWindowTitle,
"Workspace agent is no longer responding. To fix the problem, restart the workspace.",
"Restart",
"Close",
stopAndReloadCallback,
stopCallback).show();
}
}

private class StopCallback implements ConfirmCallback {

private final boolean reload;

public StopCallback(boolean reload) {
this.reload = reload;
}

@Override
public void accepted() {
workspaceServiceClient.stop(devMachine.getWorkspaceId());
workspaceServiceClient.stop(devMachine.getWorkspaceId()).then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
if (reload) {
BrowserUtils.reloadPage(false);
}
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.che.ide.util.StringUtils;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Window.Location;

/** Utility methods relating to the browser. */
public abstract class BrowserUtils {
Expand Down Expand Up @@ -67,13 +68,28 @@ public static boolean isAndroid() {
}

public static boolean hasUrlParameter(String parameter) {
return Window.Location.getParameter(parameter) != null;
return Location.getParameter(parameter) != null;
}

public static boolean hasUrlParameter(String parameter, String value) {
return StringUtils.equalNonEmptyStrings(Window.Location.getParameter(parameter), value);
return StringUtils.equalNonEmptyStrings(Location.getParameter(parameter), value);
}

/**
* Wrapper for calling {@link Location#reload()} with ability to force reloading page.
* <p>
* By default, the reload() method reloads the page from the cache, but you can force
* it to reload the page from the server by setting the forceGet parameter to true: location.reload(true).
* <p>
* See more details about argument {@code forceGet} here: http://www.w3schools.com/jsref/met_loc_reload.asp
*
* @param forceGet
* reloads the current page from the server
*/
public static native void reloadPage(boolean forceGet) /*-{
$wnd.location.reload(forceGet);
}-*/;

private BrowserUtils() {
}
}