Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael ADAM2014-10-28 16:10:33 +0000
committerMickael ADAM2014-10-28 16:23:41 +0000
commitbcf1f71ba6721572bc9b026010519daa0f037f04 (patch)
tree6ff5c1d2895e5b7b7bb003998da2a0fa36b1a117 /plugins/infra
parent8085759196a9c1544a08d75c211b821307591c96 (diff)
parent971bab65f2d9b629c915e90e4cd88417958937c4 (diff)
downloadorg.eclipse.papyrus-bcf1f71ba6721572bc9b026010519daa0f037f04.tar.gz
org.eclipse.papyrus-bcf1f71ba6721572bc9b026010519daa0f037f04.tar.xz
org.eclipse.papyrus-bcf1f71ba6721572bc9b026010519daa0f037f04.zip
Merge remote-tracking branch 'origin/bugs/440230_440226' into
1.0_Maintenance Change-Id: I5cf48cc197da2eb83cc275e3173374c84f2caf48 Signed-off-by: Mickael ADAM <mickael.adam@ALL4TEC.net>
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSModelElement.java15
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/xtend-gen/org/eclipse/papyrus/infra/gmfdiag/generator/CSSGenerator.java29
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF160
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractAlignLabelCommand.java8
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AlignLabelCommand.java23
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStyleValueCommand.java174
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusLabelEditPart.java345
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusLinkLabelDragPolicy.java97
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/RefreshTextAlignmentEditPolicy.java113
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/IPapyrusWrappingLabel.java46
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java76
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/PapyrusLabelHelper.java290
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/locator/IPapyrusBorderItemLocator.java112
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/locator/PapyrusLabelLocator.java281
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java87
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/FigureUtils.java148
16 files changed, 1782 insertions, 222 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSModelElement.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSModelElement.java
index 3c91af3e1f9..df00838d2fb 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSModelElement.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSModelElement.java
@@ -8,7 +8,7 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * MickaŽl Adam (ALL4TEC) mickael.adam@all4tec.net - bug 429642
+ * MickaÔŅĹl Adam (ALL4TEC) mickael.adam@all4tec.net - bug 429642
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.css.properties.modelelement;
@@ -70,7 +70,9 @@ public class CSSModelElement extends CustomStyleModelElement {
@Override
public IObservable doGetObservable(String propertyPath) {
if (CSSStyles.CSS_DIAGRAM_STYLESHEETS_KEY.equals(propertyPath)) {
- return new DiagramStyleSheetObservableList((View) source, domain, propertyPath);
+ if (source instanceof View){
+ return new DiagramStyleSheetObservableList((View) source, domain, propertyPath);
+ }
}
if (CSSStyles.CSS_MODEL_STYLESHEETS_KEY.equals(propertyPath)) {
// Get the resource
@@ -96,9 +98,12 @@ public class CSSModelElement extends CustomStyleModelElement {
Activator.log.error(e);
}
// Initialize the adapter of the engine to listen model styleSheet
- ExtendedCSSEngine engine = ((CSSNotationResource) notationResource).getModelEngine();
- if (engine instanceof ModelCSSEngine) {
- ((ModelCSSEngine) engine).initAdapter();
+ if (notationResource instanceof CSSNotationResource ){
+ ExtendedCSSEngine engine = ((CSSNotationResource) notationResource).getModelEngine();
+
+ if (engine instanceof ModelCSSEngine) {
+ ((ModelCSSEngine) engine).initAdapter();
+ }
}
}
return new ModelStyleSheetObservableList(notationResource, modelStyleSheetsSource.getStylesheets(), domain, modelStyleSheetsSource, StylesheetsPackage.Literals.MODEL_STYLE_SHEETS__STYLESHEETS);
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/xtend-gen/org/eclipse/papyrus/infra/gmfdiag/generator/CSSGenerator.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/xtend-gen/org/eclipse/papyrus/infra/gmfdiag/generator/CSSGenerator.java
index a076db98ff3..4fe96783a9d 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/xtend-gen/org/eclipse/papyrus/infra/gmfdiag/generator/CSSGenerator.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/xtend-gen/org/eclipse/papyrus/infra/gmfdiag/generator/CSSGenerator.java
@@ -1,15 +1,14 @@
-/**
- * generated by Xtext
- */
-package org.eclipse.papyrus.infra.gmfdiag.generator;
-
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.xtext.generator.IFileSystemAccess;
-import org.eclipse.xtext.generator.IGenerator;
-
-@SuppressWarnings("all")
-public class CSSGenerator implements IGenerator {
- @Override
-public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
- }
-}
+/**
+ * generated by Xtext
+ */
+package org.eclipse.papyrus.infra.gmfdiag.generator;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.xtext.generator.IFileSystemAccess;
+import org.eclipse.xtext.generator.IGenerator;
+
+@SuppressWarnings("all")
+public class CSSGenerator implements IGenerator {
+ public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
index 1cf6fc227d5..b8899bbe565 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
@@ -1,79 +1,81 @@
-Manifest-Version: 1.0
-Export-Package: org.eclipse.papyrus.infra.gmfdiag.common,
- org.eclipse.papyrus.infra.gmfdiag.common.adapter,
- org.eclipse.papyrus.infra.gmfdiag.common.commands,
- org.eclipse.papyrus.infra.gmfdiag.common.commands.requests,
- org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom,
- org.eclipse.papyrus.infra.gmfdiag.common.decoration,
- org.eclipse.papyrus.infra.gmfdiag.common.editpart,
- org.eclipse.papyrus.infra.gmfdiag.common.editpolicies,
- org.eclipse.papyrus.infra.gmfdiag.common.figure.edge,
- org.eclipse.papyrus.infra.gmfdiag.common.figure.node,
- org.eclipse.papyrus.infra.gmfdiag.common.handler,
- org.eclipse.papyrus.infra.gmfdiag.common.helper,
- org.eclipse.papyrus.infra.gmfdiag.common.listener,
- org.eclipse.papyrus.infra.gmfdiag.common.model,
- org.eclipse.papyrus.infra.gmfdiag.common.preferences,
- org.eclipse.papyrus.infra.gmfdiag.common.providers,
- org.eclipse.papyrus.infra.gmfdiag.common.reconciler,
- org.eclipse.papyrus.infra.gmfdiag.common.service.shape,
- org.eclipse.papyrus.infra.gmfdiag.common.snap,
- org.eclipse.papyrus.infra.gmfdiag.common.strategy,
- org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy,
- org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste,
- org.eclipse.papyrus.infra.gmfdiag.common.types,
- org.eclipse.papyrus.infra.gmfdiag.common.undocontext,
- org.eclipse.papyrus.infra.gmfdiag.common.utils
-Require-Bundle: org.eclipse.emf.edit.ui;bundle-version="2.5.0",
- org.eclipse.emf.ecore.edit;bundle-version="2.5.0",
- org.eclipse.papyrus.infra.core;bundle-version="1.0.1",
- org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="1.2.0";visibility:=reexport,
- org.eclipse.gef;bundle-version="3.7.1";visibility:=reexport,
- org.eclipse.emf.workspace;bundle-version="1.4.0",
- org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0";visibility:=reexport,
- org.eclipse.papyrus.infra.emf.appearance;bundle-version="1.0.1",
- org.eclipse.core.databinding;bundle-version="1.4.1",
- org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.0.1",
- org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.1",
- org.eclipse.ui.ide;bundle-version="3.8.0",
- org.eclipse.papyrus.infra.core.log;bundle-version="1.0.1",
- org.eclipse.papyrus.infra.emf;bundle-version="1.0.1",
- org.eclipse.papyrus.infra.widgets;bundle-version="1.0.1",
- org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.1",
- org.eclipse.papyrus.infra.services.edit;bundle-version="1.0.1",
- com.google.guava;bundle-version="11.0.0",
- org.eclipse.papyrus.infra.tools;bundle-version="1.0.1",
- org.eclipse.emf.databinding;bundle-version="1.3.0",
- org.eclipse.core.databinding.property;bundle-version="1.4.200",
- org.eclipse.gmf.runtime.draw2d.ui.render;bundle-version="1.4.1",
- org.eclipse.core.expressions,
- org.eclipse.papyrus.uml.tools;bundle-version="1.0.1",
- org.apache.batik.util;bundle-version="[1.6.0,1.7.0)",
- org.apache.batik.svggen;bundle-version="[1.6.0,1.7.0)",
- org.w3c.dom.svg;bundle-version="1.1.0",
- org.apache.batik.dom.svg;bundle-version="[1.6.0,1.7.0)",
- org.apache.batik.dom;bundle-version="[1.6.0,1.7.0)",
- org.apache.batik.xml;bundle-version="[1.6.0,1.7.0)",
- org.eclipse.gmf.tooling.runtime,
- com.ibm.icu,
- org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.1",
- org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.1",
- org.eclipse.papyrus.infra.services.decoration;bundle-version="1.0.1",
- org.eclipse.papyrus.infra.services.markerlistener;bundle-version="1.0.1",
- org.eclipse.papyrus.infra.viewpoints.configuration;bundle-version="1.0.1",
- org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.1",
- org.eclipse.papyrus.uml.tools;bundle-version="1.0.1",
- org.eclipse.gmf.runtime.diagram.ui.providers;bundle-version="1.7.0",
- org.eclipse.papyrus.infra.emf.readonly;bundle-version="1.0.1"
-Bundle-Vendor: %providerName
-Bundle-ActivationPolicy: lazy
-Bundle-ClassPath: .
-Bundle-Version: 1.0.1.qualifier
-Bundle-Localization: plugin
-Bundle-Name: %pluginName
-Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.common.Activator
-Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.eclipse.papyrus.infra.gmfdiag.common;singleto
- n:=true
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-
+Manifest-Version: 1.0
+Export-Package: org.eclipse.papyrus.infra.gmfdiag.common,
+ org.eclipse.papyrus.infra.gmfdiag.common.adapter,
+ org.eclipse.papyrus.infra.gmfdiag.common.commands,
+ org.eclipse.papyrus.infra.gmfdiag.common.commands.requests,
+ org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom,
+ org.eclipse.papyrus.infra.gmfdiag.common.decoration,
+ org.eclipse.papyrus.infra.gmfdiag.common.editpart,
+ org.eclipse.papyrus.infra.gmfdiag.common.editpolicies,
+ org.eclipse.papyrus.infra.gmfdiag.common.figure,
+ org.eclipse.papyrus.infra.gmfdiag.common.figure.edge,
+ org.eclipse.papyrus.infra.gmfdiag.common.figure.node,
+ org.eclipse.papyrus.infra.gmfdiag.common.handler,
+ org.eclipse.papyrus.infra.gmfdiag.common.helper,
+ org.eclipse.papyrus.infra.gmfdiag.common.listener,
+ org.eclipse.papyrus.infra.gmfdiag.common.locator,
+ org.eclipse.papyrus.infra.gmfdiag.common.model,
+ org.eclipse.papyrus.infra.gmfdiag.common.preferences,
+ org.eclipse.papyrus.infra.gmfdiag.common.providers,
+ org.eclipse.papyrus.infra.gmfdiag.common.reconciler,
+ org.eclipse.papyrus.infra.gmfdiag.common.service.shape,
+ org.eclipse.papyrus.infra.gmfdiag.common.snap,
+ org.eclipse.papyrus.infra.gmfdiag.common.strategy,
+ org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy,
+ org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste,
+ org.eclipse.papyrus.infra.gmfdiag.common.types,
+ org.eclipse.papyrus.infra.gmfdiag.common.undocontext,
+ org.eclipse.papyrus.infra.gmfdiag.common.utils
+Require-Bundle: org.eclipse.emf.edit.ui;bundle-version="2.5.0",
+ org.eclipse.emf.ecore.edit;bundle-version="2.5.0",
+ org.eclipse.papyrus.infra.core;bundle-version="1.0.1",
+ org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="1.2.0";visibility:=reexport,
+ org.eclipse.gef;bundle-version="3.7.1";visibility:=reexport,
+ org.eclipse.emf.workspace;bundle-version="1.4.0",
+ org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0";visibility:=reexport,
+ org.eclipse.papyrus.infra.emf.appearance;bundle-version="1.0.1",
+ org.eclipse.core.databinding;bundle-version="1.4.1",
+ org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.0.1",
+ org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.1",
+ org.eclipse.ui.ide;bundle-version="3.8.0",
+ org.eclipse.papyrus.infra.core.log;bundle-version="1.0.1",
+ org.eclipse.papyrus.infra.emf;bundle-version="1.0.1",
+ org.eclipse.papyrus.infra.widgets;bundle-version="1.0.1",
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.1",
+ org.eclipse.papyrus.infra.services.edit;bundle-version="1.0.1",
+ com.google.guava;bundle-version="11.0.0",
+ org.eclipse.papyrus.infra.tools;bundle-version="1.0.1",
+ org.eclipse.emf.databinding;bundle-version="1.3.0",
+ org.eclipse.core.databinding.property;bundle-version="1.4.200",
+ org.eclipse.gmf.runtime.draw2d.ui.render;bundle-version="1.4.1",
+ org.eclipse.core.expressions,
+ org.eclipse.papyrus.uml.tools;bundle-version="1.0.1",
+ org.apache.batik.util;bundle-version="[1.6.0,1.7.0)",
+ org.apache.batik.svggen;bundle-version="[1.6.0,1.7.0)",
+ org.w3c.dom.svg;bundle-version="1.1.0",
+ org.apache.batik.dom.svg;bundle-version="[1.6.0,1.7.0)",
+ org.apache.batik.dom;bundle-version="[1.6.0,1.7.0)",
+ org.apache.batik.xml;bundle-version="[1.6.0,1.7.0)",
+ org.eclipse.gmf.tooling.runtime,
+ com.ibm.icu,
+ org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.1",
+ org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.1",
+ org.eclipse.papyrus.infra.services.decoration;bundle-version="1.0.1",
+ org.eclipse.papyrus.infra.services.markerlistener;bundle-version="1.0.1",
+ org.eclipse.papyrus.infra.viewpoints.configuration;bundle-version="1.0.1",
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.1",
+ org.eclipse.papyrus.uml.tools;bundle-version="1.0.1",
+ org.eclipse.gmf.runtime.diagram.ui.providers;bundle-version="1.7.0",
+ org.eclipse.papyrus.infra.emf.readonly;bundle-version="1.0.1"
+Bundle-Vendor: %providerName
+Bundle-ActivationPolicy: lazy
+Bundle-ClassPath: .
+Bundle-Version: 1.0.1.qualifier
+Bundle-Localization: plugin
+Bundle-Name: %pluginName
+Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.common.Activator
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.eclipse.papyrus.infra.gmfdiag.common;singleto
+ n:=true
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractAlignLabelCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractAlignLabelCommand.java
deleted file mode 100644
index 577ea2cd271..00000000000
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractAlignLabelCommand.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import org.eclipse.gef.commands.Command;
-
-public class AbstractAlignLabelCommand extends Command {
-
-
-}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AlignLabelCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AlignLabelCommand.java
deleted file mode 100644
index e5dfcbc67ed..00000000000
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AlignLabelCommand.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart;
-
-public class AlignLabelCommand extends AbstractAlignLabelCommand {
-
- private Rectangle constraint;
-
- private PapyrusLabelEditPart label;
-
- @Override
- public void execute() {
- // TODO Auto-generated method stub
- //super.execute();
-
- System.out.println("____J'execute la commande");
- }
-
-
-
-}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStyleValueCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStyleValueCommand.java
index b0a6dcb1662..7e64962d12b 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStyleValueCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStyleValueCommand.java
@@ -1,87 +1,87 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import org.eclipse.emf.common.command.AbstractCommand;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.gmf.runtime.notation.NamedStyle;
-import org.eclipse.gmf.runtime.notation.NotationFactory;
-import org.eclipse.gmf.runtime.notation.View;
-
-public class CustomStyleValueCommand extends AbstractCommand {
-
- private boolean createStyle;
-
- private Object value;
-
- private Object oldValue;
-
- private EClass styleClass;
-
- private View view;
-
- private String styleName;
-
- private EStructuralFeature styleFeature;
-
- public CustomStyleValueCommand(View view, Object value, EClass styleClass, EStructuralFeature styleFeature, String styleName) {
- this.value = value;
- this.styleClass = styleClass;
- this.view = view;
- this.styleName = styleName;
- this.styleFeature = styleFeature;
- }
-
- @Override
- public void execute() {
- NamedStyle valueStyle = view.getNamedStyle(styleClass, styleName);
- createStyle = valueStyle == null;
- if (createStyle) {
- valueStyle = createStyle();
- } else {
- oldValue = valueStyle.eGet(styleFeature);
- }
-
- valueStyle.eSet(styleFeature, value);
- if (createStyle) {
- view.getStyles().add(valueStyle);
- }
- }
-
- protected NamedStyle createStyle() {
- NamedStyle result = (NamedStyle) NotationFactory.eINSTANCE.create(styleClass);
- result.setName(styleName);
- return result;
- }
-
- @Override
- public void redo() {
- execute();
- }
-
- @Override
- public void undo() {
- NamedStyle valueStyle = view.getNamedStyle(styleClass, styleName);
- ;
- if (createStyle) {
- view.getStyles().remove(valueStyle);
- } else {
- valueStyle.eSet(styleFeature, oldValue);
- }
- }
-
- @Override
- public boolean prepare() {
- return true;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.gmf.runtime.notation.NamedStyle;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.View;
+
+public class CustomStyleValueCommand extends AbstractCommand {
+
+ private boolean createStyle;
+
+ private Object value;
+
+ private Object oldValue;
+
+ private EClass styleClass;
+
+ private View view;
+
+ private String styleName;
+
+ private EStructuralFeature styleFeature;
+
+ public CustomStyleValueCommand(View view, Object value, EClass styleClass, EStructuralFeature styleFeature, String styleName) {
+ this.value = value;
+ this.styleClass = styleClass;
+ this.view = view;
+ this.styleName = styleName;
+ this.styleFeature = styleFeature;
+ }
+
+ @Override
+ public void execute() {
+ NamedStyle valueStyle = view.getNamedStyle(styleClass, styleName);
+ createStyle = valueStyle == null;
+ if (createStyle) {
+ valueStyle = createStyle();
+ } else {
+ oldValue = valueStyle.eGet(styleFeature);
+ }
+
+ valueStyle.eSet(styleFeature, value);
+ if (createStyle || valueStyle.eContainer() == null) {// valueStyle.eContainer() == null if CSS valueStyle is set but no Style on notation
+ view.getStyles().add(valueStyle);
+ }
+ }
+
+ protected NamedStyle createStyle() {
+ NamedStyle result = (NamedStyle) NotationFactory.eINSTANCE.create(styleClass);
+ result.setName(styleName);
+ return result;
+ }
+
+ @Override
+ public void redo() {
+ execute();
+ }
+
+ @Override
+ public void undo() {
+ NamedStyle valueStyle = view.getNamedStyle(styleClass, styleName);
+ ;
+ if (createStyle) {
+ view.getStyles().remove(valueStyle);
+ } else {
+ valueStyle.eSet(styleFeature, oldValue);
+ }
+ }
+
+ @Override
+ public boolean prepare() {
+ return true;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusLabelEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusLabelEditPart.java
index c80c3124e77..7ce1087c4d8 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusLabelEditPart.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusLabelEditPart.java
@@ -8,21 +8,85 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * Cťline Janssens (ALL4TEC) celine.janssens@all4tec.net
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 440230
* Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 443235
+ * Micka√ęl ADAM (ALL4TEC) mickael.adam@all4tec.net - text alignment implementation
+ *
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
+import org.eclipse.draw2d.Connection;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+import org.eclipse.gef.editpolicies.ResizableEditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.internal.figures.ResizableLabelLocator;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.StringValueStyle;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.LabelAlignmentEditPolicy;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.LabelPrimarySelectionEditPolicy;
-
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.RefreshTextAlignmentEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.figure.IPapyrusWrappingLabel;
+import org.eclipse.papyrus.infra.gmfdiag.common.locator.IPapyrusBorderItemLocator;
+import org.eclipse.papyrus.infra.gmfdiag.common.locator.PapyrusLabelLocator;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
public abstract class PapyrusLabelEditPart extends LabelEditPart {
+ /**
+ * Default Margin when not present in CSS
+ */
+ static final int DEFAULT_MARGIN = 0;
+
+ /**
+ * CSS Integer property to define the horizontal Label Margin
+ */
+ public static final String TOP_MARGIN_PROPERTY = "topMarginLabel"; // $NON-NLS$
+
+ /**
+ * CSS Integer property to define the vertical Label Margin
+ */
+ public static final String LEFT_MARGIN_PROPERTY = "leftMarginLabel"; // $NON-NLS$
+
+ /**
+ * CSS Integer property to define the horizontal Label Margin
+ */
+ public static final String BOTTOM_MARGIN_PROPERTY = "bottomMarginLabel"; // $NON-NLS$
+
+ /**
+ * CSS Integer property to define the vertical Label Margin
+ */
+ public static final String RIGHT_MARGIN_PROPERTY = "rightMarginLabel"; // $NON-NLS$
+
+ /** The Constant TEXT_ALIGNMENT. */
+ public static final String TEXT_ALIGNMENT = "textAlignment"; // $NON-NLS$
+
+ /** The Constant LABEL_OFFSET_Y. */
+ public static final String LABEL_OFFSET_Y = "labelOffsetY"; // $NON-NLS$
+
+ /** The Constant LABEL_OFFSET_X. */
+ public static final String LABEL_OFFSET_X = "labelOffsetX"; // $NON-NLS$
+
+ /** The Constant LABEL_CONSTRAINED. */
+ public static final String LABEL_CONSTRAINED = "labelConstrained"; // $NON-NLS$
+
+ /** The external label locator. */
+ protected PapyrusLabelLocator papyrusLabelLocator = null;
+
+ /** The affixed label locator. */
+ protected IPapyrusBorderItemLocator borderLabelLocator = null;
+
+
public PapyrusLabelEditPart(View view) {
super(view);
}
@@ -30,12 +94,285 @@ public abstract class PapyrusLabelEditPart extends LabelEditPart {
@Override
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
-
installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy());
installEditPolicy(LabelAlignmentEditPolicy.LABEL_ALIGNMENT_KEY, new LabelAlignmentEditPolicy());
installEditPolicy(LabelPrimarySelectionEditPolicy.LABEL_PRIMARY_SELECTION_KEY, new LabelPrimarySelectionEditPolicy());
+ installEditPolicy(RefreshTextAlignmentEditPolicy.REFRESH_TEXT_ALIGNMENT_EDITPOLICY, new RefreshTextAlignmentEditPolicy());
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart#refreshVisuals()
+ *
+ */
+ @Override
+ protected void refreshVisuals() {
+ super.refreshVisuals();
+ refreshLabelMargin();
+ }
+
+ /**
+ * Refresh bounds.
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart#refreshBounds()
+ */
+ @Override
+ public void refreshBounds() {
+ // try to handle both of resizable and nonresizable labels
+ if (isResizable()) {
+ handleResizableRefreshBounds();
+ } else {
+ handleNonResizableRefreshBoundS();
+ }
+ }
+
+ /**
+ * Handle non resizable refresh bound s.
+ */
+ private void handleNonResizableRefreshBoundS() {
+ int dx = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue();
+ int dy = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue();
+
+ Point offset = new Point(dx, dy);
+
+ if (getParent() instanceof AbstractConnectionEditPart) {
+
+ AbstractGraphicalEditPart parentEditPart = (AbstractGraphicalEditPart) getParent();
+
+ Connection connectionFigure = ((AbstractConnectionEditPart) getParent()).getConnectionFigure();
+
+ if (papyrusLabelLocator != null) {
+ papyrusLabelLocator.setOffset(offset);
+ } else {
+ papyrusLabelLocator = new PapyrusLabelLocator(connectionFigure, offset, getKeyPoint());
+ }
+ papyrusLabelLocator.setTextAlignment(getTextAlignment());
+ papyrusLabelLocator.setView((View) getModel());
+ parentEditPart.setLayoutConstraint(this, getFigure(), papyrusLabelLocator);
+
+ } else {
+ setExternalLabelLocator(offset);
+ getFigure().getParent().setConstraint(getFigure(), borderLabelLocator);
+ }
+ }
+
+ /**
+ * @return the papyrusLabelLocator
+ */
+ public PapyrusLabelLocator getPapyrusLabelLocator() {
+ return papyrusLabelLocator;
+ }
+
+ /**
+ * Sets the external label locator.
+ *
+ * @param offset
+ * the new external label locator
+ */
+ private void setExternalLabelLocator(Point offset) {
+ if (borderLabelLocator == null) {
+ borderLabelLocator = (IPapyrusBorderItemLocator) getBorderItemLocator();
+
+ }
+ if (offset != null) {
+ borderLabelLocator.setConstraint(new Rectangle(offset.x, offset.y, 0, 0));
+ }
+ borderLabelLocator.setView((View) getModel());
+ borderLabelLocator.setEditpart(this);
+ borderLabelLocator.setTextAlignment(getTextAlignment());
+ }
+
+ /**
+ * Gets the border item locator.
+ *
+ * @return the border item locator
+ */
+ public Object getBorderItemLocator() {
+ IFigure parentFigure = getFigure().getParent();
+ if (parentFigure != null && parentFigure.getLayoutManager() != null) {
+ Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure());
+ return constraint;
+ }
+ return null;
+ }
+
+ /**
+ * Gets the text alignment.
+ *
+ * @return the text alignment
+ */
+ public int getTextAlignment() {
+ // get the value of the CSS property
+ View model = (View) getModel();
+ StringValueStyle labelAlignment = (StringValueStyle) model.getNamedStyle(NotationPackage.eINSTANCE.getStringValueStyle(), TEXT_ALIGNMENT);
+
+ int textAlignment = 0;
+ if (labelAlignment != null) {
+ if ("left".equals(labelAlignment.getStringValue())) {
+ textAlignment = PositionConstants.LEFT;
+ }
+ if ("right".equals(labelAlignment.getStringValue())) {
+ textAlignment = PositionConstants.RIGHT;
+ }
+ if ("center".equals(labelAlignment.getStringValue())) {
+ textAlignment = PositionConstants.CENTER;
+ }
+ } else {
+ textAlignment = getDefaultTextAlignment();
+ }
+ return textAlignment;
+ }
+
+ /**
+ * Handle resizable refresh bounds.
+ */
+ private void handleResizableRefreshBounds() {
+ int dx = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue();
+ int dy = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue();
+ int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue();
+ int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue();
+
+ Rectangle rectangle = new Rectangle(dx, dy, width, height);
+ if (getParent() instanceof AbstractConnectionEditPart) {
+ ((AbstractGraphicalEditPart) getParent()).setLayoutConstraint(this,
+ getFigure(), new ResizableLabelLocator(((AbstractConnectionEditPart) getParent()).getConnectionFigure(), rectangle, getKeyPoint()));
+ } else {
+ getFigure().getParent().setConstraint(getFigure(), new ResizableLabelLocator(getFigure().getParent(), rectangle, getKeyPoint()));
+ }
+ }
+
+ /**
+ * Checks if is resizable.
+ *
+ * @return true, if is resizable
+ */
+ private boolean isResizable() {
+ EditPolicy editPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
+ if (editPolicy instanceof ResizableEditPolicy) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart#refresh()
+ *
+ */
+ @Override
+ public void refresh() {
+ super.refresh();
+ if (getBorderItemLocator() instanceof IPapyrusBorderItemLocator) {
+ // Constrained management
+ setExternalLabelLocator(null);
+ refreshLabelConstrained();
+ refreshLabelOffset();
+ }
+ }
+
+ /**
+ * Refresh label offset.
+ */
+ private void refreshLabelOffset() {
+ // get the value of the CSS property
+ Object model = getModel();
+ if (model instanceof View) {
+ int labelOffsetX = NotationUtils.getIntValue((View) getModel(), LABEL_OFFSET_X, getDefaultLabelOffsetX());
+ int labelOffsetY = NotationUtils.getIntValue((View) getModel(), LABEL_OFFSET_Y, getDefaultLabelOffsetY());
+
+ // set the value on the locator
+ ((IPapyrusBorderItemLocator) getBorderItemLocator()).setOffset(new Dimension(labelOffsetX, labelOffsetY));
+ }
+ }
+ /**
+ * Refresh label constrained.
+ */
+ private void refreshLabelConstrained() {
+ // get the value of the CSS property
+ Object model = getModel();
+ if (model instanceof View) {
+ // set the value on the locator
+ ((IPapyrusBorderItemLocator) getBorderItemLocator()).setConstrained(isLabelConstrained());
+ }
}
-}
+ /**
+ * Checks if is label constrained.
+ *
+ * @return true, if the label is constrained
+ */
+ public boolean isLabelConstrained() {
+ boolean labelConstrained = NotationUtils.getBooleanValue((View) getModel(), LABEL_CONSTRAINED, getDefaultLabelConstrained());
+ return labelConstrained;
+ }
+
+ /**
+ * Gets the default label offset y.
+ *
+ * @return the default label offset y
+ */
+ protected int getDefaultLabelOffsetY() {
+ return 0;
+ }
+
+ /**
+ * Gets the default label offset x.
+ *
+ * @return the default label offset x
+ */
+ protected int getDefaultLabelOffsetX() {
+ return 0;
+ }
+
+ /**
+ * Gets the default label constrained.
+ *
+ * @return the default label constrained
+ */
+ protected boolean getDefaultLabelConstrained() {
+ return false;
+ }
+
+ /**
+ * Gets the default text alignment.
+ *
+ * @return the default text alignment
+ */
+ protected int getDefaultTextAlignment() {
+ return PositionConstants.CENTER;
+ }
+ /**
+ *
+ */
+ public void refreshLabelMargin() {
+ IFigure figure = null;
+
+ int leftMargin = DEFAULT_MARGIN;
+ int rightMargin = DEFAULT_MARGIN;
+ int topMargin = DEFAULT_MARGIN;
+ int bottomMargin = DEFAULT_MARGIN;
+
+ Object model = this.getModel();
+
+ if (model instanceof View) {
+ leftMargin = NotationUtils.getIntValue((View) model, LEFT_MARGIN_PROPERTY, DEFAULT_MARGIN);
+ rightMargin = NotationUtils.getIntValue((View) model, RIGHT_MARGIN_PROPERTY, DEFAULT_MARGIN);
+ topMargin = NotationUtils.getIntValue((View) model, TOP_MARGIN_PROPERTY, DEFAULT_MARGIN);
+ bottomMargin = NotationUtils.getIntValue((View) model, BOTTOM_MARGIN_PROPERTY, DEFAULT_MARGIN);
+ }
+
+ figure = ((GraphicalEditPart) this).getFigure();
+
+ if (figure instanceof IPapyrusWrappingLabel) {
+ ((IPapyrusWrappingLabel) figure).setMarginLabel(leftMargin, topMargin, rightMargin, bottomMargin);
+
+ // set margin of locator:
+ if (borderLabelLocator != null) {
+ borderLabelLocator.setMargin(new Point(leftMargin + rightMargin, topMargin + bottomMargin));
+ } else if (papyrusLabelLocator != null) {
+ papyrusLabelLocator.setMargin(new Point(leftMargin + rightMargin, topMargin + bottomMargin));
+ }
+ }
+
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusLinkLabelDragPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusLinkLabelDragPolicy.java
new file mode 100644
index 00000000000..f0dc39eb51e
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusLinkLabelDragPolicy.java
@@ -0,0 +1,97 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.handles.MoveHandle;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+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.LabelEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.PapyrusLabelHelper;
+
+
+/**
+ * The Class PapyrusLinkLabelDragPolicy.
+ *
+ * @author Mickael ADAM
+ */
+public class PapyrusLinkLabelDragPolicy extends NonResizableLabelEditPolicy {
+
+ /**
+ * @see org.eclipse.gef.editpolicies.NonResizableEditPolicy#createSelectionHandles()
+ *
+ * @return
+ */
+ @Override
+ protected List<MoveHandle> createSelectionHandles() {
+ MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost());
+ mh.setBorder(null);
+ return Collections.singletonList(mh);
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy#getMoveCommand(org.eclipse.gef.requests.ChangeBoundsRequest)
+ *
+ * @param request
+ * @return
+ */
+ @Override
+ protected Command getMoveCommand(ChangeBoundsRequest request) {
+ LabelEditPart editPart = (LabelEditPart) getHost();
+ Point refPoint = editPart.getReferencePoint();
+
+ // translate the feedback figure
+ PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
+ getHostFigure().translateToAbsolute(rect);
+ rect.translate(request.getMoveDelta());
+ rect.resize(request.getSizeDelta());
+ getHostFigure().translateToRelative(rect);
+
+ if (editPart instanceof PapyrusLabelEditPart) {
+ // translate according to the text alignments
+ switch (((PapyrusLabelEditPart) editPart).getTextAlignment()) {
+ case PositionConstants.LEFT:
+ rect.translate(-getHostFigure().getBounds().width / 2, 0);
+ break;
+ case PositionConstants.CENTER:
+ break;
+ case PositionConstants.RIGHT:
+ rect.translate(getHostFigure().getBounds().width / 2, 0);
+ break;
+ default:
+ break;
+ }
+ }
+
+ Point normalPoint = PapyrusLabelHelper.offsetFromRelativeCoordinate(getHostFigure(), rect, refPoint);
+
+ ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location,
+ new EObjectAdapter((View) editPart.getModel()), normalPoint);
+ return new ICommandProxy(moveCommand);
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/RefreshTextAlignmentEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/RefreshTextAlignmentEditPolicy.java
new file mode 100644
index 00000000000..52e2be18b8b
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/RefreshTextAlignmentEditPolicy.java
@@ -0,0 +1,113 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ *
+ * 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:
+ * Micka√ęl ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import org.eclipse.core.databinding.observable.ChangeEvent;
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.gef.ui.internal.editpolicies.GraphicalEditPolicyEx;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.commands.wrappers.GEFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomStringStyleObservableValue;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart;
+
+/**
+ * this edit policy has in charge to refresh the edit part when text alignment change.
+ */
+public class RefreshTextAlignmentEditPolicy extends GraphicalEditPolicyEx implements IChangeListener {
+
+ /** key for this edit policy. */
+ public final static String REFRESH_TEXT_ALIGNMENT_EDITPOLICY = "Refresh text alignment edit policy";//$NON-NLS-N$
+
+ /** The style observable. */
+ protected IObservableValue styleObservable;
+
+ /** The view. */
+ private View view;
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void activate() {
+ // retrieve the view and the element managed by the edit part
+ view = (View) getHost().getModel();
+ if (view == null) {
+ return;
+ }
+
+ if (getHost() instanceof PapyrusLabelEditPart) {
+ // add style observable value
+ styleObservable = new CustomStringStyleObservableValue(view, EMFHelper.resolveEditingDomain(view), PapyrusLabelEditPart.TEXT_ALIGNMENT);
+ styleObservable.addChangeListener(this);
+ }
+ getHost().refresh();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void deactivate() {
+ if (styleObservable != null) {
+ styleObservable.removeChangeListener(this);
+ styleObservable.dispose();
+ styleObservable = null;
+ }
+ }
+
+ /**
+ * @see org.eclipse.core.databinding.observable.IChangeListener#handleChange(org.eclipse.core.databinding.observable.ChangeEvent)
+ *
+ * @param event
+ */
+ @Override
+ public void handleChange(ChangeEvent event) {
+
+ if (getHost() instanceof PapyrusLabelEditPart) {
+ // set the position to avoid that position move on text alignment change
+ PapyrusLabelEditPart editPart = (PapyrusLabelEditPart) getHost();
+
+ IFigure figure = editPart.getFigure();
+
+ ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_MOVE);
+ req.setEditParts(editPart);
+ req.setLocation(figure.getBounds().getLocation());
+ Command command = editPart.getCommand(req);
+ if (command != null && command.canExecute()) {
+ TransactionUtil.getEditingDomain(view).getCommandStack().execute(GEFtoEMFCommandWrapper.wrap(command));
+ }
+
+ }
+
+ // Save new location only on change
+ // final Point offset = newOffset;
+ // ChangeBoundsRequest req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
+ // req.setEditParts(editPart);
+ // req.setLocation(offset);
+ // Command command = editPart.getCommand(req);
+ // if (command != null && command.canExecute() && !cachedIsConstrained) {
+ // TransactionUtil.getEditingDomain(view).getCommandStack().execute(GEFtoEMFCommandWrapper.wrap(command));
+ // }
+
+ getHost().refresh();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/IPapyrusWrappingLabel.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/IPapyrusWrappingLabel.java
new file mode 100644
index 00000000000..1aa7ead09c7
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/IPapyrusWrappingLabel.java
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST 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:
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.figure;
+
+import org.eclipse.draw2d.IFigure;
+
+/**
+ * @author Céline JANSSENS
+ * Bug 440230
+ * This interface is dedicated to PapyrusWrappingLabel abstract methods.
+ *
+ */
+public interface IPapyrusWrappingLabel extends IFigure {
+
+ /**
+ * Set the margin of the Label in the horizontal direction and vertical Direction
+ * @param xMargin Horizontal Margin
+ * @param yMargin Vertical Margin
+ *
+ */
+ void setMarginLabel(int xMargin , int yMargin);
+
+
+
+
+
+ /**
+ * Set the margin of the Label in the horizontal direction and vertical Direction
+ * @param xMargin Horizontal Margin
+ * @param yMargin Vertical Margin
+ *
+ */
+ void setMarginLabel(int leftMargin , int topMargin, int rightMargin, int bottomMargin);
+
+} \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java
index a053c350f2e..f7eb0c705a6 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java
@@ -10,18 +10,59 @@
* Contributors:
* Atos Origin - Initial API and implementation
* Arthur Daussy - Bug 354622 - [ActivityDiagram] Object Flows selection prevent selecting other close elements.
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 440230 - Margin Label
*
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
+import org.eclipse.draw2d.MarginBorder;
+import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
+import org.eclipse.papyrus.infra.gmfdiag.common.figure.IPapyrusWrappingLabel;
+import org.eclipse.swt.graphics.Image;
/**
* This correct the bug where invisible label can be selected
*
* @author arthur daussy
*/
-public class PapyrusWrappingLabel extends WrappingLabel {
+public class PapyrusWrappingLabel extends WrappingLabel implements IPapyrusWrappingLabel{
+
+ /**
+ * Constructor.
+ *
+ * @param image
+ */
+ public PapyrusWrappingLabel(Image image) {
+ super(image);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param text
+ */
+ public PapyrusWrappingLabel(String text) {
+ super(text);
+ }
+
+ /**
+ * Constructor.
+ *
+ */
+ public PapyrusWrappingLabel() {
+ super();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param text
+ * @param image
+ */
+ public PapyrusWrappingLabel(String text, Image image) {
+ super(text, image);
+ }
/**
* Bug 354622 - [ActivityDiagram] Object Flows selection prevent selecting other close elements.
@@ -44,4 +85,37 @@ public class PapyrusWrappingLabel extends WrappingLabel {
return false;
}
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.figure.IPapyrusWrappingLabel#setMarginLabel(int, int)
+ *
+ * @param xMargin Vertical margin
+ * @param yMargin Horizontal margin
+ */
+ @Override
+ public void setMarginLabel(int xMargin, int yMargin) {
+
+ this.setMarginLabel(xMargin, yMargin , xMargin, yMargin);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.figure.IPapyrusWrappingLabel#setMarginLabel(int, int, int, int)
+ *
+ * @param leftMargin
+ * @param topMargin
+ * @param rightMargin
+ * @param bottomMargin
+ */
+ @Override
+ public void setMarginLabel(int leftMargin, int topMargin, int rightMargin, int bottomMargin) {
+ MarginBorder mb = new MarginBorder(topMargin, leftMargin, bottomMargin, rightMargin);
+ this.setBorder(mb);
+ repaint();
+ revalidate();
+
+ }
+
+
+
+
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/PapyrusLabelHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/PapyrusLabelHelper.java
new file mode 100644
index 00000000000..a2b47c95f5d
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/PapyrusLabelHelper.java
@@ -0,0 +1,290 @@
+/******************************************************************************
+ * Copyright (c) 2005, 2009 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.helper;
+
+
+import org.eclipse.draw2d.Connection;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PointList;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg;
+import org.eclipse.gmf.runtime.draw2d.ui.geometry.PointListUtilities;
+
+/**
+ * Helper class to convert the label coordinates from an offset value
+ * from a keypoint to real draw2d coordinate
+ *
+ * @author sshaw
+ *
+ */
+public class PapyrusLabelHelper {
+
+ /**
+ * Calculates the label offset from the reference point given the label bounds.
+ *
+ * @param label
+ * the <code>IFigure</code> to calculate the offset for
+ * @param bounds
+ * the <code>Rectangle</code> that is the bounding box of the label.
+ * @param ref
+ * the <code>Point</code> that is the reference point that the offset
+ * is based on.
+ * @return a <code>Point</code> which represents a value offset from the <code>ref</code> point oriented based on the nearest line segment.
+ */
+ static public Point offsetFromRelativeCoordinate(IFigure label, Rectangle bounds, Point ref) {
+ return offsetFromRelativeCoordinate(label, bounds, getParentPointList(label), ref);
+ }
+
+ /**
+ * Calculates the label offset from the reference point given the label bounds and a points list.
+ *
+ * @param label
+ * the <code>IFigure</code> to calculate the offset for
+ * @param bounds
+ * the <code>Rectangle</code> that is the bounding box of the label.
+ * @param points
+ * the <code>PointList</code> that contains that the label offset is relative to.
+ * @param ref
+ * the <code>Point</code> that is the reference point that the offset
+ * is based on.
+ * @return a <code>Point</code> which represents a value offset from the <code>ref</code> point oriented based on the nearest line segment.
+ */
+ static public Point offsetFromRelativeCoordinate(IFigure label, Rectangle bounds, PointList points, Point ref) {
+ Rectangle rect = new Rectangle(bounds);
+
+ // Componsate for the fact that we are using the
+ // figure center
+ rect.translate(rect.width / 2, rect.height / 2);
+
+ Point normalPoint = normalizeRelativePointToPointOnLine(points, ref,
+ new Point(rect.x - ref.x, rect.y - ref.y));
+
+ return normalPoint;
+ }
+
+ /**
+ * Calculates the relative coordinate that is equivalent to the offset from the reference
+ * point, that can be used to set the label location.
+ *
+ * @param label
+ * the <code>IFigure</code> to calculate the relative coordinate for
+ * @param ref
+ * a <code>Point</code> located on the parent which the offset value
+ * is relative to.
+ * @param offset
+ * a <code>Point</code> which represents a value offset from the <code>ref</code> point oriented based on the nearest line segment.
+ * @return a <code>Point</code> that is the relative coordinate of the label that can be
+ * used to set it's location.
+ */
+ static public Point relativeCoordinateFromOffset(IFigure label, Point ref, Point offset) {
+ return relativeCoordinateFromOffset(label, getParentPointList(label), ref, offset);
+ }
+
+ /**
+ * Calculates the relative coordinate that is equivalent to the offset from the reference
+ * point, that can be used to set the label location.
+ *
+ * @param label
+ * the <code>IFigure</code> to calculate the relative coordinate for
+ * @param points
+ * the <code>PointList</code> that contains that the label offset is relative to.
+ * @param ref
+ * a <code>Point</code> located on the parent which the offset value
+ * is relative to.
+ * @param offset
+ * a <code>Point</code> which represents a value offset from the <code>ref</code> point oriented based on the nearest line segment.
+ * @return a <code>Point</code> that is the relative coordinate of the label that can be
+ * used to set it's location.
+ */
+ static private Point relativeCoordinateFromOffset(IFigure label, PointList points, Point ref, Point offset) {
+ Point location = calculatePointRelativeToPointOnLine(points, ref, offset);
+ int dx = 0;
+ int dy = 0;
+
+ // switch (textAlignment) {
+ // case PositionConstants.LEFT:
+ // dx = 0;
+ // break;
+ // case PositionConstants.RIGHT:
+ // dx = -label.getBounds().width;
+ // break;
+ // case PositionConstants.MIDDLE:
+ // dx = -1 * label.getBounds().width / 2;
+ // break;
+ // default:
+ // dx = label.getBounds().width / 2;
+ // break;
+ // }
+ dx = -1 * label.getBounds().width / 2;
+ dy = -1 * label.getBounds().height / 2;
+ location.translate(dx, dy);
+
+ return location;
+ }
+
+ /**
+ * gets the point list using the passed figure to get the parent
+ *
+ * @param label
+ * the <code>IFigure</code> to use to retrieve the parent points
+ * @return List of points
+ */
+ static public PointList getParentPointList(IFigure label) {
+ IFigure parent = label.getParent();
+ if (parent instanceof Connection) {
+ return ((Connection) parent).getPoints();
+ } else {
+ PointList ptList = new PointList();
+ ptList.addPoint(parent.getBounds().getLocation());
+ return ptList;
+ }
+ }
+
+ /**
+ * Returns a point located relative to the line by the given offset.
+ *
+ * @param ptLst
+ * the point
+ * @param ptOnLine
+ * @param offset
+ * @return the relative point given the line angle
+ */
+ protected static Point calculatePointRelativeToPointOnLine(PointList ptLst, Point ptOnLine, Point offset) {
+ // Calculate slope of line
+ if (ptLst.size() == 1) {
+ // This is a node...
+ return ptLst.getFirstPoint().getTranslated(offset);
+ } else if (ptLst.size() >= 2) {
+ // This is a edge...
+ int index = PointListUtilities.findNearestLineSegIndexOfPoint(ptLst, ptOnLine);
+ if (index < 1) {
+ return ptLst.getFirstPoint().getTranslated(offset);
+ }
+ LineSeg segment = (LineSeg) PointListUtilities.getLineSegments(ptLst).get(index - 1);
+ Point relativeOffset = null;
+ if (segment != null) {
+ if (segment.isHorizontal()) {
+ if (segment.getOrigin().x > segment.getTerminus().x) {
+ relativeOffset = ptOnLine.getTranslated(offset.getNegated());
+ // System.out.println("1. Relative offset: " + relativeOffset);//$NON-NLS-1$
+ return relativeOffset;
+ } else {
+ relativeOffset = ptOnLine.getTranslated(offset);
+ // System.out.println("2. Relative offset: " + relativeOffset);//$NON-NLS-1$
+ return relativeOffset;
+ }
+ } else if (segment.isVertical()) {
+ if (segment.getOrigin().y > segment.getTerminus().y) {
+ relativeOffset = ptOnLine.getTranslated(offset.getCopy().scale(-1, 1).transpose());
+ // System.out.println("3. Relative offset: " + relativeOffset);//$NON-NLS-1$
+ return relativeOffset;
+ } else {
+ relativeOffset = ptOnLine.getTranslated(offset.getCopy().scale(1, -1).transpose());
+ // System.out.println("4. Relative offset: " + relativeOffset);//$NON-NLS-1$
+ return relativeOffset;
+ }
+ } else {
+ double slope = segment.slope();
+ double theta = Math.atan(slope);
+ Point normalizedOffset = new Point(offset);
+ Point calculatedOffset = new Point();
+ if (segment.getOrigin().x > segment.getTerminus().x) {
+ normalizedOffset = offset.getCopy().scale(-1, -1);
+ }
+
+ calculatedOffset = new Point(normalizedOffset.x
+ * Math.cos(theta) - normalizedOffset.y
+ * Math.sin(theta), normalizedOffset.x * Math.sin(theta)
+ + normalizedOffset.y * Math.cos(theta));
+ relativeOffset = ptOnLine.getTranslated(calculatedOffset);
+ // System.out.println("5. Relative offset: " + relativeOffset);//$NON-NLS-1$
+ return relativeOffset;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Calculates the normalized offset from a point on a <code>Connection</code>'s point list to an point.
+ *
+ * @param ptLst
+ * @param ptOnLine
+ * @param offset
+ * @return the normalized offset
+ */
+ private static Point normalizeRelativePointToPointOnLine(PointList ptLst, Point ptOnLine, Point offset) {
+ // Calculate slope of line
+ if (ptLst.size() == 1) {
+ // This is a node...
+ return offset;
+ } else if (ptLst.size() >= 2) {
+ // This is a edge...
+ int index = PointListUtilities.findNearestLineSegIndexOfPoint(ptLst, ptOnLine);
+ LineSeg segment = (LineSeg) PointListUtilities.getLineSegments(ptLst).get(index - 1);
+ Point normalOffset = null;
+ if (segment != null) {
+ if (segment.isHorizontal()) {
+ if (segment.getOrigin().x > segment.getTerminus().x) {
+ normalOffset = offset.getNegated();
+ //System.out.println("1. Normal offset: " + normalOffset);//$NON-NLS-1$
+ return normalOffset;
+ } else {
+ normalOffset = offset;
+ //System.out.println("2. Normal offset: " + normalOffset);//$NON-NLS-1$
+ return normalOffset;
+ }
+ } else if (segment.isVertical()) {
+ if (segment.getOrigin().y < segment.getTerminus().y) {
+ normalOffset = offset.scale(-1, 1).transpose();
+ //System.out.println("3. Normal offset: " + normalOffset);//$NON-NLS-1$
+ return normalOffset;
+ } else {
+ normalOffset = offset.scale(1, -1).transpose();
+ //System.out.println("4. Normal offset: " + normalOffset);//$NON-NLS-1$
+ return normalOffset;
+ }
+ } else {
+ Point p = ptOnLine.getTranslated(offset);
+ normalOffset = getOrthogonalDistances(segment, ptOnLine, p);
+ //System.out.println("5. Normal offset: " + normalOffset);//$NON-NLS-1$
+ return normalOffset;
+ }
+ }
+ }
+ return null;
+
+ }
+
+ /**
+ * Calculates distances from a <code>Point</code> on a <code>LineSeg</code> to
+ * another <code>Point</code>. The sign of the distances indicate direction.
+ *
+ * @param lineSeg
+ * @param ptOnLine
+ * @param refPoint
+ * @return the distance from <code>Point</code> on a <code>LineSeg</code> to another <code>Point</code>
+ */
+ private static Point getOrthogonalDistances(LineSeg lineSeg, Point ptOnLine, Point refPoint) {
+ LineSeg parallelSeg = lineSeg.getParallelLineSegThroughPoint(refPoint);
+ Point p1 = parallelSeg.perpIntersect(ptOnLine.x, ptOnLine.y);
+ double dx = p1.getDistance(refPoint) * ((p1.x > refPoint.x) ? -1 : 1);
+ double dy = p1.getDistance(ptOnLine) * ((p1.y < ptOnLine.y) ? -1 : 1);
+ Point orth = new Point(dx, dy);
+ // Reflection in the y axis
+ if (lineSeg.getOrigin().x > lineSeg.getTerminus().x) {
+ orth = orth.scale(-1, -1);
+ }
+ return orth;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/locator/IPapyrusBorderItemLocator.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/locator/IPapyrusBorderItemLocator.java
new file mode 100644
index 00000000000..b23e15f9d30
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/locator/IPapyrusBorderItemLocator.java
@@ -0,0 +1,112 @@
+/*****************************************************************************
+ * Copyright (c) 2010, 2014 CEA LIST 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:
+ * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.locator;
+
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * The Interface IPapyrusBorderItemLocator.
+ *
+ */
+public interface IPapyrusBorderItemLocator extends IBorderItemLocator {
+
+
+ /**
+ * Gets the position.
+ *
+ * @return the position
+ */
+ public int getPosition();
+
+ /**
+ * Sets the position.
+ *
+ * @param position
+ * the position to set
+ */
+ public void setPosition(int position);
+
+ /**
+ * Gets the offset.
+ *
+ * @return the offset
+ */
+ public Dimension getOffset();
+
+ /**
+ * Sets the offset.
+ *
+ * @param offset
+ * the offset to set
+ */
+ public void setOffset(Dimension offset);
+
+ /**
+ * Checks if is constrained.
+ *
+ * @return the constrained
+ */
+ public boolean isConstrained();
+
+ /**
+ * Sets the constrained.
+ *
+ * @param constrained
+ * the constrained to set
+ */
+ public void setConstrained(boolean constrained);
+
+ /**
+ * Sets the text alignment.
+ *
+ * @param textAlignment
+ * the new text alignment
+ */
+ public void setTextAlignment(int textAlignment);
+
+ /**
+ * Checks if is initialize.
+ *
+ * @return true, if is initialize
+ */
+ public boolean isInitialize();
+
+ /**
+ * Sets the view.
+ *
+ * @param model
+ * the new view
+ */
+ public void setView(View model);
+
+ /**
+ * Sets the editpart.
+ *
+ * @param editpart
+ * the new editpart
+ */
+ public void setEditpart(EditPart editpart);
+
+ /**
+ * Sets the margin.
+ *
+ * @param margin
+ * the new margin
+ */
+ public void setMargin(Point margin);
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/locator/PapyrusLabelLocator.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/locator/PapyrusLabelLocator.java
new file mode 100644
index 00000000000..18f22a38e20
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/locator/PapyrusLabelLocator.java
@@ -0,0 +1,281 @@
+/*****************************************************************************
+ * Copyright (c) 2010, 2014 CEA LIST 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:
+ * Micka√ęl ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.locator;
+
+
+import org.eclipse.draw2d.AbstractLocator;
+import org.eclipse.draw2d.Connection;
+import org.eclipse.draw2d.ConnectionLocator;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PointList;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gmf.runtime.diagram.ui.internal.util.LabelViewConstants;
+import org.eclipse.gmf.runtime.draw2d.ui.geometry.PointListUtilities;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.PapyrusLabelHelper;
+
+/**
+ * Label locator that supports locating labels whose parent is either a Node or
+ * and Edge.
+ *
+ */
+public class PapyrusLabelLocator extends AbstractLocator {
+
+ /** The alignment. */
+ private int alignment;
+
+ /** The extent. */
+ private Dimension extent;
+
+ /** The margin. */
+ private Point margin = new Point();
+
+ /** The offset. */
+ private Point offset;
+
+ /** the parent figure of this locator. */
+ protected IFigure parent;
+
+ /** The text alignment. */
+ private int textAlignment = PositionConstants.MIDDLE;
+
+ /** The view. */
+ private View view;
+
+ /**
+ * Constructor to create a an instance of <code>LabelLocator</code> which locates an IFigure offset relative to a calculated reference point.
+ *
+ * @param parent
+ * the parent figure
+ * @param offSet
+ * the relative location of the label
+ * @param alignment
+ * the alignment hint in the case the parent is a <code>Connection</code>
+ */
+
+ public PapyrusLabelLocator(IFigure parent, Point offSet, int alignment) {
+ this.parent = parent;
+ this.offset = offSet;
+ this.alignment = alignment;
+ }
+
+ /**
+ * Constructor for figure who are located and sized.
+ *
+ * @param parent
+ * the parent
+ * @param bounds
+ * the bounds
+ * @param alignment
+ * the alignment
+ */
+ public PapyrusLabelLocator(IFigure parent, Rectangle bounds, int alignment) {
+ this(parent, bounds.getLocation(), alignment);
+ this.extent = bounds.getSize();
+ }
+
+ /**
+ * Returns the alignment of ConnectionLocator.
+ *
+ * @return The alignment
+ *
+ */
+ public int getAlignment() {
+ return alignment;
+ }
+
+ /**
+ * Gets the location.
+ *
+ * @return the location
+ */
+ @SuppressWarnings("restriction")
+ private int getLocation() {
+ switch (getAlignment()) {
+ case ConnectionLocator.SOURCE:
+ return LabelViewConstants.TARGET_LOCATION;
+ case ConnectionLocator.TARGET:
+ return LabelViewConstants.SOURCE_LOCATION;
+ case ConnectionLocator.MIDDLE:
+ return LabelViewConstants.MIDDLE_LOCATION;
+ default:
+ return LabelViewConstants.MIDDLE_LOCATION;
+ }
+ }
+
+ /**
+ * getter for the offset point.
+ *
+ * @return point
+ */
+ public Point getOffset() {
+ return this.offset;
+ }
+
+ /**
+ * Returns the <code>PointList</code> describing the label's parent.
+ *
+ * @return pointList
+ */
+ protected PointList getPointList() {
+ if (parent instanceof Connection) {
+ return ((Connection) parent).getPoints();
+ } else {
+ PointList ptList = new PointList();
+ ptList.addPoint(parent.getBounds().getLocation());
+ return ptList;
+ }
+ }
+
+ /**
+ * Returns the reference point for the locator.
+ *
+ * @return the reference point
+ */
+ @Override
+ public Point getReferencePoint() {
+ if (parent instanceof Connection) {
+ PointList ptList = ((Connection) parent).getPoints();
+ return PointListUtilities.calculatePointRelativeToLine(ptList, 0, getLocation(), true);
+ } else {
+ return parent.getBounds().getLocation();
+ }
+ }
+
+ /**
+ * Gets the size.
+ *
+ * @return the size
+ */
+ public Dimension getSize() {
+ return extent.getCopy();
+ }
+
+
+ /**
+ * Gets the text alignment.
+ *
+ * @return the textAlignment
+ */
+ public int getTextAlignment() {
+ return textAlignment;
+ }
+
+ /**
+ * Positions the lable relative to the reference point with the
+ * given offsets.
+ *
+ * @param target
+ * the target
+ */
+ @Override
+ public void relocate(IFigure target) {
+
+ // The calculation of the location depends on the size of the shape so the size must be set first.
+ Dimension size = new Dimension();
+
+ if (extent != null) {
+ PapyrusLabelLocator currentConstraint = (PapyrusLabelLocator) target.getParent().getLayoutManager().getConstraint(target);
+ Dimension currentExtent = currentConstraint.getSize();
+ size = new Dimension(currentExtent);
+ if (currentExtent.width == -1) {
+ size.width = target.getPreferredSize().width;
+ }
+ if (currentExtent.height == -1) {
+ size.height = target.getPreferredSize().height;
+ }
+ target.setSize(size);
+ } else {
+ target.setSize(new Dimension(target.getPreferredSize().width, target.getPreferredSize().height));
+ }
+
+ Point location = null;
+
+ // Calculate the position
+ location = PapyrusLabelHelper.relativeCoordinateFromOffset(target, getReferencePoint(), offset);
+
+ // Translate the position according to the justification
+ switch (textAlignment) {
+ case PositionConstants.LEFT:
+ location.translate(target.getBounds().width / 2, 0);
+ break;
+ case PositionConstants.RIGHT:
+ location.translate(-target.getBounds().width / 2, 0);
+ break;
+ case PositionConstants.CENTER:
+ break;
+ default:
+ break;
+ }
+
+ // Set the location
+ target.setLocation(location);
+ }
+
+ /**
+ * Sets the alignment.
+ *
+ * @param alignment
+ * the alignment to set
+ */
+ public void setAlignment(int alignment) {
+ this.alignment = alignment;
+ }
+
+
+ /**
+ * Sets the margin.
+ *
+ * @param margin
+ * the margin to set
+ */
+ public void setMargin(Point margin) {
+ this.margin = margin;
+ }
+
+ /**
+ * setter for the offset point.
+ *
+ * @param offset
+ * the new offset
+ */
+ public void setOffset(Point offset) {
+ this.offset = offset;
+ }
+
+ /**
+ * Sets the text alignment.
+ *
+ * @param textAlignment
+ * the textAlignment to set
+ */
+ public void setTextAlignment(int textAlignment) {
+ this.textAlignment = textAlignment;
+ }
+
+ /**
+ * Sets the view.
+ *
+ * @param view
+ * the new view
+ */
+ public void setView(View view) {
+ this.view = view;
+ }
+
+
+} \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java
index cf2ac4652dd..699f3575b31 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java
@@ -16,12 +16,19 @@ package org.eclipse.papyrus.infra.gmfdiag.common.model;
import java.util.LinkedList;
import java.util.List;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.IntValueStyle;
+import org.eclipse.gmf.runtime.notation.NamedStyle;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.StringValueStyle;
+import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.core.resource.IModel;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.services.ServiceException;
@@ -247,5 +254,85 @@ public class NotationUtils {
throw new RuntimeException("Resource Set is not a ModelSet or is null"); //$NON-NLS-1$
}
}
+
+
+ /**
+ * @param view
+ * @param property
+ * @param defaultValue
+ * @return Integer corresponding to the property
+ */
+ public static int getIntValue(View view, String property, int defaultInt) {
+ int value = defaultInt;
+ EClass intValueStyle = NotationPackage.eINSTANCE.getIntValueStyle();
+ NamedStyle style ;
+
+ if (intValueStyle != null){
+
+ style = view.getNamedStyle(intValueStyle, property);
+
+ if (style != null){
+ if (style instanceof IntValueStyle){
+ value = ((IntValueStyle) style).getIntValue();
+ }
+ }
+ }
+
+ return value;
+ }
+
+
+
+ /**
+ * @param view
+ * @param property
+ * @param defaultValue
+ * @return Boolean corresponding to the property
+ */
+ public static boolean getBooleanValue(View view, String property, boolean defaultValue) {
+ boolean value = defaultValue;
+ EClass booleanValueStyle = NotationPackage.eINSTANCE.getBooleanValueStyle();
+ NamedStyle style ;
+
+ if (booleanValueStyle != null){
+
+ style = view.getNamedStyle(booleanValueStyle, property);
+
+ if (style != null){
+ if (style instanceof BooleanValueStyle){
+ value = ((BooleanValueStyle) style).isBooleanValue();
+ }
+ }
+ }
+
+ return value;
+ }
+
+
+ /**
+ * @param view
+ * @param property
+ * @param defaultValue
+ * @return String corresponding to the property
+ */
+ public static String getStringValue(View view, String property, String defaultValue) {
+ String value = defaultValue;
+ EClass stringValueStyle = NotationPackage.eINSTANCE.getStringValueStyle();
+ NamedStyle style ;
+
+ if (stringValueStyle != null){
+
+ style = view.getNamedStyle(stringValueStyle, property);
+
+ if (style != null){
+ if (style instanceof StringValueStyle){
+ value = ((StringValueStyle) style).getStringValue();
+ }
+ }
+ }
+
+ return value;
+ }
+
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/FigureUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/FigureUtils.java
new file mode 100644
index 00000000000..2ca645313d4
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/FigureUtils.java
@@ -0,0 +1,148 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.draw2d.FigureUtilities;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.LayeredPane;
+import org.eclipse.draw2d.ScalableFigure;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure;
+
+public final class FigureUtils {
+
+ private FigureUtils() {
+ // utility class
+ }
+
+ /**
+ * Returns a child figure of the given type recursively contained in the given parent figure.
+ *
+ * @param parent
+ * the parent figure
+ * @param childFigureClass
+ * the type of the child figure that is looked for
+ * @return the child figure if found, or <code>null</code> if the parent figure contains no child figure of the
+ * given type
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends IFigure> T findChildFigureInstance(final IFigure parent, final Class<T> childFigureClass) {
+ final List<IFigure> children = parent.getChildren();
+ for (final IFigure child : children) {
+ if (childFigureClass.isAssignableFrom(child.getClass())) {
+ return (T) child;
+ }
+ // look recursively
+ final IFigure subresult = findChildFigureInstance(child, childFigureClass);
+ if (subresult != null) {
+ return (T) subresult;
+ }
+ }
+ // not found
+ return null;
+ }
+
+ public static <T extends IFigure> List<T> findChildFigureInstances(final IFigure parent, final Class<T> childFigureClass) {
+ final List<T> result = new ArrayList<T>();
+ internalFindChildFigureInstances(parent, result, childFigureClass);
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T extends IFigure> void internalFindChildFigureInstances(final IFigure parent, final List<T> result, final Class<T> childFigureClass) {
+ final List<IFigure> children = parent.getChildren();
+ for (final IFigure child : children) {
+ if (childFigureClass.isAssignableFrom(child.getClass())) {
+ result.add((T) child);
+ } else {
+ internalFindChildFigureInstances(child, result, childFigureClass);
+ }
+
+ }
+ }
+
+ /**
+ * Returns the first parent figure of the given type recursively containing the given figure.
+ *
+ * @param figure
+ * the figure
+ * @param parentFigureClass
+ * the type of the parent figure that is looked for
+ * @return the parent figure if found, or <code>null</code> if the figure is not contained by any figure of the
+ * given type
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends IFigure> T findParentFigureInstance(final IFigure figure, final Class<T> parentFigureClass) {
+ IFigure parent = figure.getParent();
+ while (parent != null) {
+ if (parentFigureClass.isAssignableFrom(parent.getClass())) {
+ return (T) parent;
+ }
+ parent = parent.getParent();
+ }
+ return null;
+ }
+
+ /**
+ * Constrain the given bounds (whose presumed purpose is to become the new bounds for the given Figure), so that
+ * they don't stick out of the bounds of the {@link ResizableCompartmentFigure} in which the given figure is
+ * contained. Returns the original bounds if the given Figure is not contained in a {@link ResizableCompartmentFigure}.
+ *
+ * @param bounds
+ * The bounds to constrain (will not be modified)
+ * @param figure
+ * the figure in the containing {@link ResizableCompartmentFigure} of which the bound must be constrained
+ * @return the bounds, constrained so that they don't stick out of the {@link ResizableCompartmentFigure} in which
+ * the Figure is contained
+ *
+ */
+ public static Rectangle constrainBoundsWithinContainingCompartment(final Rectangle bounds, final IFigure figure) {
+ final Rectangle result = new Rectangle(bounds);
+ final ResizableCompartmentFigure parentCompartment = FigureUtils.findParentFigureInstance(figure, ResizableCompartmentFigure.class);
+ if (parentCompartment == null) {
+ return result;
+ }
+ final Rectangle parentBounds = parentCompartment.getBounds();
+ result.x = Math.max(result.x, 0);
+ result.y = Math.max(result.y, 0);
+ result.x = Math.min(result.x, parentBounds.width - result.width);
+ result.y = Math.min(result.y, parentBounds.height - result.height);
+ return result;
+ }
+
+ /**
+ * @return The origin of the coordinate system applied to the given figure (i.e.: the amount scrolled in the scroll
+ * pane)
+ */
+ public static Point getLayeredPaneOrigin(final IFigure figure) {
+ final LayeredPane layeredPane = FigureUtils.findChildFigureInstance(FigureUtilities.getRoot(figure), LayeredPane.class);
+ final Point origin = new Point(0, 0);
+ layeredPane.translateToRelative(origin);
+ return origin;
+ }
+
+ /**
+ * @return The scale applied to the given figure (i.e.: the zoom set by the user)
+ */
+ public static double getScale(final IFigure figure) {
+ final ScalableFigure scalableFigure = FigureUtils.findParentFigureInstance(figure, ScalableFigure.class);
+ return scalableFigure.getScale();
+ }
+
+ public static Point scaleByZoom(final Point delta, final IFigure figure) {
+ return new Point(delta).scale(1.0 / getScale(figure));
+ }
+
+}

Back to the top