Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2011-10-25 13:26:25 +0000
committercletavernie2011-10-25 13:26:25 +0000
commit42bcd0c1d277c087569ac5bfd0857930cfe23287 (patch)
treee72b4245c128c46dee6184ffab3f78460907db06 /plugins
parentc4c61404d724ba69d714ccab0c5ab797feff6b47 (diff)
downloadorg.eclipse.papyrus-42bcd0c1d277c087569ac5bfd0857930cfe23287.tar.gz
org.eclipse.papyrus-42bcd0c1d277c087569ac5bfd0857930cfe23287.tar.xz
org.eclipse.papyrus-42bcd0c1d277c087569ac5bfd0857930cfe23287.zip
359057: [Architecture - SVN - Build] The Papyrus architecture should be refactored
https://bugs.eclipse.org/bugs/show_bug.cgi?id=359057
Diffstat (limited to 'plugins')
-rw-r--r--plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/.classpath7
-rw-r--r--plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/.project28
-rw-r--r--plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/META-INF/MANIFEST.MF12
-rw-r--r--plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/about.html28
-rw-r--r--plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/build.properties7
-rw-r--r--plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/plugin.properties16
-rw-r--r--plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/plugin.xml13
-rw-r--r--plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/src/org/eclipse/papyrus/layouttool/subeditor/gmf/Activator.java67
-rw-r--r--plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/src/org/eclipse/papyrus/layouttool/subeditor/gmf/GMFLayoutAreaCreator.java203
-rw-r--r--plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/src/org/eclipse/papyrus/layouttool/subeditor/gmf/GMFSubEditor.java225
11 files changed, 613 insertions, 0 deletions
diff --git a/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/.classpath b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/.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/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/.project b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/.project
new file mode 100644
index 00000000000..bae6792645d
--- /dev/null
+++ b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.layouttool.subeditor.gmf</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>
diff --git a/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/.settings/org.eclipse.jdt.core.prefs b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..7515a5f08ad
--- /dev/null
+++ b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Tue May 12 09:36:51 CEST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/META-INF/MANIFEST.MF b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..a623e572eab
--- /dev/null
+++ b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/META-INF/MANIFEST.MF
@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-Localization: plugin
+Bundle-SymbolicName: org.eclipse.papyrus.layouttool.subeditor.gmf;singleton:=true
+Bundle-Version: 0.8.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.layouttool.subeditor.gmf.Activator
+Require-Bundle: org.eclipse.gmf.runtime.diagram.ui,
+ org.eclipse.papyrus.layouttool
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Vendor: %providerName
diff --git a/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/about.html b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/about.html
new file mode 100644
index 00000000000..35b45e096ae
--- /dev/null
+++ b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>September 30, 2009</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/build.properties b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/build.properties
new file mode 100644
index 00000000000..dfe8eecb382
--- /dev/null
+++ b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/build.properties
@@ -0,0 +1,7 @@
+#
+#Thu Sep 15 16:42:20 CEST 2011
+bin.includes=META-INF/,.,plugin.xml,build.properties,about.html,plugin.properties
+output..=bin/
+src.includes=META-INF/,.,plugin.xml,build.properties,about.html,plugin.properties
+source..=src/
+bin..=bin/
diff --git a/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/plugin.properties b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/plugin.properties
new file mode 100644
index 00000000000..ba021c921c0
--- /dev/null
+++ b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/plugin.properties
@@ -0,0 +1,16 @@
+####################################################################################
+# Copyright (c) 2008 Atos Origin.
+#
+#
+# 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:
+# Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+#
+##################################################################################
+pluginName=Papyrus Layout tools sub editor for GMF pluguin (Incubation)
+providerName=Eclipse Modeling Project
+
diff --git a/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/plugin.xml b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/plugin.xml
new file mode 100644
index 00000000000..6e6bdfe4b22
--- /dev/null
+++ b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/plugin.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.papyrus.layouttool">
+ <client
+ editor="org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor"
+ interface="org.eclipse.papyrus.layouttool.subeditor.gmf.GMFSubEditor"
+ interfaceLayoutArea="org.eclipse.papyrus.layouttool.subeditor.gmf.GMFLayoutAreaCreator">
+ </client>
+ </extension>
+
+</plugin>
diff --git a/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/src/org/eclipse/papyrus/layouttool/subeditor/gmf/Activator.java b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/src/org/eclipse/papyrus/layouttool/subeditor/gmf/Activator.java
new file mode 100644
index 00000000000..1b7cc1df323
--- /dev/null
+++ b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/src/org/eclipse/papyrus/layouttool/subeditor/gmf/Activator.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Allanic Alexia (Atos Origin) alexia.allanic@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.layouttool.subeditor.gmf;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle.
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ /** The Constant PLUGIN_ID. */
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.subeditor.gmf";
+
+ // The shared instance
+ /** The plugin. */
+ private static Activator plugin;
+
+ /**
+ * The constructor.
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance.
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/src/org/eclipse/papyrus/layouttool/subeditor/gmf/GMFLayoutAreaCreator.java b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/src/org/eclipse/papyrus/layouttool/subeditor/gmf/GMFLayoutAreaCreator.java
new file mode 100644
index 00000000000..66be4335bab
--- /dev/null
+++ b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/src/org/eclipse/papyrus/layouttool/subeditor/gmf/GMFLayoutAreaCreator.java
@@ -0,0 +1,203 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Allanic Alexia (Atos Origin) alexia.allanic@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.layouttool.subeditor.gmf;
+
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.commands.CommandStack;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
+import org.eclipse.gmf.runtime.diagram.core.internal.commands.SendToBackCommand;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
+import org.eclipse.gmf.runtime.notation.Bounds;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.layouttool.LayoutToolAreaInterface;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * The Class GMFLayoutAreaCreator.
+ */
+public class GMFLayoutAreaCreator implements LayoutToolAreaInterface {
+
+ /** The margin. */
+ private int margin = 10;
+
+ /** The my edit part node. */
+ private static EditPart myEditPartNode;
+
+ /** The node. */
+ private static Node node;
+
+ /** The edit part parent. */
+ private static EditPart editPartParent;
+
+ /** The idwp. */
+ private IDiagramWorkbenchPart idwp;
+
+ /** The ted. */
+ private static TransactionalEditingDomain ted;
+
+ /** The childs. */
+ private List<EditPart> childs;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.layouttool.LayoutToolAreaInterface#paintLayoutArea()
+ */
+ public void paintLayoutArea() {
+ idwp = (IDiagramWorkbenchPart)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .getActiveEditor();
+ editPartParent = idwp.getDiagramEditPart();
+ childs = editPartParent.getChildren();
+ if(myEditPartNode == null || !childs.contains(myEditPartNode)) {
+ createLayoutArea();
+ } else if(myEditPartNode != null && childs.contains(myEditPartNode)) {
+ deleteLayoutArea();
+ createLayoutArea();
+ }
+ }
+
+ /**
+ * Gets the area.
+ *
+ * @return the area
+ */
+ public static EditPart getArea() {
+ return myEditPartNode;
+ }
+
+ /**
+ * Delete layout area.
+ */
+ public static void deleteLayoutArea() {
+ if(myEditPartNode != null) {
+ CommandStack cs = ((GraphicalEditPart)editPartParent).getViewer().getEditDomain().getCommandStack();
+ CompositeCommand mycommand = new CompositeCommand("mcb");
+ DeleteCommand dc = new DeleteCommand(ted, (View)myEditPartNode.getModel());
+ mycommand.add(dc);
+ cs.execute(new ICommandProxy(mycommand));
+ myEditPartNode = null;
+ node = null;
+ }
+ }
+
+ /**
+ * Gets the bounds.
+ *
+ * @return the bounds
+ */
+ public static Rectangle getBounds() {
+ if(myEditPartNode != null) {
+ return ((GraphicalEditPart)myEditPartNode).getFigure().getBounds();
+ }
+ return null;
+ }
+
+ /**
+ * Gets the transactional editing domain.
+ *
+ * @return the transactional editing domain
+ */
+ private TransactionalEditingDomain getTransactionalEditingDomain() {
+ TransactionalEditingDomain ted = null;
+ IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .getActiveEditor();
+ if(activeEditor instanceof IDiagramWorkbenchPart) {
+ IDiagramWorkbenchPart workbenchPart = (IDiagramWorkbenchPart)activeEditor;
+ ted = (TransactionalEditingDomain)workbenchPart.getAdapter(EditingDomain.class);
+ if(ted == null) {
+ if(workbenchPart instanceof DiagramEditor) {
+ DiagramEditor editor = (DiagramEditor)workbenchPart;
+ ted = editor.getEditingDomain();
+ }
+ }
+ }
+ return ted;
+ }
+
+ /**
+ * Creates the layout area.
+ */
+ private void createLayoutArea() {
+ CommandStack cs = ((GraphicalEditPart)editPartParent).getViewer().getEditDomain().getCommandStack();
+ CompositeCommand command2 = new CompositeCommand("cb2");
+ CreateViewRequest.ViewDescriptor viewDescriptor = new CreateViewRequest.ViewDescriptor(null, Node.class,
+ "Note", -1, false, PreferencesHint.USE_DEFAULTS);
+ ted = getTransactionalEditingDomain();
+ CreateCommand cc = new CreateCommand(getTransactionalEditingDomain(), viewDescriptor, (View)editPartParent
+ .getModel());
+ command2.add(cc);
+ cs.execute(new ICommandProxy(command2));
+ node = (Node)((CreateViewRequest.ViewDescriptor)cc.getCommandResult().getReturnValue())
+ .getAdapter(Node.class);
+ for(EditPart n : childs) {
+ if(n.getModel().equals(node))
+ myEditPartNode = n;
+ }
+ ((GraphicalEditPart)myEditPartNode).getFigure().setBackgroundColor(null);
+ ((GraphicalEditPart)myEditPartNode).getFigure().setOpaque(false);
+ CompositeCommand command = new CompositeCommand("cb");
+ SetBoundsCommand sbc = new SetBoundsCommand(getTransactionalEditingDomain(), "changebounds",
+ new EObjectAdapter((View)myEditPartNode.getModel()), calculateBoundsLayoutArea());
+ command.add(sbc);
+
+ SendToBackCommand stbc = new SendToBackCommand(getTransactionalEditingDomain(), (View)myEditPartNode
+ .getModel());
+ command.add(stbc);
+ cs.execute(new ICommandProxy(command));
+ }
+
+ /**
+ * Calculate bounds layout area.
+ *
+ * @return the rectangle
+ */
+ private Rectangle calculateBoundsLayoutArea() {
+ int minX = ((Bounds)((Node)childs.get(0).getModel()).getLayoutConstraint()).getX();
+ int maxX = ((Bounds)((Node)childs.get(0).getModel()).getLayoutConstraint()).getX();
+ int minY = ((Bounds)((Node)childs.get(0).getModel()).getLayoutConstraint()).getY();
+ int maxY = ((Bounds)((Node)childs.get(0).getModel()).getLayoutConstraint()).getY();
+ for(EditPart e : childs) {
+ if(e != childs.get(childs.size() - 1)) {
+ minX = Math.min(minX, ((GraphicalEditPart)e).getFigure().getBounds().x - this.margin);
+ maxX = Math.max(maxX, ((GraphicalEditPart)e).getFigure().getBounds().x
+ + ((GraphicalEditPart)e).getFigure().getBounds().width + this.margin);
+ minY = Math.min(minY, ((GraphicalEditPart)e).getFigure().getBounds().y - this.margin);
+ maxY = Math.max(maxY, ((GraphicalEditPart)e).getFigure().getBounds().y
+ + ((GraphicalEditPart)e).getFigure().getBounds().height + this.margin);
+ }
+ }
+ maxX = maxX - minX;
+ maxY = maxY - minY;
+ if(minX == 0 && minY == 0 && maxX == 0 && maxY == 0) {
+ return new Rectangle(20, 20, 20, 20);
+ }
+ return new Rectangle(minX, minY, maxX, maxY);
+ }
+}
diff --git a/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/src/org/eclipse/papyrus/layouttool/subeditor/gmf/GMFSubEditor.java b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/src/org/eclipse/papyrus/layouttool/subeditor/gmf/GMFSubEditor.java
new file mode 100644
index 00000000000..56b8c246d7d
--- /dev/null
+++ b/plugins/layout/org.eclipse.papyrus.layouttool.subeditor.gmf/src/org/eclipse/papyrus/layouttool/subeditor/gmf/GMFSubEditor.java
@@ -0,0 +1,225 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Allanic Alexia (Atos Origin) alexia.allanic@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.layouttool.subeditor.gmf;
+
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.draw2d.Animation;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PointList;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.commands.CommandStack;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.internal.commands.SetConnectionBendpointsCommand;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
+import org.eclipse.gmf.runtime.notation.Bounds;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.layouttool.Activator;
+import org.eclipse.papyrus.layouttool.LayouttoolInterface;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * The Class GMFSubEditor.
+ */
+public class GMFSubEditor implements LayouttoolInterface {
+
+ /** The command. */
+ CompositeCommand command = new CompositeCommand("Apply Layout");
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.layouttool.LayouttoolInterface#execute(java.util.Map)
+ */
+ public void execute(Map<EditPart, Rectangle> map) {
+ TransactionalEditingDomain ted = getTransactionalEditingDomain();
+ if(ted != null) {
+ CommandStack cs = null;
+ // Add a command to apply new bounds of all nodes
+ for(Entry<EditPart, Rectangle> s : map.entrySet()) {
+ SetBoundsCommand boundsCommand = new SetBoundsCommand(ted, "apply layout", new EObjectAdapter((View)s
+ .getKey().getModel()), s.getValue());
+ command.add(boundsCommand);
+ GraphicalEditPart gep = (GraphicalEditPart)s.getKey();
+ if(cs == null) {
+ cs = gep.getViewer().getEditDomain().getCommandStack();
+ }
+ }
+ try {
+ // Execute layout commands with animation
+ Animation.markBegin();
+ cs.execute(new ICommandProxy(command));
+ Animation.run(1000);
+ } catch (Exception e) {
+ Activator.getDefault().log(e.getMessage() + " : Cannot apply new bounds of all nodes", e);
+ }
+ }
+ }
+
+ /**
+ * Gets the transactional editing domain.
+ *
+ * @return the transactional editing domain
+ */
+ private TransactionalEditingDomain getTransactionalEditingDomain() {
+ TransactionalEditingDomain ted = null;
+ IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .getActiveEditor();
+ if(activeEditor instanceof IDiagramWorkbenchPart) {
+ IDiagramWorkbenchPart workbenchPart = (IDiagramWorkbenchPart)activeEditor;
+ ted = (TransactionalEditingDomain)workbenchPart.getAdapter(EditingDomain.class);
+ if(ted == null) {
+ if(workbenchPart instanceof DiagramEditor) {
+ DiagramEditor editor = (DiagramEditor)workbenchPart;
+ ted = editor.getEditingDomain();
+ }
+ }
+ }
+ return ted;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.layouttool.LayouttoolInterface#getBounds(org.eclipse.gef.EditPart)
+ */
+ public Rectangle getBounds(EditPart element) {
+ if(element.getModel() instanceof Node) {
+ Node node = (Node)element.getModel();
+ if(node.getLayoutConstraint() instanceof Bounds) {
+ Bounds bounds = (Bounds)node.getLayoutConstraint();
+ return new Rectangle(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight());
+ }
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.layouttool.LayouttoolInterface#getTarget(org.eclipse.gef.EditPart)
+ */
+ public EditPart getTarget(EditPart element) {
+ if(element.getModel() instanceof Edge) {
+ Edge edge = (Edge)element.getModel();
+ removeBendPoints(edge);
+ AbstractConnectionEditPart acep = (AbstractConnectionEditPart)element;
+ return acep.getTarget();
+ }
+ return null;
+ }
+
+ /**
+ * Removes the bend points.
+ *
+ * @param edge
+ * the edge
+ */
+ public void removeBendPoints(Edge edge) {
+ SetConnectionBendpointsCommand scbc = new SetConnectionBendpointsCommand(getTransactionalEditingDomain());
+ scbc.setEdgeAdapter(new EObjectAdapter((View)edge));
+ scbc.setNewPointList(new PointList(), new Point(), new Point());
+ command.add(scbc);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.layouttool.LayouttoolInterface#getLayoutArea(org.eclipse.gef.EditPart[])
+ */
+ public Rectangle getLayoutArea(EditPart[] element) {
+ Rectangle bounds;
+ if(GMFLayoutAreaCreator.getBounds() != null) {
+ bounds = GMFLayoutAreaCreator.getBounds();
+ GMFLayoutAreaCreator.deleteLayoutArea();
+ return bounds;
+ }
+ for(EditPart e : element) {
+ if(e.getModel() instanceof Node) {
+ if(e.getParent() instanceof GraphicalEditPart) {
+ GraphicalEditPart gep = (GraphicalEditPart)e.getParent();
+ bounds = gep.getFigure().getBounds();
+ bounds.x = 0;
+ bounds.y = 0;
+ return bounds;
+ }
+ }
+ }
+ return new Rectangle(0, 0, 1000, 1000);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.layouttool.LayouttoolInterface#getSource(org.eclipse.gef.EditPart)
+ */
+ public EditPart getSource(EditPart element) {
+ if(element.getModel() instanceof Edge) {
+ Edge edge = (Edge)element.getModel();
+ removeBendPoints(edge);
+ AbstractConnectionEditPart acep = (AbstractConnectionEditPart)element;
+ return acep.getSource();
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.layouttool.LayouttoolInterface#isNode(org.eclipse.gef.EditPart)
+ */
+ public boolean isNode(EditPart element) {
+ if(element.getModel() instanceof Node) {
+ if(GMFLayoutAreaCreator.getArea() != null && element.equals(GMFLayoutAreaCreator.getArea())) {
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.layouttool.LayouttoolInterface#isRelationship(org.eclipse.gef.EditPart)
+ */
+ public boolean isRelationship(EditPart element) {
+ if(element.getModel() instanceof Edge) {
+ return true;
+ }
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.layouttool.LayouttoolInterface#getEditorClass()
+ */
+ public Class getEditorClass() {
+ return IDiagramWorkbenchPart.class;
+ }
+}

Back to the top