From f21fdbf1f4d8a44f06bcc3d5f18cbc592393d59b Mon Sep 17 00:00:00 2001 From: Florian Hoelzl <hoelzl@fortiss.org> Date: Mon, 30 Jan 2012 14:45:59 +0000 Subject: [PATCH] fixed error display refs 504 --- .../ui/editpart/ConnectionEditPartBase.java | 99 ++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/ConnectionEditPartBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/ConnectionEditPartBase.java index 0224e2ada..69e5a034c 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/ConnectionEditPartBase.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/ConnectionEditPartBase.java @@ -22,9 +22,11 @@ import static org.eclipse.draw2d.Graphics.LINE_SOLID; import static org.eclipse.gef.EditPolicy.COMPONENT_ROLE; import static org.eclipse.gef.EditPolicy.CONNECTION_BENDPOINTS_ROLE; import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_SIZE; +import static org.fortiss.tooling.base.ui.editpart.ExtendedLayerRootEditPart.DECORATION_LAYER; import static org.fortiss.tooling.base.ui.utils.LayoutDataUtils.getConnectionPoints; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import org.eclipse.draw2d.AbsoluteBendpoint; @@ -34,6 +36,7 @@ import org.eclipse.draw2d.MidpointLocator; import org.eclipse.draw2d.PolygonDecoration; import org.eclipse.draw2d.PolylineConnection; import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.emf.common.notify.Adapter; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.impl.AdapterImpl; @@ -43,6 +46,7 @@ import org.eclipse.gef.editparts.AbstractConnectionEditPart; import org.eclipse.gef.editpolicies.BendpointEditPolicy; import org.eclipse.gef.requests.BendpointRequest; import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; import org.fortiss.tooling.base.model.base.ConnectionSegmentBase; import org.fortiss.tooling.base.model.layout.Points; import org.fortiss.tooling.base.ui.editpart.command.bendpoint.CreateCommand; @@ -50,7 +54,10 @@ import org.fortiss.tooling.base.ui.editpart.command.bendpoint.DeleteCommand; import org.fortiss.tooling.base.ui.editpart.command.bendpoint.MoveCommand; import org.fortiss.tooling.base.ui.editpart.policy.RemoveEditPolicy; import org.fortiss.tooling.base.ui.layout.IDiagramLayoutConfiguration; +import org.fortiss.tooling.kernel.extension.data.IConstraintViolation; +import org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity; import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler; +import org.fortiss.tooling.kernel.ui.service.IMarkerService; import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; /** @@ -61,7 +68,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating GREEN Hash: 66658DB86881AB1ED2B4CD152E7AF051 + * @ConQAT.Rating YELLOW Hash: 9924C9304C8DC34A5FB6C0B088B11502 */ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> extends AbstractConnectionEditPart { @@ -88,6 +95,9 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> /** The simulation value label drawn in highlighted color. */ protected final Label simulationLabel; + /** The decoration figure. */ + protected Label decorationFigure; + /** * The adapter used to receive change notifications for the * {@link #modelElement}. @@ -111,7 +121,17 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> setModel(modelElement); this.modelElementHandler = (IModelElementHandler<T>) IModelElementHandlerService.INSTANCE .getModelElementHandler(modelElement); - this.relationshipLabel = new Label(modelElement.getName()); + this.relationshipLabel = new Label(modelElement.getName()) { + /** {@inheritDoc} */ + @Override + public void setBounds(Rectangle rect) { + super.setBounds(rect); + if (decorationFigure != null + && decorationFigure.getParent() != null) { + refreshDecorationFigure(); + } + } + }; this.simulationLabel = new Label(""); simulationLabel.setForegroundColor(getSimulationLabelColor()); } @@ -142,6 +162,64 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> return connection; } + /** + * Returns the position and size of the decoration figure. The computation + * may use the bounds of the base figure or the label figure, since both + * bounds were determined first. + */ + protected Rectangle determineDecorationFigureBounds() { + Rectangle r = new Rectangle(relationshipLabel.getBounds()); + r.x -= 16; + r.y -= 16; + r.width = useSmallDecorationImage() ? 8 : 16; + r.height = useSmallDecorationImage() ? 8 : 16; + return r; + } + + /** Refreshes the decoration figure using {@link IMarkerService} */ + private void refreshDecorationFigure() { + Rectangle decorationBounds = determineDecorationFigureBounds(); + decorationFigure.setBounds(decorationBounds); + decorationFigure.getParent().setConstraint(decorationFigure, + decorationBounds); + + Image icon = null; + ESeverity sev = IMarkerService.INSTANCE + .getHighestViolationSeverity(getModel()); + switch (sev) { + case ERROR: + icon = IMarkerService.INSTANCE.getImageFor(ESeverity.ERROR, + useSmallDecorationImage()).createImage(); + break; + case WARNING: + icon = IMarkerService.INSTANCE.getImageFor(ESeverity.WARNING, + useSmallDecorationImage()).createImage(); + break; + default: + } + decorationFigure.setIcon(icon); + if (icon != null) { + String message = ""; + Collection<IConstraintViolation<? extends EObject>> violations = IMarkerService.INSTANCE + .getViolations(getModel()); + for (IConstraintViolation<? extends EObject> viol : violations) { + if (viol.getSeverity() == sev) { + message = viol.getExplanation(); + break; + } + } + decorationFigure.setToolTip(new Label(message)); + } + } + + /** + * Returns whether to use small or big decoration image. Default + * implementation uses big image. + */ + protected boolean useSmallDecorationImage() { + return false; + } + /** {@inheritDoc} */ @Override public void activate() { @@ -181,6 +259,16 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> refreshBendpoints(); } + /** {@inheritDoc} */ + @Override + public void addNotify() { + super.addNotify(); + decorationFigure = createDecorationFigure(); + if (decorationFigure != null) { + getLayer(DECORATION_LAYER).add(decorationFigure); + } + } + /** {@inheritDoc} */ @SuppressWarnings("rawtypes") @Override @@ -193,6 +281,13 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> return super.getAdapter(key); } + /** + * Creates the decoration figure. + */ + protected Label createDecorationFigure() { + return new Label(); + } + /** Updates the bend points, based on the model. */ protected void refreshBendpoints() { Points pts = getConnectionPoints(modelElement); -- GitLab