From 0ef0a7ee9f66651b263defa140f0e98c917c0c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Hegedu=CC=88s?= Date: Fri, 21 Apr 2023 11:49:40 +0200 Subject: [PATCH 1/8] implement subclientId for server reload logic for RequestModelAction replace commandStack with commandStackManager --- .../glsp/server/emf/EMFModelState.java | 17 ++++-- .../server/emf/EMFSourceModelStorage.java | 6 +-- .../eclipse/glsp/server/actions/Action.java | 20 ++++++- .../actions/SaveModelActionHandler.java | 4 +- .../eclipse/glsp/server/di/DiagramModule.java | 16 ++++++ .../model/ComputedBoundsActionHandler.java | 2 +- .../core/model/ModelSubmissionHandler.java | 20 +++---- .../core/model/RequestModelActionHandler.java | 16 +++--- .../undoredo/UndoRedoActionHandler.java | 12 ++--- .../actions/DefaultActionDispatcher.java | 1 + .../internal/command/CommandStackFactory.java | 7 +++ .../internal/command/CommandStackManager.java | 13 +++++ .../command/DefaultCommandStackManager.java | 53 +++++++++++++++++++ .../GModelCommandStackFactory.java | 11 ++++ .../glsp/server/model/DefaultGModelState.java | 39 ++++++++------ .../glsp/server/model/GModelState.java | 4 +- .../eclipse/glsp/server/model/ModelState.java | 10 ++-- .../operations/OperationActionHandler.java | 12 ++--- .../server/protocol/DefaultGLSPServer.java | 2 + .../glsp/server/utils/ClientOptionsUtil.java | 10 ++++ .../glsp/server/utils/CollaborateUtil.java | 5 ++ 21 files changed, 218 insertions(+), 62 deletions(-) create mode 100644 plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackFactory.java create mode 100644 plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackManager.java create mode 100644 plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/DefaultCommandStackManager.java create mode 100644 plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/gmodel/commandstack/GModelCommandStackFactory.java create mode 100644 plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/CollaborateUtil.java diff --git a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelState.java b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelState.java index e906b722..7286db4d 100644 --- a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelState.java +++ b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelState.java @@ -17,6 +17,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.eclipse.emf.common.command.BasicCommandStack; import org.eclipse.emf.common.command.CommandStack; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.resource.Resource; @@ -24,6 +25,7 @@ import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.glsp.graph.GModelIndex; import org.eclipse.glsp.graph.GModelRoot; +import org.eclipse.glsp.server.internal.command.CommandStackManager; import org.eclipse.glsp.server.model.DefaultGModelState; import org.eclipse.glsp.server.session.ClientSession; import org.eclipse.glsp.server.session.ClientSessionListener; @@ -51,6 +53,9 @@ public class EMFModelState extends DefaultGModelState implements ClientSessionLi @Inject protected EMFIdGenerator idGenerator; + @Inject + protected CommandStackManager commandStackManager; + protected EditingDomain editingDomain; @Override @@ -59,9 +64,9 @@ public void init() { this.clientSessionManager.addListener(this, this.clientId); } - public void setEditingDomain(final EditingDomain editingDomain) { + public void setEditingDomain(final EditingDomain editingDomain, final String subclientId) { this.editingDomain = editingDomain; - setCommandStack(this.editingDomain.getCommandStack()); + commandStackManager.setCommandStack(this.editingDomain.getCommandStack(), subclientId); } public EditingDomain getEditingDomain() { return editingDomain; } @@ -102,8 +107,12 @@ protected void closeResourceSet() { } } if (result) { - commandStack.flush(); - saveIsDone(); + commandStackManager.getAllCommandStack().forEach(commandStack -> { + commandStack.flush(); + if (commandStack instanceof BasicCommandStack) { + ((BasicCommandStack) commandStack).saveIsDone(); + } + }); } } diff --git a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFSourceModelStorage.java b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFSourceModelStorage.java index 5b24f3cf..d467454c 100644 --- a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFSourceModelStorage.java +++ b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFSourceModelStorage.java @@ -56,17 +56,17 @@ public void loadSourceModel(final RequestModelAction action) { .orElseThrow(() -> new GLSPServerException("No source URI given to load model!")); URI resourceURI = URI.createFileURI(sourceURI); - EditingDomain editingDomain = getOrCreateEditingDomain(); + EditingDomain editingDomain = getOrCreateEditingDomain(action.getSubclientId()); doLoadSourceModel(editingDomain.getResourceSet(), resourceURI, action); } - protected EditingDomain getOrCreateEditingDomain() { + protected EditingDomain getOrCreateEditingDomain(final String subclientId) { if (modelState.getEditingDomain() != null) { return modelState.getEditingDomain(); } EditingDomain editingDomain = editingDomainFactory.createEditingDomain(); setupResourceSet(editingDomain.getResourceSet()); - modelState.setEditingDomain(editingDomain); + modelState.setEditingDomain(editingDomain, subclientId); return editingDomain; } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/Action.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/Action.java index 7d981b17..b2eaed92 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/Action.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/Action.java @@ -15,6 +15,8 @@ ********************************************************************************/ package org.eclipse.glsp.server.actions; +import org.eclipse.glsp.server.internal.util.GenericsUtil; + /** * Java-implementation of the `Action` interface. An action is a declarative description of a behavior that * shall be @@ -31,13 +33,22 @@ public abstract class Action { */ private final String kind; - public Action(final String kind) { + private String subclientId; + + public Action(final String kind, final String subclientId) { super(); this.kind = kind; + this.subclientId = subclientId; + } + + public Action(final String kind) { + this(kind, null); } public String getKind() { return kind; } + public String getSubclientId() { return subclientId; } + @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -47,4 +58,11 @@ public String toString() { return builder.toString(); } + public static Action addSubclientId(final Action initialAction, final Action extendedAction) { + if (initialAction.getSubclientId() != null) { + extendedAction.subclientId = initialAction.subclientId; + } + return extendedAction; + } + } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/SaveModelActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/SaveModelActionHandler.java index 4bd58ea2..44c72bdf 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/SaveModelActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/SaveModelActionHandler.java @@ -45,11 +45,11 @@ public List executeAction(final SaveModelAction action) { modelSourceWatcher.ifPresent(watcher -> watcher.pauseWatching()); try { sourceModelStorage.saveSourceModel(action); - modelState.saveIsDone(); + modelState.saveIsDone(action.getSubclientId()); } finally { modelSourceWatcher.ifPresent(watcher -> watcher.continueWatching()); } - return listOf(new SetDirtyStateAction(modelState.isDirty(), SetDirtyStateAction.Reason.SAVE)); + return listOf(new SetDirtyStateAction(modelState.isDirty(action.getSubclientId()), SetDirtyStateAction.Reason.SAVE)); } } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/DiagramModule.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/DiagramModule.java index 5fa2ccd2..00787b4f 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/DiagramModule.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/DiagramModule.java @@ -87,10 +87,14 @@ import org.eclipse.glsp.server.gson.GraphGsonConfigurationFactory; import org.eclipse.glsp.server.internal.actions.DefaultActionDispatcher; import org.eclipse.glsp.server.internal.actions.DefaultActionHandlerRegistry; +import org.eclipse.glsp.server.internal.command.CommandStackFactory; +import org.eclipse.glsp.server.internal.command.CommandStackManager; +import org.eclipse.glsp.server.internal.command.DefaultCommandStackManager; import org.eclipse.glsp.server.internal.diagram.DefaultServerConfigurationContribution; import org.eclipse.glsp.server.internal.featues.directediting.DefaultContextEditValidatorRegistry; import org.eclipse.glsp.server.internal.featues.navigation.DefaultNavigationTargetProviderRegistry; import org.eclipse.glsp.server.internal.features.contextactions.DefaultContextActionsProviderRegistry; +import org.eclipse.glsp.server.internal.gmodel.commandstack.GModelCommandStackFactory; import org.eclipse.glsp.server.internal.gson.DefaultGraphGsonConfigurationFactory; import org.eclipse.glsp.server.internal.operations.DefaultOperationHandlerRegistry; import org.eclipse.glsp.server.internal.toolpalette.DefaultToolPaletteItemProvider; @@ -210,6 +214,10 @@ protected void configureBase() { bindOptionally(PopupModelFactory.class, bindPopupModelFactory()); bindOptionally(LayoutEngine.class, bindLayoutEngine()); bindOptionally(GraphExtension.class, bindGraphExtension()); + + // Command Stack + bind(CommandStackFactory.class).to(bindCommandStackFactory()).in(Singleton.class); + bind(CommandStackManager.class).to(bindCommandStackManager()).in(Singleton.class); } protected void bindDiagramType() { @@ -372,5 +380,13 @@ protected Class bindGraphExtension() { return null; } + protected Class bindCommandStackFactory() { + return GModelCommandStackFactory.class; + } + + protected Class bindCommandStackManager() { + return DefaultCommandStackManager.class; + } + public abstract String getDiagramType(); } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ComputedBoundsActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ComputedBoundsActionHandler.java index d4be507d..8c58d234 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ComputedBoundsActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ComputedBoundsActionHandler.java @@ -45,7 +45,7 @@ public List executeAction(final ComputedBoundsAction action) { if (model != null && action.getRevision().isPresent() && action.getRevision().get().doubleValue() == model.getRevision()) { LayoutUtil.applyBounds(model, action, modelState); - return submissionHandler.submitModelDirectly(); + return submissionHandler.submitModelDirectly(action.getSubclientId()); } } return none(); diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelSubmissionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelSubmissionHandler.java index 8da40c65..002f2dfb 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelSubmissionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelSubmissionHandler.java @@ -61,28 +61,28 @@ public class ModelSubmissionHandler { * @param reason The optional reason that caused the model update. * @return A list of actions to be processed in order to submit the model. */ - public List submitModel(final String reason) { + public List submitModel(final String reason, final String subclientId) { modelFactory.createGModel(); modelState.getRoot().setRevision(modelState.getRoot().getRevision() + 1); boolean needsClientLayout = diagramConfiguration.needsClientLayout(); if (needsClientLayout) { synchronized (modelLock) { return Arrays.asList(new RequestBoundsAction(modelState.getRoot()), - new SetDirtyStateAction(modelState.isDirty(), reason)); + new SetDirtyStateAction(modelState.isDirty(subclientId), reason)); } } - return submitModelDirectly(reason); + return submitModelDirectly(reason, subclientId); } - public List submitModel() { - return submitModel(null); + public List submitModel(final String subclientId) { + return submitModel(null, subclientId); } /** * Returns a list of actions to directly update the client-side model without any server- or client-side layouting. *

* Typically {@link ActionHandler action handlers} don't invoke this method but use - * {@link #submitModel(String)} + * {@link #submitModel(String, String)} * instead, as this is only used to eventually submit the model on the client directly after all layouting is already * performed before. The only foreseen caller of this method is {@link ComputedBoundsActionHandler}. *

@@ -95,7 +95,7 @@ public List submitModel() { * @param reason The optional reason that caused the model update. * @return A list of actions to be processed in order to submit the model. */ - public List submitModelDirectly(final String reason) { + public List submitModelDirectly(final String reason, final String subclientId) { GModelRoot gModel = modelState.getRoot(); if (diagramConfiguration.getLayoutKind() == ServerLayoutKind.AUTOMATIC && layoutEngine.isPresent()) { layoutEngine.get().layout(); @@ -106,14 +106,14 @@ public List submitModelDirectly(final String reason) { List result = new ArrayList<>(); result.add(modelAction); if (!diagramConfiguration.needsClientLayout()) { - result.add(new SetDirtyStateAction(modelState.isDirty(), reason)); + result.add(new SetDirtyStateAction(modelState.isDirty(subclientId), reason)); } return result; } } - public List submitModelDirectly() { - return submitModelDirectly(null); + public List submitModelDirectly(final String subclientId) { + return submitModelDirectly(null, subclientId); } public synchronized Object getModelLock() { return modelLock; } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/RequestModelActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/RequestModelActionHandler.java index c40007d4..aaaef886 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/RequestModelActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/RequestModelActionHandler.java @@ -24,6 +24,7 @@ import org.eclipse.glsp.server.di.DiagramModule; import org.eclipse.glsp.server.features.sourcemodelwatcher.SourceModelWatcher; import org.eclipse.glsp.server.model.GModelState; +import org.eclipse.glsp.server.utils.ClientOptionsUtil; import org.eclipse.glsp.server.utils.ServerMessageUtil; import org.eclipse.glsp.server.utils.ServerStatusUtil; @@ -58,15 +59,18 @@ public class RequestModelActionHandler extends AbstractActionHandler executeAction(final RequestModelAction action) { - modelState.setClientOptions(action.getOptions()); + // only reload if not initialized + if (!ClientOptionsUtil.disableReloadIsTrue(action.getOptions()) || modelState.getRoot() == null) { + modelState.setClientOptions(action.getOptions()); - notifyStartLoading(); - sourceModelStorage.loadSourceModel(action); - notifyFinishedLoading(); + notifyStartLoading(); + sourceModelStorage.loadSourceModel(action); + notifyFinishedLoading(); - sourceModelWatcher.ifPresent(watcher -> watcher.startWatching()); + sourceModelWatcher.ifPresent(watcher -> watcher.startWatching()); + } - return modelSubmissionHandler.submitModel(); + return modelSubmissionHandler.submitModel(action.getSubclientId()); } protected void notifyStartLoading() { diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/undoredo/UndoRedoActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/undoredo/UndoRedoActionHandler.java index fd203908..ddb94d75 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/undoredo/UndoRedoActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/undoredo/UndoRedoActionHandler.java @@ -39,12 +39,12 @@ public class UndoRedoActionHandler implements ActionHandler { @Override public List execute(final Action action) { - if (action instanceof UndoAction && modelState.canUndo()) { - modelState.undo(); - return modelSubmissionHandler.submitModel(SetDirtyStateAction.Reason.UNDO); - } else if (action instanceof RedoAction && modelState.canRedo()) { - modelState.redo(); - return modelSubmissionHandler.submitModel(SetDirtyStateAction.Reason.REDO); + if (action instanceof UndoAction && modelState.canUndo(action.getSubclientId())) { + modelState.undo(action.getSubclientId()); + return modelSubmissionHandler.submitModel(SetDirtyStateAction.Reason.UNDO, action.getSubclientId()); + } else if (action instanceof RedoAction && modelState.canRedo(action.getSubclientId())) { + modelState.redo(action.getSubclientId()); + return modelSubmissionHandler.submitModel(SetDirtyStateAction.Reason.REDO, action.getSubclientId()); } LOGGER.warn("Cannot undo or redo"); return none(); diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/actions/DefaultActionDispatcher.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/actions/DefaultActionDispatcher.java index 03d87259..4a05493c 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/actions/DefaultActionDispatcher.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/actions/DefaultActionDispatcher.java @@ -192,6 +192,7 @@ protected List> runAction(final Action action) { for (final ActionHandler actionHandler : actionHandlers) { final List responses = actionHandler.execute(action).stream() .map(response -> ResponseAction.respond(action, response)) + .map(response -> Action.addSubclientId(action, response)) .collect(Collectors.toList()); results.addAll(dispatchAll(responses)); if (action instanceof UpdateModelAction) { diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackFactory.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackFactory.java new file mode 100644 index 00000000..9fa927ad --- /dev/null +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackFactory.java @@ -0,0 +1,7 @@ +package org.eclipse.glsp.server.internal.command; + +import org.eclipse.emf.common.command.CommandStack; + +public interface CommandStackFactory { + CommandStack createCommandStack(); +} diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackManager.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackManager.java new file mode 100644 index 00000000..bc9f8fa2 --- /dev/null +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackManager.java @@ -0,0 +1,13 @@ +package org.eclipse.glsp.server.internal.command; + +import org.eclipse.emf.common.command.CommandStack; + +import java.util.List; + +public interface CommandStackManager { + CommandStack getOrCreateCommandStack(String subclientId); + + List getAllCommandStack(); + + void setCommandStack(CommandStack commandStack, String subclientId); +} diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/DefaultCommandStackManager.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/DefaultCommandStackManager.java new file mode 100644 index 00000000..d734100b --- /dev/null +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/DefaultCommandStackManager.java @@ -0,0 +1,53 @@ +package org.eclipse.glsp.server.internal.command; + +import com.google.inject.Inject; +import org.eclipse.emf.common.command.CommandStack; +import org.eclipse.glsp.server.utils.CollaborateUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DefaultCommandStackManager implements CommandStackManager { + + @Inject + CommandStackFactory factory; + + // subclientId, CommandStack + protected Map commandStackMap = new HashMap<>(); + + @Override + public CommandStack getOrCreateCommandStack(final String subclientId) { + String subclientIdOrFallback = getSubclientIdOrFallback(subclientId); + if (commandStackMap.containsKey(subclientIdOrFallback)) { + return commandStackMap.get(getSubclientIdOrFallback(subclientIdOrFallback)); + } + + CommandStack commandStack = factory.createCommandStack(); + commandStackMap.put(subclientIdOrFallback, commandStack); + return commandStack; + } + + @Override + public List getAllCommandStack() { + return new ArrayList<>(commandStackMap.values()); + } + + @Override + public void setCommandStack(final CommandStack commandStack, final String subclientId) { + String subclientIdOrFallback = getSubclientIdOrFallback(subclientId); + if (commandStackMap.containsKey(subclientIdOrFallback)) { + commandStackMap.get(subclientIdOrFallback).flush(); + } + commandStackMap.put(subclientIdOrFallback, commandStack); + } + + private String getSubclientIdOrFallback(final String subclientId) { + if (subclientId != null) { + return subclientId; + } + return CollaborateUtil.FALLBACK_SUBCLIENT_ID; + } + +} diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/gmodel/commandstack/GModelCommandStackFactory.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/gmodel/commandstack/GModelCommandStackFactory.java new file mode 100644 index 00000000..4b280354 --- /dev/null +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/gmodel/commandstack/GModelCommandStackFactory.java @@ -0,0 +1,11 @@ +package org.eclipse.glsp.server.internal.gmodel.commandstack; + +import org.eclipse.emf.common.command.CommandStack; +import org.eclipse.glsp.server.internal.command.CommandStackFactory; + +public class GModelCommandStackFactory implements CommandStackFactory { + @Override + public CommandStack createCommandStack() { + return new GModelCommandStack(); + } +} diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java index ef66fb54..5a061640 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java @@ -25,26 +25,33 @@ import org.eclipse.glsp.graph.GModelIndex; import org.eclipse.glsp.graph.GModelRoot; import org.eclipse.glsp.server.di.ClientId; +import org.eclipse.glsp.server.internal.command.CommandStackManager; import org.eclipse.glsp.server.internal.gmodel.commandstack.GModelCommandStack; import com.google.inject.Inject; public class DefaultGModelState implements GModelState { + public DefaultGModelState() { + System.out.println("test"); + } + @Inject @ClientId protected String clientId; + @Inject + protected CommandStackManager commandStackManager; + protected Map options; protected final Map properties = new HashMap<>(); protected GModelRoot currentModel; - protected CommandStack commandStack; protected String editMode; protected GModelIndex index = GModelIndex.empty(); @Inject public void init() { - setCommandStack(new GModelCommandStack()); + commandStackManager.setCommandStack(new GModelCommandStack(), null); } @Override @@ -71,13 +78,6 @@ protected GModelIndex getOrUpdateIndex(final GModelRoot newRoot) { protected void setRoot(final GModelRoot newRoot) { this.currentModel = newRoot; } - protected void setCommandStack(final CommandStack commandStack) { - if (this.commandStack != null) { - this.commandStack.flush(); - } - this.commandStack = commandStack; - } - @Override public void setClientOptions(final Map options) { this.options = options; } @@ -85,43 +85,50 @@ protected void setCommandStack(final CommandStack commandStack) { public GModelIndex getIndex() { return index; } @Override - public void execute(final Command command) { + public void execute(final Command command, String subclientId) { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); if (commandStack != null) { commandStack.execute(command); } } @Override - public boolean canUndo() { + public boolean canUndo(final String subclientId) { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); return commandStack != null && commandStack.canUndo(); } @Override - public boolean canRedo() { + public boolean canRedo(final String subclientId) { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); return commandStack != null && commandStack.canRedo(); } @Override - public void undo() { + public void undo(final String subclientId) { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); if (commandStack != null) { commandStack.undo(); } } @Override - public void redo() { + public void redo(final String subclientId) { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); if (commandStack != null) { commandStack.redo(); } } @Override - public boolean isDirty() { + public boolean isDirty(final String subclientId) { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); return commandStack instanceof BasicCommandStack && ((BasicCommandStack) commandStack).isSaveNeeded(); } @Override - public void saveIsDone() { + public void saveIsDone(final String subclientId) { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); if (commandStack instanceof BasicCommandStack) { ((BasicCommandStack) commandStack).saveIsDone(); } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/GModelState.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/GModelState.java index e9ea274d..70ffa118 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/GModelState.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/GModelState.java @@ -36,12 +36,12 @@ public interface GModelState extends ModelState { /** * Called after a save has been successfully performed. */ - void saveIsDone(); + void saveIsDone(String subclientId); /** * Uses its {@link BasicCommandStack} to execute a given {@link Command}. * * @param command The {@link Command} to be executed. */ - void execute(Command command); + void execute(Command command, String subclientId); } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/ModelState.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/ModelState.java index 0a9598ff..731dcc79 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/ModelState.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/ModelState.java @@ -34,15 +34,15 @@ interface ModelState { void updateRoot(T newRoot); - boolean canUndo(); + boolean canUndo(String subclientId); - boolean canRedo(); + boolean canRedo(String subclientId); - void undo(); + void undo(String subclientId); - void redo(); + void redo(String subclientId); - boolean isDirty(); + boolean isDirty(String subclientId); String getEditMode(); diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/OperationActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/OperationActionHandler.java index 30b0d059..6e56c867 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/OperationActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/OperationActionHandler.java @@ -62,18 +62,18 @@ protected List executeOperation(final Operation operation) { protected List executeHandler(final Operation operation, final OperationHandler handler) { Optional command = handler.execute(operation); if (command.isPresent()) { - exexcuteCommand(command.get()); - return submitModel(); + exexcuteCommand(command.get(), operation.getSubclientId()); + return submitModel(operation.getSubclientId()); } return none(); } - protected void exexcuteCommand(final Command command) { - modelState.execute(command); + protected void exexcuteCommand(final Command command, final String subclientId) { + modelState.execute(command, subclientId); } - protected List submitModel() { - return modelSubmissionHandler.submitModel(SetDirtyStateAction.Reason.OPERATION); + protected List submitModel(final String subclientId) { + return modelSubmissionHandler.submitModel(SetDirtyStateAction.Reason.OPERATION, subclientId); } /** diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/protocol/DefaultGLSPServer.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/protocol/DefaultGLSPServer.java index 5903d988..3fa50fd7 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/protocol/DefaultGLSPServer.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/protocol/DefaultGLSPServer.java @@ -28,6 +28,7 @@ import org.apache.logging.log4j.Logger; import org.eclipse.glsp.server.actions.ActionMessage; import org.eclipse.glsp.server.actions.ActionRegistry; +import org.eclipse.glsp.server.model.GModelState; import org.eclipse.glsp.server.session.ClientSession; import org.eclipse.glsp.server.session.ClientSessionManager; import org.eclipse.glsp.server.types.GLSPServerException; @@ -120,6 +121,7 @@ public CompletableFuture initializeClientSession(final InitializeClientSes ClientSession session = sessionManager.getOrCreateClientSession(params.getClientSessionId(), params.getDiagramType()); clientSessions.put(params.getClientSessionId(), session); + GModelState modelState = session.getInjector().getInstance(GModelState.class); return handleInitializeClientSessionArgs(params.getArgs()); } catch (GLSPServerException exception) { throw new ResponseErrorException( diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/ClientOptionsUtil.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/ClientOptionsUtil.java index 05c6deb4..9fd49381 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/ClientOptionsUtil.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/ClientOptionsUtil.java @@ -27,6 +27,8 @@ public final class ClientOptionsUtil { public static final String SOURCE_URI = "sourceUri"; private static final String FILE_PREFIX = "file://"; + private static final String DISABLE_RELOAD = "disableReload"; + private ClientOptionsUtil() {} public static Optional getSourceUri(final Map options) { @@ -35,7 +37,15 @@ public static Optional getSourceUri(final Map options) { public static Optional getDiagramType(final Map options) { return MapUtil.getValue(options, DIAGRAM_TYPE); + } + + public static Optional getDisableReload(final Map options) { + return MapUtil.getValue(options, DISABLE_RELOAD).map(Boolean::valueOf); + } + public static Boolean disableReloadIsTrue(final Map options) { + Optional disableReload = getDisableReload(options); + return disableReload.isPresent() && disableReload.get(); } public static Optional getSourceUriAsFile(final Map options) { diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/CollaborateUtil.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/CollaborateUtil.java new file mode 100644 index 00000000..73f51d1f --- /dev/null +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/CollaborateUtil.java @@ -0,0 +1,5 @@ +package org.eclipse.glsp.server.utils; + +public class CollaborateUtil { + public static final String FALLBACK_SUBCLIENT_ID = "FALLBACK_SUBCLIENT_ID"; +} From 6d96d400f5a1a5ff0d607fb2fde41b1dbb25e037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Hegedu=CC=88s?= Date: Mon, 8 May 2023 14:14:38 +0200 Subject: [PATCH 2/8] fix selection bug: subclientId not passed to response actions --- ...tractGModelCreateNodeOperationHandler.java | 6 +++++- .../GModelCreateNodeOperationHandler.java | 6 +++++- .../command/DefaultCommandStackManager.java | 4 ++-- .../glsp/server/model/DefaultGModelState.java | 4 ---- .../glsp/server/utils/CollaborateUtil.java | 5 ----- .../glsp/server/utils/CollaborationUtil.java | 21 +++++++++++++++++++ 6 files changed, 33 insertions(+), 13 deletions(-) delete mode 100644 plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/CollaborateUtil.java create mode 100644 plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/CollaborationUtil.java diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/AbstractGModelCreateNodeOperationHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/AbstractGModelCreateNodeOperationHandler.java index 960369e6..d7f21eb5 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/AbstractGModelCreateNodeOperationHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/AbstractGModelCreateNodeOperationHandler.java @@ -22,6 +22,7 @@ import org.eclipse.glsp.graph.GModelElement; import org.eclipse.glsp.graph.GNode; import org.eclipse.glsp.graph.GPoint; +import org.eclipse.glsp.server.actions.Action; import org.eclipse.glsp.server.actions.ActionDispatcher; import org.eclipse.glsp.server.actions.SelectAction; import org.eclipse.glsp.server.operations.AbstractCreateOperationHandler; @@ -59,7 +60,10 @@ public void executeOperation(final CreateNodeOperation operation) { .map(location -> LayoutUtil.getRelativeLocation(location, container)); GModelElement element = createNode(relativeLocation, operation.getArgs()); container.getChildren().add(element); - actionDispatcher.dispatchAfterNextUpdate(new SelectAction(), new SelectAction(List.of(element.getId()))); + actionDispatcher.dispatchAfterNextUpdate( + Action.addSubclientId(operation, new SelectAction()), + Action.addSubclientId(operation, new SelectAction(List.of(element.getId()))) + ); } /** diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelCreateNodeOperationHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelCreateNodeOperationHandler.java index b297c5bd..5f02eff8 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelCreateNodeOperationHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelCreateNodeOperationHandler.java @@ -23,6 +23,7 @@ import org.eclipse.glsp.graph.GModelElement; import org.eclipse.glsp.graph.GNode; import org.eclipse.glsp.graph.GPoint; +import org.eclipse.glsp.server.actions.Action; import org.eclipse.glsp.server.actions.ActionDispatcher; import org.eclipse.glsp.server.actions.SelectAction; import org.eclipse.glsp.server.operations.CreateEdgeOperation; @@ -59,7 +60,10 @@ public void executeCreation(final CreateNodeOperation operation) { Optional relativeLocation = getRelativeLocation(container, absoluteLocation); GModelElement element = createNode(relativeLocation, operation.getArgs()); container.getChildren().add(element); - actionDispatcher.dispatchAfterNextUpdate(new SelectAction(), new SelectAction(List.of(element.getId()))); + actionDispatcher.dispatchAfterNextUpdate( + Action.addSubclientId(operation, new SelectAction()), + Action.addSubclientId(operation, new SelectAction(List.of(element.getId()))) + ); } protected Optional getLocation(final CreateNodeOperation operation) { diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/DefaultCommandStackManager.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/DefaultCommandStackManager.java index d734100b..d0fec9a1 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/DefaultCommandStackManager.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/DefaultCommandStackManager.java @@ -2,7 +2,7 @@ import com.google.inject.Inject; import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.glsp.server.utils.CollaborateUtil; +import org.eclipse.glsp.server.utils.CollaborationUtil; import java.util.ArrayList; import java.util.HashMap; @@ -47,7 +47,7 @@ private String getSubclientIdOrFallback(final String subclientId) { if (subclientId != null) { return subclientId; } - return CollaborateUtil.FALLBACK_SUBCLIENT_ID; + return CollaborationUtil.FALLBACK_SUBCLIENT_ID; } } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java index 5a061640..a2896720 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java @@ -32,10 +32,6 @@ public class DefaultGModelState implements GModelState { - public DefaultGModelState() { - System.out.println("test"); - } - @Inject @ClientId protected String clientId; diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/CollaborateUtil.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/CollaborateUtil.java deleted file mode 100644 index 73f51d1f..00000000 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/CollaborateUtil.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.eclipse.glsp.server.utils; - -public class CollaborateUtil { - public static final String FALLBACK_SUBCLIENT_ID = "FALLBACK_SUBCLIENT_ID"; -} diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/CollaborationUtil.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/CollaborationUtil.java new file mode 100644 index 00000000..82989403 --- /dev/null +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/CollaborationUtil.java @@ -0,0 +1,21 @@ +/******************************************************************************** + * Copyright (c) 2020 EclipseSource and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +package org.eclipse.glsp.server.utils; + +public class CollaborationUtil { + public static final String FALLBACK_SUBCLIENT_ID = "FALLBACK_SUBCLIENT_ID"; +} From cfa706509bb635ef944b74f7e850bdc5679e1700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Hegedu=CC=88s?= Date: Mon, 8 May 2023 17:37:08 +0200 Subject: [PATCH 3/8] add subclientId to EmfModelState interface --- .../eclipse/glsp/server/emf/EMFModelState.java | 2 +- .../glsp/server/emf/EMFModelStateImpl.java | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelState.java b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelState.java index 72b7e21f..49501a96 100644 --- a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelState.java +++ b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelState.java @@ -20,7 +20,7 @@ import org.eclipse.glsp.server.model.GModelState; public interface EMFModelState extends GModelState { - void setEditingDomain(EditingDomain editingDomain); + void setEditingDomain(EditingDomain editingDomain, String subclientId); EditingDomain getEditingDomain(); diff --git a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java index 0cfb1097..de793027 100644 --- a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java +++ b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java @@ -17,6 +17,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.eclipse.emf.common.command.BasicCommandStack; import org.eclipse.emf.common.command.CommandStack; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.resource.Resource; @@ -24,6 +25,7 @@ import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.glsp.graph.GModelIndex; import org.eclipse.glsp.graph.GModelRoot; +import org.eclipse.glsp.server.internal.command.CommandStackManager; import org.eclipse.glsp.server.model.DefaultGModelState; import org.eclipse.glsp.server.session.ClientSession; import org.eclipse.glsp.server.session.ClientSessionListener; @@ -50,6 +52,9 @@ public class EMFModelStateImpl extends DefaultGModelState implements EMFModelSta @Inject protected ClientSessionManager clientSessionManager; + @Inject + protected CommandStackManager commandStackManager; + @Inject protected EMFIdGenerator idGenerator; @@ -62,9 +67,9 @@ public void init() { } @Override - public void setEditingDomain(final EditingDomain editingDomain) { + public void setEditingDomain(final EditingDomain editingDomain, final String subclientId) { this.editingDomain = editingDomain; - setCommandStack(this.editingDomain.getCommandStack()); + commandStackManager.setCommandStack(this.editingDomain.getCommandStack(), subclientId); } @Override @@ -107,8 +112,12 @@ protected void closeResourceSet() { } } if (result) { - commandStack.flush(); - saveIsDone(); + commandStackManager.getAllCommandStack().forEach(commandStack -> { + commandStack.flush(); + if (commandStack instanceof BasicCommandStack) { + ((BasicCommandStack) commandStack).saveIsDone(); + } + }); } } From d835a03afa0ad0b4be3cdc2fce9c93dcbbe9bdb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Hegedu=CC=88s?= Date: Mon, 8 May 2023 17:54:59 +0200 Subject: [PATCH 4/8] move CommandStackManager out of internal --- .../src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java | 2 +- .../server/{internal => }/command/CommandStackFactory.java | 2 +- .../server/{internal => }/command/CommandStackManager.java | 2 +- .../{internal => }/command/DefaultCommandStackManager.java | 2 +- .../src/org/eclipse/glsp/server/di/DiagramModule.java | 6 +++--- .../gmodel/commandstack/GModelCommandStackFactory.java | 2 +- .../org/eclipse/glsp/server/model/DefaultGModelState.java | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) rename plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/{internal => }/command/CommandStackFactory.java (72%) rename plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/{internal => }/command/CommandStackManager.java (85%) rename plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/{internal => }/command/DefaultCommandStackManager.java (97%) diff --git a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java index de793027..1296c129 100644 --- a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java +++ b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java @@ -25,7 +25,7 @@ import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.glsp.graph.GModelIndex; import org.eclipse.glsp.graph.GModelRoot; -import org.eclipse.glsp.server.internal.command.CommandStackManager; +import org.eclipse.glsp.server.command.CommandStackManager; import org.eclipse.glsp.server.model.DefaultGModelState; import org.eclipse.glsp.server.session.ClientSession; import org.eclipse.glsp.server.session.ClientSessionListener; diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackFactory.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/CommandStackFactory.java similarity index 72% rename from plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackFactory.java rename to plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/CommandStackFactory.java index 9fa927ad..9068ba62 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackFactory.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/CommandStackFactory.java @@ -1,4 +1,4 @@ -package org.eclipse.glsp.server.internal.command; +package org.eclipse.glsp.server.command; import org.eclipse.emf.common.command.CommandStack; diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackManager.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/CommandStackManager.java similarity index 85% rename from plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackManager.java rename to plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/CommandStackManager.java index bc9f8fa2..bced2277 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/CommandStackManager.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/CommandStackManager.java @@ -1,4 +1,4 @@ -package org.eclipse.glsp.server.internal.command; +package org.eclipse.glsp.server.command; import org.eclipse.emf.common.command.CommandStack; diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/DefaultCommandStackManager.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/DefaultCommandStackManager.java similarity index 97% rename from plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/DefaultCommandStackManager.java rename to plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/DefaultCommandStackManager.java index d0fec9a1..ab774af9 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/command/DefaultCommandStackManager.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/DefaultCommandStackManager.java @@ -1,4 +1,4 @@ -package org.eclipse.glsp.server.internal.command; +package org.eclipse.glsp.server.command; import com.google.inject.Inject; import org.eclipse.emf.common.command.CommandStack; diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/DiagramModule.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/DiagramModule.java index 00787b4f..d08fb71b 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/DiagramModule.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/DiagramModule.java @@ -87,9 +87,9 @@ import org.eclipse.glsp.server.gson.GraphGsonConfigurationFactory; import org.eclipse.glsp.server.internal.actions.DefaultActionDispatcher; import org.eclipse.glsp.server.internal.actions.DefaultActionHandlerRegistry; -import org.eclipse.glsp.server.internal.command.CommandStackFactory; -import org.eclipse.glsp.server.internal.command.CommandStackManager; -import org.eclipse.glsp.server.internal.command.DefaultCommandStackManager; +import org.eclipse.glsp.server.command.CommandStackFactory; +import org.eclipse.glsp.server.command.CommandStackManager; +import org.eclipse.glsp.server.command.DefaultCommandStackManager; import org.eclipse.glsp.server.internal.diagram.DefaultServerConfigurationContribution; import org.eclipse.glsp.server.internal.featues.directediting.DefaultContextEditValidatorRegistry; import org.eclipse.glsp.server.internal.featues.navigation.DefaultNavigationTargetProviderRegistry; diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/gmodel/commandstack/GModelCommandStackFactory.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/gmodel/commandstack/GModelCommandStackFactory.java index 4b280354..70fa53fe 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/gmodel/commandstack/GModelCommandStackFactory.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/gmodel/commandstack/GModelCommandStackFactory.java @@ -1,7 +1,7 @@ package org.eclipse.glsp.server.internal.gmodel.commandstack; import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.glsp.server.internal.command.CommandStackFactory; +import org.eclipse.glsp.server.command.CommandStackFactory; public class GModelCommandStackFactory implements CommandStackFactory { @Override diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java index 5e1873d6..93409511 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java @@ -25,7 +25,7 @@ import org.eclipse.glsp.graph.GModelIndex; import org.eclipse.glsp.graph.GModelRoot; import org.eclipse.glsp.server.di.ClientId; -import org.eclipse.glsp.server.internal.command.CommandStackManager; +import org.eclipse.glsp.server.command.CommandStackManager; import org.eclipse.glsp.server.internal.gmodel.commandstack.GModelCommandStack; import com.google.inject.Inject; From 19a4bfd82653bfdeace3bfc0f499aeaf2125fd4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Hegedu=CC=88s?= Date: Wed, 10 May 2023 01:01:15 +0200 Subject: [PATCH 5/8] give access to command package from outside --- plugins/org.eclipse.glsp.server/META-INF/MANIFEST.MF | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/org.eclipse.glsp.server/META-INF/MANIFEST.MF b/plugins/org.eclipse.glsp.server/META-INF/MANIFEST.MF index f2de91a4..7203ce44 100644 --- a/plugins/org.eclipse.glsp.server/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.glsp.server/META-INF/MANIFEST.MF @@ -32,6 +32,7 @@ Export-Package: org.eclipse.glsp.server.actions, org.eclipse.glsp.server.features.validation, org.eclipse.glsp.server.gmodel, org.eclipse.glsp.server.gson, + org.eclipse.glsp.server.command, org.eclipse.glsp.server.internal.actions;x-internal:=true, org.eclipse.glsp.server.internal.di.scope;x-internal:=true, org.eclipse.glsp.server.internal.diagram;x-internal:=true, From 78a5fbdfb54492c92b46dfd067b91afcd131da6d Mon Sep 17 00:00:00 2001 From: Olaf Lessenich Date: Wed, 3 May 2023 13:49:21 +0200 Subject: [PATCH 6/8] fix findings --- .../src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java | 2 +- .../org/eclipse/glsp/server/command/CommandStackManager.java | 2 +- .../glsp/server/command/DefaultCommandStackManager.java | 4 ++-- .../org/eclipse/glsp/server/protocol/DefaultGLSPServer.java | 2 -- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java index 1296c129..d88a1f4b 100644 --- a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java +++ b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelStateImpl.java @@ -112,7 +112,7 @@ protected void closeResourceSet() { } } if (result) { - commandStackManager.getAllCommandStack().forEach(commandStack -> { + commandStackManager.getAllCommandStacks().forEach(commandStack -> { commandStack.flush(); if (commandStack instanceof BasicCommandStack) { ((BasicCommandStack) commandStack).saveIsDone(); diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/CommandStackManager.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/CommandStackManager.java index bced2277..2d810828 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/CommandStackManager.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/CommandStackManager.java @@ -7,7 +7,7 @@ public interface CommandStackManager { CommandStack getOrCreateCommandStack(String subclientId); - List getAllCommandStack(); + List getAllCommandStacks(); void setCommandStack(CommandStack commandStack, String subclientId); } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/DefaultCommandStackManager.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/DefaultCommandStackManager.java index ab774af9..53c64ded 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/DefaultCommandStackManager.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/command/DefaultCommandStackManager.java @@ -21,7 +21,7 @@ public class DefaultCommandStackManager implements CommandStackManager { public CommandStack getOrCreateCommandStack(final String subclientId) { String subclientIdOrFallback = getSubclientIdOrFallback(subclientId); if (commandStackMap.containsKey(subclientIdOrFallback)) { - return commandStackMap.get(getSubclientIdOrFallback(subclientIdOrFallback)); + return commandStackMap.get(subclientIdOrFallback); } CommandStack commandStack = factory.createCommandStack(); @@ -30,7 +30,7 @@ public CommandStack getOrCreateCommandStack(final String subclientId) { } @Override - public List getAllCommandStack() { + public List getAllCommandStacks() { return new ArrayList<>(commandStackMap.values()); } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/protocol/DefaultGLSPServer.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/protocol/DefaultGLSPServer.java index 3fa50fd7..5903d988 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/protocol/DefaultGLSPServer.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/protocol/DefaultGLSPServer.java @@ -28,7 +28,6 @@ import org.apache.logging.log4j.Logger; import org.eclipse.glsp.server.actions.ActionMessage; import org.eclipse.glsp.server.actions.ActionRegistry; -import org.eclipse.glsp.server.model.GModelState; import org.eclipse.glsp.server.session.ClientSession; import org.eclipse.glsp.server.session.ClientSessionManager; import org.eclipse.glsp.server.types.GLSPServerException; @@ -121,7 +120,6 @@ public CompletableFuture initializeClientSession(final InitializeClientSes ClientSession session = sessionManager.getOrCreateClientSession(params.getClientSessionId(), params.getDiagramType()); clientSessions.put(params.getClientSessionId(), session); - GModelState modelState = session.getInjector().getInstance(GModelState.class); return handleInitializeClientSessionArgs(params.getArgs()); } catch (GLSPServerException exception) { throw new ResponseErrorException( From 3d8d7f4fc02a74c42649f5f5a6a013be7f31f6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Hegedu=CC=88s?= Date: Thu, 1 Feb 2024 19:49:59 +0100 Subject: [PATCH 7/8] Add comment to subclientId, fix remaining findings from Merge --- .../src/org/eclipse/glsp/server/actions/Action.java | 7 ++++--- .../server/features/core/model/ModelSubmissionHandler.java | 2 +- .../features/core/model/RequestModelActionHandler.java | 3 --- .../server/gmodel/GModelCreateNodeOperationHandler.java | 7 ++++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/Action.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/Action.java index e7387a6d..1ea32038 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/Action.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/Action.java @@ -16,7 +16,6 @@ package org.eclipse.glsp.server.actions; import org.eclipse.glsp.server.protocol.GLSPServer; -import org.eclipse.glsp.server.internal.util.GenericsUtil; /** * Java-implementation of the `Action` interface. An action is a declarative description of a behavior that @@ -41,10 +40,12 @@ public abstract class Action { */ private boolean receivedFromClient; + /** + * Unique identifier specifying the initiator of the action in a collaboration session. + * This value is initialized on the initating client. + */ private String subclientId; - public Action(final String kind) { - public Action(final String kind, final String subclientId) { super(); this.kind = kind; diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelSubmissionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelSubmissionHandler.java index 87b8f830..e7ebbbb4 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelSubmissionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelSubmissionHandler.java @@ -88,7 +88,7 @@ public List submitInitialModel(final RequestModelAction requestAction) { * Therefore we temporarily store the action later retrival */ this.requestModelAction = Optional.of(requestAction); - return submitModel(); + return submitModel(requestAction.getSubclientId()); } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/RequestModelActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/RequestModelActionHandler.java index e71614a0..6d9d0ad1 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/RequestModelActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/RequestModelActionHandler.java @@ -29,9 +29,6 @@ import org.eclipse.glsp.server.model.GModelState; import org.eclipse.glsp.server.utils.ClientOptionsUtil; import org.eclipse.glsp.server.utils.StatusActionUtil; -import org.eclipse.glsp.server.utils.ClientOptionsUtil; -import org.eclipse.glsp.server.utils.ServerMessageUtil; -import org.eclipse.glsp.server.utils.ServerStatusUtil; import com.google.inject.Inject; diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelCreateNodeOperationHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelCreateNodeOperationHandler.java index 6b701699..e3921114 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelCreateNodeOperationHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelCreateNodeOperationHandler.java @@ -64,10 +64,11 @@ public void executeCreation(final CreateNodeOperation operation) { Optional relativeLocation = getRelativeLocation(container, absoluteLocation); GModelElement element = createNode(relativeLocation, operation.getArgs()); container.getChildren().add(element); - actionDispatcher.dispatchAfterNextUpdate(SelectAction.addSelection(List.of(element.getId()))); actionDispatcher.dispatchAfterNextUpdate( - Action.addSubclientId(operation, new SelectAction()), - Action.addSubclientId(operation, new SelectAction(List.of(element.getId()))) + Action.addSubclientId( + operation, + SelectAction.addSelection(List.of(element.getId())) + ) ); } From b214e079a3339bb7a44f89cc59fef591876af603 Mon Sep 17 00:00:00 2001 From: MatthiasHofstaetter Date: Fri, 9 Aug 2024 17:10:56 +0200 Subject: [PATCH 8/8] * set subclientid within ActionDispatcher to remove it from method signatures --- .../actions/SaveModelActionHandler.java | 5 ++- .../model/ComputedBoundsActionHandler.java | 2 +- .../core/model/ModelSubmissionHandler.java | 18 ++++----- .../undoredo/UndoRedoActionHandler.java | 12 +++--- .../actions/DefaultActionDispatcher.java | 7 ++++ .../glsp/server/model/DefaultGModelState.java | 37 +++++++++++-------- .../glsp/server/model/GModelState.java | 6 ++- .../eclipse/glsp/server/model/ModelState.java | 10 ++--- .../operations/OperationActionHandler.java | 12 +++--- 9 files changed, 63 insertions(+), 46 deletions(-) diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/SaveModelActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/SaveModelActionHandler.java index 44c72bdf..18fd9952 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/SaveModelActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/SaveModelActionHandler.java @@ -45,11 +45,12 @@ public List executeAction(final SaveModelAction action) { modelSourceWatcher.ifPresent(watcher -> watcher.pauseWatching()); try { sourceModelStorage.saveSourceModel(action); - modelState.saveIsDone(action.getSubclientId()); + modelState.saveIsDone(); } finally { modelSourceWatcher.ifPresent(watcher -> watcher.continueWatching()); } - return listOf(new SetDirtyStateAction(modelState.isDirty(action.getSubclientId()), SetDirtyStateAction.Reason.SAVE)); + return listOf( + new SetDirtyStateAction(modelState.isDirty(), SetDirtyStateAction.Reason.SAVE)); } } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ComputedBoundsActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ComputedBoundsActionHandler.java index 8c58d234..d4be507d 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ComputedBoundsActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ComputedBoundsActionHandler.java @@ -45,7 +45,7 @@ public List executeAction(final ComputedBoundsAction action) { if (model != null && action.getRevision().isPresent() && action.getRevision().get().doubleValue() == model.getRevision()) { LayoutUtil.applyBounds(model, action, modelState); - return submissionHandler.submitModelDirectly(action.getSubclientId()); + return submissionHandler.submitModelDirectly(); } } return none(); diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelSubmissionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelSubmissionHandler.java index e7ebbbb4..8e15a563 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelSubmissionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelSubmissionHandler.java @@ -103,7 +103,7 @@ public List submitInitialModel(final RequestModelAction requestAction) { * @param reason The optional reason that caused the model update. * @return A list of actions to be processed in order to submit the model. */ - public List submitModel(final String reason, final String subclientId) { + public List submitModel(final String reason) { modelFactory.createGModel(); int revision = this.requestModelAction.isPresent() ? 0 : this.modelState.getRoot().getRevision() + 1; modelState.getRoot().setRevision(revision); @@ -112,14 +112,14 @@ public List submitModel(final String reason, final String subclientId) { if (needsClientLayout) { synchronized (modelLock) { return Arrays.asList(new RequestBoundsAction(modelState.getRoot()), - new SetDirtyStateAction(modelState.isDirty(subclientId), reason)); + new SetDirtyStateAction(modelState.isDirty(), reason)); } } - return submitModelDirectly(reason, subclientId); + return submitModelDirectly(reason); } - public List submitModel(final String subclientId) { - return submitModel(null, subclientId); + public List submitModel() { + return submitModel(null); } /** @@ -139,7 +139,7 @@ public List submitModel(final String subclientId) { * @param reason The optional reason that caused the model update. * @return A list of actions to be processed in order to submit the model. */ - public List submitModelDirectly(final String reason, final String subclientId) { + public List submitModelDirectly(final String reason) { GModelRoot gModel = modelState.getRoot(); if (diagramConfiguration.getLayoutKind() == ServerLayoutKind.AUTOMATIC && layoutEngine.isPresent()) { layoutEngine.get().layout(); @@ -152,7 +152,7 @@ public List submitModelDirectly(final String reason, final String subcli List result = new ArrayList<>(); result.add(modelAction); if (!diagramConfiguration.needsClientLayout()) { - result.add(new SetDirtyStateAction(modelState.isDirty(subclientId), reason)); + result.add(new SetDirtyStateAction(modelState.isDirty(), reason)); } if (validator.isPresent()) { List markers = validator.get() // @@ -163,8 +163,8 @@ public List submitModelDirectly(final String reason, final String subcli } } - public List submitModelDirectly(final String subclientId) { - return submitModelDirectly(null, subclientId); + public List submitModelDirectly() { + return submitModelDirectly(null); } protected SetModelAction createSetModeAction(final GModelRoot newRoot) { diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/undoredo/UndoRedoActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/undoredo/UndoRedoActionHandler.java index ddb94d75..fd203908 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/undoredo/UndoRedoActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/undoredo/UndoRedoActionHandler.java @@ -39,12 +39,12 @@ public class UndoRedoActionHandler implements ActionHandler { @Override public List execute(final Action action) { - if (action instanceof UndoAction && modelState.canUndo(action.getSubclientId())) { - modelState.undo(action.getSubclientId()); - return modelSubmissionHandler.submitModel(SetDirtyStateAction.Reason.UNDO, action.getSubclientId()); - } else if (action instanceof RedoAction && modelState.canRedo(action.getSubclientId())) { - modelState.redo(action.getSubclientId()); - return modelSubmissionHandler.submitModel(SetDirtyStateAction.Reason.REDO, action.getSubclientId()); + if (action instanceof UndoAction && modelState.canUndo()) { + modelState.undo(); + return modelSubmissionHandler.submitModel(SetDirtyStateAction.Reason.UNDO); + } else if (action instanceof RedoAction && modelState.canRedo()) { + modelState.redo(); + return modelSubmissionHandler.submitModel(SetDirtyStateAction.Reason.REDO); } LOGGER.warn("Cannot undo or redo"); return none(); diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/actions/DefaultActionDispatcher.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/actions/DefaultActionDispatcher.java index f89f6099..bbeb989e 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/actions/DefaultActionDispatcher.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/actions/DefaultActionDispatcher.java @@ -39,6 +39,7 @@ import org.eclipse.glsp.server.di.ClientId; import org.eclipse.glsp.server.disposable.Disposable; import org.eclipse.glsp.server.features.core.model.UpdateModelAction; +import org.eclipse.glsp.server.model.GModelState; import org.eclipse.glsp.server.protocol.GLSPClient; import org.eclipse.glsp.server.utils.FutureUtil; @@ -85,6 +86,10 @@ public class DefaultActionDispatcher extends Disposable implements ActionDispatc @Inject protected Provider client; + // use modelstate here to set subclient id + @Inject + protected GModelState modelState; + public DefaultActionDispatcher() { this.name = getClass().getSimpleName() + " " + COUNT.incrementAndGet(); this.thread = new Thread(this::runThread); @@ -193,6 +198,8 @@ protected List> runAction(final Action action) { throw new IllegalArgumentException("No handler registered for action: " + action); } + this.modelState.setParticipationID(action.getSubclientId()); + List> results = new ArrayList<>(); for (final ActionHandler actionHandler : actionHandlers) { final List responses = actionHandler.execute(action).stream() diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java index 93409511..7144bdae 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/DefaultGModelState.java @@ -24,8 +24,8 @@ import org.eclipse.emf.common.command.CommandStack; import org.eclipse.glsp.graph.GModelIndex; import org.eclipse.glsp.graph.GModelRoot; -import org.eclipse.glsp.server.di.ClientId; import org.eclipse.glsp.server.command.CommandStackManager; +import org.eclipse.glsp.server.di.ClientId; import org.eclipse.glsp.server.internal.gmodel.commandstack.GModelCommandStack; import com.google.inject.Inject; @@ -46,6 +46,7 @@ public class DefaultGModelState implements GModelState { protected GModelRoot currentModel; protected String editMode; protected GModelIndex index = GModelIndex.empty(); + protected String participationId; @Inject public void init() { @@ -83,50 +84,50 @@ protected GModelIndex getOrUpdateIndex(final GModelRoot newRoot) { public GModelIndex getIndex() { return index; } @Override - public void execute(final Command command, String subclientId) { - CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); + public void execute(final Command command) { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(this.participationId); if (commandStack != null) { commandStack.execute(command); } } @Override - public boolean canUndo(final String subclientId) { - CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); + public boolean canUndo() { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(this.participationId); return commandStack != null && commandStack.canUndo(); } @Override - public boolean canRedo(final String subclientId) { - CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); + public boolean canRedo() { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(this.participationId); return commandStack != null && commandStack.canRedo(); } @Override - public void undo(final String subclientId) { - CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); + public void undo() { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(this.participationId); if (commandStack != null) { commandStack.undo(); } } @Override - public void redo(final String subclientId) { - CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); + public void redo() { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(this.participationId); if (commandStack != null) { commandStack.redo(); } } @Override - public boolean isDirty(final String subclientId) { - CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); + public boolean isDirty() { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(this.participationId); return commandStack instanceof BasicCommandStack && ((BasicCommandStack) commandStack).isSaveNeeded(); } @Override - public void saveIsDone(final String subclientId) { - CommandStack commandStack = commandStackManager.getOrCreateCommandStack(subclientId); + public void saveIsDone() { + CommandStack commandStack = commandStackManager.getOrCreateCommandStack(this.participationId); if (commandStack instanceof BasicCommandStack) { ((BasicCommandStack) commandStack).saveIsDone(); } @@ -153,4 +154,10 @@ public

Optional

getProperty(final String key, final Class

type) { public void clearProperty(final String key) { properties.remove(key); } + + @Override + public void setParticipationID(final String id) { + this.participationId = id; + + } } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/GModelState.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/GModelState.java index 70ffa118..c147ba73 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/GModelState.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/GModelState.java @@ -36,12 +36,14 @@ public interface GModelState extends ModelState { /** * Called after a save has been successfully performed. */ - void saveIsDone(String subclientId); + void saveIsDone(); /** * Uses its {@link BasicCommandStack} to execute a given {@link Command}. * * @param command The {@link Command} to be executed. */ - void execute(Command command, String subclientId); + void execute(Command command); + + void setParticipationID(String id); } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/ModelState.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/ModelState.java index 731dcc79..0a9598ff 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/ModelState.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/model/ModelState.java @@ -34,15 +34,15 @@ interface ModelState { void updateRoot(T newRoot); - boolean canUndo(String subclientId); + boolean canUndo(); - boolean canRedo(String subclientId); + boolean canRedo(); - void undo(String subclientId); + void undo(); - void redo(String subclientId); + void redo(); - boolean isDirty(String subclientId); + boolean isDirty(); String getEditMode(); diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/OperationActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/OperationActionHandler.java index 1fa35e44..82a12d80 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/OperationActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/OperationActionHandler.java @@ -62,18 +62,18 @@ protected List executeOperation(final Operation operation) { protected List executeHandler(final Operation operation, final OperationHandler handler) { Optional command = handler.execute(operation); if (command.isPresent()) { - exexcuteCommand(command.get(), operation.getSubclientId()); - return submitModel(operation.getSubclientId()); + exexcuteCommand(command.get()); + return submitModel(); } return none(); } - protected void exexcuteCommand(final Command command, final String subclientId) { - modelState.execute(command, subclientId); + protected void exexcuteCommand(final Command command) { + modelState.execute(command); } - protected List submitModel(final String subclientId) { - return modelSubmissionHandler.submitModel(SetDirtyStateAction.Reason.OPERATION, subclientId); + protected List submitModel() { + return modelSubmissionHandler.submitModel(SetDirtyStateAction.Reason.OPERATION); } /**