Skip to content

Commit

Permalink
CompositeNetworkEditPart wrongly uses EContentAdapter
Browse files Browse the repository at this point in the history
The CompositeNetworkEditPart was attaching an EContentAdapter to all its
contained elements. As this class is also used for typed Subapps this
could lead to major performance issues.

With this commit the code that is used for untyped subapps is also used
for CompositeNetworkEditParts.
  • Loading branch information
azoitl authored and oberlehner committed May 7, 2024
1 parent 4a3c80d commit 50653b9
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 151 deletions.
Expand Up @@ -42,6 +42,10 @@
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.fordiac.ide.gef.draw2d.ConnectorBorder;
import org.eclipse.fordiac.ide.gef.draw2d.SingleLineBorder;
import org.eclipse.fordiac.ide.gef.editparts.AbstractFBNetworkEditPart;
Expand All @@ -54,6 +58,7 @@
import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement;
import org.eclipse.fordiac.ide.model.libraryElement.INamedElement;
import org.eclipse.fordiac.ide.model.libraryElement.InterfaceList;
import org.eclipse.fordiac.ide.model.libraryElement.LibraryElementPackage;
import org.eclipse.fordiac.ide.model.libraryElement.SubAppType;
import org.eclipse.fordiac.ide.model.libraryElement.VarDeclaration;
import org.eclipse.fordiac.ide.ui.preferences.PreferenceConstants;
Expand Down Expand Up @@ -176,6 +181,71 @@ public Dimension getPreferredSize(final int wHint, final int hHint) {
private InstanceComment instanceComment;
private Figure commentContainer;

private final Adapter contentAdapter = new AdapterImpl() {
@Override
public void notifyChanged(final Notification notification) {
super.notifyChanged(notification);
switch (notification.getEventType()) {
case Notification.ADD, Notification.ADD_MANY, Notification.MOVE, Notification.REMOVE,
Notification.REMOVE_MANY:
refreshChildren();
break;
case Notification.SET:
refreshVisuals();
break;
default:
break;
}
}
};

private final Adapter interfaceAdapter = new EContentAdapter() {
@Override
public void notifyChanged(final Notification notification) {
super.notifyChanged(notification);
switch (notification.getEventType()) {
case Notification.ADD:
if (LibraryElementPackage.eINSTANCE.getConfigurableObject_Attributes()
.equals(notification.getFeature())) {
refreshVisuals();
break;
}
//$FALL-THROUGH$
case Notification.ADD_MANY, Notification.MOVE, Notification.REMOVE, Notification.REMOVE_MANY:
refreshChildren();
break;
default:
break;
}
}
};

@Override
public void activate() {
super.activate();
if ((null != getModel()) && !getModel().eAdapters().contains(contentAdapter)) {
getModel().eAdapters().add(contentAdapter);
if ((null != getInterfaceList()) && !getInterfaceList().eAdapters().contains(interfaceAdapter)) {
getInterfaceList().eAdapters().add(interfaceAdapter);
}
}
}

@Override
public void deactivate() {
super.deactivate();
if (null != getModel()) {
getModel().eAdapters().remove(contentAdapter);
if (null != getInterfaceList()) {
getInterfaceList().eAdapters().remove(interfaceAdapter);
}
}
if ((controlListener != null) && (getParent() != null) && (getParent().getViewer() != null)
&& (getParent().getViewer().getControl() != null)) {
getParent().getViewer().getControl().removeControlListener(controlListener);
}
}

@Override
protected IFigure createFigure() {
final IFigure mainFigure = new Figure();
Expand Down Expand Up @@ -383,15 +453,6 @@ protected void addChildVisual(final EditPart childEditPart, final int index) {
}
}

@Override
public void deactivate() {
super.deactivate();
if ((controlListener != null) && (getParent() != null) && (getParent().getViewer() != null)
&& (getParent().getViewer().getControl() != null)) {
getParent().getViewer().getControl().removeControlListener(controlListener);
}
}

/**
* Removes the childEditParts figures from the correct container.
*
Expand Down
@@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2008 - 2017 Profactor GmbH, AIT, fortiss GmbH
* 2019 - 2020 Johannes Kepler University Linz
* Copyright (c) 2008, 2024 Profactor GmbH, AIT, fortiss GmbH,
* Johannes Kepler University Linz
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -17,78 +17,13 @@
*******************************************************************************/
package org.eclipse.fordiac.ide.application.editparts;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.fordiac.ide.application.policies.FBNetworkXYLayoutEditPolicy;
import org.eclipse.fordiac.ide.model.libraryElement.InterfaceList;
import org.eclipse.fordiac.ide.model.libraryElement.LibraryElementPackage;
import org.eclipse.fordiac.ide.model.libraryElement.SubApp;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.editpolicies.RootComponentEditPolicy;

public class UISubAppNetworkEditPart extends EditorWithInterfaceEditPart {
private final Adapter contentAdapter = new AdapterImpl() {
@Override
public void notifyChanged(final Notification notification) {
super.notifyChanged(notification);
switch (notification.getEventType()) {
case Notification.ADD, Notification.ADD_MANY, Notification.MOVE, Notification.REMOVE,
Notification.REMOVE_MANY:
refreshChildren();
break;
case Notification.SET:
refreshVisuals();
break;
default:
break;
}
}
};

private final Adapter subAppInterfaceAdapter = new EContentAdapter() {
@Override
public void notifyChanged(final Notification notification) {
super.notifyChanged(notification);
switch (notification.getEventType()) {
case Notification.ADD:
if (LibraryElementPackage.eINSTANCE.getConfigurableObject_Attributes()
.equals(notification.getFeature())) {
refreshVisuals();
break;
}
//$FALL-THROUGH$
case Notification.ADD_MANY, Notification.MOVE, Notification.REMOVE, Notification.REMOVE_MANY:
refreshChildren();
break;
default:
break;
}
}
};

@Override
public void activate() {
super.activate();
if ((null != getModel()) && !getModel().eAdapters().contains(contentAdapter)) {
getModel().eAdapters().add(contentAdapter);
if ((null != getSubApp()) && !getSubApp().getInterface().eAdapters().contains(subAppInterfaceAdapter)) {
getSubApp().getInterface().eAdapters().add(subAppInterfaceAdapter);
}
}
}

@Override
public void deactivate() {
super.deactivate();
if (null != getModel()) {
getModel().eAdapters().remove(contentAdapter);
if (null != getSubApp()) {
getSubApp().getInterface().eAdapters().remove(subAppInterfaceAdapter);
}
}
}

public SubApp getSubApp() {
return (SubApp) getModel().eContainer();
Expand Down
@@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2008 - 2012, 2014, 2016, 2017 Profactor GmbH, fortiss GmbH
* 2020 Johannes Kepler University Linz
* Copyright (c) 2008, 2024 Profactor GmbH, fortiss GmbH,
* Johannes Kepler University Linz
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -17,15 +17,10 @@

import java.util.List;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.fordiac.ide.application.editparts.EditorWithInterfaceEditPart;
import org.eclipse.fordiac.ide.model.libraryElement.AdapterDeclaration;
import org.eclipse.fordiac.ide.model.libraryElement.CompositeFBType;
import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement;
import org.eclipse.fordiac.ide.model.libraryElement.InterfaceList;
import org.eclipse.fordiac.ide.model.libraryElement.LibraryElementPackage;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.editpolicies.RootComponentEditPolicy;
Expand All @@ -35,74 +30,6 @@
*/
public class CompositeNetworkEditPart extends EditorWithInterfaceEditPart {

/** The adapter. */
private Adapter adapter;

/*
* (non-Javadoc)
*
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#activate()
*/
@Override
public void activate() {
if (!isActive()) {
super.activate();
getModel().eAdapters().add(getContentAdapter());
getModel().eContainer().eAdapters().add(getContentAdapter());
}
}

/*
* (non-Javadoc)
*
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#deactivate()
*/
@Override
public void deactivate() {
if (isActive()) {
super.deactivate();
getModel().eAdapters().remove(getContentAdapter());
getModel().eContainer().eAdapters().remove(getContentAdapter());
}
}

/**
* Gets the content adapter.
*
* @return the content adapter
*/
public Adapter getContentAdapter() {
if (null == adapter) {
adapter = new EContentAdapter() {
@Override
public void notifyChanged(final Notification notification) {
super.notifyChanged(notification);
// if the notification is from the out_mapped In Out vars we are in the middle
// of an in out var change, ignore it!
if (notification.getFeatureID(
InterfaceList.class) != LibraryElementPackage.INTERFACE_LIST__OUT_MAPPED_IN_OUT_VARS) {
switch (notification.getEventType()) {
case Notification.ADD, Notification.ADD_MANY:
refreshChildren();
break;
case Notification.MOVE:
if (notification.getNewValue() instanceof IInterfaceElement) {
refreshChildren();
}
break;
case Notification.REMOVE, Notification.REMOVE_MANY:
refreshChildren();
break;
default:
break;
}
}
}
};
}
return adapter;
}

@SuppressWarnings("unchecked")
@Override
protected List<?> getModelChildren() {
Expand Down

0 comments on commit 50653b9

Please sign in to comment.