Commit 979d366f authored by Johannes Eder's avatar Johannes Eder

Hierarchic element behavior

refs 2446
parent 237b0580
......@@ -24,6 +24,7 @@ Export-Package: org.fortiss.tooling.base.ui,
org.fortiss.tooling.base.ui.dnd.jface,
org.fortiss.tooling.base.ui.editor,
org.fortiss.tooling.base.ui.editpart,
org.fortiss.tooling.base.ui.editpart.allocation,
org.fortiss.tooling.base.ui.editpart.anchor,
org.fortiss.tooling.base.ui.editpart.command,
org.fortiss.tooling.base.ui.editpart.command.bendpoint,
......
......@@ -17,8 +17,10 @@ $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_GRID_SIZE;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getNodeBounds;
import java.util.ArrayList;
import java.util.List;
import org.conqat.ide.commons.ui.swt.FontUtils;
......@@ -40,6 +42,7 @@ 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.model.element.IConnector;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.ui.editpart.PositionedEditPartBase;
import org.fortiss.tooling.base.ui.editpart.figure.TransparentLabel;
......@@ -78,7 +81,6 @@ public abstract class AllocationElementEditPartBase<T extends ILayoutedModelElem
protected AllocationElementEditPartBase(T modelElement, EObject allocationObject) {
super(modelElement);
this.allocationObject = allocationObject;
// determineBaseFigureBounds();
}
/**
......@@ -136,12 +138,13 @@ public abstract class AllocationElementEditPartBase<T extends ILayoutedModelElem
EObject parentElement =
KernelModelElementUtils.getParentElement(getModel(), EObject.class, false);
EList<? extends ILayoutedModelElement> layoutElements =
EcoreUtils.getChildrenWithType(parentElement, getModel().getClass());
EcoreUtils.getChildrenWithType(parentElement, ILayoutedModelElement.class);
Rectangle reduce =
layoutElements.stream().map(m -> getNodeBounds(m))
.reduce(new Rectangle(), (a, b) -> a.union(b));
int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE;
for(ILayoutedModelElement ml : layoutElements) {
org.fortiss.tooling.base.model.layout.Rectangle nodePosition =
LayoutDataUtils.getNodeBounds(ml);
......@@ -156,13 +159,11 @@ public abstract class AllocationElementEditPartBase<T extends ILayoutedModelElem
RootEditPart root = getRoot();
if(isAllocationTargetElement()) {
IAllocationPositionService.INSTANCE.setMinTargetPos(root, new Point(minX, minY));
reduce.resize(DefaultLayoutConstants.DEFAULT_GRID_SIZE,
DefaultLayoutConstants.DEFAULT_GRID_SIZE);
reduce.resize(DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE);
IAllocationPositionService.INSTANCE.setTargetAllocationBounds(root, reduce);
} else {
IAllocationPositionService.INSTANCE.setMinSourcePos(root, new Point(minX, minY));
reduce.resize(DefaultLayoutConstants.DEFAULT_GRID_SIZE,
DefaultLayoutConstants.DEFAULT_GRID_SIZE);
reduce.resize(DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE);
IAllocationPositionService.INSTANCE.setSourceAllocationBounds(root, reduce);
}
......@@ -217,16 +218,21 @@ public abstract class AllocationElementEditPartBase<T extends ILayoutedModelElem
public void performRequest(Request req) {
if(req.getType() == RequestConstants.REQ_OPEN) {
EditPart parent = getParent();
req.getExtendedData().put(getModel(), getModel());
List<Object> elements = new ArrayList<>();
elements.addAll(getSubElements());
elements.addAll(getConnectorsOf(getModel()));
req.getExtendedData().put(parent, elements);
parent.performRequest(req);
}
super.performRequest(req);
}
/** Returns the sub elements of T if exisiting. */
/** Returns the sub elements of T if existing. */
abstract public List<T> getSubElements();
/** Returns the {@link IConnector}s of element */
abstract public List<IConnector> getConnectorsOf(T element);
/** {@inheritDoc} */
@Override
protected void refreshVisuals() {
......
......@@ -18,6 +18,10 @@ $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.ui.utils.DecorationIconUtils.getMarkerServiceDecorationIcon;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
......@@ -26,9 +30,12 @@ import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.NodeEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.RootEditPart;
import org.eclipse.swt.graphics.Color;
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;
......@@ -38,8 +45,9 @@ import org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity;
import org.fortiss.tooling.kernel.ui.service.IMarkerService;
/**
* Implementation similar to {@link PositionedEditPartBase} except that T does not have to be a
* {@link ILayoutedModelElement}
* Implementation similar to {@link PositionedEditPartBase} except that <b>T</b> does not have to be
* a {@link ILayoutedModelElement}. <b>S</b> is the type of model element to be displayed in this
* sub diagram.
*
* @author eder
* @author $Author: hoelzl $
......@@ -62,6 +70,9 @@ public abstract class AllocationSubDiagramEditPartBase<T extends EObject> extend
/** The layout configuration. */
private IDiagramLayoutConfiguration layoutConfiguration;
/** List of all children visible in this edit part. */
private List<?> modelChildren = new ArrayList<>();
/**
* @param modelElement
*/
......@@ -69,6 +80,7 @@ public abstract class AllocationSubDiagramEditPartBase<T extends EObject> extend
IDiagramLayoutConfiguration layoutConfiguration) {
super(modelElement);
this.layoutConfiguration = layoutConfiguration;
modelChildren = getInitialModelSubElements();
}
/** {@inheritDoc} */
......@@ -87,6 +99,15 @@ public abstract class AllocationSubDiagramEditPartBase<T extends EObject> extend
return prettyRoundedRectangle;
}
/** {@inheritDoc} */
@Override
protected final List<?> getModelChildren() {
return modelChildren;
}
/** Returns a list of all sub elements contained by T */
protected abstract List<?> getInitialModelSubElements();
/**
* Returns the position and size of the background figure of this sub diagram.
*/
......@@ -213,4 +234,49 @@ public abstract class AllocationSubDiagramEditPartBase<T extends EObject> extend
return layoutConfiguration;
}
/** {@inheritDoc} */
@Override
public void performRequest(Request req) {
if(req.getType() == RequestConstants.REQ_OPEN) {
if(req.getExtendedData().isEmpty()) {
// sub diagram background selection
// works only with hierarchic elements
if(!modelChildren.isEmpty()) {
Object object = modelChildren.get(0);
IHierarchicElement parentElement =
getParentElement((EObject)object, IHierarchicElement.class, false);
if(parentElement == null) {
return;
}
IHierarchicElement parentParentElement =
getParentElement(parentElement, IHierarchicElement.class, false);
if(parentParentElement != null) {
List<Object> children = new ArrayList<>();
children.addAll(parentParentElement.getContainedElements());
children.addAll(parentParentElement.getConnectors());
modelChildren = children;
refresh();
}
}
}
Object object = req.getExtendedData().get(this);
if(object instanceof List<?> && !((List<?>)object).isEmpty()) {
// sub diagram child selection
modelChildren = (List<?>)object;
refresh();
}
}
}
/** {@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();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment