Skip to content

Commit

Permalink
TypeEditor put an EContentAdapter on the whole type
Browse files Browse the repository at this point in the history
In several places the interface editor used an EContentAdapter either on
the whole type or at least on the InterfaceList. This was partly not
needed or costed a lot of performance. This fix reduces the number of
adapters and uses less heavy adapters where possible.
  • Loading branch information
azoitl authored and oberlehner committed May 8, 2024
1 parent a279997 commit b296c85
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2023 Profactor GmbH, TU Wien ACIN, fortiss GmbH
* Copyright (c) 2011, 2024 Profactor GmbH, TU Wien ACIN, fortiss GmbH
* Johannes Kepler University,
* Primetals Technologies Austria GmbH
*
Expand All @@ -26,50 +26,52 @@
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.Notifier;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.fordiac.ide.fbtypeeditor.figures.FBTypeFigure;
import org.eclipse.fordiac.ide.gef.editparts.AbstractConnectableEditPart;
import org.eclipse.fordiac.ide.gef.listeners.DiagramFontChangeListener;
import org.eclipse.fordiac.ide.model.libraryElement.AdapterType;
import org.eclipse.fordiac.ide.model.libraryElement.FBType;
import org.eclipse.fordiac.ide.model.libraryElement.LibraryElementPackage;
import org.eclipse.fordiac.ide.model.libraryElement.VersionInfo;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.widgets.Display;

