Switch editors in read only mode when ws agent has stopped (#9912)

* CHE-9620. Switch editors in read only mode when ws agent has stopped
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
6.19.x
RomanNikitenko 2018-06-07 11:19:34 +03:00 committed by GitHub
parent a37a1e4cce
commit 2db2f5fcd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 1 deletions

View File

@ -1186,6 +1186,9 @@ public interface CoreLocalizationConstant extends Messages {
@Key("message.projectCreated")
String projectCreated(String projectName);
@Key("message.switch.editors.in.readOnly.mode")
String messageSwitchEditorsInReadOnlyMode();
@Key("ssh.connect.info")
String sshConnectInfo(
String machineName,

View File

@ -13,8 +13,10 @@ package org.eclipse.che.ide.editor;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Lists.newArrayList;
import static java.lang.Boolean.parseBoolean;
import static java.util.stream.Collectors.toList;
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.EMERGE_MODE;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.WARNING;
import static org.eclipse.che.ide.api.parts.PartStackType.EDITING;
import com.google.gwt.core.client.Scheduler;
@ -74,6 +76,7 @@ import org.eclipse.che.ide.api.selection.SelectionChangedEvent;
import org.eclipse.che.ide.api.selection.SelectionChangedHandler;
import org.eclipse.che.ide.api.statepersistance.StateComponent;
import org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent;
import org.eclipse.che.ide.api.workspace.event.WsAgentServerStoppedEvent;
import org.eclipse.che.ide.editor.synchronization.EditorContentSynchronizer;
import org.eclipse.che.ide.part.editor.multipart.EditorMultiPartStackPresenter;
import org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter;
@ -94,7 +97,8 @@ public class EditorAgentImpl
ActivePartChangedHandler,
SelectionChangedHandler,
StateComponent,
WorkspaceStoppedEvent.Handler {
WorkspaceStoppedEvent.Handler,
WsAgentServerStoppedEvent.Handler {
private final EventBus eventBus;
private final WorkspaceAgent workspaceAgent;
@ -146,6 +150,7 @@ public class EditorAgentImpl
eventBus.addHandler(ActivePartChangedEvent.TYPE, this);
eventBus.addHandler(SelectionChangedEvent.TYPE, this);
eventBus.addHandler(WorkspaceStoppedEvent.TYPE, this);
eventBus.addHandler(WsAgentServerStoppedEvent.TYPE, this);
}
@Override
@ -805,6 +810,35 @@ public class EditorAgentImpl
}
}
@Override
public void onWsAgentServerStopped(WsAgentServerStoppedEvent event) {
List<EditorPartPresenter> editorsToReadOnlyMode =
getOpenedEditors()
.stream()
.filter(
editor ->
editor instanceof HasReadOnlyProperty
&& !((HasReadOnlyProperty) editor).isReadOnly())
.collect(toList());
if (editorsToReadOnlyMode.isEmpty()) {
return;
}
notificationManager.notify(
"", coreLocalizationConstant.messageSwitchEditorsInReadOnlyMode(), WARNING, EMERGE_MODE);
editorsToReadOnlyMode.forEach(
editor -> {
EditorTab editorTab = editorMultiPartStack.getTabByPart(editor);
if (editorTab != null) {
editorTab.setReadOnlyMark(true);
}
((HasReadOnlyProperty) editor).setReadOnly(true);
});
}
private static class RestoreStateEditorCallBack extends OpenEditorCallbackImpl {
private final int cursorOffset;
private final int topLine;

View File

@ -278,6 +278,7 @@ messages.startingMachine=Starting machine \"{0}\"
messages.startingOperation=Starting {0}
messages.machine.not.found=Machine {0} not found
message.projectCreated=Project {0} created
message.switch.editors.in.readOnly.mode=Workspace agent is not running, open editors are switched to read-only mode
############### Buttons ###############################
ok = OK