Commit 9baa9ca4 authored by Eyrak Paen-Rochlitz's avatar Eyrak Paen-Rochlitz
Browse files

[ui.structure] Make inherited connections fixed

parent 438d56a1
......@@ -36,25 +36,32 @@ import org.eclipse.etrice.ui.structure.support.SPPSupport;
import org.eclipse.etrice.ui.structure.support.StructureClassSupport;
import org.eclipse.etrice.ui.structure.support.provider.DecorationProvider;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddBendpointFeature;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.ICreateConnectionFeature;
import org.eclipse.graphiti.features.ICreateFeature;
import org.eclipse.graphiti.features.IDeleteFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.ILayoutFeature;
import org.eclipse.graphiti.features.IMoveBendpointFeature;
import org.eclipse.graphiti.features.IMoveShapeFeature;
import org.eclipse.graphiti.features.IReconnectionFeature;
import org.eclipse.graphiti.features.IRemoveBendpointFeature;
import org.eclipse.graphiti.features.IRemoveFeature;
import org.eclipse.graphiti.features.IResizeShapeFeature;
import org.eclipse.graphiti.features.IUpdateFeature;
import org.eclipse.graphiti.features.context.IAddBendpointContext;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.context.IBendpointContext;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.features.context.IDeleteContext;
import org.eclipse.graphiti.features.context.IDoubleClickContext;
import org.eclipse.graphiti.features.context.ILayoutContext;
import org.eclipse.graphiti.features.context.IMoveBendpointContext;
import org.eclipse.graphiti.features.context.IMoveShapeContext;
import org.eclipse.graphiti.features.context.IPictogramElementContext;
import org.eclipse.graphiti.features.context.IReconnectionContext;
import org.eclipse.graphiti.features.context.IRemoveBendpointContext;
import org.eclipse.graphiti.features.context.IRemoveContext;
import org.eclipse.graphiti.features.context.IResizeShapeContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
......@@ -304,6 +311,33 @@ public class ProviderDispatcher {
return super.getRemoveFeature(context);
}
@Override
public IMoveBendpointFeature getMoveBendpointFeature(IMoveBendpointContext context) {
IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
if (fp!=null)
return fp.getMoveBendpointFeature(context);
else
return super.getMoveBendpointFeature(context);
}
@Override
public IAddBendpointFeature getAddBendpointFeature(IAddBendpointContext context) {
IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
if (fp!=null)
return fp.getAddBendpointFeature(context);
else
return super.getAddBendpointFeature(context);
}
@Override
public IRemoveBendpointFeature getRemoveBendpointFeature(IRemoveBendpointContext context) {
IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
if (fp!=null)
return fp.getRemoveBendpointFeature(context);
else
return super.getRemoveBendpointFeature(context);
}
@Override
public ICustomFeature[] getCustomFeatures(ICustomContext context) {
ArrayList<ICustomFeature> result = new ArrayList<ICustomFeature>();
......@@ -338,6 +372,12 @@ public class ProviderDispatcher {
return bo;
}
private EObject getBusinessObject(IBendpointContext context) {
PictogramElement pictogramElement = context.getConnection();
EObject bo = (EObject) getBusinessObjectForPictogramElement(pictogramElement);
return bo;
}
private EObject getBusinessObject(ICustomContext context) {
PictogramElement[] pes = context.getPictogramElements();
if (pes.length>0) {
......
......@@ -33,24 +33,33 @@ import org.eclipse.etrice.ui.structure.support.feature.ConnectionUpdateFeature;
import org.eclipse.etrice.ui.structure.support.provider.ConnectionProvider;
import org.eclipse.etrice.ui.structure.support.provider.DecorationProvider;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddBendpointFeature;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.ICreateConnectionFeature;
import org.eclipse.graphiti.features.IDeleteFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.IMoveBendpointFeature;
import org.eclipse.graphiti.features.IReconnectionFeature;
import org.eclipse.graphiti.features.IRemoveBendpointFeature;
import org.eclipse.graphiti.features.IRemoveFeature;
import org.eclipse.graphiti.features.IUpdateFeature;
import org.eclipse.graphiti.features.context.IAddBendpointContext;
import org.eclipse.graphiti.features.context.IAddConnectionContext;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.context.ICreateConnectionContext;
import org.eclipse.graphiti.features.context.IDeleteContext;
import org.eclipse.graphiti.features.context.IMoveBendpointContext;
import org.eclipse.graphiti.features.context.IReconnectionContext;
import org.eclipse.graphiti.features.context.IRemoveBendpointContext;
import org.eclipse.graphiti.features.context.IRemoveContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.context.impl.ReconnectionContext;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
import org.eclipse.graphiti.features.impl.DefaultAddBendpointFeature;
import org.eclipse.graphiti.features.impl.DefaultMoveBendpointFeature;
import org.eclipse.graphiti.features.impl.DefaultReconnectionFeature;
import org.eclipse.graphiti.features.impl.DefaultRemoveBendpointFeature;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.algorithms.Polyline;
import org.eclipse.graphiti.mm.pictograms.Anchor;
......@@ -395,8 +404,64 @@ public class BindingSupport {
return true;
}
}
private class MoveBendpointFeature extends DefaultMoveBendpointFeature {
public MoveBendpointFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public boolean canMoveBendpoint(IMoveBendpointContext context) {
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(context.getConnection());
if (bo instanceof Binding) {
Binding b = (Binding) bo;
if (!isInherited(getDiagram(), b)) {
return true;
}
}
return false;
}
}
private class AddBendpointFeature extends DefaultAddBendpointFeature {
public AddBendpointFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public boolean canAddBendpoint(IAddBendpointContext context) {
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(context.getConnection());
if (bo instanceof Binding) {
Binding b = (Binding) bo;
if (!isInherited(getDiagram(), b)) {
return true;
}
}
return false;
}
}
private class RemoveBendpointFeature extends DefaultRemoveBendpointFeature {
public RemoveBendpointFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public boolean canRemoveBendpoint(IRemoveBendpointContext context) {
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(context.getConnection());
if (bo instanceof Binding) {
Binding b = (Binding) bo;
if (!isInherited(getDiagram(), b)) {
return true;
}
}
return false;
}
}
private IFeatureProvider fp;
public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
......@@ -438,6 +503,24 @@ public class BindingSupport {
public IDeleteFeature getDeleteFeature(IDeleteContext context) {
return new DeleteFeature(fp);
}
@Override
public IMoveBendpointFeature getMoveBendpointFeature(IMoveBendpointContext context) {
IMoveBendpointFeature ret = new MoveBendpointFeature(fp);
return ret;
}
@Override
public IAddBendpointFeature getAddBendpointFeature(IAddBendpointContext context) {
IAddBendpointFeature ret = new AddBendpointFeature(fp);
return ret;
}
@Override
public IRemoveBendpointFeature getRemoveBendpointFeature(IRemoveBendpointContext context) {
IRemoveBendpointFeature ret = new RemoveBendpointFeature(fp);
return ret;
}
}
class BehaviorProvider extends BaseToolBehaviorProvider {
......
......@@ -17,6 +17,7 @@ package org.eclipse.etrice.ui.structure.support;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.room.ActorContainerClass;
import org.eclipse.etrice.core.room.ActorContainerRef;
import org.eclipse.etrice.core.room.Binding;
import org.eclipse.etrice.core.room.LayerConnection;
import org.eclipse.etrice.core.room.RefSAPoint;
import org.eclipse.etrice.core.room.RelaySAPoint;
......@@ -35,24 +36,33 @@ import org.eclipse.etrice.ui.structure.support.context.InitialAddConnectionConte
import org.eclipse.etrice.ui.structure.support.feature.ConnectionUpdateFeature;
import org.eclipse.etrice.ui.structure.support.provider.ConnectionProvider;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddBendpointFeature;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.ICreateConnectionFeature;
import org.eclipse.graphiti.features.IDeleteFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.IMoveBendpointFeature;
import org.eclipse.graphiti.features.IReconnectionFeature;
import org.eclipse.graphiti.features.IRemoveBendpointFeature;
import org.eclipse.graphiti.features.IRemoveFeature;
import org.eclipse.graphiti.features.IUpdateFeature;
import org.eclipse.graphiti.features.context.IAddBendpointContext;
import org.eclipse.graphiti.features.context.IAddConnectionContext;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.context.ICreateConnectionContext;
import org.eclipse.graphiti.features.context.IDeleteContext;
import org.eclipse.graphiti.features.context.IMoveBendpointContext;
import org.eclipse.graphiti.features.context.IReconnectionContext;
import org.eclipse.graphiti.features.context.IRemoveBendpointContext;
import org.eclipse.graphiti.features.context.IRemoveContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.context.impl.ReconnectionContext;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
import org.eclipse.graphiti.features.impl.DefaultAddBendpointFeature;
import org.eclipse.graphiti.features.impl.DefaultMoveBendpointFeature;
import org.eclipse.graphiti.features.impl.DefaultReconnectionFeature;
import org.eclipse.graphiti.features.impl.DefaultRemoveBendpointFeature;
import org.eclipse.graphiti.mm.GraphicsAlgorithmContainer;
import org.eclipse.graphiti.mm.algorithms.Polyline;
import org.eclipse.graphiti.mm.pictograms.Anchor;
......@@ -340,6 +350,63 @@ public class LayerConnectionSupport {
}
}
private class AddBendpointFeature extends DefaultAddBendpointFeature {
public AddBendpointFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public boolean canAddBendpoint(IAddBendpointContext context) {
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(context.getConnection());
if (bo instanceof LayerConnection) {
LayerConnection lc = (LayerConnection) bo;
if (!isInherited(getDiagram(), lc)) {
return true;
}
}
return false;
}
}
private class MoveBendpointFeature extends DefaultMoveBendpointFeature {
public MoveBendpointFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public boolean canMoveBendpoint(IMoveBendpointContext context) {
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(context.getConnection());
if (bo instanceof LayerConnection) {
LayerConnection lc = (LayerConnection) bo;
if (!isInherited(getDiagram(), lc)) {
return true;
}
}
return false;
}
}
private class RemoveBendpointFeature extends DefaultRemoveBendpointFeature {
public RemoveBendpointFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public boolean canRemoveBendpoint(IRemoveBendpointContext context) {
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(context.getConnection());
if (bo instanceof LayerConnection) {
LayerConnection lc = (LayerConnection) bo;
if (!isInherited(getDiagram(), lc)) {
return true;
}
}
return false;
}
}
private IFeatureProvider fp;
public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
......@@ -381,6 +448,24 @@ public class LayerConnectionSupport {
public IReconnectionFeature getReconnectionFeature(IReconnectionContext context) {
return new ReconnectionFeature(fp);
}
@Override
public IMoveBendpointFeature getMoveBendpointFeature(IMoveBendpointContext context) {
IMoveBendpointFeature ret = new MoveBendpointFeature(fp);
return ret;
}
@Override
public IAddBendpointFeature getAddBendpointFeature(IAddBendpointContext context) {
IAddBendpointFeature ret = new AddBendpointFeature(fp);
return ret;
}
@Override
public IRemoveBendpointFeature getRemoveBendpointFeature(IRemoveBendpointContext context) {
IRemoveBendpointFeature ret = new RemoveBendpointFeature(fp);
return ret;
}
}
class BehaviorProvider extends BaseToolBehaviorProvider {
......
......@@ -18,6 +18,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.room.ActorClass;
......@@ -44,9 +45,10 @@ public class SuperDiagramPositionProvider implements IPositionProvider {
private class Parent {
String key;
PosAndSize posInv;
}
private PosAndSize superDiagramPosition;
private PosAndSize posInvSuper;
private HashMap<String, PosAndSize> obj2pos;
private HashMap<String, Pos> obj2text;
private HashMap<String, ArrayList<Pos>> obj2bendpoints;
......@@ -62,7 +64,7 @@ public class SuperDiagramPositionProvider implements IPositionProvider {
// defaults
parent = new Parent();
parent.key = getKey(sc);
// parent.inv & parent.inner at mapPositions()
// parent.posInv is initialized in mapPositions()
if (sc instanceof ActorClass) {
ActorClass base = ((ActorClass) sc).getActorBase();
......@@ -77,10 +79,11 @@ public class SuperDiagramPositionProvider implements IPositionProvider {
pp.obj2pos = this.obj2pos;
pp.obj2text = this.obj2text;
pp.obj2bendpoints = this.obj2bendpoints;
pp.superDiagramPosition = this.superDiagramPosition;
pp.posInvSuper = this.posInvSuper;
Parent newParent = new Parent();
newParent.key = getKey(parent);
newParent.posInv = invisibleRect;
pp.parent = newParent;
......@@ -95,7 +98,7 @@ public class SuperDiagramPositionProvider implements IPositionProvider {
@Override
public PosAndSize getDiagramPosition() {
return superDiagramPosition;
return posInvSuper;
}
@Override
......@@ -113,9 +116,12 @@ public class SuperDiagramPositionProvider implements IPositionProvider {
@Override
public List<Pos> getConnectionBendpoints(EObject obj) {
ArrayList<Pos> list = obj2bendpoints.get(getKey(obj));
return (list == null || list.isEmpty())
? Collections.emptyList()
: new ArrayList<Pos>(list);
int offsetX = parent.posInv.getX() - posInvSuper.getX();
int offsetY = parent.posInv.getY() - posInvSuper.getY();
return (list == null || list.isEmpty()) ? Collections.emptyList()
: new ArrayList<Pos>(list).stream()
.map(p -> new Pos((p.getX() + offsetX), (p.getY() + offsetY)))
.collect(Collectors.toList());
}
private void mapPositions(ActorClass ac) {
......@@ -132,9 +138,9 @@ public class SuperDiagramPositionProvider implements IPositionProvider {
if(!sc.eResource().getURI().equals(ac.eResource().getURI()))
return;
PosAndSize acInv = DiagramUtil.getPosAndSize(acShape.getGraphicsAlgorithm());
superDiagramPosition = acInv;
posInvSuper = DiagramUtil.getPosAndSize(acShape.getGraphicsAlgorithm());
parent.posInv = posInvSuper;
// refs & interface items
for (Shape shape : acShape.getChildren()) {
EObject obj = linkService.getBusinessObjectForLinkedPictogramElement(shape);
......
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