diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/commands/CreateNestedArchimateConnectionsWithDialogCommand.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/commands/CreateNestedArchimateConnectionsWithDialogCommand.java index e99da4433..80f6b2fb1 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/commands/CreateNestedArchimateConnectionsWithDialogCommand.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/commands/CreateNestedArchimateConnectionsWithDialogCommand.java @@ -16,30 +16,21 @@ import com.archimatetool.editor.diagram.dialog.NewNestedRelationDialog; import com.archimatetool.editor.diagram.dialog.NewNestedRelationsDialog; import com.archimatetool.editor.diagram.dialog.NewNestedRelationsDialog.SelectedRelationshipType; -import com.archimatetool.editor.model.DiagramModelUtils; import com.archimatetool.editor.preferences.ConnectionPreferences; import com.archimatetool.model.IArchimateElement; import com.archimatetool.model.IArchimateFactory; import com.archimatetool.model.IArchimateRelationship; -import com.archimatetool.model.IDiagramModelArchimateComponent; -import com.archimatetool.model.IDiagramModelArchimateConnection; import com.archimatetool.model.IDiagramModelArchimateObject; -import com.archimatetool.model.IDiagramModelConnection; -import com.archimatetool.model.IDiagramModelObject; import com.archimatetool.model.IFolder; import com.archimatetool.model.util.ArchimateModelUtils; /** - * Compound Command to create new connections/relations between parent and childObjects in nested objects. - * This is used when the user drags objects into a parent Archimate object and nested connections/relations to child are required. + * Compound Command to create new relations between parent and childObjects in nested objects. + * This is used when the user drags objects into a parent Archimate object and nested relations to child are required. * - * Cases are: * 1. User drags newly created child object(s) into the parent where there is _no_ relationship. - * Ask via a dialog what user wants. If yes, create relationship & connection. + * Ask via a dialog what user wants. If yes, create relationship. * This is when creating new child objects from palette or from DnD from model tree. - * 2. User drags child object(s) into parent where there is a relationship - check if there is a connection, if not make one. - * This is when user drags child objects on diagram or from tree into parent and a relationship exists but no connection. - * 3. Cases 1 & 2 can happen together if more than one child is dragged into parent. * * @author Phillip Beauvoir */ @@ -61,11 +52,8 @@ public CreateNestedArchimateConnectionsWithDialogCommand(IDiagramModelArchimateO @Override public void execute() { - // Add new relationships/connection if user wants them - createConnectionDialogCommands(); - - // Add missing connections (may have been deleted by user) - createNewConnectionCommands(); + // Add new relationships if user wants them + createRelationshipDialogCommands(); super.execute(); } @@ -90,7 +78,7 @@ public boolean canRedo() { /** * Child Objects that don't have a relationship set with parent - ask user if they want one */ - void createConnectionDialogCommands() { + void createRelationshipDialogCommands() { // Gather suitable child objects List childObjectsForDialog = new ArrayList(); for(IDiagramModelArchimateObject childObject : fChildObjects) { @@ -106,7 +94,8 @@ void createConnectionDialogCommands() { if(dialog.open() == Window.OK) { EClass eClass = dialog.getSelectedType(); if(eClass != null) { - Command cmd = new CreateRelationshioAndDiagramArchimateConnectionCommand(fParentObject, childObjectsForDialog.get(0), eClass); + Command cmd = new AddRelationshipCommand(fParentObject.getArchimateElement(), + childObjectsForDialog.get(0).getArchimateElement(), eClass); add(cmd); } } @@ -120,7 +109,8 @@ else if(childObjectsForDialog.size() > 1) { List selectedTypes = dialog.getSelectedTypes(); for(SelectedRelationshipType selType : selectedTypes) { - Command cmd = new CreateRelationshioAndDiagramArchimateConnectionCommand(fParentObject, selType.childObject, selType.relationshipType); + Command cmd = new AddRelationshipCommand(fParentObject.getArchimateElement(), + selType.childObject.getArchimateElement(), selType.relationshipType); add(cmd); } } @@ -154,102 +144,17 @@ boolean canAddNewRelationship(IDiagramModelArchimateObject parentObject, IDiagra return false; } - - /** - * Create Commands for child objects that don't have connections and need new ones - * - * TODO A3: If O1--C1--O2. C1 is also connected to parent. - * O1 or O2 is added to parent - should add connection from C1 to parent? - * Or should it be only when O1 AND O2 are added to parent? - * - */ - void createNewConnectionCommands() { - IArchimateElement parentElement = fParentObject.getArchimateElement(); - - // Check connections between parent and child objects that are being dragged in - for(IDiagramModelArchimateObject childObject : fChildObjects) { - IArchimateElement childElement = childObject.getArchimateElement(); - - for(IArchimateRelationship relation : parentElement.getSourceRelationships()) { - if(relation.getTarget() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) { - // And there's not one already there... - if(!DiagramModelUtils.hasDiagramModelArchimateConnection(fParentObject, childObject, relation)) { - add(new CreateDiagramArchimateConnectionCommand(fParentObject, childObject, relation)); - } - } - } - } - - // Check connections between parent and child connections of objects - for(IArchimateRelationship relation : parentElement.getSourceRelationships()) { - if(relation.getTarget() instanceof IArchimateRelationship) { - IDiagramModelArchimateConnection dmc = findConnection((IArchimateRelationship)relation.getTarget()); - if(dmc != null) { - if(!DiagramModelUtils.hasDiagramModelArchimateConnection(fParentObject, dmc, relation)) { - add(new CreateDiagramArchimateConnectionCommand(fParentObject, dmc, relation)); - } - } - } - } - - for(IArchimateRelationship relation : parentElement.getTargetRelationships()) { - if(relation.getSource() instanceof IArchimateRelationship) { - IDiagramModelArchimateConnection dmc = findConnection((IArchimateRelationship)relation.getSource()); - if(dmc != null) { - if(!DiagramModelUtils.hasDiagramModelArchimateConnection(fParentObject, dmc, relation)) { - add(new CreateDiagramArchimateConnectionCommand(fParentObject, dmc, relation)); - } - } - } - } - } - - private IDiagramModelArchimateConnection findConnection(IArchimateRelationship relation) { - for(IDiagramModelObject dmo : fParentObject.getChildren()) { - for(IDiagramModelConnection dmc : dmo.getSourceConnections()) { - if(dmc instanceof IDiagramModelArchimateConnection) { - if(((IDiagramModelArchimateConnection)dmc).getArchimateRelationship() == relation) { - return (IDiagramModelArchimateConnection)dmc; - } - } - } - for(IDiagramModelConnection dmc : dmo.getTargetConnections()) { - if(dmc instanceof IDiagramModelArchimateConnection) { - if(((IDiagramModelArchimateConnection)dmc).getArchimateRelationship() == relation) { - return (IDiagramModelArchimateConnection)dmc; - } - } - } - } - - return null; - } - - static class CreateRelationshioAndDiagramArchimateConnectionCommand extends CompoundCommand { - - CreateRelationshioAndDiagramArchimateConnectionCommand(IDiagramModelArchimateObject sourceObject, - IDiagramModelArchimateObject targetObject, EClass relationshipType) { - - IArchimateRelationship relationship = (IArchimateRelationship)IArchimateFactory.eINSTANCE.create(relationshipType); - - Command cmd = new AddRelationshipCommand(sourceObject.getArchimateElement(), targetObject.getArchimateElement(), relationship); - add(cmd); - - cmd = new CreateDiagramArchimateConnectionCommand(sourceObject, targetObject, relationship); - add(cmd); - } - } - + static class AddRelationshipCommand extends Command { private IArchimateElement source; private IArchimateElement target; private IArchimateRelationship relationship; private IFolder folder; - public AddRelationshipCommand(IArchimateElement source, IArchimateElement target, IArchimateRelationship relationship) { + public AddRelationshipCommand(IArchimateElement source, IArchimateElement target, EClass relationshipType) { this.source = source; this.target = target; - this.relationship = relationship; + this.relationship = (IArchimateRelationship)IArchimateFactory.eINSTANCE.create(relationshipType); } @Override @@ -279,45 +184,4 @@ public void dispose() { relationship = null; } } - - /** - * Create New Connection Command based on existing relation - */ - static class CreateDiagramArchimateConnectionCommand extends Command { - IDiagramModelArchimateConnection connection; - IDiagramModelArchimateComponent source; - IDiagramModelArchimateComponent target; - IArchimateRelationship relationship; - - CreateDiagramArchimateConnectionCommand(IDiagramModelArchimateComponent source, IDiagramModelArchimateComponent target, IArchimateRelationship relationship) { - this.source = source; - this.target = target; - this.relationship = relationship; - } - - @Override - public void execute() { - connection = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection(); - connection.setArchimateRelationship(relationship); - connection.connect(source, target); - } - - @Override - public void redo() { - connection.reconnect(); - } - - @Override - public void undo() { - connection.disconnect(); - } - - @Override - public void dispose() { - connection = null; - source = null; - target = null; - relationship = null; - } - } } 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 new file mode 100644 index 000000000..d875a18ba --- /dev/null +++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/commands/DeleteNestedConnectionsCommand.java @@ -0,0 +1,77 @@ +/** + * 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.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.getSource() == fParentObject) { + Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(connection); + add(cmd); + } + } + } + } + +} 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 3958365f1..e3751cdf9 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 @@ -5,7 +5,6 @@ */ package com.archimatetool.editor.diagram.editparts; -import java.util.ArrayList; import java.util.List; import org.eclipse.draw2d.ConnectionAnchor; @@ -113,12 +112,12 @@ protected Adapter getECoreAdapter() { @Override protected List getModelSourceConnections() { - return getFilteredModelSourceConnections(); + return getModel().getSourceConnections(); } @Override protected List getModelTargetConnections() { - return getFilteredModelTargetConnections(); + return getModel().getTargetConnections(); } public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection) { @@ -179,46 +178,4 @@ protected void refreshConnectionAnchors() { ((EditPart)editPart).refresh(); } } - - // =================================== Filtering ==================================================== - - public List getFilteredModelSourceConnections() { - return getFilteredConnections(getModel().getSourceConnections()); - } - - public List getFilteredModelTargetConnections() { - return getFilteredConnections(getModel().getTargetConnections()); - } - - /** - * See if any connections are filtered out - * @param originalList - * @return A list of filtered connections - */ - private List getFilteredConnections(List originalList) { - IConnectionEditPartFilter[] filters = getRootEditPartFilterProvider().getEditPartFilters(IConnectionEditPartFilter.class); - if(filters != null) { - List filteredList = new ArrayList(); - - for(IDiagramModelConnection connection : originalList) { - boolean add = true; - - for(IConnectionEditPartFilter filter : filters) { - add = filter.isConnectionVisible(this, connection); - - if(!add) { // no point in trying the next filter - break; - } - } - - if(add) { - filteredList.add(connection); - } - } - - return filteredList; - } - - return originalList; - } } \ No newline at end of file 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 316aa4b47..3433570c5 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 @@ -25,8 +25,6 @@ public class ArchimateDiagramPart extends AbstractDiagramPart { public ArchimateDiagramPart() { - // Add a Nested Connection Filter - addEditPartFilter(new NestedConnectionEditPartFilter()); } @Override diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/ArchimateRelationshipEditPart.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/ArchimateRelationshipEditPart.java index aeb0ce83d..bbdc92120 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/ArchimateRelationshipEditPart.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/ArchimateRelationshipEditPart.java @@ -5,7 +5,6 @@ */ package com.archimatetool.editor.diagram.editparts; -import java.util.ArrayList; import java.util.List; import org.eclipse.draw2d.ConnectionAnchor; @@ -119,12 +118,12 @@ public void createEditPolicies() { @Override protected List getModelSourceConnections() { - return getFilteredModelSourceConnections(); + return getModel().getSourceConnections(); } @Override protected List getModelTargetConnections() { - return getFilteredModelTargetConnections(); + return getModel().getTargetConnections(); } public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection) { @@ -149,60 +148,4 @@ public ConnectionAnchor getTargetConnectionAnchor(Request request) { return new LineConnectionAnchor(getFigure()); } - - // =================================== Filtering ==================================================== - - public List getFilteredModelSourceConnections() { - return getFilteredConnections(getModel().getSourceConnections()); - } - - public List getFilteredModelTargetConnections() { - return getFilteredConnections(getModel().getTargetConnections()); - } - - /** - * See if any connections are filtered out - * @param originalList - * @return A list of filtered connections - */ - private List getFilteredConnections(List originalList) { - IEditPartFilterProvider filterProvider = getRootEditPartFilterProvider(); - - if(filterProvider == null) { - return originalList; - } - - IConnectionEditPartFilter[] filters = getRootEditPartFilterProvider().getEditPartFilters(IConnectionEditPartFilter.class); - if(filters != null) { - List filteredList = new ArrayList(); - - for(IDiagramModelConnection connection : originalList) { - boolean add = true; - - for(IConnectionEditPartFilter filter : filters) { - add = filter.isConnectionVisible(this, connection); - - if(!add) { // no point in trying the next filter - break; - } - } - - if(add) { - filteredList.add(connection); - } - } - - return filteredList; - } - - return originalList; - } - - protected IEditPartFilterProvider getRootEditPartFilterProvider() { - if(getRoot() != null && getRoot().getContents() instanceof IEditPartFilterProvider) { - return (IEditPartFilterProvider)getRoot().getContents(); - } - return null; - } - } diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/IConnectionEditPartFilter.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/IConnectionEditPartFilter.java deleted file mode 100644 index c6f86ebf7..000000000 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/IConnectionEditPartFilter.java +++ /dev/null @@ -1,29 +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.editparts; - -import org.eclipse.gef.EditPart; - -import com.archimatetool.model.IDiagramModelConnection; - - - - -/** - * Filter to show/hide EditPart Connections - * - * @author Phillip Beauvoir - */ -public interface IConnectionEditPartFilter extends IEditPartFilter { - - /** - * Filter connection of associated editPart - * @param editPart The Attached EditPart for the connection - * @param connection - * @return True if connection is to be visible - */ - boolean isConnectionVisible(EditPart editPart, IDiagramModelConnection connection); -} 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 deleted file mode 100644 index 247ca7435..000000000 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/NestedConnectionEditPartFilter.java +++ /dev/null @@ -1,33 +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.editparts; - -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; - - -/** - * Nested Connection Filter for EditParts - * - * @author Phillip Beauvoir - */ -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; - } -} \ 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 d9281c163..6207513fc 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,6 +15,7 @@ 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; @@ -32,32 +33,48 @@ public class ArchimateContainerLayoutPolicy extends ArchimateDiagramLayoutPolicy protected Command getAddCommand(Request generic) { Object parent = getHost().getModel(); - // Add relations/connections between parent and child if Prefs set and if parent is an Archimate object - boolean doAddNestedConnections = ConnectionPreferences.createRelationWhenMovingElement() && parent instanceof IDiagramModelArchimateObject; - ChangeBoundsRequest request = (ChangeBoundsRequest)generic; CompoundCommand command = new CompoundCommand(); - List childObjects = new ArrayList(); + // Add relations between parent and child if Prefs set and if parent is an Archimate object + boolean doAddNestedRelations = ConnectionPreferences.createRelationWhenMovingElement() && parent instanceof IDiagramModelArchimateObject; + List childObjectsForNewRelations = 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))); command.add(addCommand); // If we use nested connections, and child is an Archimate diagram object add it to the list - if(doAddNestedConnections && addCommand.child instanceof IDiagramModelArchimateObject) { - childObjects.add((IDiagramModelArchimateObject)addCommand.child); + if(doAddNestedRelations && addCommand.child instanceof IDiagramModelArchimateObject) { + childObjectsForNewRelations.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 so add the sub command - if(!childObjects.isEmpty()) { - Command cmd = new CreateNestedArchimateConnectionsWithDialogCommand((IDiagramModelArchimateObject)parent, childObjects); + // We have some child objects for new relations so add the sub commands + if(!childObjectsForNewRelations.isEmpty()) { + Command cmd = new CreateNestedArchimateConnectionsWithDialogCommand((IDiagramModelArchimateObject)parent, childObjectsForNewRelations); command.add(cmd); } + // We have some child objects for deletion connections + if(!childObjectsForDeletedConnections.isEmpty()) { + Command cmd = new DeleteNestedConnectionsCommand((IDiagramModelArchimateObject)parent, childObjectsForNewRelations); + command.add(cmd); + } + return command.unwrap(); } } 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 b2cd5037b..175327d26 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/model/DiagramModelUtils.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/model/DiagramModelUtils.java @@ -323,86 +323,6 @@ public static boolean isNestedConnectionTypeRelationship(IArchimateRelationship return false; } - /** - * @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) { - 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; - } - - IDiagramModelArchimateComponent source = (IDiagramModelArchimateComponent)connection.getSource(); - IDiagramModelArchimateComponent target = (IDiagramModelArchimateComponent)connection.getTarget(); - - // If the connection's source element contains the target - if(source instanceof IDiagramModelArchimateObject) { - IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject)source; - if(parent.getChildren().contains(target)) { - // 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 element contains the source - // TODO: Not sure if this directionality should be allowed - if(target instanceof IDiagramModelArchimateObject) { - IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject)target; - if(parent.getChildren().contains(source)) { - // And it's a relationship type we have chosen to hide - for(EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) { - if(connection.getArchimateRelationship().eClass() == eClass) { - 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 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; - } - } - } - } - - return false; - } - // ======================================================================================================== /** diff --git a/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/model/DiagramModelUtilsNestedRelationsTests.java b/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/model/DiagramModelUtilsNestedRelationsTests.java index 32f1e80fa..5b6b72528 100644 --- a/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/model/DiagramModelUtilsNestedRelationsTests.java +++ b/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/model/DiagramModelUtilsNestedRelationsTests.java @@ -5,22 +5,18 @@ */ package com.archimatetool.editor.model; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.eclipse.emf.ecore.EClass; import org.junit.Before; import org.junit.Test; -import com.archimatetool.editor.preferences.IPreferenceConstants; -import com.archimatetool.editor.preferences.Preferences; import com.archimatetool.model.FolderType; import com.archimatetool.model.IArchimateElement; import com.archimatetool.model.IArchimateFactory; import com.archimatetool.model.IArchimateModel; import com.archimatetool.model.IArchimateRelationship; import com.archimatetool.model.IDiagramModel; -import com.archimatetool.model.IDiagramModelArchimateConnection; import com.archimatetool.model.IDiagramModelArchimateObject; import com.archimatetool.model.util.ArchimateModelUtils; import com.archimatetool.testingtools.ArchimateTestModel; @@ -112,31 +108,4 @@ public void testIsNestedConnectionTypeRelationship() { } } - @Test - public void testShouldBeHiddenConnection() { - IDiagramModelArchimateConnection connection = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection(); - connection.setArchimateRelationship(relationship1); - connection.connect(dmo1, dmo2); - assertTrue(DiagramModelUtils.shouldBeHiddenConnection(connection)); - - // swap - connection.connect(dmo2, dmo1); - assertTrue(DiagramModelUtils.shouldBeHiddenConnection(connection)); - - // Set prefs to say no - Preferences.STORE.setValue(IPreferenceConstants.USE_NESTED_CONNECTIONS, false); - - connection.connect(dmo3, dmo4); - assertFalse(DiagramModelUtils.shouldBeHiddenConnection(connection)); - - // Set prefs to say yes - Preferences.STORE.setValue(IPreferenceConstants.USE_NESTED_CONNECTIONS, true); - - assertTrue(DiagramModelUtils.shouldBeHiddenConnection(connection)); - - // Another one to be sure - association - connection.setArchimateRelationship(relationship2); - connection.connect(dmo4, dmo5); - assertTrue(DiagramModelUtils.shouldBeHiddenConnection(connection)); - } } \ No newline at end of file