Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillipus committed Dec 11, 2024
1 parent c2e18d9 commit 7dfa691
Showing 1 changed file with 78 additions and 9 deletions.
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,29 +123,91 @@ protected void eCoreChanged(Notification msg) {
case Notification.REMOVE:
case Notification.REMOVE_MANY:
case Notification.MOVE:
updateConnections();

refreshSourceConnections();
refreshTargetConnections();
refreshChildren();

updateConnections(getRoot().getContents());

refreshChildren();
break;

default:
super.eCoreChanged(msg);
}
}

protected void updateConnections(EditPart editPart) {
for(Object object : editPart.getChildren()) {
if(object instanceof AbstractConnectedEditPart child && child != this) {
child.refreshSourceConnections();
child.refreshTargetConnections();
updateConnections(child);
protected void updateConnections() {
// Get the EditPartRegistry
Map<?, ?> editPartRegistry = getRoot().getViewer().getEditPartRegistry();

// Get the model objects that might need updating
for(IDiagramModelObject dmo : getObjectsToUpdate()) {
// If we have the EditPart then update its connections
if(editPartRegistry.get(dmo) instanceof AbstractConnectedEditPart editPart) {
editPart.refreshSourceConnections();
editPart.refreshTargetConnections();
}
}
}

protected Set<IDiagramModelObject> getObjectsToUpdate() {
Set<IDiagramModelObject> set = new HashSet<>();

for(IDiagramModelConnection connection : getModel().getSourceConnections()) {
for(IDiagramModelConnection c : connection.getSourceConnections()) {
IConnectable source = c.getSource();
IConnectable target = c.getTarget();

if(source instanceof IDiagramModelObject dmo) {
set.add(dmo);
}
if(target instanceof IDiagramModelObject dmo) {
set.add(dmo);
}
}

for(IDiagramModelConnection c : connection.getTargetConnections()) {
IConnectable source = c.getSource();
IConnectable target = c.getTarget();

if(source instanceof IDiagramModelObject dmo) {
set.add(dmo);
}
if(target instanceof IDiagramModelObject dmo) {
set.add(dmo);
}
}
}

for(IDiagramModelConnection connection : getModel().getTargetConnections()) {
for(IDiagramModelConnection c : connection.getSourceConnections()) {
IConnectable source = c.getSource();
IConnectable target = c.getTarget();

if(source instanceof IDiagramModelObject dmo) {
set.add(dmo);
}
if(target instanceof IDiagramModelObject dmo) {
set.add(dmo);
}
}

for(IDiagramModelConnection c : connection.getTargetConnections()) {
IConnectable source = c.getSource();
IConnectable target = c.getTarget();

if(source instanceof IDiagramModelObject dmo) {
set.add(dmo);
}
if(target instanceof IDiagramModelObject dmo) {
set.add(dmo);
}
}
}

return set;
}

@Override
protected void refreshFigure() {
// Set Enabled according to current Viewpoint
Expand Down

0 comments on commit 7dfa691

Please sign in to comment.