Просмотр исходного кода

Added unloading strategy for shared editing domain editors

Andreas Mülder 13 лет назад
Родитель
Сommit
c01ef41d89

+ 8 - 2
de.itemis.gmf.utils/plugins/de.itemis.gmf.runtime.commons/src/de/itemis/gmf/runtime/commons/decorators/BaseDecorator.java

@@ -25,6 +25,8 @@ import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget;
  */
 public abstract class BaseDecorator extends AbstractDecorator {
 
+	private IGraphicalEditPart gep;
+
 	private EObject semanticElement;
 
 	public BaseDecorator(IDecoratorTarget decoratorTarget) {
@@ -41,12 +43,13 @@ public abstract class BaseDecorator extends AbstractDecorator {
 			refresh();
 		}
 	};
-	private IGraphicalEditPart gep;
 
 	public void activate() {
-
 		DiagramEventBroker.getInstance(gep.getEditingDomain())
 				.addNotificationListener(semanticElement, notificationListener);
+		DiagramEventBroker.getInstance(gep.getEditingDomain())
+				.addNotificationListener(gep.getNotationView(),
+						notificationListener);
 	}
 
 	public void deactivate() {
@@ -58,6 +61,9 @@ public abstract class BaseDecorator extends AbstractDecorator {
 		DiagramEventBroker.getInstance(gep.getEditingDomain())
 				.removeNotificationListener(semanticElement,
 						notificationListener);
+		DiagramEventBroker.getInstance(gep.getEditingDomain())
+				.removeNotificationListener(gep.getNotationView(),
+						notificationListener);
 	}
 
 }

+ 30 - 33
de.itemis.gmf.utils/plugins/de.itemis.gmf.runtime.commons/src/de/itemis/gmf/runtime/commons/decorators/InteractiveDecorator.java

@@ -13,34 +13,41 @@ import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget.Di
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.GC;
 import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Display;
 
 /**
  * 
  * @author terfloth - Initial contribution
  * 
- * TODO: extract margin property
- *
+ *         TODO: extract margin property
+ * 
  */
 public abstract class InteractiveDecorator extends BaseDecorator {
 
-	
 	protected MouseListener decorationMouseListener;
 
+	protected abstract IFigure getToolTipFigure(EObject element);
+
+	protected abstract Image getDecorationImage(EObject element);
+
+	protected abstract boolean shouldDecorate(EObject element);
+
 	public InteractiveDecorator(IDecoratorTarget decoratorTarget) {
 		super(decoratorTarget);
-		
+
 		decorationMouseListener = new MouseListener() {
 			public void mousePressed(MouseEvent me) {
-				InteractiveDecorator.this.mousePressed(getDecoration(), getSemanticElement());
+				InteractiveDecorator.this.mousePressed(getDecoration(),
+						getSemanticElement());
 			}
 
 			public void mouseReleased(MouseEvent me) {
-				InteractiveDecorator.this.mouseReleased(getDecoration(), getSemanticElement());
+				InteractiveDecorator.this.mouseReleased(getDecoration(),
+						getSemanticElement());
 			}
 
 			public void mouseDoubleClicked(MouseEvent me) {
-				InteractiveDecorator.this.mouseDoubleClicked(getDecoration(), getSemanticElement());
+				InteractiveDecorator.this.mouseDoubleClicked(getDecoration(),
+						getSemanticElement());
 			}
 		};
 	}
@@ -66,21 +73,16 @@ public abstract class InteractiveDecorator extends BaseDecorator {
 		return decoration;
 	}
 
-	
 	public EObject getSemanticElement() {
-		return (EObject) getDecoratorTarget()
-				.getAdapter(EObject.class);
+		return (EObject) getDecoratorTarget().getAdapter(EObject.class);
 	}
 
-	
-	
 	protected void disposeDecoration() {
-		if (getDecoration() != null) getDecoration().removeMouseListener(decorationMouseListener);
+		if (getDecoration() != null)
+			getDecoration().removeMouseListener(decorationMouseListener);
 		removeDecoration();
 	}
 
-	
-	
 	/**
 	 * TODO: move to UtilityClass
 	 * 
@@ -103,42 +105,37 @@ public abstract class InteractiveDecorator extends BaseDecorator {
 		return scaled;
 	}
 
-	protected void renderToolTip(final Decoration decoration, final EObject semanticElement) {
+	protected void renderToolTip(final Decoration decoration,
+			final EObject semanticElement) {
 		decoration.addMouseMotionListener(new MouseMotionListener() {
 			public void mouseDragged(MouseEvent me) {
 			}
-	
+
 			public void mouseEntered(MouseEvent me) {
 				IFigure toolTip = getToolTipFigure(semanticElement);
-				if (toolTip != null) decoration.setToolTip(toolTip);
-	
+				if (toolTip != null)
+					decoration.setToolTip(toolTip);
+
 			}
-	
+
 			public void mouseExited(MouseEvent me) {
 			}
-	
+
 			public void mouseHover(MouseEvent me) {
 			}
-	
+
 			public void mouseMoved(MouseEvent me) {
 			}
 		});
 	}
 
-	protected abstract IFigure getToolTipFigure(EObject element);
-
-	protected abstract Image getDecorationImage(EObject element);
-
-	protected abstract boolean shouldDecorate(EObject element);
-
 	protected void mousePressed(Decoration decoration, EObject element) {
 	}
-	
+
 	protected void mouseReleased(Decoration decoration, EObject element) {
 	}
-	
+
 	protected void mouseDoubleClicked(Decoration decoration, EObject element) {
 	}
-	
-	
+
 }

+ 74 - 0
de.itemis.gmf.utils/plugins/de.itemis.gmf.runtime.commons/src/de/itemis/gmf/runtime/commons/editparts/ControlEditPart.java

@@ -0,0 +1,74 @@
+/**
+ * Copyright (c) 2013 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package de.itemis.gmf.runtime.commons.editparts;
+
+import org.eclipse.draw2d.Figure;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public abstract class ControlEditPart extends ShapeEditPart {
+
+	private ControlWrapper wrapper;
+
+	public abstract Control createControl(Composite parent);
+
+	public ControlEditPart(View view) {
+		super(view);
+	}
+
+	@Override
+	protected IFigure getLayer(Object layer) {
+		return super.getLayer(layer);
+	}
+
+	@Override
+	protected IFigure createFigure() {
+		Composite composite = (Composite) getViewer().getControl();
+		wrapper = new ControlWrapper(createControl(composite));
+		return wrapper;
+	}
+
+	public class ControlWrapper extends Figure {
+
+		private Control control;
+
+		public ControlWrapper(Control control) {
+			this.control = control;
+		}
+
+		public Dimension getPreferredSize(int wHint, int hHint) {
+			Point p = control.computeSize(wHint, hHint);
+			return new Dimension(p.x, p.y);
+		}
+
+		@Override
+		public void setBounds(Rectangle rect) {
+			super.setBounds(rect);
+			rect = rect.getCopy();
+			translateToAbsolute(rect);
+			control.setBounds(rect.x, rect.y, rect.width, rect.height);
+			System.out.println("Set Bounds " + rect);
+			super.setBounds(rect);
+		}
+	}
+
+}