Selaa lähdekoodia

Share project "de.itemis.gmf.runtime.commons" into "https://svn.codespot.com/a/eclipselabs.org/yakindu"

Andreas Mülder 14 vuotta sitten
vanhempi
commit
6a88f1e7c1

+ 7 - 0
plugins/de.itemis.gmf.runtime.commons/.classpath

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 28 - 0
plugins/de.itemis.gmf.runtime.commons/.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>de.itemis.gmf.runtime.commons</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 8 - 0
plugins/de.itemis.gmf.runtime.commons/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,8 @@
+#Wed May 11 13:37:16 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

+ 12 - 0
plugins/de.itemis.gmf.runtime.commons/META-INF/MANIFEST.MF

@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Extension
+Bundle-SymbolicName: de.itemis.gmf.runtime.commons
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: itemis AG
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.eclipse.gmf.runtime.diagram.ui.properties;bundle-version="1.4.2"
+Export-Package: de.itemis.gmf.runtime.commons.editparts,
+ de.itemis.gmf.runtime.commons.editpolicies,
+ de.itemis.gmf.runtime.commons.figures,
+ de.itemis.gmf.runtime.commons.properties

+ 4 - 0
plugins/de.itemis.gmf.runtime.commons/build.properties

@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .

+ 54 - 0
plugins/de.itemis.gmf.runtime.commons/src/de/itemis/gmf/runtime/commons/commands/CompartmentRepositionEObjectCommand.java

@@ -0,0 +1,54 @@
+package de.itemis.gmf.runtime.commons.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.emf.commands.core.commands.RepositionEObjectCommand;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * @see http://wiki.eclipse.org/GMF/Recipes
+ * 
+ */
+@SuppressWarnings("rawtypes")
+public class CompartmentRepositionEObjectCommand extends
+		RepositionEObjectCommand {
+
+	EditPart childToMove = null;
+	int newIndex = 0;
+
+	public CompartmentRepositionEObjectCommand(
+			TransactionalEditingDomain editingDomain, String label,
+			EList elements, EObject element, int displacement) {
+		super(editingDomain, label, elements, element, displacement);
+	}
+
+	public CompartmentRepositionEObjectCommand(EditPart childToMove,
+			TransactionalEditingDomain editingDomain, String label,
+			EList elements, EObject element, int displacement, int newIndex) {
+		super(editingDomain, label, elements, element, displacement);
+
+		this.childToMove = childToMove;
+		this.newIndex = newIndex;
+	}
+
+	@Override
+	public CommandResult doExecuteWithResult(IProgressMonitor progressMonitor,
+			IAdaptable info) throws ExecutionException {
+		CommandResult rs = super.doExecuteWithResult(progressMonitor, info);
+
+		EditPart compartment = childToMove.getParent();
+
+		ViewUtil.repositionChildAt((View) compartment.getModel(),
+				(View) childToMove.getModel(), newIndex);
+		compartment.refresh();
+
+		return rs;
+	}
+}

+ 40 - 0
plugins/de.itemis.gmf.runtime.commons/src/de/itemis/gmf/runtime/commons/editparts/EllipseFixedSizeShapeNodeEditPart.java

@@ -0,0 +1,40 @@
+/**
+ * Copyright (c) 2011 itemis AG 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:
+ * 	itemis AG - initial API and implementation
+ * 
+ */
+package de.itemis.gmf.runtime.commons.editparts;
+
+import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+import org.eclipse.gmf.runtime.notation.View;
+
+import de.itemis.gmf.runtime.commons.figures.EllipseAnchorDefaultSizeNodeFigure;
+
+/**
+ * 
+ * @author andreas muelder (andreas.muelder@itemis.de)
+ * 
+ */
+public abstract class EllipseFixedSizeShapeNodeEditPart extends
+		FixedSizeShapeNodeEditPart {
+
+	public EllipseFixedSizeShapeNodeEditPart(View view) {
+		super(view);
+	}
+
+	@Override
+	protected NodeFigure createNodeFigure() {
+		final NodeFigure figure = new EllipseAnchorDefaultSizeNodeFigure(
+				getDefaultSize());
+		figure.setLayoutManager(getLayoutManager());
+		figure.add(getPrimaryShape());
+		return figure;
+	}
+
+}

