Skip to content
Snippets Groups Projects
Commit f21fdbf1 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

fixed error display

refs 504
parent c523da86
No related branches found
No related tags found
No related merge requests found
...@@ -22,9 +22,11 @@ import static org.eclipse.draw2d.Graphics.LINE_SOLID; ...@@ -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.COMPONENT_ROLE;
import static org.eclipse.gef.EditPolicy.CONNECTION_BENDPOINTS_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.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 static org.fortiss.tooling.base.ui.utils.LayoutDataUtils.getConnectionPoints;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import org.eclipse.draw2d.AbsoluteBendpoint; import org.eclipse.draw2d.AbsoluteBendpoint;
...@@ -34,6 +36,7 @@ import org.eclipse.draw2d.MidpointLocator; ...@@ -34,6 +36,7 @@ import org.eclipse.draw2d.MidpointLocator;
import org.eclipse.draw2d.PolygonDecoration; import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.PolylineConnection; import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.draw2d.geometry.Point; 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.Adapter;
import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.common.notify.impl.AdapterImpl;
...@@ -43,6 +46,7 @@ import org.eclipse.gef.editparts.AbstractConnectionEditPart; ...@@ -43,6 +46,7 @@ import org.eclipse.gef.editparts.AbstractConnectionEditPart;
import org.eclipse.gef.editpolicies.BendpointEditPolicy; import org.eclipse.gef.editpolicies.BendpointEditPolicy;
import org.eclipse.gef.requests.BendpointRequest; import org.eclipse.gef.requests.BendpointRequest;
import org.eclipse.swt.graphics.Color; 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.base.ConnectionSegmentBase;
import org.fortiss.tooling.base.model.layout.Points; import org.fortiss.tooling.base.model.layout.Points;
import org.fortiss.tooling.base.ui.editpart.command.bendpoint.CreateCommand; import org.fortiss.tooling.base.ui.editpart.command.bendpoint.CreateCommand;
...@@ -50,7 +54,10 @@ import org.fortiss.tooling.base.ui.editpart.command.bendpoint.DeleteCommand; ...@@ -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.command.bendpoint.MoveCommand;
import org.fortiss.tooling.base.ui.editpart.policy.RemoveEditPolicy; import org.fortiss.tooling.base.ui.editpart.policy.RemoveEditPolicy;
import org.fortiss.tooling.base.ui.layout.IDiagramLayoutConfiguration; 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.extension.IModelElementHandler;
import org.fortiss.tooling.kernel.ui.service.IMarkerService;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
/** /**
...@@ -61,7 +68,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; ...@@ -61,7 +68,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating GREEN Hash: 66658DB86881AB1ED2B4CD152E7AF051 * @ConQAT.Rating YELLOW Hash: 9924C9304C8DC34A5FB6C0B088B11502
*/ */
public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
extends AbstractConnectionEditPart { extends AbstractConnectionEditPart {
...@@ -88,6 +95,9 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> ...@@ -88,6 +95,9 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
/** The simulation value label drawn in highlighted color. */ /** The simulation value label drawn in highlighted color. */
protected final Label simulationLabel; protected final Label simulationLabel;
/** The decoration figure. */
protected Label decorationFigure;
/** /**
* The adapter used to receive change notifications for the * The adapter used to receive change notifications for the
* {@link #modelElement}. * {@link #modelElement}.
...@@ -111,7 +121,17 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> ...@@ -111,7 +121,17 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
setModel(modelElement); setModel(modelElement);
this.modelElementHandler = (IModelElementHandler<T>) IModelElementHandlerService.INSTANCE this.modelElementHandler = (IModelElementHandler<T>) IModelElementHandlerService.INSTANCE
.getModelElementHandler(modelElement); .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(""); this.simulationLabel = new Label("");
simulationLabel.setForegroundColor(getSimulationLabelColor()); simulationLabel.setForegroundColor(getSimulationLabelColor());
} }
...@@ -142,6 +162,64 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> ...@@ -142,6 +162,64 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
return connection; 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} */ /** {@inheritDoc} */
@Override @Override
public void activate() { public void activate() {
...@@ -181,6 +259,16 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> ...@@ -181,6 +259,16 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
refreshBendpoints(); refreshBendpoints();
} }
/** {@inheritDoc} */
@Override
public void addNotify() {
super.addNotify();
decorationFigure = createDecorationFigure();
if (decorationFigure != null) {
getLayer(DECORATION_LAYER).add(decorationFigure);
}
}
/** {@inheritDoc} */ /** {@inheritDoc} */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
...@@ -193,6 +281,13 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> ...@@ -193,6 +281,13 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
return super.getAdapter(key); return super.getAdapter(key);
} }
/**
* Creates the decoration figure.
*/
protected Label createDecorationFigure() {
return new Label();
}
/** Updates the bend points, based on the model. */ /** Updates the bend points, based on the model. */
protected void refreshBendpoints() { protected void refreshBendpoints() {
Points pts = getConnectionPoints(modelElement); Points pts = getConnectionPoints(modelElement);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment