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

refactoring of the graphical editor (not yet working fully).

parent adbfba69
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.ui.dnd.DragContext;
import org.fortiss.tooling.base.ui.dnd.DropContext;
import org.fortiss.tooling.base.ui.editpart.RootEditPartBase;
import org.fortiss.tooling.base.ui.editpart.DiagramEditPartBase;
import org.fortiss.tooling.kernel.extension.IConnectionCompositor;
import org.fortiss.tooling.kernel.extension.data.IConnectionCompositionContext;
import org.fortiss.tooling.kernel.service.IElementCompositorService;
......@@ -91,7 +91,7 @@ public abstract class HierarchicElementConnectionCompositorBase<HE extends IHier
if (context instanceof DragContext) {
DragContext dc = (DragContext) context;
// Is an internal feedback connection allowed?
if (dc.getSource() instanceof RootEditPartBase
if (dc.getSource() instanceof DiagramEditPartBase
&& dc.getTarget() instanceof RootEditPart) {
return canConnectInterally();
}
......
......@@ -19,7 +19,7 @@ package org.fortiss.tooling.base.ui.dnd;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.EditPart;
import org.fortiss.tooling.base.ui.editpart.RootEditPartBase;
import org.fortiss.tooling.base.ui.editpart.DiagramEditPartBase;
import org.fortiss.tooling.kernel.extension.data.IElementCompositionContext;
/**
......@@ -61,6 +61,6 @@ public class DropContext implements IElementCompositionContext {
/** Returns whether drop target is root edit part (base). */
public boolean isRoot() {
return dropTarget instanceof RootEditPartBase;
return dropTarget instanceof DiagramEditPartBase;
}
}
/*--------------------------------------------------------------------------+
$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.editor.gef;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.FreeformLayer;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Layer;
import org.eclipse.draw2d.LayeredPane;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.editparts.ScalableRootEditPart;
/**
* This class is an extension to the {@link ScalableRootEditPart}. It provides
* four additional printable layers: the node layer, the label layer, the
* decoration layer and the custom layer.
* <P>
* The node layer is between the primary layer and the connection layer defined
* by {@link ScalableRootEditPart}. The label, decoration and custom layer are
* above the connection layer.
* <P>
* Typically graphical figures like boxes and ellipses are displayed in the node
* layer. Labels are displayed in the label layer. Markers and decorations are
* shown in the decoration layer. Finally, the custom layer may be used to
* display further information.
* <P>
* If an edit part wants to display information below all other layers (but of
* course above the grid layer), it can use the
* {@link LayerConstants#PRIMARY_LAYER}.
* <P>
* If an edit part wants to display information above the decorations, it can
* use the {@link #CUSTOM_LAYER}.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public final class ExtendedLayerRootEditPart extends ScalableRootEditPart {
/** The node layer ID. */
public static final String NODE_LAYER = ExtendedLayerRootEditPart.class
.getName() + ".nodeLayer";
/** The label layer ID. */
public static final String LABEL_LAYER = ExtendedLayerRootEditPart.class
.getName() + ".labelLayer";
/** The decoration layer ID. */
public static final String DECORATION_LAYER = ExtendedLayerRootEditPart.class
.getName() + ".decorationLayer";
/** The custom layer ID. */
public static final String CUSTOM_LAYER = ExtendedLayerRootEditPart.class
.getName() + ".customLayer";
/** Stores the node and connector layer. */
private Layer nodeLayer;
/** Stores the label layer. */
private Layer labelLayer;
/** Stores the decoration layer. */
private Layer decorationLayer;
/** Stores the custom layer. */
private Layer customLayer;
/** {@inheritDoc} */
@Override
protected LayeredPane createPrintableLayers() {
LayeredPane pane = super.createPrintableLayers();
nodeLayer = createDefaultLayer();
labelLayer = createDefaultLayer();
decorationLayer = createDefaultLayer();
customLayer = createDefaultLayer();
pane.addLayerBefore(nodeLayer, NODE_LAYER, PRIMARY_LAYER);
pane.addLayerBefore(labelLayer, LABEL_LAYER, CONNECTION_LAYER);
pane.addLayerBefore(decorationLayer, DECORATION_LAYER, LABEL_LAYER);
pane.addLayerBefore(customLayer, CUSTOM_LAYER, DECORATION_LAYER);
return pane;
}
/** {@inheritDoc} */
@Override
public IFigure getContentPane() {
return getLayer(NODE_LAYER);
}
/** Creates the default layer with XYLayout. */
private Layer createDefaultLayer() {
Layer l = new FreeformLayer();
l.setOpaque(false);
l.setLayoutManager(new XYLayout());
l.setBackgroundColor(ColorConstants.white);
return l;
}
}
......@@ -120,6 +120,7 @@ public class GraphicalViewerEditorBase<T extends EObject> extends EditorBase<T>
/** {@inheritDoc} */
@Override
public void createPartControl(Composite parent) {
viewer.setRootEditPart(new ExtendedLayerRootEditPart());
viewer.createControl(parent);
getEditDomain().addViewer(viewer);
......
......@@ -25,7 +25,6 @@ import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.ConnectionLayer;
import org.eclipse.draw2d.ConnectionRouter;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FreeformLayer;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.emf.ecore.EObject;
......@@ -33,47 +32,43 @@ import org.eclipse.gef.LayerConstants;
import org.eclipse.swt.SWT;
/**
* The base class for roots of the editpart hierarchy.
* The base class for graphical diagrams.
*
* @param <T>
* the type of the model element wrapped.
* the type of the model element shown.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 76BF89DC0EFA9511DDF95CA4EC32C074
*/
public abstract class RootEditPartBase<T extends EObject> extends
public abstract class DiagramEditPartBase<T extends EObject> extends
GraphicalEditPartBase<T> {
/** Stores the connection router. */
private final ConnectionRouter connectionRouter;
/** Constructor. */
protected RootEditPartBase(T modelElement, ConnectionRouter connectionRouter) {
protected DiagramEditPartBase(T modelElement,
ConnectionRouter connectionRouter) {
super(modelElement);
this.connectionRouter = connectionRouter;
}
/** Constructor. */
protected RootEditPartBase(T modelElement) {
protected DiagramEditPartBase(T modelElement) {
this(modelElement, new BendpointConnectionRouter());
}
/** {@inheritDoc} */
@Override
protected IFigure createFigure() {
Figure f = new FreeformLayer();
setConnectionRouter();
f.setBackgroundColor(ColorConstants.white);
Figure f = new Figure();
f.setOpaque(false);
f.setLayoutManager(new XYLayout());
ConnectionLayer cLayer = (ConnectionLayer) getLayer(LayerConstants.CONNECTION_LAYER);
if (cLayer != null) {
cLayer.setAntialias(SWT.ON);
cLayer.setConnectionRouter(connectionRouter);
}
f.setBackgroundColor(ColorConstants.white);
return f;
}
......@@ -86,4 +81,13 @@ public abstract class RootEditPartBase<T extends EObject> extends
result.addAll(modelElementHandler.getConnectors(modelElement));
return result;
}
/** Sets anti-aliasing and the conenction router on connection layer. */
private void setConnectionRouter() {
ConnectionLayer cLayer = (ConnectionLayer) getLayer(LayerConstants.CONNECTION_LAYER);
if (cLayer != null) {
cLayer.setAntialias(SWT.ON);
cLayer.setConnectionRouter(connectionRouter);
}
}
}
......@@ -24,7 +24,6 @@ import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
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.fortiss.tooling.base.model.layout.ILayoutedModelElement;
......@@ -51,16 +50,15 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
public abstract class NodeEditPartBase<T extends ILayoutedModelElement & INamedCommentedElement>
extends PositionedEditPartBase<T> {
/** The label used for the name. */
protected final Label nameLabel = new Label();
/** Constructor. */
protected NodeEditPartBase(T modelObject) {
super(modelObject);
}
/** Creates the node edit part. */
private void createLabelFigure() {
/** Creates the label figure. */
@Override
public Label createLabelFigure() {
Label nameLabel = new Label();
Rectangle rect = LayoutDataUtils.getNodeBounds(modelElement);
int inset = 2 * RecommendedLayoutConstants.RECTANGULAR_SHAPE_INSETS;
rect = new Rectangle(rect.x + inset, rect.y + inset, rect.width - 2
......@@ -72,7 +70,8 @@ public abstract class NodeEditPartBase<T extends ILayoutedModelElement & INamedC
nameLabel.setTextPlacement(PositionConstants.EAST);
nameLabel.setIcon(IModelElementHandlerService.INSTANCE
.getModelElementHandler(modelElement).getIcon());
getLayer(LayerConstants.GUIDE_LAYER).add(nameLabel);
return nameLabel;
}
/**
......@@ -115,7 +114,7 @@ public abstract class NodeEditPartBase<T extends ILayoutedModelElement & INamedC
protected void refreshVisuals() {
super.refreshVisuals();
nameLabel.setText(modelElement.getName());
labelFigure.setText(modelElement.getName());
String tooltipText = StringUtils.wrapLongLines(modelElement.getName()
+ ": " + modelElement.getComment(), 100);
baseFigure.setToolTip(new Label(tooltipText));
......
......@@ -19,6 +19,7 @@ package org.fortiss.tooling.base.ui.editpart;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.DragTracker;
......@@ -29,6 +30,7 @@ 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.editor.gef.ExtendedLayerRootEditPart;
/**
* The base class for all edit parts which are positioned using x/y coordinates.
......@@ -44,9 +46,15 @@ import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
*/
public abstract class PositionedEditPartBase<T extends ILayoutedModelElement>
extends LayoutedEditPartBase<T> implements NodeEditPart {
/** The base figure of this node edit part. */
/** The base figure of this positioned edit part. */
protected IFigure baseFigure;
/** The label figure. */
protected Label labelFigure;
/** The decoration figure. */
protected IFigure decorationFigure;
/** Constructor. */
protected PositionedEditPartBase(T modelElement) {
super(modelElement);
......@@ -57,17 +65,40 @@ public abstract class PositionedEditPartBase<T extends ILayoutedModelElement>
*/
@Override
protected final IFigure createFigure() {
baseFigure = createBaseFigure();
// createLabelFigure();
// TODO (FH): implement marker support
// figure.add(markerFigure);
labelFigure = createLabelFigure();
if (labelFigure != null) {
getLayer(ExtendedLayerRootEditPart.LABEL_LAYER).add(labelFigure);
}
decorationFigure = createDecorationFigure();
if (decorationFigure != null) {
getLayer(ExtendedLayerRootEditPart.DECORATION_LAYER).add(
decorationFigure);
}
baseFigure = createBaseFigure();
return baseFigure;
}
/** Creates the outer base figure. */
/** Creates the base figure. */
protected abstract IFigure createBaseFigure();
/**
* Creates the label figure. The default implementation does not create a
* figure.
*/
protected Label createLabelFigure() {
return null;
}
/**
* Creates the decoration figure. The default implementation does not create
* a figure.
*/
protected IFigure createDecorationFigure() {
return null;
}
/**
* Returns the position and size this edit part's main figure should have in
* the layout.
......@@ -90,19 +121,6 @@ public abstract class PositionedEditPartBase<T extends ILayoutedModelElement>
*/
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() {
......
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