Skip to content
Snippets Groups Projects
Commit a4d86182 authored by Dongyue Mou's avatar Dongyue Mou
Browse files

fixed label display in sub diagram edit part

parent 69140744
No related branches found
No related tags found
No related merge requests found
......@@ -73,7 +73,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 8B8903072134F354F6341CC0495960D2
* @ConQAT.Rating YELLOW Hash: AD9BFEBCE8FA4EC287F6E64A52348B0B
*/
public abstract class PositionedEditPartBase<T extends ILayoutedModelElement> extends
GraphicalEditPartBase<T> implements NodeEditPart {
......@@ -266,11 +266,11 @@ public abstract class PositionedEditPartBase<T extends ILayoutedModelElement> ex
public void addNotify() {
labelFigure = createLabelFigure();
if(labelFigure != null) {
getLayer(LABEL_LAYER).add(labelFigure);
registerLabelFigure(labelFigure);
}
decorationFigure = createDecorationFigure();
if(decorationFigure != null) {
getLayer(DECORATION_LAYER).add(decorationFigure);
registerDecorationFigure(decorationFigure);
}
// called last, since it also refreshes label and decoration
super.addNotify();
......@@ -279,15 +279,35 @@ public abstract class PositionedEditPartBase<T extends ILayoutedModelElement> ex
/** {@inheritDoc} */
@Override
public void removeNotify() {
if(labelFigure != null) {
getLayer(LABEL_LAYER).remove(labelFigure);
if(labelFigure != null && labelFigure.getParent() != null) {
labelFigure.getParent().remove(labelFigure);
}
if(decorationFigure != null) {
getLayer(DECORATION_LAYER).remove(decorationFigure);
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 PositionedEditPartBase)
((PositionedEditPartBase<?>)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 PositionedEditPartBase)
((PositionedEditPartBase<?>)getParent()).registerDecorationFigure(figure);
else
getLayer(DECORATION_LAYER).add(figure);
}
/**
* {@inheritDoc}
* <p>
......
......@@ -17,36 +17,40 @@ $Id: ElementEditPartBase.java 8344 2013-08-05 08:11:09Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editpart;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_SIZE;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_INSETS;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.fortiss.tooling.base.layout.DefaultLayoutConstants;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.ui.editpart.figure.TransparentLabel;
import org.fortiss.tooling.base.ui.utils.LayoutDataUtils;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
/**
* The base class for graphical edit parts which encapsulate nodes (i.e. the
* main modeling elements). All of them have a name label and an activation
* mode.
* The base class for a (partial) diagram edit parts, which is intended to be part of another
* diagram.
*
* @param <T>
* the type of the model element wrapped.
*
* @author hoelzl
* @author mou
* @author $Author: hoelzl $
* @version $Rev: 8344 $
* @ConQAT.Rating GREEN Hash: 7E81A6A123F7421DD0D73BE0F9C7D72A
* @ConQAT.Rating YELLOW Hash: 3804FA8B123026E3F6491108A4226863
*/
public abstract class SubDiagramEditPartBase<T extends ILayoutedModelElement & INamedCommentedElement>
extends ElementEditPartBase<T> {
/** the label layer for internal labels */
private Figure labelFigureLayer;
/** Constructor. */
protected SubDiagramEditPartBase(T modelObject) {
super(modelObject);
......@@ -78,47 +82,55 @@ public abstract class SubDiagramEditPartBase<T extends ILayoutedModelElement & I
if(result == null) {
result = new Rectangle();
}
result.expand(DefaultLayoutConstants.DEFAULT_GRID_SIZE,
DefaultLayoutConstants.DEFAULT_GRID_SIZE);
result.setLocation(DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE);
result.expand(DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE);
result.resize(DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE);
return result;
}
/** {@inheritDoc} */
@Override
protected Rectangle determineLabelFigureBounds() {
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;
return textBounds;
}
/** {@inheritDoc} */
@Override
public Label createLabelFigure() {
Label nameLabel = new TransparentLabel() {
/** {@inheritDoc} */
@Override
protected boolean useLocalCoordinates() {
return true;
}
Label label = super.createLabelFigure();
label.setLabelAlignment(PositionConstants.LEFT);
return label;
}
/** {@inheritDoc} */
@Override
public void add(IFigure figure, Object constraint, int index) {
// TODO Auto-generated method stub
super.add(figure, constraint, index);
}
};
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()));
nameLabel.setIconAlignment(PositionConstants.TOP | PositionConstants.LEFT);
return nameLabel;
/** {@inheritDoc} */
@Override
protected void registerLabelFigure(IFigure figure) {
if(labelFigureLayer == null) {
labelFigureLayer = new Figure() {
/** {@inheritDoc} */
@Override
protected boolean useLocalCoordinates() {
return true;
}
};
labelFigureLayer.setLayoutManager(new XYLayout());
super.registerLabelFigure(labelFigureLayer);
}
labelFigureLayer.add(figure);
}
/** {@inheritDoc} */
@Override
protected Rectangle determineLabelFigureBounds() {
Rectangle textBounds = labelFigure.getTextBounds();
Rectangle labelBounds = determineBaseFigureBounds();
labelBounds.y += 2 * DefaultLayoutConstants.DEFAULT_SHAPE_INSETS;
labelBounds.x += 2 * DefaultLayoutConstants.DEFAULT_SHAPE_INSETS;
labelBounds.width -= 4 * DefaultLayoutConstants.DEFAULT_SHAPE_INSETS;
labelBounds.height = textBounds.height * 2;
return labelBounds;
protected void refreshVisuals() {
Rectangle r = determineBaseFigureBounds();
labelFigureLayer.setBounds(r);
labelFigureLayer.getParent().setConstraint(labelFigureLayer, r);
super.refreshVisuals();
}
}
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