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

Repaired and Improved state automaton layout.

refs 352
parent c0cc84ea
No related branches found
No related tags found
No related merge requests found
......@@ -21,12 +21,9 @@ import java.util.List;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.fortiss.tooling.base.layout.LayoutKeyConstants;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.OffsetOrientation;
import org.fortiss.tooling.base.ui.editpart.FreeConnectorEditPartBase;
import org.fortiss.tooling.base.ui.editpart.StickyConnectorEditPartBase;
import org.fortiss.tooling.base.ui.utils.LayoutDataUtils;
/**
* A command to move connectors. The operation is performed differently for
......@@ -46,8 +43,8 @@ public class MoveConnectorCommand extends ChangeBoundsRequestCommandBase {
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
@SuppressWarnings("unchecked")
public void execute() {
super.execute();
for (EditPart editpart : (List<EditPart>) getRequest().getEditParts()) {
......@@ -56,16 +53,10 @@ public class MoveConnectorCommand extends ChangeBoundsRequestCommandBase {
}
/** Performs the move of an edit part. */
@SuppressWarnings("rawtypes")
protected void performMove(EditPart editpart, ChangeBoundsRequest request) {
if (editpart instanceof StickyConnectorEditPartBase) {
// The orientation was already calculated for the sourceFeedback
OffsetOrientation offsetOrientation = (OffsetOrientation) request
.getExtendedData().get(
LayoutKeyConstants.CONNECTOR_OFFSET_ORIENTATION);
LayoutDataUtils.setConnectorOffsetOrientation(
(ILayoutedModelElement) editpart.getModel(),
offsetOrientation);
((StickyConnectorEditPartBase) editpart).performMove(request);
} else if (editpart instanceof FreeConnectorEditPartBase) {
moveNode((ILayoutedModelElement) editpart.getModel());
}
......
......@@ -184,18 +184,20 @@ public class DiagramEditorBase<T extends EObject> extends GEFEditorBase<T>
viewer));
viewer.getControl().setBackground(parent.getBackground());
viewer.setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, true);
viewer.setProperty(SnapToGrid.PROPERTY_GRID_ORIGIN, new Point(
DefaultLayoutConstants.DEFAULT_GRID_ORIGIN_X,
DefaultLayoutConstants.DEFAULT_GRID_ORIGIN_Y));
Dimension gridSpacing = new Dimension(
DefaultLayoutConstants.DEFAULT_GRID_SIZE,
DefaultLayoutConstants.DEFAULT_GRID_SIZE);
viewer.setProperty(SnapToGrid.PROPERTY_GRID_SPACING, gridSpacing);
viewer.setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, true);
viewer.setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, true);
if (enableSnapToGrid()) {
viewer.setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, true);
viewer.setProperty(SnapToGrid.PROPERTY_GRID_ORIGIN, new Point(
DefaultLayoutConstants.DEFAULT_GRID_ORIGIN_X,
DefaultLayoutConstants.DEFAULT_GRID_ORIGIN_Y));
Dimension gridSpacing = new Dimension(
DefaultLayoutConstants.DEFAULT_GRID_SIZE,
DefaultLayoutConstants.DEFAULT_GRID_SIZE);
viewer.setProperty(SnapToGrid.PROPERTY_GRID_SPACING, gridSpacing);
viewer.setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, true);
viewer.setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, true);
}
// this is needed by direct connection feature. the root edit part
// becomes transparent when GEF selects a tool on button down event.
// we have to reloacte the call to the underlying root's content
......@@ -226,6 +228,14 @@ public class DiagramEditorBase<T extends EObject> extends GEFEditorBase<T>
return getEditedObject();
}
/**
* Returns whether snap-to-grid should be enabled. The default is
* <code>true</code>.
*/
protected boolean enableSnapToGrid() {
return true;
}
/** Listener used to refresh on editor preference changes. */
private final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {
......
......@@ -23,24 +23,33 @@ import org.conqat.ide.commons.ui.swt.FontUtils;
import org.conqat.lib.commons.string.StringUtils;
import org.eclipse.draw2d.ChopboxAnchor;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.Viewport;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.SnapToHelper;
import org.eclipse.gef.editparts.ScalableRootEditPart;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.fortiss.tooling.base.layout.DefaultLayoutConstants;
import org.fortiss.tooling.base.layout.LayoutKeyConstants;
import org.fortiss.tooling.base.model.layout.Dimension;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.OffsetOrientation;
import org.fortiss.tooling.base.ui.editpart.figure.TransparentLabel;
import org.fortiss.tooling.base.ui.editpart.policy.ConnectionGraphicalNodeEditPolicy;
import org.fortiss.tooling.base.ui.editpart.policy.ElementLayoutEditPolicy;
import org.fortiss.tooling.base.ui.editpart.policy.RemoveEditPolicy;
import org.fortiss.tooling.base.ui.utils.LayoutDataUtils;
import org.fortiss.tooling.base.ui.utils.RectangleLayoutUtils;
import org.fortiss.tooling.base.ui.utils.SnapToGridUtils;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
......@@ -179,4 +188,54 @@ public abstract class ElementEditPartBase<T extends ILayoutedModelElement & INam
protected boolean enableSnapToGrid() {
return true;
}
/**
* Shows the movement feedback for connectors.
*
* @param hostEditPart
* the host edit part
*/
@SuppressWarnings("unchecked")
public void showMoveFeedback(Request request, EditPart hostEditPart,
IFigure hostFigure) {
// get the bounds of the parent
Rectangle containerBounds = LayoutDataUtils.getNodeBounds(getModel());
// get the child position relative to the parent
Point childPos = hostFigure.getBounds().getLocation()
.getTranslated(containerBounds.getLocation().getNegated());
// get the current mouse position
Point mousePos = ((ChangeBoundsRequest) request).getLocation();
// fix offset in mouse position because of possibly scrolled editing
// window
Point clientAreaOffset = new Point(
((Viewport) ((ScalableRootEditPart) getRoot()).getFigure())
.getClientArea().getLocation());
mousePos.translate(clientAreaOffset);
// get the mouse position relative to the parent
Point relativePos = mousePos.getTranslated(containerBounds
.getLocation().getNegated());
// do border clamping
OffsetOrientation orient = RectangleLayoutUtils
.calculateRectangleBorderOrientation(relativePos,
containerBounds.getSize(),
DefaultLayoutConstants.DEFAULT_SHAPE_INSETS);
// snap to grid
orient.setOffset(SnapToGridUtils.snapToGrid(orient.getOffset()));
// use the calculated value for positioning
Dimension d = LayoutDataUtils.getNodeSize(getModel());
org.fortiss.tooling.base.model.layout.Point p = LayoutDataUtils
.getAbsolute(orient, d,
DefaultLayoutConstants.DEFAULT_SHAPE_INSETS);
relativePos.setLocation(p.getX(), p.getY());
// store the orientation in the request so that the command can use
// it
request.getExtendedData().put(
LayoutKeyConstants.CONNECTOR_OFFSET_ORIENTATION, orient);
// MoveDelta needs positions relative to the child
relativePos.translate(childPos.getNegated());
((ChangeBoundsRequest) request).setMoveDelta(relativePos);
}
}
......@@ -18,10 +18,14 @@ $Id$
package org.fortiss.tooling.base.ui.editpart;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.fortiss.tooling.base.layout.DefaultLayoutConstants;
import org.fortiss.tooling.base.layout.LayoutKeyConstants;
import org.fortiss.tooling.base.model.base.EntryConnectorBase;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.OffsetOrientation;
import org.fortiss.tooling.base.ui.utils.LayoutDataUtils;
import org.fortiss.tooling.base.ui.utils.RectangleLayoutUtils;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
......@@ -61,4 +65,13 @@ public abstract class StickyConnectorEditPartBase<T extends ILayoutedModelElemen
protected boolean isTarget() {
return modelElement instanceof EntryConnectorBase;
}
/** Performs the move the connector using the request data. */
public void performMove(ChangeBoundsRequest request) {
OffsetOrientation offsetOrientation = (OffsetOrientation) request
.getExtendedData().get(
LayoutKeyConstants.CONNECTOR_OFFSET_ORIENTATION);
LayoutDataUtils.setConnectorOffsetOrientation(getModel(),
offsetOrientation);
}
}
......@@ -17,22 +17,10 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editpart.policy;
import org.eclipse.draw2d.Viewport;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.Request;
import org.eclipse.gef.editparts.ScalableRootEditPart;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.fortiss.tooling.base.layout.DefaultLayoutConstants;
import org.fortiss.tooling.base.layout.LayoutKeyConstants;
import org.fortiss.tooling.base.model.layout.Dimension;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.OffsetOrientation;
import org.fortiss.tooling.base.ui.editpart.ElementEditPartBase;
import org.fortiss.tooling.base.ui.utils.LayoutDataUtils;
import org.fortiss.tooling.base.ui.utils.RectangleLayoutUtils;
import org.fortiss.tooling.base.ui.utils.SnapToGridUtils;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
/**
......@@ -61,50 +49,10 @@ public class ConstrainedNonResizableEditPolicy<T extends ILayoutedModelElement &
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public void showSourceFeedback(Request request) {
if (REQ_MOVE.equals(request.getType())) {
// get the bounds of the parent
Rectangle containerBounds = LayoutDataUtils.getNodeBounds(part
.getModel());
// get the child position relative to the parent
Point childPos = getHostFigure().getBounds().getLocation()
.getTranslated(containerBounds.getLocation().getNegated());
// get the current mouse position
Point mousePos = ((ChangeBoundsRequest) request).getLocation();
// fix offset in mouse position because of possibly scrolled editing
// window
Point clientAreaOffset = new Point(
((Viewport) ((ScalableRootEditPart) part.getRoot())
.getFigure()).getClientArea().getLocation());
mousePos.translate(clientAreaOffset);
// get the mouse position relative to the parent
Point relativePos = mousePos.getTranslated(containerBounds
.getLocation().getNegated());
// do border clamping
OffsetOrientation orient = RectangleLayoutUtils
.calculateRectangleBorderOrientation(relativePos,
containerBounds.getSize(),
DefaultLayoutConstants.DEFAULT_SHAPE_INSETS);
// snap to grid
orient.setOffset(SnapToGridUtils.snapToGrid(orient.getOffset()));
// use the calculated value for positioning
Dimension d = LayoutDataUtils.getNodeSize(part.getModel());
org.fortiss.tooling.base.model.layout.Point p = LayoutDataUtils
.getAbsolute(orient, d,
DefaultLayoutConstants.DEFAULT_SHAPE_INSETS);
relativePos.setLocation(p.getX(), p.getY());
// store the orientation in the request so that the command can use
// it
request.getExtendedData().put(
LayoutKeyConstants.CONNECTOR_OFFSET_ORIENTATION, orient);
// MoveDelta needs positions relative to the child
relativePos.translate(childPos.getNegated());
((ChangeBoundsRequest) request).setMoveDelta(relativePos);
part.showMoveFeedback(request, getHost(), getHostFigure());
}
super.showSourceFeedback(request);
}
......
......@@ -20,15 +20,13 @@ package org.fortiss.tooling.base.ui.layout;
import org.eclipse.draw2d.geometry.Point;
/**
* TODO: I don't understand this comment + we do not inherit ILayouter
*
* An ILayouter handles specialized layouts of points like snap to grid or move
* to border.
* An IPointLayouter handles specialized layouts of points like snap to grid or
* move to border.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash: 9E4D64CB75CDF6BCFA08098F50F4C363
* @ConQAT.Rating YELLOW Hash: A6761DE2B2E5EC31B0777B1641AD625A
*/
public interface IPointLayouter {
......
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