+ 60 - 0
plugins/de.itemis.gmf.runtime.commons/src/de/itemis/gmf/runtime/commons/editparts/FixedSizeShapeNodeEditPart.java

@@ -0,0 +1,60 @@
+/**
+ * Copyright (c) 2011 itemis AG 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:
+ * 	itemis AG - initial API and implementation
+ * 
+ */
+package de.itemis.gmf.runtime.commons.editparts;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.LayoutManager;
+import org.eclipse.draw2d.StackLayout;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableEditPolicyEx;
+import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
+import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * EditPart for Shapes that should not be resized.
+ * 
+ * @author andreas muelder (andreas.muelder@itemis.de)
+ * 
+ */
+public abstract class FixedSizeShapeNodeEditPart extends ShapeNodeEditPart {
+
+	public FixedSizeShapeNodeEditPart(final View view) {
+		super(view);
+	}
+
+	public abstract Dimension getDefaultSize();
+
+	public abstract IFigure getPrimaryShape();
+
+	@Override
+	protected NodeFigure createNodeFigure() {
+		final NodeFigure figure = new DefaultSizeNodeFigure(getDefaultSize());
+		figure.setLayoutManager(getLayoutManager());
+		figure.add(getPrimaryShape());
+		return figure;
+	}
+
+	protected LayoutManager getLayoutManager() {
+		return new StackLayout();
+	}
+
+	@Override
+	protected void createDefaultEditPolicies() {
+		super.createDefaultEditPolicies();
+		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
+				new NonResizableEditPolicyEx());
+	}
+
+}

+ 111 - 0
plugins/de.itemis.gmf.runtime.commons/src/de/itemis/gmf/runtime/commons/editpolicies/CompartmentEditPolicy.java

@@ -0,0 +1,111 @@
+package de.itemis.gmf.runtime.commons.editpolicies;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.CreateRequest;
+import org.eclipse.gmf.runtime.diagram.core.commands.AddCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableEditPolicyEx;
+import org.eclipse.gmf.runtime.emf.commands.core.commands.RepositionEObjectCommand;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
+import org.eclipse.gmf.runtime.notation.View;
+
+import de.itemis.gmf.runtime.commons.commands.CompartmentRepositionEObjectCommand;
+
+/**
+ * @see http://wiki.eclipse.org/GMF/Recipes
+ * 
+ */
+public class CompartmentEditPolicy extends
+		org.eclipse.gef.editpolicies.FlowLayoutEditPolicy {
+
+	private EStructuralFeature feature = null;
+
+	@Override
+	protected Command createAddCommand(EditPart child, EditPart after) {
+		int index = getHost().getChildren().indexOf(after);
+		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
+				.getEditingDomain();
+		AddCommand command = new AddCommand(editingDomain, new EObjectAdapter(
+				(View) getHost().getModel()), new EObjectAdapter(
+				(View) child.getModel()), index);
+		return new ICommandProxy(command);
+	}
+
+	@Override
+	protected EditPolicy createChildEditPolicy(EditPart child) {
+		ResizableEditPolicyEx policy = new ResizableEditPolicyEx();
+		policy.setResizeDirections(0);
+		return policy;
+	}
+
+	@Override
+	@SuppressWarnings("rawtypes")
+	protected Command createMoveChildCommand(EditPart child, EditPart after) {
+
+		int newIndex;
+		int displacement;
+
+		int childIndex = getHost().getChildren().indexOf(child);
+		int afterIndex = getHost().getChildren().indexOf(after);
+
+		if (afterIndex == -1) {
+			newIndex = getHost().getChildren().size() - 1;
+			displacement = newIndex - childIndex;
+		} else {
+			newIndex = afterIndex;
+			displacement = afterIndex - childIndex;
+			if (childIndex <= afterIndex) {
+				newIndex--;
+				displacement--;
+			}
+		}
+
+		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
+				.getEditingDomain();
+
+		RepositionEObjectCommand command = new CompartmentRepositionEObjectCommand(
+				child, editingDomain, "", (EList) ((View) child.getParent()
+						.getModel()).getElement().eGet(feature),
+				((View) child.getModel()).getElement(), displacement, newIndex);
+
+		eraseLayoutTargetFeedback(null);
+
+		return new ICommandProxy(command);
+	}
+
+	@Override
+	protected Command getCreateCommand(CreateRequest request) {
+		return null;
+	}
+
+	@Override
+	protected Command getDeleteDependantCommand(Request request) {
+		return null;
+	}
+
+	@Override
+	protected Command getOrphanChildrenCommand(Request request) {
+		return null;
+	}
+
+	/**
+	 * @param feature
+	 *            has to be an EList
+	 */
+	public CompartmentEditPolicy(EStructuralFeature feature) {
+		super();
+		this.feature = feature;
+	}
+
+	@Override
+	protected boolean isHorizontal() {
+		return true;
+	}
+}

