Skip to content

Commit

Permalink
migrated AbstractOperationHandler => GModelOperationHandler
Browse files Browse the repository at this point in the history
Issue #269
  • Loading branch information
rsoika committed Jul 28, 2023
1 parent 177a342 commit a3c05e0
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.emf.common.command.Command;
import org.eclipse.glsp.graph.GModelElement;
import org.eclipse.glsp.server.actions.ActionDispatcher;
import org.eclipse.glsp.server.operations.AbstractOperationHandler;
import org.eclipse.glsp.server.operations.GModelOperationHandler;
import org.openbpmn.bpmn.elements.core.BPMNElement;
import org.openbpmn.extensions.BPMNElementExtension;
import org.openbpmn.glsp.bpmn.BPMNGEdge;
Expand All @@ -44,7 +45,7 @@
*
*/
public class BPMNApplyPropertiesUpdateOperationHandler
extends AbstractOperationHandler<BPMNApplyPropertiesUpdateOperation> {
extends GModelOperationHandler<BPMNApplyPropertiesUpdateOperation> {
private static Logger logger = LogManager.getLogger(BPMNApplyPropertiesUpdateOperationHandler.class);

@Inject
Expand All @@ -56,11 +57,15 @@ public class BPMNApplyPropertiesUpdateOperationHandler
@Inject
protected Set<BPMNElementExtension> extensions;

@Override
public Optional<Command> createCommand(BPMNApplyPropertiesUpdateOperation operation) {
return commandOf(() -> executeOperation(operation));
}

/**
*
*/
@Override
protected void executeOperation(final BPMNApplyPropertiesUpdateOperation operation) {
private void executeOperation(final BPMNApplyPropertiesUpdateOperation operation) {
long l = System.currentTimeMillis();
String jsonData = operation.getJsonData();
String category = operation.getCategory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.emf.common.command.Command;
import org.eclipse.glsp.graph.GCompartment;
import org.eclipse.glsp.graph.GDimension;
import org.eclipse.glsp.graph.GModelElement;
import org.eclipse.glsp.graph.GNode;
import org.eclipse.glsp.graph.GPoint;
import org.eclipse.glsp.graph.builder.impl.GLayoutOptions;
import org.eclipse.glsp.graph.util.GraphUtil;
import org.eclipse.glsp.server.operations.AbstractOperationHandler;
import org.eclipse.glsp.server.operations.ChangeBoundsOperation;
import org.eclipse.glsp.server.operations.GModelOperationHandler;
import org.eclipse.glsp.server.types.ElementAndBounds;
import org.openbpmn.bpmn.elements.Activity;
import org.openbpmn.bpmn.elements.Association;
import org.openbpmn.bpmn.elements.BPMNProcess;
import org.openbpmn.bpmn.elements.Lane;
Expand All @@ -46,6 +49,7 @@
import org.openbpmn.bpmn.exceptions.BPMNInvalidReferenceException;
import org.openbpmn.bpmn.exceptions.BPMNInvalidTypeException;
import org.openbpmn.bpmn.exceptions.BPMNMissingElementException;
import org.openbpmn.glsp.bpmn.BPMNGNode;
import org.openbpmn.glsp.bpmn.PoolGNode;
import org.openbpmn.glsp.model.BPMNGModelState;
import org.openbpmn.glsp.utils.BPMNGModelUtil;
Expand Down Expand Up @@ -85,13 +89,18 @@
* @author rsoika
*
*/
public class BPMNChangeBoundsOperationHandler extends AbstractOperationHandler<ChangeBoundsOperation> {
public class BPMNChangeBoundsOperationHandler extends GModelOperationHandler<ChangeBoundsOperation> {

private static Logger logger = LogManager.getLogger(BPMNChangeBoundsOperationHandler.class);

@Inject
protected BPMNGModelState modelState;

@Override
public Optional<Command> createCommand(ChangeBoundsOperation operation) {
return commandOf(() -> executeOperation(operation));
}

/**
* Update the bounds for all selected elements in the GModel and also in the
* BPMNModel.
Expand All @@ -100,8 +109,7 @@ public class BPMNChangeBoundsOperationHandler extends AbstractOperationHandler<C
* this case we remove the label from the selection because the
* updateFlowElement method treads the label automatically.
*/
@Override
public void executeOperation(final ChangeBoundsOperation operation) {
private void executeOperation(final ChangeBoundsOperation operation) {
// iterate over all new Bounds...
logger.debug("=== ChangeBoundsOperation - " + operation.getNewBounds().size() + " new bounds");

Expand Down Expand Up @@ -238,6 +246,15 @@ private void updateFlowElement(final GNode gNode, final BPMNElementNode bpmnElem
// see:
// https://github.com/eclipse-glsp/glsp/discussions/741#discussioncomment-3688606
gNode.setSize(newSize);

// If we have a Task, than we need to reposition the extension label too!
if (bpmnElementNode instanceof Activity && gNode instanceof BPMNGNode) {
GCompartment extensionCompartment = BPMNGModelUtil.findExtensionCompartment((BPMNGNode) gNode);
if (extensionCompartment != null) {
extensionCompartment.setPosition(GraphUtil.point(3, newSize.getHeight() - 12));
}
}

}
// if the flow Element has a BPMNLabel, than we need to adjust finally the
// position of the label too
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import java.util.Optional;
import java.util.logging.Logger;

import org.eclipse.emf.common.command.Command;
import org.eclipse.glsp.graph.GEdge;
import org.eclipse.glsp.graph.GPoint;
import org.eclipse.glsp.server.operations.AbstractOperationHandler;
import org.eclipse.glsp.server.operations.ChangeRoutingPointsOperation;
import org.eclipse.glsp.server.operations.GModelOperationHandler;
import org.eclipse.glsp.server.types.ElementAndRoutingPoints;
import org.openbpmn.glsp.model.BPMNGModelState;

Expand All @@ -39,15 +40,20 @@
* @author rsoika
*
*/
public class BPMNChangeRoutingPointsOperationHandler extends AbstractOperationHandler<ChangeRoutingPointsOperation> {
public class BPMNChangeRoutingPointsOperationHandler extends GModelOperationHandler<ChangeRoutingPointsOperation> {

private static Logger logger = Logger.getLogger(BPMNChangeRoutingPointsOperationHandler.class.getName());

@Inject
protected BPMNGModelState modelState;


@Override
public void executeOperation(final ChangeRoutingPointsOperation operation) {
public Optional<Command> createCommand(ChangeRoutingPointsOperation operation) {
return commandOf(() -> executeOperation(operation));
}

private void executeOperation(final ChangeRoutingPointsOperation operation) {

List<ElementAndRoutingPoints> routingPoints = operation.getNewRoutingPoints();
logger.fine("=== ChangeRoutingPointsOperation - " + routingPoints.size() + " routing points");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
package org.openbpmn.glsp.operations;

import java.util.List;
import java.util.Optional;
import java.util.logging.Logger;

import org.eclipse.glsp.server.operations.AbstractOperationHandler;
import org.eclipse.emf.common.command.Command;
import org.eclipse.glsp.server.operations.DeleteOperation;
import org.eclipse.glsp.server.operations.GModelOperationHandler;
import org.openbpmn.bpmn.elements.Association;
import org.openbpmn.bpmn.elements.BPMNProcess;
import org.openbpmn.bpmn.elements.Message;
Expand All @@ -37,14 +39,18 @@
* Lanes, Processes and
* Messages.
*/
public class BPMNDeleteNodeHandler extends AbstractOperationHandler<DeleteOperation> {
public class BPMNDeleteNodeHandler extends GModelOperationHandler<DeleteOperation> {
private static Logger logger = Logger.getLogger(BPMNDeleteNodeHandler.class.getName());

@Inject
protected BPMNGModelState modelState;

@Override
public void executeOperation(final DeleteOperation operation) {
public Optional<Command> createCommand(DeleteOperation operation) {
return commandOf(() -> executeOperation(operation));
}

private void executeOperation(final DeleteOperation operation) {

List<String> elementIds = operation.getElementIds();
if (elementIds == null || elementIds.size() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.emf.common.command.Command;
import org.eclipse.glsp.graph.GPoint;
import org.eclipse.glsp.server.actions.ActionDispatcher;
import org.eclipse.glsp.server.actions.SelectAction;
import org.eclipse.glsp.server.operations.AbstractOperationHandler;
import org.eclipse.glsp.server.operations.GModelOperationHandler;
import org.eclipse.glsp.server.operations.PasteOperation;
import org.openbpmn.bpmn.elements.BPMNProcess;
import org.openbpmn.bpmn.elements.SequenceFlow;
Expand All @@ -49,7 +51,7 @@
* @see {@link BPMNClipboardDataActionHandler}
* @author rsoika
*/
public class BPMNPasteOperationHandler extends AbstractOperationHandler<PasteOperation> {
public class BPMNPasteOperationHandler extends GModelOperationHandler<PasteOperation> {

private static Logger logger = LogManager.getLogger(BPMNPasteOperationHandler.class);

Expand All @@ -59,6 +61,11 @@ public class BPMNPasteOperationHandler extends AbstractOperationHandler<PasteOpe
@Inject
protected ActionDispatcher actionDispatcher;

@Override
public Optional<Command> createCommand(PasteOperation operation) {
return commandOf(() -> executeOperation(operation));
}

/**
* This method copies the current element selection into the diagram. The
* selection is stored in the data structure with the key 'bpmn' which is
Expand All @@ -70,8 +77,7 @@ public class BPMNPasteOperationHandler extends AbstractOperationHandler<PasteOpe
* new ElementIDs. Next the method copies the BPMN Edges by reconnecting the
* clone to the new ElementIDs.
*/
@Override
protected void executeOperation(PasteOperation operation) {
private void executeOperation(PasteOperation operation) {
BPMNPoint refPoint = null;
double xOffset = 0;
double yOffset = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
********************************************************************************/
package org.openbpmn.glsp.operations;

import java.util.Optional;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.glsp.server.operations.AbstractOperationHandler;
import org.eclipse.emf.common.command.Command;
import org.eclipse.glsp.server.operations.GModelOperationHandler;
import org.eclipse.glsp.server.operations.ReconnectEdgeOperation;
import org.openbpmn.bpmn.BPMNTypes;
import org.openbpmn.bpmn.elements.core.BPMNElementEdge;
Expand All @@ -34,15 +37,19 @@
* @author rsoika
*
*/
public class BPMNReconnectEdgeOperationHandler extends AbstractOperationHandler<ReconnectEdgeOperation> {
public class BPMNReconnectEdgeOperationHandler extends GModelOperationHandler<ReconnectEdgeOperation> {

private static Logger logger = LogManager.getLogger(BPMNReconnectEdgeOperationHandler.class);

@Inject
protected BPMNGModelState modelState;

@Override
public void executeOperation(final ReconnectEdgeOperation operation) {
public Optional<Command> createCommand(ReconnectEdgeOperation operation) {
return commandOf(() -> executeOperation(operation));
}

private void executeOperation(final ReconnectEdgeOperation operation) {

String edgeID = operation.getEdgeElementId();
String sourceElementID = operation.getSourceElementId();
Expand Down

0 comments on commit a3c05e0

Please sign in to comment.