Skip to content
Snippets Groups Projects
Commit 7faffeab authored by Johannes Eder's avatar Johannes Eder
Browse files

sub diagram labels

refs 2446
parent 72a55e6f
No related branches found
No related tags found
No related merge requests found
......@@ -17,14 +17,19 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editpart.allocation;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_INSETS;
import static org.fortiss.tooling.base.ui.editpart.ExtendedLayerRootEditPart.DECORATION_LAYER;
import static org.fortiss.tooling.base.ui.editpart.ExtendedLayerRootEditPart.LABEL_LAYER;
import static org.fortiss.tooling.base.ui.utils.DecorationIconUtils.getMarkerServiceDecorationIcon;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement;
import java.util.ArrayList;
import java.util.List;
import org.conqat.ide.commons.ui.swt.FontUtils;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
......@@ -34,16 +39,22 @@ import org.eclipse.gef.NodeEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.RootEditPart;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.fortiss.tooling.base.layout.DefaultLayoutConstants;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.ui.editpart.GraphicalEditPartBase;
import org.fortiss.tooling.base.ui.editpart.PositionedEditPartBase;
import org.fortiss.tooling.base.ui.editpart.figure.PrettyRoundedRectangle;
import org.fortiss.tooling.base.ui.editpart.figure.TransparentLabel;
import org.fortiss.tooling.base.ui.layout.IDiagramLayoutConfiguration;
import org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
import org.fortiss.tooling.kernel.ui.service.IMarkerService;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
/**
* Implementation similar to {@link PositionedEditPartBase} except that <b>T</b> does not have to be
......@@ -56,7 +67,7 @@ import org.fortiss.tooling.kernel.ui.service.IMarkerService;
* @param <T>
* @ConQAT.Rating RED Hash:
*/
public abstract class AllocationSubDiagramEditPartBase<T extends EObject> extends
public abstract class AllocationSubDiagramEditPartBase<T extends INamedCommentedElement> extends
GraphicalEditPartBase<T> implements NodeEditPart {
/** The base figure of this positioned edit part. */
......@@ -73,6 +84,9 @@ public abstract class AllocationSubDiagramEditPartBase<T extends EObject> extend
/** List of all children visible in this edit part. */
private List<?> modelChildren = new ArrayList<>();
/** The default font for titles. */
public static Font DEFAULT_TITLE_FONT = FontUtils.derive(JFaceResources.getDefaultFont(), 0,
SWT.BOLD);
/**
* @param modelElement
......@@ -100,6 +114,73 @@ public abstract class AllocationSubDiagramEditPartBase<T extends EObject> extend
return prettyRoundedRectangle;
}
/** Creates the label figure. */
public Label createLabelFigure() {
Label nameLabel = new TransparentLabel();
nameLabel.setForegroundColor(getForegroundColor());
nameLabel.setFont(DEFAULT_TITLE_FONT);
nameLabel.setTextAlignment(PositionConstants.LEFT | PositionConstants.TOP);
nameLabel.setTextPlacement(PositionConstants.EAST);
nameLabel.setIcon(IModelElementHandlerService.INSTANCE.getModelElementHandler(getModel())
.getIcon(getModel()));
return nameLabel;
}
/**
* Creates the decoration figure. The default implementation does not create
* a figure.
*/
protected Label createDecorationFigure() {
return new TransparentLabel();
}
/** {@inheritDoc} */
@Override
public void addNotify() {
labelFigure = createLabelFigure();
if(labelFigure != null) {
registerLabelFigure(labelFigure);
}
decorationFigure = createDecorationFigure();
if(decorationFigure != null) {
registerDecorationFigure(decorationFigure);
}
// called last, since it also refreshes label and decoration
super.addNotify();
}
/** {@inheritDoc} */
@Override
public void removeNotify() {
if(labelFigure != null && labelFigure.getParent() != null) {
labelFigure.getParent().remove(labelFigure);
}
if(decorationFigure != null && decorationFigure.getParent() != null) {
decorationFigure.getParent().remove(decorationFigure);
}
super.removeNotify();
}
/**
* Register the new label figure into the label figure structure.
*/
protected void registerLabelFigure(IFigure figure) {
if(getParent() instanceof AllocationSubDiagramEditPartBase)
((AllocationSubDiagramEditPartBase<?>)getParent()).registerLabelFigure(figure);
else
getLayer(LABEL_LAYER).add(figure);
}
/**
* Register the new decoration figure into the decoration figure structure.
*/
protected void registerDecorationFigure(IFigure figure) {
if(getParent() instanceof AllocationSubDiagramEditPartBase)
((AllocationSubDiagramEditPartBase<?>)getParent()).registerDecorationFigure(figure);
else
getLayer(DECORATION_LAYER).add(figure);
}
/** {@inheritDoc} */
@Override
protected final List<?> getModelChildren() {
......@@ -199,7 +280,15 @@ public abstract class AllocationSubDiagramEditPartBase<T extends EObject> extend
* implementation returns an invisible rectangle.
*/
protected Rectangle determineLabelFigureBounds() {
return new Rectangle();
Rectangle textBounds = labelFigure.getTextBounds();
textBounds.y = DEFAULT_SHAPE_INSETS / 2;
textBounds.x = DEFAULT_SHAPE_INSETS;
textBounds.width = textBounds.width + 4 * DEFAULT_SHAPE_INSETS;
textBounds.height = textBounds.height * 2;
if(isTargetDiagram()) {
textBounds.y += baseFigure.getBounds().y;
}
return textBounds;
}
/**
......@@ -208,7 +297,7 @@ public abstract class AllocationSubDiagramEditPartBase<T extends EObject> extend
* implementation returns an empty string.
*/
protected String determineLabelFigureText() {
return getModel().toString();
return getModel().getName();
}
/** Returns the current tooltip description. */
......@@ -279,15 +368,4 @@ public abstract class AllocationSubDiagramEditPartBase<T extends EObject> extend
}
}
/** {@inheritDoc} */
@Override
public void removeNotify() {
if(labelFigure != null && labelFigure.getParent() != null) {
labelFigure.getParent().remove(labelFigure);
}
if(decorationFigure != null && decorationFigure.getParent() != null) {
decorationFigure.getParent().remove(decorationFigure);
}
super.removeNotify();
}
}
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