Browse Source

Refactoring to solve performance problems (YAKHMI-427, YAKHMI-428).

markus.muehlbrandt@itemis.de 13 years ago
parent
commit
311afe86f2

+ 18 - 1
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editor/StatechartDiagramEditor.java

@@ -18,6 +18,8 @@ import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.draw2d.ConnectionLayer;
 import org.eclipse.draw2d.ViewportAwareConnectionLayerClippingStrategy;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.transaction.ResourceSetChangeEvent;
 import org.eclipse.emf.transaction.ResourceSetListener;
 import org.eclipse.emf.transaction.ResourceSetListenerImpl;
@@ -26,6 +28,7 @@ import org.eclipse.gef.RootEditPart;
 import org.eclipse.gef.editparts.LayerManager;
 import org.eclipse.gmf.runtime.common.ui.services.marker.MarkerNavigationService;
 import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorSite;
@@ -53,9 +56,23 @@ public class StatechartDiagramEditor extends BreadcrumbDiagramEditor implements
 	private ResourceSetListener validationListener = new ResourceSetListenerImpl() {
 		@Override
 		public void resourceSetChanged(ResourceSetChangeEvent event) {
-			validate();
+			if (!isGraphModelAffected(event)) {
+				validate();
+			}
 		}
 	};
+	
+	private boolean isGraphModelAffected(ResourceSetChangeEvent event){
+		for (Notification notification:event.getNotifications()) {
+			if (notification.getNotifier() instanceof EObject) {
+				EObject eObject = (EObject) notification.getNotifier();
+				if (NotationPackage.eINSTANCE == eObject.eClass().getEPackage()) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
 
 	public StatechartDiagramEditor() {
 		super(true);

+ 95 - 14
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/StateEditPart.java

@@ -24,10 +24,13 @@ import org.eclipse.emf.ecore.EStructuralFeature;
 import org.eclipse.gef.EditPart;
 import org.eclipse.gef.EditPolicy;
 import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.Handle;
 import org.eclipse.gef.Request;
 import org.eclipse.gef.commands.Command;
 import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gef.handles.AbstractHandle;
 import org.eclipse.gef.requests.GroupRequest;
+import org.eclipse.gef.tools.ResizeTracker;
 import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
 import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
@@ -36,6 +39,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableEditPolicyEx;
 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableEditPolicyEx;
 import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
 import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
+import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
 import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
 import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
 import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
@@ -43,6 +47,7 @@ import org.eclipse.gmf.runtime.notation.Compartment;
 import org.eclipse.gmf.runtime.notation.Node;
 import org.eclipse.gmf.runtime.notation.NotationPackage;
 import org.eclipse.gmf.runtime.notation.View;
+import org.yakindu.sct.model.sgraph.SGraphPackage;
 import org.yakindu.sct.model.sgraph.State;
 import org.yakindu.sct.ui.editor.editor.figures.StateFigure;
 import org.yakindu.sct.ui.editor.editor.figures.utils.GridDataFactory;
@@ -127,6 +132,14 @@ public class StateEditPart extends ShapeNodeEditPart implements
 						return UnexecutableCommand.INSTANCE;
 					}
 				});
+
+		if (isCollapsed()) {
+			installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
+					getNonResizableEditPolicyEx());
+		} else {
+			installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
+					getResizableEditPolicyEx());
+		}
 	}
 
 	@Override
@@ -172,7 +185,7 @@ public class StateEditPart extends ShapeNodeEditPart implements
 		// mark all figures covered by the blur shadow extended bounds as dirty
 		// (an update is enforced at the end of this method to ensure the area
 		// gets repainted)
-		NodeFigure nodeFigure = getNodeFigure();
+		final NodeFigure nodeFigure = getNodeFigure();
 		Rectangle extendedBlurShadowBounds = nodeFigure.getBounds()
 				.getExpanded(new Insets(StateFigure.BLUR_SHADOW_WIDTH));
 		nodeFigure.translateToAbsolute(extendedBlurShadowBounds);
@@ -180,6 +193,7 @@ public class StateEditPart extends ShapeNodeEditPart implements
 				org.eclipse.draw2d.FigureUtilities.getRoot(nodeFigure),
 				extendedBlurShadowBounds);
 
+		// TODO: Calculate the 'default' size
 		int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
 				.getSize_Width())).intValue();
 		int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
@@ -193,26 +207,13 @@ public class StateEditPart extends ShapeNodeEditPart implements
 		Point loc = new Point(x, y);
 
 		if (isCollapsed()) {
-			// TODO: Calculate the 'default' size
 			((GraphicalEditPart) getParent()).setLayoutConstraint(this,
 					getFigure(), new Rectangle(loc, new Dimension(58, 66)));
-			installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
-					new NonResizableEditPolicyEx());
 		} else {
 			((GraphicalEditPart) getParent()).setLayoutConstraint(this,
 					getFigure(), new Rectangle(loc, size));
-			installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
-					new ResizableEditPolicyEx());
 		}
 