+ 39 - 0
plugins/de.itemis.gmf.runtime.commons/src/de/itemis/gmf/runtime/commons/editpolicies/OneWayConnectionHandlesEditPolicy.java

@@ -0,0 +1,39 @@
+/**
+ * Copyright (c) 2011 itemis AG 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:
+ * 	itemis AG - initial API and implementation
+ * 
+ */
+package de.itemis.gmf.runtime.commons.editpolicies;
+
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ConnectionHandleEditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.handles.ConnectionHandle.HandleDirection;
+
+/**
+ * Shows the connection handles only for one direction
+ * 
+ * @author andreas muelder (andreas.muelder@itemis.de)
+ * 
+ */
+public class OneWayConnectionHandlesEditPolicy extends
+		ConnectionHandleEditPolicy {
+
+	private final HandleDirection direction;
+
+	public OneWayConnectionHandlesEditPolicy(HandleDirection direction) {
+		this.direction = direction;
+	}
+
+	@Override
+	protected String buildTooltip(HandleDirection direction) {
+		if (direction == this.direction) {
+			return super.buildTooltip(direction);
+		}
+		return null;
+	}
+}

+ 44 - 0
plugins/de.itemis.gmf.runtime.commons/src/de/itemis/gmf/runtime/commons/figures/EllipseAnchorDefaultSizeNodeFigure.java

@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2011 itemis AG 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:
+ * 	itemis AG - initial API and implementation
+ * 
+ */
+package de.itemis.gmf.runtime.commons.figures;
+
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.draw2d.EllipseAnchor;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
+
+/**
+ * 
+ * {@link DefaultSizeNodeFigure} with fixed anchors on the ellipse child
+ * 
+ * @author andreas muelder (andreas.muelder@itemis.de)
+ * 
+ */
+public class EllipseAnchorDefaultSizeNodeFigure extends DefaultSizeNodeFigure {
+
+	public EllipseAnchorDefaultSizeNodeFigure(Dimension defSize) {
+		super(defSize);
+	}
+
+	@Override
+	protected ConnectionAnchor createAnchor(PrecisionPoint p) {
+		return createDefaultAnchor();
+	}
+
+	@Override
+	protected ConnectionAnchor createDefaultAnchor() {
+		return new EllipseAnchor((IFigure) getChildren().get(0));
+	}
+
+}

+ 37 - 0
plugins/de.itemis.gmf.runtime.commons/src/de/itemis/gmf/runtime/commons/figures/FixedConnectionAnchor.java

@@ -0,0 +1,37 @@
+package de.itemis.gmf.runtime.commons.figures;
+
+import org.eclipse.draw2d.AbstractConnectionAnchor;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.Rectangle;
+
+public class FixedConnectionAnchor extends AbstractConnectionAnchor {
+
+	private final double xOffset;
+	private final double yOffset;
+
+	public FixedConnectionAnchor(IFigure owner, PrecisionPoint offset) {
+		this(owner, offset.preciseX(), offset.preciseY());
+	}
+
+	public FixedConnectionAnchor(IFigure owner, double xOffset, double yOffset) {
+		super(owner);
+		this.xOffset = xOffset;
+		this.yOffset = yOffset;
+	}
+
+	@Override
+	public Point getLocation(Point point) {
+		return getLocation();
+	}
+
+	public Point getLocation() {
+		Rectangle r = getOwner().getBounds();
+		Point p = new PrecisionPoint(r.x + r.width * xOffset, r.y + r.height
+				* yOffset);
+		getOwner().translateToAbsolute(p);
+		return p;
+	}
+
+}

