Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael ADAM2014-09-09 15:00:59 +0000
committerMickael ADAM2014-09-23 12:06:57 +0000
commit3d8a37d4c55ba794588e8f17d5abc89aa9a8fcb4 (patch)
tree6072e6f533d7c79e7cde62a70c1cd5a1fef6445b /plugins/infra
parent802249ab83497e7e4f8b472a89c92b3486db874b (diff)
downloadorg.eclipse.papyrus-3d8a37d4c55ba794588e8f17d5abc89aa9a8fcb4.tar.gz
org.eclipse.papyrus-3d8a37d4c55ba794588e8f17d5abc89aa9a8fcb4.tar.xz
org.eclipse.papyrus-3d8a37d4c55ba794588e8f17d5abc89aa9a8fcb4.zip
440226: [All Diagrams] Allow Left side label edition (not only right
side ) https://bugs.eclipse.org/bugs/show_bug.cgi?id=440226 Patch Set 1: -Squach Previous commit Description of previous Patch Set: Patch set 1 - Applied new locator to Port of component diagram - add method to notationUtils to getIntValue etc.. Patch Set 3: -Implementation of text alignment for PortNameEP and PapyrusLabelEP(Label from connection) -Add button/command to set alignement -Fix custumStyleValueCommand Patch Set 4: -Implementation for SysML -Use of PapyrusEditPart for PortEditPart -Some Fix -TODO use generation to chance override of the portEditPart(xtend already change, but code not generated). This must be do for each diagram. It will be do on an other commit. Patch Set 2: -fix on xtend Patch set 3 et 4 et 5: -fix conflict resolved error Change-Id: Ie0699d213abd4a7c39f8cff457c7dfe27a41eba3 Signed-off-by: Mickael ADAM <mickael.adam@ALL4TEC.net>
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF161
-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.java477
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/RefreshTextAlignmentEditPolicy.java115
-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.java94
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/locator/PapyrusLabelLocator.java333
7 files changed, 1377 insertions, 267 deletions
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 1effd1c4ca7..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,80 +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,
- 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/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 d3cf12ce35e..bfb924e4a7b 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
@@ -1,101 +1,378 @@
-/*****************************************************************************
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net
- * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 443235
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
-
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
-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.figure.IPapyrusWrappingLabel;
-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 = 1;
-
- /**
- * CSS Integer property to define the horizontal Label Margin
- */
- static final String X_MARGIN_PROPERTY = "xMarginLabel";
-
- /**
- * CSS Integer property to define the vertical Label Margin
- */
- static final String Y_MARGIN_PROPERTY = "yMarginLabel";
-
-
- public PapyrusLabelEditPart(View view) {
- super(view);
- }
-
- @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());
- }
-
-
-
- /**
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart#refreshVisuals()
- *
- */
- @Override
- protected void refreshVisuals() {
- super.refreshVisuals();
- refreshLabelMargin();
- }
-
- /**
- *
- */
- public void refreshLabelMargin() {
- IFigure figure = null;
-
- int horizontalMargin = DEFAULT_MARGIN;
- int verticalMargin= DEFAULT_MARGIN;
-
- Object model = this.getModel();
-
-
-
- if (model instanceof View) {
- horizontalMargin = NotationUtils.getIntValue((View)model, X_MARGIN_PROPERTY, DEFAULT_MARGIN);
- verticalMargin = NotationUtils.getIntValue((View)model, Y_MARGIN_PROPERTY, DEFAULT_MARGIN);
- }
-
- if (this instanceof GraphicalEditPart){
- figure = ((GraphicalEditPart) this).getFigure();
-
- if (figure instanceof IPapyrusWrappingLabel){
- ((IPapyrusWrappingLabel)figure).setMarginLabel(horizontalMargin, verticalMargin);
- }
-
- }
-
-
- }
-
+/*****************************************************************************
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net
+ * 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 = 1;
+
+ /**
+ * CSS Integer property to define the horizontal Label Margin
+ */
+ static final String X_MARGIN_PROPERTY = "xMarginLabel";
+
+ /**
+ * CSS Integer property to define the vertical Label Margin
+ */
+ static final String Y_MARGIN_PROPERTY = "yMarginLabel";
+
+ /** The Constant TEXT_ALIGNMENT. */
+ private static final String TEXT_ALIGNMENT = "textAlignment";
+
+ /** The Constant LABEL_OFFSET_Y. */
+ private static final String LABEL_OFFSET_Y = "labelOffsetY";
+
+ /** The Constant LABEL_OFFSET_X. */
+ private static final String LABEL_OFFSET_X = "labelOffsetX";
+
+ /** The Constant LABEL_CONSTRAINED. */
+ private static final String LABEL_CONSTRAINED = "labelConstrained";
+
+ /** The label locator. */
+ protected PapyrusLabelLocator labelLocator;
+
+ /** The external label locator. */
+ protected IPapyrusBorderItemLocator externalLabelLocator;
+
+
+ public PapyrusLabelEditPart(View view) {
+ super(view);
+ }
+
+ @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 (labelLocator != null) {
+ labelLocator.setOffset(offset);
+ } else {
+ labelLocator = new PapyrusLabelLocator(connectionFigure, offset, getKeyPoint());
+ }
+ labelLocator.setTextAlignment(getTextAlignment());
+ labelLocator.setView((View) getModel());
+ parentEditPart.setLayoutConstraint(this, getFigure(), labelLocator);
+
+ } else {
+ setExternalLabelLocator(offset);
+ getFigure().getParent().setConstraint(getFigure(), externalLabelLocator);
+ }
+ }
+
+ /**
+ * Sets the external label locator.
+ *
+ * @param offset
+ * the new external label locator
+ */
+ private void setExternalLabelLocator(Point offset) {
+ if (externalLabelLocator == null) {
+ externalLabelLocator = (IPapyrusBorderItemLocator) getBorderItemLocator();
+ }
+ if (offset != null) {
+ externalLabelLocator.setConstraint(new Rectangle(offset.x, offset.y, 0, 0));
+ }
+ externalLabelLocator.setView((View) getModel());
+ externalLabelLocator.setTextAlignment(getTextAlignment());
+ externalLabelLocator.setPosition(getPositionOnParent());
+ }
+
+ /**
+ * 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();
+ // View eContainer = (View) model.eContainer();// Pas sur le eContainer
+ 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;
+ }
+
+ /**
+ * 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) {
+ boolean labelConstrained = NotationUtils.getBooleanValue((View) getModel(), LABEL_CONSTRAINED, getDefaultLabelConstrained());
+ // set the value on the locator
+ ((IPapyrusBorderItemLocator) getBorderItemLocator()).setConstrained(labelConstrained);
+ }
+ // Set the position from the parent position
+ ((IPapyrusBorderItemLocator) getBorderItemLocator()).setPosition(getPositionOnParent());
+ }
+
+ /**
+ * Refresh label text alignement.
+ */
+ private void refreshLabelTextAlignement() {
+ ((IPapyrusBorderItemLocator) getBorderItemLocator()).setTextAlignment(getTextAlignment());
+ }
+
+ /**
+ * Gets the position on parent.
+ *
+ * @return the position on parent
+ */
+ public int getPositionOnParent() {
+ Rectangle portBounds = null;
+ Rectangle parentBounds = null;
+ int position = PositionConstants.EAST;
+
+ // Get the port figure
+ if (getParent() instanceof IPapyrusEditPart) {
+ IFigure portPrimaryShape = ((IPapyrusEditPart) getParent()).getPrimaryShape();
+ portBounds = portPrimaryShape.getBounds();
+
+ // Get the port's parent figure
+ // if it's a papyrus edit part and the figure is paint(width !=0)
+ if (getParent().getParent() instanceof IPapyrusEditPart && portBounds.width != 0) {
+ IFigure parentPrimaryShape = ((IPapyrusEditPart) getParent().getParent()).getPrimaryShape();
+ parentBounds = parentPrimaryShape.getBounds();
+
+ if (portBounds.x + portBounds.width / 2 == parentBounds.x) {
+ // West position
+ position = PositionConstants.WEST;
+ } else if (portBounds.x + portBounds.width / 2 == parentBounds.getBottomRight().x) {
+ // East Position
+ position = PositionConstants.EAST;
+ } else if (portBounds.y + portBounds.height / 2 == parentBounds.y) {
+ position = PositionConstants.NORTH;
+ } else if (portBounds.y + portBounds.height / 2 == parentBounds.getBottomRight().y) {
+ position = PositionConstants.SOUTH;
+ }
+ }
+ }
+
+ return position;
+ }
+
+ /**
+ * 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 horizontalMargin = DEFAULT_MARGIN;
+ int verticalMargin = DEFAULT_MARGIN;
+
+ Object model = this.getModel();
+
+
+
+ if (model instanceof View) {
+ horizontalMargin = NotationUtils.getIntValue((View) model, X_MARGIN_PROPERTY, DEFAULT_MARGIN);
+ verticalMargin = NotationUtils.getIntValue((View) model, Y_MARGIN_PROPERTY, DEFAULT_MARGIN);
+ }
+
+ figure = ((GraphicalEditPart) this).getFigure();
+
+ if (figure instanceof IPapyrusWrappingLabel) {
+ ((IPapyrusWrappingLabel) figure).setMarginLabel(horizontalMargin, verticalMargin);
+ }
+
+ }
+
} \ 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/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..6d41ebf2463
--- /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,115 @@
+/*****************************************************************************
+ * 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.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
+import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.gef.ui.internal.editpolicies.GraphicalEditPolicyEx;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomStringStyleObservableValue;
+
+/**
+ * this edit policy has in charge to refresh the edit part when text alignment change.
+ */
+public class RefreshTextAlignmentEditPolicy extends GraphicalEditPolicyEx implements IChangeListener, NotificationListener {
+
+ /** The Constant TEXT_ALIGNMENT. */
+ public static final String TEXT_ALIGNMENT = "textAlignment";
+
+ /** key for this edit policy. */
+ public final static String REFRESH_TEXT_ALIGNMENT_EDITPOLICY = "REFRESH_TEXT_ALIGNMENT_EDITPOLICY";
+
+ /** The style observable. */
+ protected IObservableValue styleObservable;
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void activate() {
+ // retrieve the view and the element managed by the edit part
+ View view = (View) getHost().getModel();
+ if (view == null) {
+ return;
+ }
+
+ styleObservable = new CustomStringStyleObservableValue(view, EMFHelper.resolveEditingDomain(view), TEXT_ALIGNMENT);
+ styleObservable.addChangeListener(this);
+
+ // adds a listener on the view and the element controlled by the editpart
+ getDiagramEventBroker().addNotificationListener(view, this);
+ getDiagramEventBroker().addNotificationListener(view.eContainer(), this);
+
+ EObject semanticElement = EMFHelper.getEObject(getHost());
+ if (semanticElement != null) {
+ getDiagramEventBroker().addNotificationListener(semanticElement, this);
+ }
+ getHost().refresh();
+ }
+
+ /**
+ * Gets the diagram event broker from the editing domain.
+ *
+ * @return the diagram event broker
+ */
+ protected DiagramEventBroker getDiagramEventBroker() {
+ TransactionalEditingDomain theEditingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
+ if (theEditingDomain != null) {
+ return DiagramEventBroker.getInstance(theEditingDomain);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void deactivate() {
+ if (styleObservable != null) {
+ styleObservable.removeChangeListener(this);
+ styleObservable.dispose();
+ styleObservable = null;
+ }
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener#notifyChanged(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ */
+ @Override
+ public void notifyChanged(Notification notification) {
+ getHost().refresh();
+ }
+
+ /**
+ * @see org.eclipse.core.databinding.observable.IChangeListener#handleChange(org.eclipse.core.databinding.observable.ChangeEvent)
+ *
+ * @param event
+ */
+ @Override
+ public void handleChange(ChangeEvent event) {
+ getHost().refresh();
+ }
+}
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..2163e676cdd
--- /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,94 @@
+/*****************************************************************************
+ * 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.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);
+}
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..0997ab1d624
--- /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,333 @@
+/*****************************************************************************
+ * 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.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.diagram.ui.internal.util.LabelViewConstants;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
+import org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg;
+import org.eclipse.gmf.runtime.draw2d.ui.geometry.PointListUtilities;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+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 parent figure of this locator. */
+ protected IFigure parent;
+
+ /** The alignment. */
+ private int alignment;
+
+ /** The offset. */
+ private Point offset;
+
+ /** The extent. */
+ private Dimension extent;
+
+ /** The cached string. */
+ private String cachedString;
+
+ /** The text alignment. */
+ private int textAlignment = PositionConstants.MIDDLE;
+
+ /**
+ * Gets the text alignment.
+ *
+ * @return the textAlignment
+ */
+ public int getTextAlignment() {
+ return textAlignment;
+ }
+
+ /**
+ * Sets the text alignment.
+ *
+ * @param textAlignment
+ * the textAlignment to set
+ */
+ public void setTextAlignment(int textAlignment) {
+ this.textAlignment = textAlignment;
+ }
+
+ /** The cached bounds. */
+ private Rectangle cachedBounds = new Rectangle();
+ // private int dx;
+ /** The cached offset. */
+ private Point cachedOffset;
+
+ /** The view. */
+ private View view;
+
+ /** The cached segment. */
+ private LineSeg cachedSegment;
+
+ /**
+ * 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();
+ }
+
+ /**
+ * getter for the offset point.
+ *
+ * @return point
+ */
+ public Point getOffset() {
+ return this.offset;
+ }
+
+ /**
+ * setter for the offset point.
+ *
+ * @param offset
+ * the new offset
+ */
+ public void setOffset(Point offset) {
+ this.offset = offset;
+ }
+
+ /**
+ * 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));
+ }
+
+ // Get the segment
+ PointList ptLst = PapyrusLabelHelper.getParentPointList(target);
+ int index = PointListUtilities.findNearestLineSegIndexOfPoint(ptLst, getReferencePoint());
+ LineSeg segment = (LineSeg) PointListUtilities.getLineSegments(ptLst).get(index - 1);
+
+ Point location = null;
+ // If it's a rename
+ if (cachedString != null && !cachedString.equals(((WrappingLabel) target).getText())) {
+ // System.out.println("Rename");
+ // location = PapyrusLabelHelper.relativeCoordinateFromOffset(target, getReferencePoint(), offSet, textAlignment);
+ location = cachedBounds.getLocation();
+
+ int x;
+ int textWidth = ((IFigure) target.getChildren().get(0)).getBounds().width;
+
+ // Set Location
+ switch (textAlignment) {
+ case PositionConstants.LEFT:
+ x = 0;
+ break;
+ case PositionConstants.RIGHT:
+ x = textWidth - cachedBounds.width;
+ break;
+ case PositionConstants.CENTER:
+ x = (textWidth - cachedBounds.width) / 2;
+ break;
+ default:
+ x = 0;
+ break;
+ }
+
+ location.translate(x, 0);
+ IFigure tmpTarget = target;
+ tmpTarget.translate(x, 0);
+ final Point viewLocation = PapyrusLabelHelper.offsetFromRelativeCoordinate(tmpTarget, cachedBounds, getReferencePoint());
+
+ try {
+ TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(view);
+ org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.utils.TransactionHelper.run(domain, new Runnable() {
+
+ @Override
+ public void run() {
+ // Add modelStylesheet to the resource without command
+ ViewUtil.setStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_X(), Integer.valueOf(viewLocation.x));
+ ViewUtil.setStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_Y(), Integer.valueOf(viewLocation.y));
+ }
+ });
+ } catch (Exception e) {
+ System.out.println(e.toString());
+ }
+
+ } else
+ // At the creation or It's a d&d move or // If it a move the connnection
+ if (cachedBounds.height == 0 || !offset.equals(cachedOffset) || !segment.equals(cachedSegment)) {
+ // System.out.println("Creation/open: " + ((WrappingLabel) target).getText() + " offSet: " + offset + " textAlign: " + textAlignment);
+ location = PapyrusLabelHelper.relativeCoordinateFromOffset(target, getReferencePoint(), offset);
+ } else {
+ // nothing change, in refresh case
+ location = cachedBounds.getLocation();
+ }
+
+ // Set the location
+ target.setLocation(location);
+
+ cachedString = ((WrappingLabel) target).getText();
+ cachedBounds = target.getBounds();
+ cachedOffset = offset;
+ cachedSegment = segment;
+ }
+
+ /**
+ * Returns the reference point for the locator.
+ *
+ * @return the reference point
+ */
+ @Override
+ protected 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 location.
+ *
+ * @return the location
+ */
+ 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;
+ }
+ }
+
+ /**
+ * Returns the alignment of ConnectionLocator.
+ *
+ * @return The alignment
+ *
+ */
+ public int getAlignment() {
+ return alignment;
+ }
+
+ /**
+ * Sets the alignment.
+ *
+ * @param alignment
+ * the alignment to set
+ */
+ public void setAlignment(int alignment) {
+ this.alignment = alignment;
+ }
+
+
+ /**
+ * Gets the size.
+ *
+ * @return the size
+ */
+ public Dimension getSize() {
+ return extent.getCopy();
+ }
+
+ /**
+ * 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;
+ }
+ }
+
+ /**
+ * Sets the view.
+ *
+ * @param view
+ * the new view
+ */
+ public void setView(View view) {
+ this.view = view;
+ }
+
+
+} \ No newline at end of file

Back to the top