diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/commands/DeleteNestedConnectionsCommand.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/commands/DeleteNestedConnectionsCommand.java
deleted file mode 100644
index 001734ab2..000000000
--- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/commands/DeleteNestedConnectionsCommand.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * This program and the accompanying materials
- * are made available under the terms of the License
- * which accompanies this distribution in the file LICENSE.txt
- */
-package com.archimatetool.editor.diagram.commands;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-
-import com.archimatetool.editor.model.DiagramModelUtils;
-import com.archimatetool.model.IDiagramModelArchimateConnection;
-import com.archimatetool.model.IDiagramModelArchimateObject;
-import com.archimatetool.model.IDiagramModelConnection;
-
-/**
- * Compound Command to delete nested connections between parent and childObjects in nested objects.
- * This is used when the user drags objects into a parent Archimate object and nested connections to child are removed.
- *
- * @author Phillip Beauvoir
- */
-public class DeleteNestedConnectionsCommand extends CompoundCommand {
-
- IDiagramModelArchimateObject fParentObject;
- List fChildObjects;
-
- public DeleteNestedConnectionsCommand(IDiagramModelArchimateObject parentObject, IDiagramModelArchimateObject childObject) {
- fParentObject = parentObject;
- fChildObjects = new ArrayList();
- fChildObjects.add(childObject);
- }
-
- public DeleteNestedConnectionsCommand(IDiagramModelArchimateObject parentObject, List childObjects) {
- fParentObject = parentObject;
- fChildObjects = childObjects;
- }
-
- @Override
- public void execute() {
- createDeleteCommands();
-
- super.execute();
- }
-
- // These should return true always because sub-commands are only created on execute()
-
- @Override
- public boolean canExecute() {
- return true;
- }
-
- @Override
- public boolean canUndo() {
- return true;
- }
-
- @Override
- public boolean canRedo() {
- return true;
- }
-
- /**
- * Child Objects that have connections
- */
- void createDeleteCommands() {
- for(IDiagramModelArchimateObject child : fChildObjects) {
- for(IDiagramModelConnection connection : child.getTargetConnections()) {
- if(connection instanceof IDiagramModelArchimateConnection && DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection)connection)) {
- for(IDiagramModelConnection subconnection : connection.getTargetConnections()) {
- Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(subconnection);
- add(cmd);
- }
-
- for(IDiagramModelConnection subconnection : connection.getSourceConnections()) {
- Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(subconnection);
- add(cmd);
- }
- }
- }
- }
- }
-}
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractArchimateElementEditPart.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractArchimateElementEditPart.java
index 0b4cee05c..156a4cc9a 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractArchimateElementEditPart.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractArchimateElementEditPart.java
@@ -5,6 +5,10 @@
*/
package com.archimatetool.editor.diagram.editparts;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.gef.EditPart;
@@ -16,7 +20,10 @@
import com.archimatetool.editor.preferences.IPreferenceConstants;
import com.archimatetool.model.IArchimateModel;
import com.archimatetool.model.IArchimatePackage;
+import com.archimatetool.model.IConnectable;
import com.archimatetool.model.IDiagramModelArchimateObject;
+import com.archimatetool.model.IDiagramModelConnection;
+import com.archimatetool.model.IDiagramModelObject;
import com.archimatetool.model.IFeatures;
import com.archimatetool.model.IProfile;
import com.archimatetool.model.util.LightweightEContentAdapter;
@@ -118,6 +125,7 @@ protected void eCoreChanged(Notification msg) {
case Notification.MOVE:
refreshSourceConnections();
refreshTargetConnections();
+ refreshRelatedConnections();
refreshChildren();
break;
@@ -126,6 +134,52 @@ protected void eCoreChanged(Notification msg) {
}
}
+ /**
+ * Refresh all connections and their connections in case we have nested connection->connections
+ */
+ protected void refreshRelatedConnections() {
+ // Get the EditPartRegistry
+ Map, ?> editPartRegistry = getRoot().getViewer().getEditPartRegistry();
+
+ // Get the model objects that might need updating
+ for(IDiagramModelObject dmo : getObjectsToUpdateConnections(getModel())) {
+ // If we have the EditPart then update its connections
+ if(editPartRegistry.get(dmo) instanceof AbstractConnectedEditPart editPart) {
+ editPart.refreshSourceConnections();
+ editPart.refreshTargetConnections();
+ }
+ }
+ }
+
+ /**
+ * Get all connected objects that might need to have their connections updated when nesting
+ */
+ protected Set getObjectsToUpdateConnections(IConnectable connectable) {
+ Set set = new HashSet<>();
+
+ for(IDiagramModelConnection connection : connectable.getSourceConnections()) {
+ if(connection.getSource() instanceof IDiagramModelObject dmo) {
+ set.add(dmo);
+ }
+ if(connection.getTarget() instanceof IDiagramModelObject dmo) {
+ set.add(dmo);
+ }
+ set.addAll(getObjectsToUpdateConnections(connection));
+ }
+
+ for(IDiagramModelConnection connection : connectable.getTargetConnections()) {
+ if(connection.getSource() instanceof IDiagramModelObject dmo) {
+ set.add(dmo);
+ }
+ if(connection.getTarget() instanceof IDiagramModelObject dmo) {
+ set.add(dmo);
+ }
+ set.addAll(getObjectsToUpdateConnections(connection));
+ }
+
+ return set;
+ }
+
@Override
protected void refreshFigure() {
// Set Enabled according to current Viewpoint
@@ -141,13 +195,7 @@ protected void refreshFigure() {
@Override
protected void applicationPreferencesChanged(PropertyChangeEvent event) {
- // Hidden connections
- if(IPreferenceConstants.HIDDEN_RELATIONS_TYPES.equals(event.getProperty()) ||
- IPreferenceConstants.USE_NESTED_CONNECTIONS.equals(event.getProperty())) {
- refreshSourceConnections();
- refreshTargetConnections();
- }
- else if(IPreferenceConstants.VIEWPOINTS_GHOST_DIAGRAM_ELEMENTS.equals(event.getProperty())) {
+ if(IPreferenceConstants.VIEWPOINTS_GHOST_DIAGRAM_ELEMENTS.equals(event.getProperty())) {
refreshFigure();
}
else {
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractConnectedEditPart.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractConnectedEditPart.java
index 2da31c60a..6d9eba938 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractConnectedEditPart.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractConnectedEditPart.java
@@ -64,15 +64,9 @@ protected void eCoreChanged(Notification msg) {
case Notification.REMOVE:
case Notification.REMOVE_MANY:
case Notification.MOVE:
- if(feature == IArchimatePackage.Literals.CONNECTABLE__SOURCE_CONNECTIONS) {
- refreshSourceConnections();
- }
- else if(feature == IArchimatePackage.Literals.CONNECTABLE__TARGET_CONNECTIONS) {
- refreshTargetConnections();
- }
- else {
- refreshChildren();
- }
+ refreshSourceConnections();
+ refreshTargetConnections();
+ refreshChildren();
break;
case Notification.SET:
@@ -83,11 +77,11 @@ else if(feature == IArchimatePackage.Literals.CONNECTABLE__TARGET_CONNECTIONS) {
// Locked
else if(feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) {
updateEditPolicies(); // Update Edit Policies of this and parent
- if(getParent() instanceof AbstractDiagramPart) {
- ((AbstractDiagramPart)getParent()).updateEditPolicies();
+ if(getParent() instanceof AbstractDiagramPart part) {
+ part.updateEditPolicies();
}
- else if(getParent() instanceof AbstractBaseEditPart) {
- ((AbstractBaseEditPart)getParent()).updateEditPolicies();
+ else if(getParent() instanceof AbstractBaseEditPart part) {
+ part.updateEditPolicies();
}
}
else {
@@ -109,7 +103,13 @@ else if(getParent() instanceof AbstractBaseEditPart) {
@Override
protected void applicationPreferencesChanged(PropertyChangeEvent event) {
- if(IPreferenceConstants.USE_ORTHOGONAL_ANCHOR.equals(event.getProperty())) {
+ // Hidden connections
+ if(IPreferenceConstants.HIDDEN_RELATIONS_TYPES.equals(event.getProperty()) ||
+ IPreferenceConstants.USE_NESTED_CONNECTIONS.equals(event.getProperty())) {
+ refreshSourceConnections();
+ refreshTargetConnections();
+ }
+ else if(IPreferenceConstants.USE_ORTHOGONAL_ANCHOR.equals(event.getProperty())) {
refreshConnectionAnchors();
}
@@ -121,6 +121,22 @@ protected Adapter getECoreAdapter() {
return adapter;
}
+ /**
+ * Make this public
+ */
+ @Override
+ public void refreshSourceConnections() {
+ super.refreshSourceConnections();
+ }
+
+ /**
+ * Make this public
+ */
+ @Override
+ public void refreshTargetConnections() {
+ super.refreshTargetConnections();
+ }
+
@Override
protected List getModelSourceConnections() {
return getFilteredModelSourceConnections();
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractDiagramPart.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractDiagramPart.java
index 842e792a6..185692c69 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractDiagramPart.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractDiagramPart.java
@@ -53,6 +53,11 @@ public abstract class AbstractDiagramPart extends AbstractFilteredEditPart
private Adapter adapter = new LightweightEContentAdapter(this::eCoreChanged, IFeature.class);
+ protected AbstractDiagramPart() {
+ // Add a Nested Connection Filter
+ addEditPartFilter(new NestedConnectionEditPartFilter());
+ }
+
/**
* Message from the ECore Adapter
* @param msg
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/ArchimateDiagramPart.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/ArchimateDiagramPart.java
index f2dcc6d69..c761e5a7c 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/ArchimateDiagramPart.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/ArchimateDiagramPart.java
@@ -31,8 +31,6 @@ public ArchimateDiagramPart() {
if(!ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.VIEWPOINTS_GHOST_DIAGRAM_ELEMENTS)) {
addEditPartFilter(new ViewpointEditPartFilter());
}
- // Add a Nested Connection Filter
- addEditPartFilter(new NestedConnectionEditPartFilter());
}
@Override
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/ArchimateElementEditPart.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/ArchimateElementEditPart.java
index a8275d198..5e28f1b2e 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/ArchimateElementEditPart.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/ArchimateElementEditPart.java
@@ -16,9 +16,9 @@
import com.archimatetool.editor.diagram.directedit.MultiLineTextDirectEditManager;
import com.archimatetool.editor.diagram.figures.IContainerFigure;
-import com.archimatetool.editor.diagram.policies.ArchimateContainerEditPolicy;
import com.archimatetool.editor.diagram.policies.ArchimateContainerLayoutPolicy;
import com.archimatetool.editor.diagram.policies.ArchimateDNDEditPolicy;
+import com.archimatetool.editor.diagram.policies.BasicContainerEditPolicy;
import com.archimatetool.editor.diagram.policies.ContainerHighlightEditPolicy;
import com.archimatetool.editor.diagram.policies.PartComponentEditPolicy;
import com.archimatetool.editor.diagram.policies.PartDirectEditTitlePolicy;
@@ -60,7 +60,7 @@ protected void createEditPolicies() {
installEditPolicy(EditPolicy.LAYOUT_ROLE, new ArchimateContainerLayoutPolicy());
// Orphaning
- installEditPolicy(EditPolicy.CONTAINER_ROLE, new ArchimateContainerEditPolicy());
+ installEditPolicy(EditPolicy.CONTAINER_ROLE, new BasicContainerEditPolicy());
// Snap to Geometry feedback
installEditPolicy("Snap Feedback", new SnapFeedbackPolicy()); //$NON-NLS-1$
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/NestedConnectionEditPartFilter.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/NestedConnectionEditPartFilter.java
index 247ca7435..4d801330a 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/NestedConnectionEditPartFilter.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/NestedConnectionEditPartFilter.java
@@ -8,8 +8,6 @@
import org.eclipse.gef.EditPart;
import com.archimatetool.editor.model.DiagramModelUtils;
-import com.archimatetool.editor.preferences.ConnectionPreferences;
-import com.archimatetool.model.IDiagramModelArchimateConnection;
import com.archimatetool.model.IDiagramModelConnection;
@@ -22,12 +20,6 @@ public class NestedConnectionEditPartFilter implements IConnectionEditPartFilter
@Override
public boolean isConnectionVisible(EditPart editPart, IDiagramModelConnection connection) {
- // If the connection is an Archimate type and its target element is an Archimate type
- // and this box contains that box and that box qualifies, don't show the connection
- if(ConnectionPreferences.useNestedConnections() && connection instanceof IDiagramModelArchimateConnection) {
- return !DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection)connection);
- }
-
- return true;
+ return !DiagramModelUtils.shouldBeHiddenConnection(connection);
}
}
\ No newline at end of file
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/policies/ArchimateContainerEditPolicy.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/policies/ArchimateContainerEditPolicy.java
deleted file mode 100644
index 8c6aa7857..000000000
--- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/policies/ArchimateContainerEditPolicy.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- * This program and the accompanying materials
- * are made available under the terms of the License
- * which accompanies this distribution in the file LICENSE.txt
- */
-package com.archimatetool.editor.diagram.policies;
-
-import java.util.List;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.requests.GroupRequest;
-
-import com.archimatetool.editor.model.DiagramModelUtils;
-import com.archimatetool.model.IArchimateElement;
-import com.archimatetool.model.IArchimateFactory;
-import com.archimatetool.model.IArchimateRelationship;
-import com.archimatetool.model.IDiagramModelArchimateConnection;
-import com.archimatetool.model.IDiagramModelArchimateObject;
-import com.archimatetool.model.IDiagramModelObject;
-
-
-
-/**
- * Archimate Type Container EditPolicy
- *
- * @author Phillip Beauvoir
- */
-public class ArchimateContainerEditPolicy extends BasicContainerEditPolicy {
-
- /*
- * Over-ride this to add an explicit connection when removing from an Archimate container if nested
- */
- @Override
- public Command getOrphanChildrenCommand(GroupRequest request) {
- CompoundCommand command = (CompoundCommand)super.getOrphanChildrenCommand(request);
-
- /* This behavior has been disabled because connections have already been created
- * in a hiden state when nesting the child inside its parent.
- * TODO: Clean-up if no side effects have been found after some time...
- */
- // If we use nested connections and the EditPart model is an Archimate type object
-// if(ConnectionPreferences.useNestedConnections() && (getHost().getModel() instanceof IDiagramModelArchimateObject)) {
-// createNewConnectionCommands((IDiagramModelArchimateObject)getHost().getModel(), request.getEditParts(), command);
-// }
-
- return command;
- }
-
- /**
- * When Archimate child objects are dragged out of a parent Archimate object check to see if new connections should be created
- *
- * TODO A3: If O1--C1--O2 and in parent. C1 is also connected to parent (and hidden).
- * O1 or O2 is removed from parent - should add connection from C1 to parent?
- * Or should it be only when O1 AND O2 are removed from parent?
- */
- void createNewConnectionCommands(IDiagramModelArchimateObject parentObject, List> childEditParts, CompoundCommand command) {
- IArchimateElement parentElement = parentObject.getArchimateElement();
-
- for(Object o : childEditParts) {
- IDiagramModelObject child = (IDiagramModelObject)((EditPart)o).getModel();
-
- // If it's an Archimate type child object...
- if(child instanceof IDiagramModelArchimateObject) {
- IDiagramModelArchimateObject childObject = (IDiagramModelArchimateObject)child;
- IArchimateElement childElement = childObject.getArchimateElement();
-
- // See if there are any (nested type) relationships between parent element and child element...
- for(IArchimateRelationship relation : parentElement.getSourceRelationships()) {
- if(relation.getTarget() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
- // And there's not a connection already there then add one
- if(!DiagramModelUtils.hasDiagramModelArchimateConnection(parentObject, childObject, relation)) {
- command.add(new CreateDiagramArchimateConnectionCommand(parentObject, childObject, relation));
- }
- }
- }
- }
- }
- }
-
- /**
- * Create New Connection Command based on existing relation
- */
- static class CreateDiagramArchimateConnectionCommand extends Command {
- IDiagramModelArchimateConnection fConnection;
- IDiagramModelArchimateObject fSource;
- IDiagramModelArchimateObject fTarget;
- IArchimateRelationship fRelation;
-
- CreateDiagramArchimateConnectionCommand(IDiagramModelArchimateObject source, IDiagramModelArchimateObject target, IArchimateRelationship relation) {
- fSource = source;
- fTarget = target;
- fRelation = relation;
- }
-
- @Override
- public void execute() {
- fConnection = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
- fConnection.setArchimateRelationship(fRelation);
- fConnection.connect(fSource, fTarget);
- }
-
- @Override
- public void redo() {
- fConnection.reconnect();
- }
-
- @Override
- public void undo() {
- fConnection.disconnect();
- }
-
- @Override
- public void dispose() {
- fConnection = null;
- fSource = null;
- fTarget = null;
- fRelation = null;
- }
- }
-
-}
\ No newline at end of file
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/policies/ArchimateContainerLayoutPolicy.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/policies/ArchimateContainerLayoutPolicy.java
index 37d644742..304ad758f 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/policies/ArchimateContainerLayoutPolicy.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/policies/ArchimateContainerLayoutPolicy.java
@@ -15,7 +15,6 @@
import org.eclipse.gef.requests.ChangeBoundsRequest;
import com.archimatetool.editor.diagram.commands.CreateNestedArchimateConnectionsWithDialogCommand;
-import com.archimatetool.editor.diagram.commands.DeleteNestedConnectionsCommand;
import com.archimatetool.editor.preferences.ConnectionPreferences;
import com.archimatetool.model.IDiagramModelArchimateObject;
@@ -42,11 +41,6 @@ protected Command getAddCommand(Request generic) {
List childObjectsForNewConnections = new ArrayList();
- // Delete connections between parent and child if Prefs set and if parent is an Archimate object
- boolean doDeleteNestedConnections = ConnectionPreferences.useNestedConnections();
-
- List childObjectsForDeletedConnections = new ArrayList();
-
for(Object editPart : request.getEditParts()) {
GraphicalEditPart child = (GraphicalEditPart)editPart;
AddObjectCommand addCommand = createAddCommand(request, child, translateToModelConstraint(getConstraintFor(request, child)));
@@ -56,17 +50,6 @@ protected Command getAddCommand(Request generic) {
if(doAddNestedConnections && addCommand.child instanceof IDiagramModelArchimateObject) {
childObjectsForNewConnections.add((IDiagramModelArchimateObject)addCommand.child);
}
-
- // If we need to delete some nested connections
- if(doDeleteNestedConnections && addCommand.child instanceof IDiagramModelArchimateObject) {
- childObjectsForDeletedConnections.add((IDiagramModelArchimateObject)addCommand.child);
- }
- }
-
- // We have some child objects for deletion connections
- if(!childObjectsForDeletedConnections.isEmpty()) {
- Command cmd = new DeleteNestedConnectionsCommand((IDiagramModelArchimateObject)parent, childObjectsForDeletedConnections);
- command.add(cmd);
}
// We have some child objects so add the sub command
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/model/DiagramModelUtils.java b/com.archimatetool.editor/src/com/archimatetool/editor/model/DiagramModelUtils.java
index 1da79fc66..62d69eb75 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/model/DiagramModelUtils.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/model/DiagramModelUtils.java
@@ -271,65 +271,40 @@ public static boolean isNestedConnectionTypeRelationship(IArchimateRelationship
* @param connection The connection to check
* @return true if a connection should be hidden when its source (parent) element contains its target (child) element
*/
- public static boolean shouldBeHiddenConnection(IDiagramModelArchimateConnection connection) {
+ public static boolean shouldBeHiddenConnection(IDiagramModelConnection connection) {
if(!ConnectionPreferences.useNestedConnections()) {
return false;
}
- // Only if the connection's source and target are both ArchiMate concepts
- if(!(connection.getSource() instanceof IDiagramModelArchimateComponent) && !(connection.getTarget() instanceof IDiagramModelArchimateComponent)) {
- return false;
+ // This is an Archimate connection
+ // and the connection's source is an Archimate object and the connection's target is an Archimate object
+ // and the connection's source contains the connection's target or the connection's target contains the connection's source
+ if(connection instanceof IDiagramModelArchimateConnection dmc
+ && connection.getSource() instanceof IDiagramModelArchimateObject source
+ && connection.getTarget() instanceof IDiagramModelArchimateObject target
+ && (source == target.eContainer() || target == source.eContainer())) {
+ return isNestedConnectionTypeRelationship(dmc.getArchimateRelationship());
}
-
- IDiagramModelArchimateComponent source = (IDiagramModelArchimateComponent)connection.getSource();
- IDiagramModelArchimateComponent target = (IDiagramModelArchimateComponent)connection.getTarget();
-
- // If the connection's source element contains the target element, or the connection's target element contains the source element
- if(source instanceof IDiagramModelArchimateObject && target instanceof IDiagramModelArchimateObject) {
- if(((IDiagramModelContainer)source).getChildren().contains((IDiagramModelArchimateObject)target)
- || ((IDiagramModelContainer)target).getChildren().contains((IDiagramModelArchimateObject)source)) {
- // And it's a relationship type we have chosen to hide
- for(EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
- if(connection.getArchimateRelationship().eClass() == eClass) {
- return true;
- }
- }
- }
+
+ // This is a plain connection
+ // and the connection's source is an object and the connection's target is an object
+ // and the connection's source contains the connection's target
+ if(connection.getSource() instanceof IDiagramModelObject source
+ && connection.getTarget() instanceof IDiagramModelObject target
+ && (source == target.eContainer() || target == source.eContainer())) {
+ return true;
}
-
- // If connection's source is an element and target is a connection
- if(source instanceof IDiagramModelArchimateObject && target instanceof IDiagramModelArchimateConnection) {
- IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject)source;
- IConnectable connectionSource = ((IDiagramModelArchimateConnection)target).getSource();
- IConnectable connectionTarget = ((IDiagramModelArchimateConnection)target).getTarget();
-
- if(parent.getChildren().contains(connectionSource) && parent.getChildren().contains(connectionTarget)) {
- // And it's a relationship type we have chosen to hide
- for(EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
- if(connection.getArchimateRelationship().eClass() == eClass) {
- return true;
- }
- }
- }
+
+ // If the connection's source is a connection and is a hidden type
+ if(connection.getSource() instanceof IDiagramModelConnection dmc) {
+ return shouldBeHiddenConnection(dmc);
}
-
- // If connection's target is an element and source is a connection
- // TODO: Not sure if this directionality should be allowed
- if(target instanceof IDiagramModelArchimateObject && source instanceof IDiagramModelArchimateConnection) {
- IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject)target;
- IConnectable connectionSource = ((IDiagramModelArchimateConnection)source).getSource();
- IConnectable connectionTarget = ((IDiagramModelArchimateConnection)source).getTarget();
-
- if(parent.getChildren().contains(connectionSource) && parent.getChildren().contains(connectionTarget)) {
- // And it's a relationship type we have chosen to hide
- for(EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
- if(connection.getArchimateRelationship().eClass() == eClass) {
- return true;
- }
- }
- }
+
+ // If the connection's target is a connection and is a hidden type
+ if(connection.getTarget() instanceof IDiagramModelConnection dmc) {
+ return shouldBeHiddenConnection(dmc);
}
-
+
return false;
}
diff --git a/com.archimatetool.help/help/Text/prefs_connections.html b/com.archimatetool.help/help/Text/prefs_connections.html
index 6157663ff..a77d1db5d 100644
--- a/com.archimatetool.help/help/Text/prefs_connections.html
+++ b/com.archimatetool.help/help/Text/prefs_connections.html
@@ -97,7 +97,7 @@ Automatic Relationship Management
Select the types of relationship that will be offered when new implicit connections are created between child and parent elements in a View. These are "reversed" nestings.
Relation types to hide when elements are nested
- Select the types of relationship connection that will be hidden in a View when there are nested parent and child elements.
+ Select the types of relationship connection that will be hidden in a View when there are nested parent and child elements. Non-ArchiMate connections are hidden by default when a connected object is nested.