+ 124 - 0
plugins/de.itemis.gmf.runtime.commons/src/de/itemis/gmf/runtime/commons/properties/SemanticPropertySection.java

@@ -0,0 +1,124 @@
+/**
+ * Copyright (c) 2011 itemis AG 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:
+ * 	itemis AG - initial API and implementation
+ * 
+ */
+package de.itemis.gmf.runtime.commons.properties;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.provider.IItemPropertySource;
+import org.eclipse.emf.edit.ui.provider.PropertySource;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.properties.sections.AdvancedPropertySection;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.IPropertySourceProvider;
+
+/**
+ * Copied from GMF Tooling generated code. Property Section, that uses
+ * {@link IItemPropertySource} generated by EMF (edit plugin) to display
+ * semantic model information in the property section.
+ * 
+ * @author andreas muelder (andreas.muelder@itemis.de)
+ * 
+ */
+public class SemanticPropertySection extends AdvancedPropertySection implements
+		IPropertySourceProvider {
+
+	@Override
+	public IPropertySource getPropertySource(final Object object) {
+		if (object instanceof IPropertySource) {
+			return (IPropertySource) object;
+		}
+		final AdapterFactory af = getAdapterFactory(object);
+		if (af != null) {
+			final IItemPropertySource ips = (IItemPropertySource) af.adapt(
+					object, IItemPropertySource.class);
+			if (ips != null) {
+				return new PropertySource(object, ips);
+			}
+		}
+		if (object instanceof IAdaptable) {
+			return (IPropertySource) ((IAdaptable) object)
+					.getAdapter(IPropertySource.class);
+		}
+		return null;
+	}
+
+	@Override
+	protected IPropertySourceProvider getPropertySourceProvider() {
+		return this;
+	}
+
+	/**
+	 * Modify/unwrap selection.
+	 */
+	protected Object transformSelection(final Object selected) {
+
+		if (selected instanceof EditPart) {
+			final Object model = ((EditPart) selected).getModel();
+			return model instanceof View ? ((View) model).getElement() : null;
+		}
+		if (selected instanceof View) {
+			return ((View) selected).getElement();
+		}
+		if (selected instanceof IAdaptable) {
+			final View view = (View) ((IAdaptable) selected)
+					.getAdapter(View.class);
+			if (view != null) {
+				return view.getElement();
+			}
+		}
+		return selected;
+	}
+
+	@SuppressWarnings({ "rawtypes", "unchecked" })
+	@Override
+	public void setInput(final IWorkbenchPart part, final ISelection selection) {
+		if (selection.isEmpty()
+				|| false == selection instanceof StructuredSelection) {
+			super.setInput(part, selection);
+			return;
+		}
+		final StructuredSelection structuredSelection = ((StructuredSelection) selection);
+		final ArrayList transformedSelection = new ArrayList(
+				structuredSelection.size());
+		for (final Iterator it = structuredSelection.iterator(); it.hasNext();) {
+			final Object r = transformSelection(it.next());
+			if (r != null) {
+				transformedSelection.add(r);
+			}
+		}
+		super.setInput(part, new StructuredSelection(transformedSelection));
+	}
+
+	protected AdapterFactory getAdapterFactory(final Object object) {
+		if (getEditingDomain() instanceof AdapterFactoryEditingDomain) {
+			return ((AdapterFactoryEditingDomain) getEditingDomain())
+					.getAdapterFactory();
+		}
+		final TransactionalEditingDomain editingDomain = TransactionUtil
+				.getEditingDomain(object);
+		if (editingDomain != null) {
+			return ((AdapterFactoryEditingDomain) editingDomain)
+					.getAdapterFactory();
+		}
+		return null;
+	}
+}