diff options
author | Mickael ADAM | 2014-10-27 16:16:09 +0000 |
---|---|---|
committer | Mickael ADAM | 2014-10-28 10:27:08 +0000 |
commit | 971bab65f2d9b629c915e90e4cd88417958937c4 (patch) | |
tree | 52c22c725b1dbabb29df2ad37d86fb8503af5a82 | |
parent | 38d958f9df4ce4fe65fae133126883a52517824f (diff) | |
download | org.eclipse.papyrus-971bab65f2d9b629c915e90e4cd88417958937c4.tar.gz org.eclipse.papyrus-971bab65f2d9b629c915e90e4cd88417958937c4.tar.xz org.eclipse.papyrus-971bab65f2d9b629c915e90e4cd88417958937c4.zip |
448506: [All Diagram] Bounds of Text Editor when text is aligned on
right/center is false
https://bugs.eclipse.org/bugs/show_bug.cgi?id=448506
Patch set 1:
-Fix it
-> on locator for port Label
-> on MultiLineLabelDirectEditManager for link label
Change-Id: I88b81c92dfd4d5d43ad4608082e8bb7140be3aaf
Signed-off-by: Mickael ADAM <mickael.adam@ALL4TEC.net>
2 files changed, 68 insertions, 16 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/directedit/MultilineLabelDirectEditManager.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/directedit/MultilineLabelDirectEditManager.java index 81558d2188f..033da2713cc 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/directedit/MultilineLabelDirectEditManager.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/directedit/MultilineLabelDirectEditManager.java @@ -30,6 +30,7 @@ import org.eclipse.jface.action.IAction; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; import org.eclipse.papyrus.uml.diagram.common.figure.node.IMultilineEditableFigure; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; @@ -42,8 +43,7 @@ import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.part.CellEditorActionHandler; /** - * Inspired from {@link org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager} - * but use static to avoid concurrency problem on restore (Bug 444063) + * Inspired from {@link org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager} but use static to avoid concurrency problem on restore (Bug 444063) */ public class MultilineLabelDirectEditManager extends DirectEditManagerBase { @@ -52,9 +52,11 @@ public class MultilineLabelDirectEditManager extends DirectEditManagerBase { private static IActionBars actionBars; private CellEditorActionHandler actionHandler; - + protected boolean multiLine = false; + private GraphicalEditPart source; + /** * Constructor. * @@ -64,6 +66,8 @@ public class MultilineLabelDirectEditManager extends DirectEditManagerBase { */ public MultilineLabelDirectEditManager(GraphicalEditPart source, Class editorType, CellEditorLocator locator) { super(source, editorType, locator); + this.source = source; + if (editorType != null && MultiLineCellEditor.class.isAssignableFrom(editorType)) { multiLine = true; } @@ -101,15 +105,14 @@ public class MultilineLabelDirectEditManager extends DirectEditManagerBase { return new TextCellEditor(composite, SWT.MULTI | SWT.WRAP); } return super.createCellEditorOn(composite); - } - + } + /** * constructor - * + * * @param source * <code>GraphicalEditPart</code> to support direct edit of. The - * figure of the <code>source</code> edit part must be of type - * <code>WrapLabel</code>. + * figure of the <code>source</code> edit part must be of type <code>WrapLabel</code>. */ public MultilineLabelDirectEditManager(ITextAwareEditPart source) { super(source); @@ -126,6 +129,7 @@ public class MultilineLabelDirectEditManager extends DirectEditManagerBase { return getCellEditorLocator(source); } + @Override protected CellEditor doCreateCellEditorOn(Composite composite) { ILabelDelegate label = (ILabelDelegate) getEditPart().getAdapter(ILabelDelegate.class); @@ -153,7 +157,7 @@ public class MultilineLabelDirectEditManager extends DirectEditManagerBase { /** * This method is used to set the cell editors text - * + * * @param toEdit * String to be set in the cell editor */ @@ -186,9 +190,25 @@ public class MultilineLabelDirectEditManager extends DirectEditManagerBase { protected void initCellEditor() { super.initCellEditor(); - //Hook the cell editor's copy/paste actions to the actionBars so that they can + if (source instanceof PapyrusLabelEditPart) { + int alignment = ((PapyrusLabelEditPart) source).getTextAlignment(); + Text text = (Text) getCellEditor().getControl(); + switch (alignment) { + case PositionConstants.RIGHT: + text.setOrientation(SWT.RIGHT_TO_LEFT); + break; + case PositionConstants.LEFT: + text.setOrientation(SWT.LEFT_TO_RIGHT); + break; + default: + text.setOrientation(SWT.LEFT_TO_RIGHT); + break; + } + } + + // Hook the cell editor's copy/paste actions to the actionBars so that they can // be invoked via keyboard shortcuts. - + IActionBars editorActionBars = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage().getActiveEditor() .getEditorSite().getActionBars(); @@ -202,7 +222,7 @@ public class MultilineLabelDirectEditManager extends DirectEditManagerBase { actionBars.updateActionBars(); } - + /** * @see org.eclipse.gef.tools.DirectEditManager#bringDown() */ diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/XtextDirectEditManager.java b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/XtextDirectEditManager.java index 681569d9ac4..67c575b858d 100644 --- a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/XtextDirectEditManager.java +++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/XtextDirectEditManager.java @@ -50,6 +50,7 @@ import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.ResourceManager; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; import org.eclipse.papyrus.uml.xtext.integration.core.ContextElementAdapter.IContextElementProvider; import org.eclipse.papyrus.uml.xtext.integration.core.IXtextFakeContextResourcesProvider; import org.eclipse.papyrus.uml.xtext.integration.ui.Activator; @@ -136,7 +137,7 @@ public class XtextDirectEditManager extends DirectEditManagerEx { private IXtextFakeContextResourcesProvider fakeProvider; - private static final int LABEL_MIN_WIDTH = 75; + private static final int LABEL_MIN_WIDTH = 50; private IContextElementProvider contextProvider; @@ -203,7 +204,6 @@ public class XtextDirectEditManager extends DirectEditManagerEx { public void relocate(CellEditor celleditor) { StyledText text = (StyledText) celleditor.getControl(); - Rectangle rect = label.getTextBounds().getCopy(); if (label.getText().length() <= 0) { // if there is no text, let's assume a default size @@ -287,7 +287,39 @@ public class XtextDirectEditManager extends DirectEditManagerEx { } source.getFigure().translateToAbsolute(rect); if (!rect.equals(new Rectangle(text.getBounds()))) { - text.setBounds(rect.x, rect.y, rect.width, rect.height); + // If it's a papyrus Label, needs to manage text alignment + if (source instanceof PapyrusLabelEditPart) { + PapyrusLabelEditPart label = (PapyrusLabelEditPart) source; + int alignment = label.getTextAlignment(); + switch (alignment) { + case PositionConstants.LEFT: + text.setAlignment(SWT.LEFT); + text.setBounds(rect.x, rect.y, rect.width, rect.height); + break; + case PositionConstants.RIGHT: + text.setAlignment(SWT.RIGHT); + if (rect.width <= LABEL_MIN_WIDTH) { + text.setBounds(source.getFigure().getBounds().getTopRight().x - LABEL_MIN_WIDTH, rect.y, rect.width, rect.height); + } else { + text.setBounds(rect.x, rect.y, rect.width, rect.height); + } + break; + case PositionConstants.CENTER: + text.setAlignment(SWT.CENTER); + if (rect.width <= LABEL_MIN_WIDTH) { + text.setBounds(source.getFigure().getBounds().x + source.getFigure().getBounds().width / 2 - LABEL_MIN_WIDTH / 2, rect.y, rect.width, rect.height); + } else { + text.setBounds(rect.x, rect.y, rect.width, rect.height); + } + break; + + default: + text.setBounds(rect.x, rect.y, rect.width, rect.height); + break; + } + } else { + text.setBounds(rect.x, rect.y, rect.width, rect.height); + } } } }; @@ -388,7 +420,7 @@ public class XtextDirectEditManager extends DirectEditManagerEx { IActionBars editorActionBars = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage().getActiveEditor().getEditorSite() .getActionBars(); - if (actionBars != null){ + if (actionBars != null) { restoreSavedActions(editorActionBars); } saveCurrentActions(editorActionBars); |