-		// ensure repaint is performed (so blur shadow covered area is
-		// repainted)
-		// If a redraw is done in this method the state is drawn on creation
-		// process at position 0,0 and then "jumps" to the correct position (See
-		// YAKHMI-62).
-		if (isActive()) {
-			nodeFigure.getUpdateManager().performUpdate();
-		}
 	}
 
 	/**
@@ -323,11 +324,91 @@ public class StateEditPart extends ShapeNodeEditPart implements
 		return (State) super.resolveSemanticElement();
 	}
 
+	private NonResizableEditPolicyEx getNonResizableEditPolicyEx() {
+		return new NonResizableEditPolicyEx() {
+
+			protected void replaceHandleDragEditPartsTracker(Handle handle) {
+				if (handle instanceof AbstractHandle) {
+					AbstractHandle h = (AbstractHandle) handle;
+					h.setDragTracker(new DragEditPartsTrackerEx(getHost()) {
+						protected void executeCurrentCommand() {
+							super.executeCurrentCommand();
+							// ensure repaint is performed (so blur shadow
+							// covered area is repainted)
+							if (isActive()) {
+								getNodeFigure().getUpdateManager()
+										.performUpdate();
+							}
+						};
+					});
+				}
+			}
+		};
+	}
+
+	private ResizableEditPolicyEx getResizableEditPolicyEx() {
+		return new ResizableEditPolicyEx() {
+			/**
+			 * Replaces the handle's default DragEditPartsTracker with the
+			 * extended DragEditPartsTrackerEx
+			 * 
+			 * @param handle
+			 */
+			protected void replaceHandleDragEditPartsTracker(Handle handle) {
+				if (handle instanceof AbstractHandle) {
+					AbstractHandle h = (AbstractHandle) handle;
+					h.setDragTracker(new DragEditPartsTrackerEx(getHost()) {
+						protected void executeCurrentCommand() {
+							super.executeCurrentCommand();
+							// ensure repaint is performed (so blur shadow
+							// covered area is repainted)
+							if (isActive()) {
+								getNodeFigure().getUpdateManager()
+										.performUpdate();
+							}
+						};
+					});
+				}
+			}
+
+			protected ResizeTracker getResizeTracker(int direction) {
+				return new ResizeTracker((GraphicalEditPart) getHost(),
+						direction) {
+					@Override
+					protected void executeCurrentCommand() {
+						super.executeCurrentCommand();
+						// ensure repaint is performed (so blur shadow covered
+						// area is repainted)
+						if (isActive()) {
+							getNodeFigure().getUpdateManager().performUpdate();
+						}
+					}
+				};
+			}
+		};
+	}
+
 	@Override
 	protected void handleNotificationEvent(Notification notification) {
+
 		if (notification.getFeature() == NotationPackage.Literals.DRAWER_STYLE__COLLAPSED) {
+
+			if (isCollapsed()) {
+				installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
+						getNonResizableEditPolicyEx());
+
+			} else {
+
+				installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
+						getResizableEditPolicyEx());
+			}
 			refreshVisuals();
+		} else if (notification.getFeature() == SGraphPackage.Literals.NAMED_ELEMENT__NAME) {
+			// ensure repaint is performed (so blur shadow covered area is
+			// repainted) if LabelText changes state bounds
+			getNodeFigure().getUpdateManager().performUpdate();
 		}
+
 		super.handleNotificationEvent(notification);
 	}
 }

+ 16 - 2
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/extensions/ExpressionLanguageProviderExtensions.java

@@ -10,6 +10,9 @@
  */
 package org.yakindu.sct.ui.editor.extensions;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.Platform;
@@ -28,6 +31,8 @@ public class ExpressionLanguageProviderExtensions {
 	private static final String ATTR_RESOURCE_EXTENSION = "resourceExtension";
 
 	private static final String ATTR_SEMANTIC_TARGET = "semanticTarget";
+	
+	private static final Map<String, IExpressionLanguageProvider> providerMap = new HashMap<String, IExpressionLanguageProvider>();
 
 	public enum SemanticTarget {
 		StatechartSpecification, StateSpecification, TransitionSpecification
@@ -54,8 +59,17 @@ public class ExpressionLanguageProviderExtensions {
 						.getAttribute(ATTR_RESOURCE_EXTENSION);
 				if (SemanticTarget.valueOf(semanticTarget) == target
 						&& resourceExtension.endsWith(registeredExtension)) {
-					return (IExpressionLanguageProvider) configurationElement
-							.createExecutableExtension(ATTR_CLASS);
+					
+					String key = target.name()+configurationElement.getNamespaceIdentifier();
+					if (providerMap.get(key)!=null) {
+						return providerMap.get(key);
+					}
+					else {
+						IExpressionLanguageProvider provider = (IExpressionLanguageProvider) configurationElement
+								.createExecutableExtension(ATTR_CLASS);
+						providerMap.put(key, provider);
+						return provider;
+					}
 				}
 			} catch (CoreException e) {
 				e.printStackTrace();