Skip to content

Commit

Permalink
Improve nested connections and hide normal nested connections
Browse files Browse the repository at this point in the history
- Don't delete nested connection to connections, instead hide them
- This also fixes some cases where there were dangling connection to connections when nested
- Normal connections are now hidden when nested

- DiagramModelUtils#shouldBeHiddenConnection is now recursive and applies to any type of connection
- Update all connected objects in the chain when nesting
- Always refresh source and target connections when adding/removing an object
- All diagram parts have a NestedConnectionEditPartFilter
- Delete ArchimateContainerEditPolicy and DeleteNestedConnectionsCommand because they're not used
  • Loading branch information
Phillipus committed Dec 14, 2024
1 parent e73bc4f commit ba07da5
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 311 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -116,8 +123,11 @@ protected void eCoreChanged(Notification msg) {
case Notification.REMOVE:
case Notification.REMOVE_MANY:
case Notification.MOVE:
// This object's connections have to refreshed now in case we delete this
refreshSourceConnections();
refreshTargetConnections();
// Update any related connecions as well
refreshRelatedConnections();
refreshChildren();
break;

Expand All @@ -126,6 +136,48 @@ 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 to be refreshed when nesting when there are connection to connections.
* However, this gets objects that don't need updating when there are no connection to connections so could do with some more work.
*/
protected Set<IDiagramModelObject> getObjectsToUpdateConnections(IConnectable connectable) {
Set<IDiagramModelObject> set = new HashSet<>();

// All source and target connections of the connectable
Set<IDiagramModelConnection> connections = new HashSet<>(connectable.getSourceConnections());
connections.addAll(connectable.getTargetConnections());

// Add source and target objects if not this object
for(IDiagramModelConnection connection : connections) {
if(connection.getSource() instanceof IDiagramModelObject dmo && dmo != getModel()) {
set.add(dmo);
}
if(connection.getTarget() instanceof IDiagramModelObject dmo && dmo != getModel()) {
set.add(dmo);
}
set.addAll(getObjectsToUpdateConnections(connection));
}

return set;
}

@Override
protected void refreshFigure() {
// Set Enabled according to current Viewpoint
Expand All @@ -141,13 +193,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 {
Expand All @@ -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();
}

Expand All @@ -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<IDiagramModelConnection> getModelSourceConnections() {
return getFilteredModelSourceConnections();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand All @@ -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);
}
}
Loading

0 comments on commit ba07da5

Please sign in to comment.