|
@@ -12,10 +12,16 @@ package org.yakindu.sct.ui.editor.providers;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
-import org.eclipse.core.resources.IMarker;
|
|
|
import org.eclipse.draw2d.FlowLayout;
|
|
|
import org.eclipse.draw2d.Label;
|
|
|
+import org.eclipse.gef.EditDomain;
|
|
|
+import org.eclipse.gef.EditPart;
|
|
|
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
|
|
|
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
|
|
|
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
|
|
|
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
|
|
|
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain;
|
|
|
+import org.eclipse.gmf.runtime.diagram.ui.services.decorator.AbstractDecorator;
|
|
|
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider;
|
|
|
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget;
|
|
|
import org.eclipse.gmf.runtime.notation.Edge;
|
|
@@ -24,75 +30,111 @@ import org.eclipse.swt.graphics.Image;
|
|
|
import org.eclipse.ui.IEditorPart;
|
|
|
import org.eclipse.ui.ISharedImages;
|
|
|
import org.eclipse.ui.PlatformUI;
|
|
|
-import org.yakindu.base.gmf.runtime.decorators.AbstractMarkerBasedDecorationProvider;
|
|
|
+import org.eclipse.xtext.diagnostics.Severity;
|
|
|
+import org.eclipse.xtext.validation.Issue;
|
|
|
+import org.yakindu.base.gmf.runtime.decorators.AbstractDecoratorProvider;
|
|
|
import org.yakindu.sct.model.sgraph.FinalState;
|
|
|
import org.yakindu.sct.model.sgraph.Pseudostate;
|
|
|
+import org.yakindu.sct.model.sgraph.ui.validation.SCTIssue;
|
|
|
import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
|
|
|
-import org.yakindu.sct.ui.editor.validation.IMarkerType;
|
|
|
+import org.yakindu.sct.ui.editor.validation.IValidationIssueStore;
|
|
|
+import org.yakindu.sct.ui.editor.validation.IValidationIssueStore.IResourceIssueStoreListener;
|
|
|
|
|
|
-public class StatechartValidationDecorationProvider extends AbstractMarkerBasedDecorationProvider implements
|
|
|
- IDecoratorProvider, IMarkerType {
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author Andreas Muelder - Initial contribution and API
|
|
|
+ *
|
|
|
+ */
|
|
|
+public class StatechartValidationDecorationProvider extends AbstractDecoratorProvider implements IDecoratorProvider {
|
|
|
|
|
|
private static final String KEY = "org.yakindu.sct.ui.editor.validation";
|
|
|
|
|
|
- @Override
|
|
|
+ private IValidationIssueStore issueStore;
|
|
|
+
|
|
|
+ public void createDecorators(IDecoratorTarget decoratorTarget) {
|
|
|
+ EditPart editPart = (EditPart) decoratorTarget.getAdapter(EditPart.class);
|
|
|
+ if (editPart instanceof GraphicalEditPart || editPart instanceof AbstractConnectionEditPart) {
|
|
|
+ EditDomain ed = editPart.getViewer().getEditDomain();
|
|
|
+ if (!(ed instanceof DiagramEditDomain)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (shouldInstall(((DiagramEditDomain) ed).getEditorPart())) {
|
|
|
+ decoratorTarget.installDecorator(getDecoratorKey(), createStatusDecorator(decoratorTarget));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
protected boolean shouldInstall(IEditorPart part) {
|
|
|
- return part instanceof StatechartDiagramEditor;
|
|
|
+ if (part instanceof StatechartDiagramEditor) {
|
|
|
+ issueStore = (IValidationIssueStore) part.getAdapter(IValidationIssueStore.class);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
protected String getDecoratorKey() {
|
|
|
return KEY;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected StatusDecorator createStatusDecorator(IDecoratorTarget decoratorTarget) {
|
|
|
+ protected ValidationDecorator createStatusDecorator(IDecoratorTarget decoratorTarget) {
|
|
|
return new ValidationDecorator(decoratorTarget);
|
|
|
}
|
|
|
|
|
|
- public static class ValidationDecorator extends StatusDecorator {
|
|
|
+ public class ValidationDecorator extends AbstractDecorator implements IResourceIssueStoreListener {
|
|
|
|
|
|
public ValidationDecorator(IDecoratorTarget decoratorTarget) {
|
|
|
super(decoratorTarget);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected void createDecorators(View view, List<IMarker> markers) {
|
|
|
+ public void refresh() {
|
|
|
+ removeDecoration();
|
|
|
+ View view = (View) getDecoratorTarget().getAdapter(View.class);
|
|
|
+ if (view == null || view.eResource() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ EditPart editPart = (EditPart) getDecoratorTarget().getAdapter(EditPart.class);
|
|
|
+ if (editPart == null || editPart.getViewer() == null || !(editPart instanceof IPrimaryEditPart)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ decorate(view);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void activate() {
|
|
|
+ issueStore.addIssueStoreListener(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deactivate() {
|
|
|
+ super.deactivate();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void decorate(View view) {
|
|
|
String elementId = ViewUtil.getIdStr(view);
|
|
|
if (elementId == null) {
|
|
|
return;
|
|
|
}
|
|
|
- int severity = IMarker.SEVERITY_INFO;
|
|
|
- IMarker foundMarker = null;
|
|
|
+ List<SCTIssue> issues = issueStore.getIssues(elementId);
|
|
|
+ Severity severity = Severity.INFO;
|
|
|
Label toolTip = null;
|
|
|
- for (int i = 0; i < markers.size(); i++) {
|
|
|
- IMarker marker = markers.get(i);
|
|
|
- String attribute = marker.getAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID,
|
|
|
- "");
|
|
|
- if (attribute.equals(elementId)) {
|
|
|
- int nextSeverity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
|
|
|
- Image nextImage = getImage(nextSeverity);
|
|
|
- if (foundMarker == null) {
|
|
|
- foundMarker = marker;
|
|
|
- toolTip = new Label(marker.getAttribute(IMarker.MESSAGE, ""), //$NON-NLS-1$
|
|
|
- nextImage);
|
|
|
- } else {
|
|
|
- if (toolTip.getChildren().isEmpty()) {
|
|
|
- Label comositeLabel = new Label();
|
|
|
- FlowLayout fl = new FlowLayout(false);
|
|
|
- fl.setMinorSpacing(0);
|
|
|
- comositeLabel.setLayoutManager(fl);
|
|
|
- comositeLabel.add(toolTip);
|
|
|
- toolTip = comositeLabel;
|
|
|
- }
|
|
|
- toolTip.add(new Label(marker.getAttribute(IMarker.MESSAGE, ""), //$NON-NLS-1$
|
|
|
- nextImage));
|
|
|
+ if (issues.isEmpty())
|
|
|
+ return;
|
|
|
+ for (int i = 0; i < issues.size(); i++) {
|
|
|
+ Issue issue = issues.get(i);
|
|
|
+ Severity nextSeverity = issue.getSeverity();
|
|
|
+ Image nextImage = getImage(nextSeverity);
|
|
|
+ if (toolTip == null) {
|
|
|
+ toolTip = new Label(issue.getMessage(), nextImage);
|
|
|
+ } else {
|
|
|
+ if (toolTip.getChildren().isEmpty()) {
|
|
|
+ Label comositeLabel = new Label();
|
|
|
+ FlowLayout fl = new FlowLayout(false);
|
|
|
+ fl.setMinorSpacing(0);
|
|
|
+ comositeLabel.setLayoutManager(fl);
|
|
|
+ comositeLabel.add(toolTip);
|
|
|
+ toolTip = comositeLabel;
|
|
|
}
|
|
|
- severity = (nextSeverity > severity) ? nextSeverity : severity;
|
|
|
+ toolTip.add(new Label(issue.getMessage(), nextImage));
|
|
|
}
|
|
|
- }
|
|
|
- if (foundMarker == null) {
|
|
|
- return;
|
|
|
+ severity = (nextSeverity.ordinal() < severity.ordinal()) ? nextSeverity : severity;
|
|
|
}
|
|
|
|
|
|
if (view instanceof Edge) {
|
|
@@ -107,18 +149,13 @@ public class StatechartValidationDecorationProvider extends AbstractMarkerBasedD
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected String getMarkerType() {
|
|
|
- return SCT_MARKER_TYPE;
|
|
|
- }
|
|
|
-
|
|
|
- private Image getImage(int severity) {
|
|
|
+ protected Image getImage(Severity severity) {
|
|
|
String imageName = ISharedImages.IMG_OBJS_ERROR_TSK;
|
|
|
switch (severity) {
|
|
|
- case IMarker.SEVERITY_ERROR:
|
|
|
+ case ERROR:
|
|
|
imageName = ISharedImages.IMG_OBJS_ERROR_TSK;
|
|
|
break;
|
|
|
- case IMarker.SEVERITY_WARNING:
|
|
|
+ case WARNING:
|
|
|
imageName = ISharedImages.IMG_OBJS_WARN_TSK;
|
|
|
break;
|
|
|
default:
|
|
@@ -126,5 +163,10 @@ public class StatechartValidationDecorationProvider extends AbstractMarkerBasedD
|
|
|
}
|
|
|
return PlatformUI.getWorkbench().getSharedImages().getImage(imageName);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void issuesChanged() {
|
|
|
+ refresh();
|
|
|
+ }
|
|
|
}
|
|
|
}
|