Skip to content

Commit

Permalink
Remove unnecessary 'ApplyTaskEditAction' and update operation handlers
Browse files Browse the repository at this point in the history
- Use 'EditTaskOperation' directly from the client
- Minor checkstyle cleanup and refactoring for Paste handler
- Make CutOperationHandler GModel-specific as it returns recording cmd
- Let LayoutOperationHandler inherit from generic base class
- Update some JavaDoc

Relates to eclipse-glsp/glsp#864
  • Loading branch information
martin-fleck-at committed Jan 30, 2023
1 parent 19c071f commit d739b0f
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.eclipse.glsp.example.workflow.provider.PreviousNodeNavigationTargetProvider;
import org.eclipse.glsp.example.workflow.provider.WorkflowCommandPaletteActionProvider;
import org.eclipse.glsp.example.workflow.provider.WorkflowContextMenuItemProvider;
import org.eclipse.glsp.example.workflow.taskedit.ApplyTaskEditActionHandler;
import org.eclipse.glsp.example.workflow.taskedit.EditTaskOperationHandler;
import org.eclipse.glsp.example.workflow.taskedit.TaskEditContextActionProvider;
import org.eclipse.glsp.example.workflow.taskedit.TaskEditValidator;
Expand Down Expand Up @@ -123,7 +122,6 @@ protected void configureActionHandlers(final MultiBinding<ActionHandler> binding
super.configureActionHandlers(binding);
binding.rebind(RequestContextActionsHandler.class, WorkflowRequestContextActionsHandler.class);
binding.add(LogActionHandler.class);
binding.add(ApplyTaskEditActionHandler.class);
}

