From f46b3cc4f7e208990af991c043edc96a7226952b Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Wed, 28 Feb 2024 22:42:08 +0100 Subject: [PATCH] adapted new GLSP Validation API Issue #338 --- .../org/openbpmn/glsp/BPMNDiagramModule.java | 8 --- .../glsp/validators/BPMNGLSPValidator.java | 49 ++++++++++++-- .../glsp/validators/LabelEditValidator.java | 66 ------------------- 3 files changed, 45 insertions(+), 78 deletions(-) delete mode 100644 open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/validators/LabelEditValidator.java diff --git a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/BPMNDiagramModule.java b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/BPMNDiagramModule.java index 39ab0bd1..dccb6bed 100644 --- a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/BPMNDiagramModule.java +++ b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/BPMNDiagramModule.java @@ -24,7 +24,6 @@ import org.eclipse.glsp.server.features.commandpalette.CommandPaletteActionProvider; import org.eclipse.glsp.server.features.core.model.GModelFactory; import org.eclipse.glsp.server.features.core.model.SourceModelStorage; -import org.eclipse.glsp.server.features.directediting.ContextEditValidator; import org.eclipse.glsp.server.features.toolpalette.ToolPaletteItemProvider; import org.eclipse.glsp.server.features.validation.ModelValidator; import org.eclipse.glsp.server.gmodel.GModelCutOperationHandler; @@ -75,7 +74,6 @@ import org.openbpmn.glsp.provider.BPMNCommandPaletteActionProvider; import org.openbpmn.glsp.provider.BPMNToolPaletteItemProvider; import org.openbpmn.glsp.validators.BPMNGLSPValidator; -import org.openbpmn.glsp.validators.LabelEditValidator; import com.google.inject.multibindings.Multibinder; @@ -206,12 +204,6 @@ protected Class bindModelValidator() { return BPMNGLSPValidator.class; } - @Override - protected void configureContextEditValidators(final MultiBinding binding) { - super.configureContextEditValidators(binding); - binding.add(LabelEditValidator.class); - } - /** * Add Create actions to the palette that opens up on Ctrl+Space */ diff --git a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/validators/BPMNGLSPValidator.java b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/validators/BPMNGLSPValidator.java index 2b4dc7b8..e99e16a5 100644 --- a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/validators/BPMNGLSPValidator.java +++ b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/validators/BPMNGLSPValidator.java @@ -22,6 +22,7 @@ import org.eclipse.glsp.graph.GModelElement; import org.eclipse.glsp.server.features.validation.Marker; import org.eclipse.glsp.server.features.validation.MarkerKind; +import org.eclipse.glsp.server.features.validation.MarkersReason; import org.eclipse.glsp.server.features.validation.ModelValidator; import org.openbpmn.bpmn.validation.BPMNValidationError; import org.openbpmn.glsp.model.BPMNGModelState; @@ -49,10 +50,51 @@ public class BPMNGLSPValidator implements ModelValidator { @Inject protected BPMNGModelState modelState; + private List bpmnMarkers = null;; + @Override - public List validate(final GModelElement... elements) { - logger.fine("...starting validating model..."); + public List validate(final List elements, final String reason) { + + // init bpmn marker list.... + if (MarkersReason.BATCH.equals(reason)) { + createBPMNMarkers(); + } + List markers = new ArrayList<>(); + for (GModelElement element : elements) { + if (MarkersReason.LIVE.equals(reason)) { + markers.addAll(doLiveValidation(element)); + } else if (MarkersReason.BATCH.equals(reason)) { + markers.addAll(doBatchValidation(element)); + } else { + markers.addAll(doValidationForCustomReason(element, reason)); + } + if (!element.getChildren().isEmpty()) { + markers.addAll(validate(element.getChildren(), reason)); + } + } + + return markers; + } + + @Override + public List doBatchValidation(final GModelElement element) { + + logger.info("...validate " + element.getId()); + + List result = new ArrayList<>(); + for (Marker marker : bpmnMarkers) { + if (marker.getElementId().equals(element.getId())) { + result.add(marker); + } + } + + return result; + } + + private void createBPMNMarkers() { + logger.fine("...starting validating model..."); + bpmnMarkers = new ArrayList<>(); // Meta Model validation... List errorList = modelState.getBpmnModel().validate(); @@ -60,13 +102,12 @@ public List validate(final GModelElement... elements) { // Convert ErrorList into a GLSP Marker List for (BPMNValidationError _error : errorList) { if (BPMNValidationError.ErrorType.ERROR.equals(_error.getErrorType())) { - markers.add(new Marker(_error.getLabel(), _error.getDescription(), _error.getElementId(), + bpmnMarkers.add(new Marker(_error.getLabel(), _error.getDescription(), _error.getElementId(), MarkerKind.ERROR)); } } - return markers; } } \ No newline at end of file diff --git a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/validators/LabelEditValidator.java b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/validators/LabelEditValidator.java deleted file mode 100644 index 00001151..00000000 --- a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/validators/LabelEditValidator.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022 Imixs Software Solutions GmbH 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 - * http://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.openbpmn.glsp.validators; - -import java.util.Optional; -import java.util.logging.Logger; - -import org.eclipse.glsp.server.features.directediting.ContextEditValidator; -import org.eclipse.glsp.server.features.directediting.RequestEditValidationAction; -import org.eclipse.glsp.server.features.directediting.ValidationStatus; -import org.eclipse.glsp.server.model.GModelState; -import org.openbpmn.glsp.bpmn.BPMNGNode; - -import com.google.inject.Inject; - -/** - * This ContextEditValidator reacts on label-edits within the diagram pane and - * updates the corresponding 'name' property from the parent BaseElement node. - *

- * This means if the user edits the label of a ElementNode he indirectly edit - * the 'name' property. - * - * @author rsoika - * - */ -public class LabelEditValidator implements ContextEditValidator { - private static Logger logger = Logger.getLogger(LabelEditValidator.class.getName()); - - @Override - public String getContextId() { - return "label-edit"; - } - - @Inject - protected GModelState modelState; - - @SuppressWarnings("checkstyle:cyclomaticComplexity") - @Override - public ValidationStatus validate(final RequestEditValidationAction action) { - String text = action.getText(); - String id = action.getModelElementId(); - logger.fine("...validate Element: " + id); - // test if this element is a BaseElement with the property 'name' - Optional element = modelState.getIndex().findElementByClass(id, BPMNGNode.class); - if (!element.isEmpty()) { - // We have a BaseElemtn, update the name attribute - element.get().setName(text); - } - // no further validation needed - return ValidationStatus.ok(); - } - -}