Skip to content

Commit

Permalink
adapted new GLSP Validation API
Browse files Browse the repository at this point in the history
Issue #338
  • Loading branch information
rsoika committed Feb 28, 2024
1 parent bccae22 commit f46b3cc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -206,12 +204,6 @@ protected Class<? extends ModelValidator> bindModelValidator() {
return BPMNGLSPValidator.class;
}

@Override
protected void configureContextEditValidators(final MultiBinding<ContextEditValidator> binding) {
super.configureContextEditValidators(binding);
binding.add(LabelEditValidator.class);
}

/**
* Add Create actions to the palette that opens up on Ctrl+Space
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,24 +50,64 @@ public class BPMNGLSPValidator implements ModelValidator {
@Inject
protected BPMNGModelState modelState;

private List<Marker> bpmnMarkers = null;;

@Override
public List<Marker> validate(final GModelElement... elements) {
logger.fine("...starting validating model...");
public List<Marker> validate(final List<GModelElement> elements, final String reason) {

// init bpmn marker list....
if (MarkersReason.BATCH.equals(reason)) {
createBPMNMarkers();
}

List<Marker> 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<Marker> doBatchValidation(final GModelElement element) {

logger.info("...validate " + element.getId());

List<Marker> 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<BPMNValidationError> errorList = modelState.getBpmnModel().validate();

// 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;
}

}

This file was deleted.

0 comments on commit f46b3cc

Please sign in to comment.