@Override
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
* Gson type adapter that can determine the actual Java class to use for a JSON
* object based on a discriminator property.
*/
@SuppressWarnings("restriction")
public abstract class PropertyBasedTypeAdapter<T> extends TypeAdapter<T> {

private final Gson gson;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import org.eclipse.glsp.server.features.validation.ModelValidator;
import org.eclipse.glsp.server.features.validation.RequestMarkersHandler;
import org.eclipse.glsp.server.features.validation.SetMarkersAction;
import org.eclipse.glsp.server.gmodel.GModelCutOperationHandler;
import org.eclipse.glsp.server.gson.GraphGsonConfigurationFactory;
import org.eclipse.glsp.server.internal.actions.DefaultActionDispatcher;
import org.eclipse.glsp.server.internal.actions.DefaultActionHandlerRegistry;
Expand All @@ -97,7 +98,6 @@
import org.eclipse.glsp.server.model.DefaultGModelState;
import org.eclipse.glsp.server.model.GModelState;
import org.eclipse.glsp.server.operations.CompoundOperationHandler;
import org.eclipse.glsp.server.operations.CutOperationHandler;
import org.eclipse.glsp.server.operations.LayoutOperationHandler;
import org.eclipse.glsp.server.operations.OperationActionHandler;
import org.eclipse.glsp.server.operations.OperationHandler;
Expand Down Expand Up @@ -337,7 +337,7 @@ protected Class<? extends ActionHandlerRegistry> bindActionHandlerRegistry() {
protected void configureOperationHandlers(final MultiBinding<OperationHandler<?>> binding) {
binding.add(CompoundOperationHandler.class);
binding.add(LayoutOperationHandler.class);
binding.add(CutOperationHandler.class);
binding.add(GModelCutOperationHandler.class);
}

protected Class<? extends OperationHandlerRegistry> bindOperationHandlerRegistry() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@

import com.google.inject.Inject;

/**
* Syncs the bounds computed by the client (i.e. the actual bounds after applying CSS styles) back to the GModel. In
* this default implementation the updated bounds are stored transient. This means they are applied to the graphical
* model but are not persisted to the source model.
*/
public class ComputedBoundsActionHandler extends AbstractActionHandler<ComputedBoundsAction> {

@Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/********************************************************************************
* Copyright (c) 2020-2023 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.gmodel;

import java.util.List;
import java.util.Optional;

import org.eclipse.emf.common.command.Command;
import org.eclipse.glsp.server.actions.ActionDispatcher;
import org.eclipse.glsp.server.operations.CutOperation;
import org.eclipse.glsp.server.operations.DeleteOperation;
import org.eclipse.glsp.server.operations.GModelOperationHandler;

import com.google.inject.Inject;

/**
* Performs the cut operation by dispatching a {@link DeleteOperation} for the elements to be cut.
*/
public class GModelCutOperationHandler extends GModelOperationHandler<CutOperation> {

@Inject
protected ActionDispatcher actionDispatcher;

protected List<String> getElementsToCut(final CutOperation cutAction) {
return cutAction.getEditorContext().getSelectedElementIds();
}

@Override
public Optional<Command> createCommand(final CutOperation operation) {
List<String> elementsToCut = getElementsToCut(operation);
return elementsToCut.isEmpty()
? doNothing()
: commandOf(() -> actionDispatcher.dispatch(new DeleteOperation(elementsToCut)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -62,7 +63,8 @@ public GModelPasteOperationHandler(final GraphGsonConfigurationFactory gsonConfi
@Override
public Optional<Command> createCommand(final PasteOperation operation) {
List<GModelElement> elements = getCopiedElements(operation.getClipboardData().get("application/json"));
return elements.isEmpty() ? doNothing()
return elements.isEmpty()
? doNothing()
: commandOf(() -> executePaste(elements, operation.getEditorContext()));
}

Expand All @@ -76,8 +78,9 @@ public void executePaste(final List<GModelElement> elements, final EditorContext
modelState.getRoot().getChildren().addAll(elements);
}

protected ArrayList<GModelElement> getCopiedElements(final String jsonString) {
return new ArrayList<>(Arrays.asList(gson.fromJson(jsonString, GModelElement[].class)));
protected List<GModelElement> getCopiedElements(final String jsonString) {
GModelElement[] elements = gson.fromJson(jsonString, GModelElement[].class);
return elements != null ? new ArrayList<>(Arrays.asList(elements)) : Collections.emptyList();
}

protected GPoint computeOffset(final List<GModelElement> elements, final Optional<GPoint> lastMousePosition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,10 @@
********************************************************************************/
package org.eclipse.glsp.server.operations;

import java.util.List;
import java.util.Optional;

import org.eclipse.emf.common.command.Command;
import org.eclipse.glsp.server.actions.ActionDispatcher;

import com.google.inject.Inject;
import org.eclipse.glsp.server.gmodel.GModelCutOperationHandler;

/**
* Performs the cut operation by dispatching a {@link DeleteOperation} for the elements to be cut.
* @deprecated Use {@link GModelCutOperationHandler} instead for GModel-based languages.
*/
public class CutOperationHandler extends GModelOperationHandler<CutOperation> {

@Inject
protected ActionDispatcher actionDispatcher;

protected List<String> getElementsToCut(final CutOperation cutAction) {
return cutAction.getEditorContext().getSelectedElementIds();
}

@Override
public Optional<Command> createCommand(final CutOperation operation) {
List<String> elementsToCut = getElementsToCut(operation);
return elementsToCut.isEmpty()
? doNothing()
: commandOf(() -> actionDispatcher.dispatch(new DeleteOperation(elementsToCut)));
}
}
@Deprecated
public class CutOperationHandler extends GModelCutOperationHandler {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

import org.eclipse.emf.common.command.Command;
import org.eclipse.glsp.server.diagram.DiagramConfiguration;
import org.eclipse.glsp.server.internal.gmodel.commandstack.GModelRecordingCommand;
import org.eclipse.glsp.server.layout.LayoutEngine;
import org.eclipse.glsp.server.layout.ServerLayoutKind;

import com.google.inject.Inject;

/**
* Delegates to the configured {@link LayoutEngine} to apply a layout.
* The default handler for `{@link LayoutOperation}s. Does invoke the (optional) layout engine if the server is
* configured for manual layouting. Changes are stored transient in the graphical model and are not persisted in the
* source model.
*/
public class LayoutOperationHandler extends GModelOperationHandler<LayoutOperation> {
public class LayoutOperationHandler extends BasicOperationHandler<LayoutOperation> {

@Inject
protected Optional<LayoutEngine> layoutEngine;
Expand All @@ -39,7 +42,7 @@ public class LayoutOperationHandler extends GModelOperationHandler<LayoutOperati
public Optional<Command> createCommand(final LayoutOperation operation) {
return layoutEngine.isEmpty() || diagramConfiguration.getLayoutKind() != ServerLayoutKind.MANUAL
? doNothing()
: commandOf(() -> layoutEngine.get().layout());
: Optional.of(new GModelRecordingCommand(modelState.getRoot(), getLabel(), () -> layoutEngine.get().layout()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
import org.eclipse.glsp.server.model.GModelState;

/**
* An operation handler can execute {@link Operation}s of a certain type (subclass).
* The operation handler processes the operation in the {@link OperationHandler#execute(Operation)} method. The result
* of the execution is an update of the {@link GModelState} state.
* This update is reversible (undo) and can be reapplied (redo). For basic diagram languages these updates are typically
* applied directly on the {@link GModelState} using EMF {@link Command}s and the
* {@link GModelState#execute(org.eclipse.emf.common.command.Command)} method. For more complex diagram languages the
* GModel state might be updated indirectly and the operation handler manipulates a custom model representation.
* An operation handler can execute {@link Operation}s of a certain type (subclass). The operation handler creates a
* command in the {@link #createCommand(Operation)} method. The result represents an update of the {@link GModelState}
* state and is later executed via {@link GModelState#execute(org.eclipse.emf.common.command.Command)}. If an empty
* command is returned, no changes are executed and the state is not modified, i.e., not made dirty. The command
* execution is reversible (undo) and can be re-applied (redo).
*
* The {@link OperationActionHandler} is responsible for retrieving all available (valid) operation handlers for an
* operation that is dispatched via {@link ActionDispatcher}.
Expand Down Expand Up @@ -58,7 +56,7 @@ default Class<O> getHandledOperationType() {
Optional<Command> createCommand(O operation);

/**
* Executes the operation handler for the given {@link Operation}. If the given action cannot be handled by this
* Executes the operation handler for the given {@link Operation}. If the given operation cannot be handled by this
* operation handler an empty command is returned an no changes are executed.
*
* @param operation The operation that should be executed or empty if nothing should be done.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected CompletableFuture<InitializeResult> handleIntializeArgs(final Initiali

protected void validateServerInitialized() {
if (!isInitialized()) {
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.serverNotInitialized,
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.ServerNotInitialized,
"The GLSP server has not been initialized.", null));
}
}
Expand Down

0 comments on commit d739b0f

Please sign in to comment.