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

refactored base edit part hierarchy

parent ca10ba5f
No related branches found
No related tags found
No related merge requests found
......@@ -17,13 +17,34 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editpart;
import java.util.ArrayList;
import java.util.List;
import org.conqat.lib.commons.collections.CollectionUtils;
import org.eclipse.draw2d.ChopboxAnchor;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.swt.graphics.Color;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.ui.editpart.figure.AntiAliasedEllipse;
import org.fortiss.tooling.base.ui.editpart.policy.ConnectionGraphicalNodeEditPolicy;
import org.fortiss.tooling.base.ui.editpart.policy.RemoveEditPolicy;
import org.fortiss.tooling.base.ui.layout.constants.RecommendedLayoutConstants;
import org.fortiss.tooling.base.ui.layout.util.LayoutDataUtils;
/**
* Base class for connector edit parts.
*
* @author hummel
* @author hoelzl
* @author $Author$
* @version $Rev$
......@@ -36,4 +57,137 @@ public abstract class ConnectorEditPartBase<T extends ILayoutedModelElement & IC
protected ConnectorEditPartBase(T modelElement) {
super(modelElement);
}
/** {@inheritDoc} */
@Override
protected Rectangle determinePosition() {
Rectangle r = LayoutDataUtils.getNodeBounds(modelElement);
r.setSize(RecommendedLayoutConstants.DEFAULT_CONNECTOR_DIMENSION);
return r;
}
/** {@inheritDoc} */
@Override
protected IFigure createBaseFigure() {
Figure base = new Figure();
base.setLayoutManager(new XYLayout());
Ellipse connector = new AntiAliasedEllipse();
base.add(connector,
RecommendedLayoutConstants.DEFAULT_CONNECTOR_FIGURE_BOUNDS);
if (isTarget()) {
connector.setBackgroundColor(getTargetBackgroundColor());
connector.setForegroundColor(getTargetForegroundColor());
} else {
connector.setBackgroundColor(getSourceBackgroundColor());
connector.setForegroundColor(getSourceForegroundColor());
}
return base;
}
/** Returns background color for target role. */
protected Color getTargetForegroundColor() {
return getForegroundColor();
}
/** Returns background color for target role. */
protected Color getTargetBackgroundColor() {
return getBackgroundColor();
}
/** Returns background color for source role. */
protected Color getSourceForegroundColor() {
return getForegroundColor();
}
/** Returns background color for source role. */
protected Color getSourceBackgroundColor() {
return getForegroundColor();
}
/** {@inheritDoc} */
@Override
protected Color getForegroundColor() {
return ColorConstants.black;
}
/** {@inheritDoc} */
@Override
protected Color getBackgroundColor() {
return ColorConstants.white;
}
/** {@inheritDoc} */
@Override
protected ConnectionAnchor defaultConnectionAnchor() {
return new ChopboxAnchor(baseFigure);
}
/** {@inheritDoc} */
@SuppressWarnings({ "unchecked" })
@Override
protected void refreshVisuals() {
super.refreshVisuals();
refreshSourceConnections();
refreshTargetConnections();
for (ConnectionEditPart editPart : (List<ConnectionEditPart>) getSourceConnections()) {
editPart.refresh();
}
for (ConnectionEditPart editPart : (List<ConnectionEditPart>) getTargetConnections()) {
editPart.refresh();
}
}
/**
* {@inheritDoc}
*/
@Override
protected List<IConnection> getModelSourceConnections() {
if (!isTarget()) {
return filterConnections(modelElement.getOutgoingList(),
getRootHierarchicElement());
}
return CollectionUtils.emptyList();
}
/** {@inheritDoc} */
@Override
protected List<IConnection> getModelTargetConnections() {
if (isTarget()) {
return filterConnections(modelElement.getIncomingList(),
getRootHierarchicElement());
}
return CollectionUtils.emptyList();
}
/** Filters any channels not owned by the given owner. */
private List<IConnection> filterConnections(List<IConnection> connections,
IHierarchicElement owner) {
List<IConnection> result = new ArrayList<IConnection>();
for (IConnection connection : connections) {
if (connection.eContainer() == owner) {
result.add(connection);
}
}
return result;
}
/** {@inheritDoc} */
@Override
protected void createEditPolicies() {
installEditPolicy(EditPolicy.COMPONENT_ROLE, new RemoveEditPolicy());
installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE,
new ConnectionGraphicalNodeEditPolicy());
}
/** Returns the root element for this connector edit part. */
protected abstract IHierarchicElement getRootHierarchicElement();
/**
* Returns whether the underlying connector edit part acts as a target
* connector in the current view (i.e. edit part).
*/
protected abstract boolean isTarget();
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editpart;
import java.util.ArrayList;
import java.util.List;
import org.conqat.lib.commons.collections.CollectionUtils;
import org.eclipse.draw2d.ChopboxAnchor;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.EditPolicy;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.ui.editpart.figure.AntiAliasedEllipse;
import org.fortiss.tooling.base.ui.editpart.figure.LabeledConnectorFigure;
import org.fortiss.tooling.base.ui.editpart.policy.ConnectionGraphicalNodeEditPolicy;
import org.fortiss.tooling.base.ui.editpart.policy.RemoveEditPolicy;
import org.fortiss.tooling.base.ui.layout.constants.RecommendedLayoutConstants;
/**
* The super class of the connector edit parts used with rectangular shapes.
*
* @author hoelzlf
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class LabeledConnectorEditPartBase<T extends IConnector & ILayoutedModelElement>
extends ConnectorEditPartBase<T> {
/** The figure used for the port and its label. */
protected LabeledConnectorFigure labelConnectorFigure;
/** The figure used for the connector itself. */
protected IFigure connectorFigure;
/** Creates the edit part. */
public LabeledConnectorEditPartBase(T connector) {
super(connector);
}
/** {@inheritDoc} */
@Override
protected IFigure createFigure() {
return getConnectorFigure();
}
/** Returns the figure used for the connector (including the label). */
protected LabeledConnectorFigure getConnectorFigure() {
if (connectorFigure == null) {
connectorFigure = createConnectorFigure();
labelConnectorFigure = new LabeledConnectorFigure(connectorFigure,
getConnectorDimension(), getConnectorFigureBounds());
}
return labelConnectorFigure;
}
/** Creates the figure used for the connector (excluding the label). */
protected IFigure createConnectorFigure() {
Ellipse connector = new AntiAliasedEllipse();
connector.setBounds(getConnectorFigureBounds());
if (isReceiving()) {
connector.setBackgroundColor(ColorConstants.white);
connector.setForegroundColor(ColorConstants.black);
} else {
connector.setBackgroundColor(ColorConstants.black);
connector.setForegroundColor(ColorConstants.black);
}
return connector;
}
/** {@inheritDoc} */
@Override
protected ConnectionAnchor defaultConnectionAnchor() {
return new ChopboxAnchor(connectorFigure);
}
/** {@inheritDoc} */
@SuppressWarnings({ "unchecked" })
@Override
protected void refreshVisuals() {
super.refreshVisuals();
refreshSourceConnections();
refreshTargetConnections();
for (ConnectionEditPart editPart : (List<ConnectionEditPart>) getSourceConnections()) {
editPart.refresh();
}
for (ConnectionEditPart editPart : (List<ConnectionEditPart>) getTargetConnections()) {
editPart.refresh();
}
}
/** {@inheritDoc} */
@Override
protected void createEditPolicies() {
installEditPolicy(EditPolicy.COMPONENT_ROLE, new RemoveEditPolicy());
installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE,
new ConnectionGraphicalNodeEditPolicy());
}
/** Returns the root element for this connector edit part. */
protected abstract IHierarchicElement getRootHierarchicElement();
/**
* Returns whether the underlying connector edit part acts as a destination
* connector in the current view (i.e. edit part).
*/
protected abstract boolean isReceiving();
/**
* Returns the dimension of the connector edit part (not only its visible
* figure part).
*/
protected Dimension getConnectorDimension() {
return RecommendedLayoutConstants.DEFAULT_CONNECTOR_DIMENSION;
}
/**
* Returns the bounds of the visible figure of the connector edit part.
*/
protected Rectangle getConnectorFigureBounds() {
return RecommendedLayoutConstants.DEFAULT_CONNECTOR_FIGURE_BOUNDS;
}
/**
* {@inheritDoc}
*/
@Override
protected List<IConnection> getModelSourceConnections() {
if (!isReceiving()) {
return filterConnections(modelElement.getOutgoingList(),
getRootHierarchicElement());
}
return CollectionUtils.emptyList();
}
/** {@inheritDoc} */
@Override
protected List<IConnection> getModelTargetConnections() {
if (isReceiving()) {
return filterConnections(modelElement.getIncomingList(),
getRootHierarchicElement());
}
return CollectionUtils.emptyList();
}
/** Filters any channels not owned by the given owner. */
private List<IConnection> filterConnections(List<IConnection> connections,
IHierarchicElement owner) {
List<IConnection> result = new ArrayList<IConnection>();
for (IConnection connection : connections) {
if (connection.eContainer() == owner) {
result.add(connection);
}
}
return result;
}
}
......@@ -20,15 +20,13 @@ package org.fortiss.tooling.base.ui.editpart;
import java.util.List;
import org.conqat.lib.commons.string.StringUtils;
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.eclipse.gef.EditPolicy;
import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.swt.graphics.Color;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.ui.editpart.policy.RemoveEditPolicy;
import org.fortiss.tooling.base.ui.layout.constants.RecommendedLayoutConstants;
......@@ -56,56 +54,25 @@ public abstract class NodeEditPartBase<T extends ILayoutedModelElement & INamedC
/** The label used for the name. */
protected final Label nameLabel = new Label();
/** Whether this is active. Also see {@link #setActive(boolean)}. */
protected boolean active = false;
/** Constructor. */
protected NodeEditPartBase(T modelObject) {
super(modelObject);
}
/** Creates the node edit part. */
private void createLabelFigure() {
Rectangle rect = LayoutDataUtils.getNodeBounds(modelElement);
int inset = 2 * RecommendedLayoutConstants.RECTANGULAR_SHAPE_INSETS;
rect = new Rectangle(rect.x + inset, rect.y + inset, rect.width - 2
* inset, rect.height - 2 * inset);
nameLabel.setForegroundColor(getForegroundColor());
nameLabel.setFont(RecommendedLayoutConstants.TITLE_FONT);
nameLabel.setTextAlignment(PositionConstants.LEFT
| PositionConstants.TOP);
nameLabel.setTextPlacement(PositionConstants.EAST);
nameLabel.setIcon(IModelElementHandlerService.INSTANCE.getModelElementHandler(
modelElement).getIcon());
}
/**
* {@inheritDoc}
*/
@Override
protected final IFigure createFigure() {
IFigure figure = createBaseFigure();
figure.setBackgroundColor(getBackgroundColor());
figure.setLayoutManager(new XYLayout());
figure.add(nameLabel);
// TODO (FH): implement marker support
// figure.add(markerFigure);
return figure;
}
/** Creates the outer base figure. */
protected abstract IFigure createBaseFigure();
/**
* Returns the foreground color used.
*/
protected abstract Color getForegroundColor();
/**
* Returns the background color used.
*/
protected abstract Color getBackgroundColor();
/**
* Returns the background color for active nodes.
*/
protected Color getActiveColor() {
return getBackgroundColor();
nameLabel.setIcon(IModelElementHandlerService.INSTANCE
.getModelElementHandler(modelElement).getIcon());
getLayer(LayerConstants.GUIDE_LAYER).add(nameLabel);
}
/**
......@@ -149,31 +116,8 @@ public abstract class NodeEditPartBase<T extends ILayoutedModelElement & INamedC
super.refreshVisuals();
nameLabel.setText(modelElement.getName());
IFigure figure = getFigure();
String tooltipText = StringUtils.wrapLongLines(modelElement.getName()
+ ": " + modelElement.getComment(), 100);
figure.setToolTip(new Label(tooltipText));
figure.setBackgroundColor(active ? getActiveColor()
: getBackgroundColor());
Rectangle rect = LayoutDataUtils.getNodeBounds(modelElement);
int inset = 2 * RecommendedLayoutConstants.RECTANGULAR_SHAPE_INSETS;
rect = new Rectangle(inset, inset, rect.width - 2 * inset, rect.height
- 2 * inset);
figure.setConstraint(nameLabel, rect);
}
/**
* This method can be used to mark this editpart as active, which can be
* used e.g. for displaying the active state in the simulation.
*/
public void setActive(boolean active) {
if (this.active != active) {
this.active = active;
refreshVisuals();
}
baseFigure.setToolTip(new Label(tooltipText));
}
}
......@@ -22,16 +22,13 @@ import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.DragTracker;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.NodeEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.requests.SelectionRequest;
import org.eclipse.gef.tools.ConnectionDragCreationTool;
import org.eclipse.gef.tools.DragEditPartsTracker;
import org.eclipse.swt.graphics.Color;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.ui.editpart.figure.MarkerFigure;
import org.fortiss.tooling.base.ui.layout.util.LayoutDataUtils;
import org.fortiss.tooling.kernel.ui.service.IMarkerService;
/**
* The base class for all edit parts which are positioned using x/y coordinates.
......@@ -47,46 +44,29 @@ import org.fortiss.tooling.kernel.ui.service.IMarkerService;
*/
public abstract class PositionedEditPartBase<T extends ILayoutedModelElement>
extends LayoutedEditPartBase<T> implements NodeEditPart {
/**
* Figure used for displaying markers. This figure has to be added in the
* subclasses.
*/
protected final MarkerFigure markerFigure = new MarkerFigure();
/** The base figure of this node edit part. */
protected IFigure baseFigure;
/** Constructor. */
protected PositionedEditPartBase(T modelElement) {
super(modelElement);
}
/** {@inheritDoc} */
/**
* {@inheritDoc}
*/
@Override
public void refresh() {
// we have to make sure, that we are registered as constraint with our
// parent (if we have one)
if (getParent() instanceof GraphicalEditPart) {
((GraphicalEditPart) getParent()).getFigure().setConstraint(
getFigure(), determinePosition());
}
protected final IFigure createFigure() {
baseFigure = createBaseFigure();
// createLabelFigure();
// TODO (FH): implement marker support
// figure.add(markerFigure);
super.refresh();
markerFigure.setMarkers(IMarkerService.INSTANCE
.getViolations(modelElement));
return baseFigure;
}
/** {@inheritDoc} */
@Override
protected void refreshVisuals() {
super.refreshVisuals();
IFigure figure = getFigure();
if (markerFigure.getParent() == figure) {
Rectangle rect = LayoutDataUtils.getNodeBounds(modelElement);
figure.setConstraint(markerFigure, new Rectangle(rect.width - 18,
rect.height - 18, 16, 16));
}
}
/** Creates the outer base figure. */
protected abstract IFigure createBaseFigure();
/**
* Returns the position and size this edit part's main figure should have in
......@@ -94,12 +74,44 @@ public abstract class PositionedEditPartBase<T extends ILayoutedModelElement>
*/
protected abstract Rectangle determinePosition();
/**
* Returns the foreground color used.
*/
protected abstract Color getForegroundColor();
/**
* Returns the background color used.
*/
protected abstract Color getBackgroundColor();
/**
* Returns the default connection anchor for this port (does not depend on
* type of connection).
*/
protected abstract ConnectionAnchor defaultConnectionAnchor();
/** {@inheritDoc} */
@Override
public void refresh() {
// we have to make sure, that we are registered as constraint with our
// parent (if we have one)
// if (getParent() instanceof GraphicalEditPart) {
// ((GraphicalEditPart) getParent()).getFigure().setConstraint(
// getFigure(), determinePosition());
// }
super.refresh();
}
/** {@inheritDoc} */
@Override
protected void refreshVisuals() {
super.refreshVisuals();
baseFigure.setBounds(determinePosition());
baseFigure.setForegroundColor(getForegroundColor());
baseFigure.setBackgroundColor(getBackgroundColor());
}
/**
* {@inheritDoc}
* <p>
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editpart.figure;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
/**
* This class implements dynamic behavior of a labeled connector figure, which
* displays the label if the figure has no connections.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class LabeledConnectorFigure extends Figure {
/** Stores the label figure. */
private final Label label = new Label();
/** Constructor. */
public LabeledConnectorFigure(IFigure baseFigure, Dimension connectorSize,
Rectangle figureBounds) {
setLayoutManager(new XYLayout());
add(baseFigure, figureBounds);
Rectangle preferred = new Rectangle(connectorSize.width, 0, -1,
connectorSize.height);
add(label, preferred);
}
/** Sets the label text and tooltip. */
public void setLabelText(String text) {
label.setText(text);
}
}
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