public class FBTypeEditPart extends AbstractConnectableEditPart {

private ControlListener controlListener;
final List<AbstractContainerElement> containerChildren = new ArrayList<>(6);
private DiagramFontChangeListener fontChangeListener;

private final Adapter adapter = new EContentAdapter() {
private final Adapter versionInfoAdapter = new EContentAdapter() {
@Override
public void notifyChanged(final Notification notification) {
super.notifyChanged(notification);
if (Notification.REMOVING_ADAPTER != notification.getEventType()) {
final Object feature = notification.getFeature();
if ((LibraryElementPackage.eINSTANCE.getVersionInfo().equals(feature))
|| (LibraryElementPackage.eINSTANCE.getVersionInfo_Version().equals(feature))) {
getFigure().updateVersionInfoLabel();
}

Display.getDefault().syncExec(() -> {
if ((null != getParent()) && (null != getFigure()) && (getFigure().isShowing())) {
refresh();
}
});
final Object feature = notification.getFeature();
if (!notification.isTouch() && (LibraryElementPackage.eINSTANCE.getVersionInfo_Version().equals(feature)
|| LibraryElementPackage.eINSTANCE.getLibraryElement_VersionInfo().equals(feature))) {
getFigure().updateVersionInfoLabel();
}
}

@Override
protected void addAdapter(final Notifier notifier) {
// in addition to the root FBType we only want to get VersionInfo updates,
// therefore we limit the addAdapter to VersionInfos
if (notifier instanceof VersionInfo) {
super.addAdapter(notifier);
}
}
};

@Override
public void activate() {
super.activate();
getModel().eAdapters().add(adapter);
getModel().eAdapters().add(versionInfoAdapter);
JFaceResources.getFontRegistry().addListener(getFontChangeListener());
// position the FB at 0,0
((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), new Rectangle(0, 0, -1, -1));
Expand All @@ -81,9 +83,8 @@ public void deactivate() {
if (controlListener != null) {
getParent().getViewer().getControl().removeControlListener(controlListener);
}
getModel().eAdapters().remove(adapter);
getModel().eAdapters().remove(versionInfoAdapter);
JFaceResources.getFontRegistry().removeListener(getFontChangeListener());

}

private IPropertyChangeListener getFontChangeListener() {
Expand Down
@@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2011 - 2017 Profactor GmbH, fortiss GmbH
* 2019 Johannes Kepler University Linz
* Copyright (c) 2011, 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 @@ -25,9 +25,9 @@
import org.eclipse.draw2d.ShortestPathConnectionRouter;
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.gef.editparts.AbstractDiagramEditPart;
import org.eclipse.fordiac.ide.gef.policies.EmptyXYLayoutEditPolicy;
import org.eclipse.fordiac.ide.model.emf.SingleRecursiveContentAdapter;
import org.eclipse.fordiac.ide.model.libraryElement.FBType;
import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement;
import org.eclipse.gef.EditPolicy;
Expand All @@ -36,7 +36,7 @@

public class FBTypeRootEditPart extends AbstractDiagramEditPart {

private Adapter adapter;
private Adapter interfaceAdapter;
private final Map<IInterfaceElement, CommentTypeField> commentTypeFieldCache = new HashMap<>();

@Override
Expand All @@ -48,21 +48,21 @@ protected ConnectionRouter createConnectionRouter(final IFigure figure) {
public void activate() {
if (!isActive()) {
super.activate();
getModel().eAdapters().add(getContentAdapter());
getModel().getInterfaceList().eAdapters().add(getInterfaceAdapter());
}
}

@Override
public void deactivate() {
if (isActive()) {
super.deactivate();
getModel().eAdapters().remove(getContentAdapter());
getModel().getInterfaceList().eAdapters().remove(getInterfaceAdapter());
}
}

public Adapter getContentAdapter() {
if (null == adapter) {
adapter = new EContentAdapter() {
public Adapter getInterfaceAdapter() {
if (null == interfaceAdapter) {
interfaceAdapter = new SingleRecursiveContentAdapter() {
@Override
public void notifyChanged(final Notification notification) {
super.notifyChanged(notification);
Expand All @@ -79,7 +79,7 @@ public void notifyChanged(final Notification notification) {
}
};
}
return adapter;
return interfaceAdapter;
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 - 2017 Profactor GmbH, TU Wien ACIN, fortiss GmbH
* Copyright (c) 2011, 2024 Profactor GmbH, TU Wien ACIN, fortiss GmbH
*
* 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 @@ -22,7 +22,6 @@
import org.eclipse.draw2d.geometry.Dimension;
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.fbtypeeditor.policies.EventInputContainerLayoutEditPolicy;
import org.eclipse.fordiac.ide.fbtypeeditor.policies.EventOutputContainerLayoutEditPolicy;
import org.eclipse.fordiac.ide.fbtypeeditor.policies.PlugContainerLayoutEditPolicy;
Expand All @@ -31,6 +30,7 @@
import org.eclipse.fordiac.ide.fbtypeeditor.policies.VarInOutOutputContainerLayoutEditPolicy;
import org.eclipse.fordiac.ide.fbtypeeditor.policies.VariableInputContainerLayoutEditPolicy;
import org.eclipse.fordiac.ide.fbtypeeditor.policies.VariableOutputContainerLayoutEditPolicy;
import org.eclipse.fordiac.ide.model.emf.SingleRecursiveContentAdapter;
import org.eclipse.fordiac.ide.model.libraryElement.FunctionFBType;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
Expand All @@ -49,7 +49,7 @@ public InterfaceContainerFigure() {
}
}

private final Adapter econtentAdapter = new EContentAdapter() {
private final Adapter econtentAdapter = new SingleRecursiveContentAdapter() {
@Override
public void notifyChanged(final Notification notification) {
refresh();
Expand Down
@@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2011 - 2017 Profactor GmbH, TU Wien ACIN, fortiss GmbH
* 2019 Johannes Kepler University
* Copyright (c) 2011, 2024 Profactor GmbH, TU Wien ACIN, fortiss GmbH,
* Johannes Kepler University
*
* 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 @@ -23,7 +23,7 @@
import org.eclipse.draw2d.Label;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.fordiac.ide.gef.annotation.AnnotableGraphicalEditPart;
import org.eclipse.fordiac.ide.gef.annotation.FordiacAnnotationUtil;
import org.eclipse.fordiac.ide.gef.annotation.GraphicalAnnotationModelEvent;
Expand Down Expand Up @@ -82,7 +82,7 @@ public void deactivate() {

@Override
protected Adapter createAdapter() {
return new EContentAdapter() {
return new AdapterImpl() {
@Override
public void notifyChanged(final Notification notification) {
super.notifyChanged(notification);
Expand Down

0 comments on commit b296c85

Please sign in to comment.