Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2016-02-11 14:29:48 +0000
committerGerrit Code Review @ Eclipse.org2016-02-18 12:29:40 +0000
commita9fe08a26226520edbf4ff449e1eb1429fe96ad0 (patch)
tree9d8e47c345a97ece898f6980cf918d7762fe69ee
parent2e8c94439179dff0a141c446b82cac403cb68a4b (diff)
downloadorg.eclipse.papyrus-a9fe08a26226520edbf4ff449e1eb1429fe96ad0.tar.gz
org.eclipse.papyrus-a9fe08a26226520edbf4ff449e1eb1429fe96ad0.tar.xz
org.eclipse.papyrus-a9fe08a26226520edbf4ff449e1eb1429fe96ad0.zip
Bug 482790: [table] Column with AcceptEventAction row causes
AssertionException https://bugs.eclipse.org/bugs/show_bug.cgi?id=482790 Manage the simple select reference dialog instead of Text completion when the namespace is null for the object to edit. Change-Id: I057d3ad95214e4f9881959f544e5b25ec22101f3 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/AbstractStyledTextCellEditor.java1103
-rwxr-xr-xplugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/editor/UMLReferenceTextWithCompletionCellEditor.java217
2 files changed, 704 insertions, 616 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/AbstractStyledTextCellEditor.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/AbstractStyledTextCellEditor.java
index 5350b8333d8..476effe46e5 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/AbstractStyledTextCellEditor.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/AbstractStyledTextCellEditor.java
@@ -1,541 +1,562 @@
-/*****************************************************************************
- * Copyright (c) 2013 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.celleditor;
-
-
-
-import org.eclipse.jface.fieldassist.ControlDecoration;
-import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
-import org.eclipse.nebula.widgets.nattable.edit.config.RenderErrorHandling;
-import org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor;
-import org.eclipse.nebula.widgets.nattable.edit.editor.ControlDecorationProvider;
-import org.eclipse.nebula.widgets.nattable.edit.editor.EditorSelectionEnum;
-import org.eclipse.nebula.widgets.nattable.edit.editor.IEditErrorHandler;
-import org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor;
-import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
-import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
-import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
-import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
-import org.eclipse.nebula.widgets.nattable.style.IStyle;
-import org.eclipse.nebula.widgets.nattable.widget.EditModeEnum;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.custom.VerifyKeyListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Text;
-
-/**
- * duplicated code from {@link TextCellEditor}. Here we replace Text by StyledText
- * This code is used with XText Cell Editor
- *
- * @author vl222926
- *
- */
-public abstract class AbstractStyledTextCellEditor extends AbstractCellEditor implements KeyListener {
-
- /**
- * The StyledText control which is the editor wrapped by this TextCellEditor.
- */
- private StyledText text = null;
-
- /**
- * Flag to configure if the wrapped text editor control is editable or not.
- */
- private boolean editable = true;
-
- /**
- * Flag to configure whether the editor should commit and move the selection
- * in the corresponding way if the up or down key is pressed.
- */
- private final boolean commitOnUpDown;
-
- /**
- * Flag to configure whether the selection should move after a value was
- * committed after pressing enter.
- */
- private final boolean moveSelectionOnEnter;
-
- /**
- * The selection mode that should be used on activating the wrapped text control.
- * By default the behaviour is to set the selection at the end of the containing text
- * if the text editor control is activated with an initial value. If it is activated
- * only specifying the original canonical value, the default behaviour is to select
- * the whole text contained in the text editor control.
- *
- * <p>
- * You can override this default behaviour by setting an {@link EditorSelectionEnum} explicitly. With this you are able e.g. to set the selection at the beginning of the contained text, so writing in the text control will result in prefixing.
- *
- * <p>
- * Note that on overriding the behaviour, you override both activation cases.
- */
- private EditorSelectionEnum selectionMode;
-
- /**
- * The {@link ControlDecorationProvider} responsible for adding a {@link ControlDecoration} to the wrapped editor control. Can be configured via
- * convenience methods of this TextCellEditor.
- */
- protected final ControlDecorationProvider decorationProvider = new ControlDecorationProvider();
-
- /**
- * The {@link IEditErrorHandler} that is used for showing conversion errors on typing into
- * this editor. By default this is the {@link RenderErrorHandling} which will render the
- * content in the editor red to indicate a conversion error.
- */
- private IEditErrorHandler inputConversionErrorHandler = new RenderErrorHandling(decorationProvider);
-
- /**
- * The {@link IEditErrorHandler} that is used for showing validation errors on typing into
- * this editor. By default this is the {@link RenderErrorHandling} which will render the
- * content in the editor red to indicate a validation error.
- */
- private IEditErrorHandler inputValidationErrorHandler = new RenderErrorHandling(decorationProvider);
-
- /**
- * Flag to determine whether this editor should try to commit and close on pressing the enter key.
- * The default is of course <code>true</code>, but for a multi line text editor, the enter key
- * should be treated as inserting a new line instead of committing.
- */
- protected boolean commitOnEnter = true;
-
- /**
- * Creates the default TextCellEditor that does not commit on pressing the up/down arrow keys
- * and will not move the selection on committing a value by pressing enter.
- */
- public AbstractStyledTextCellEditor() {
- this(false);
- }
-
- /**
- * Creates a TextCellEditor that will not move the selection on committing a value by pressing enter.
- *
- * @param commitOnUpDown
- * Flag to configure whether the editor should commit
- * and move the selection in the corresponding way if the up or down key is pressed.
- */
- public AbstractStyledTextCellEditor(boolean commitOnUpDown) {
- this(commitOnUpDown, false);
- }
-
- /**
- * Creates a TextCellEditor.
- *
- * @param commitOnUpDown
- * Flag to configure whether the editor should commit
- * and move the selection in the corresponding way if the up or down key is pressed.
- * @param moveSelectionOnEnter
- * Flag to configure whether the selection should move after a value was
- * committed after pressing enter.
- */
- public AbstractStyledTextCellEditor(boolean commitOnUpDown, boolean moveSelectionOnEnter) {
- this.commitOnUpDown = commitOnUpDown;
- this.moveSelectionOnEnter = moveSelectionOnEnter;
- }
-
- @Override
- protected Control activateCell(final Composite parent, Object originalCanonicalValue) {
- this.text = createEditorControl(parent);
-
- // If the originalCanonicalValue is a Character it is possible the editor is activated by keypress
- if (originalCanonicalValue instanceof Character) {
- this.text.setText(originalCanonicalValue.toString());
- selectText(this.selectionMode != null ? this.selectionMode : EditorSelectionEnum.END);
- }
- // if there is no initial value, handle the original canonical value to transfer it to the text control
- else {
- setCanonicalValue(originalCanonicalValue);
- selectText(this.selectionMode != null ? this.selectionMode : EditorSelectionEnum.ALL);
- }
-
- if (!isEditable()) {
- this.text.setEditable(false);
- }
-
- // show an error decoration if this is enabled
- this.decorationProvider.createErrorDecorationIfRequired(this.text);
-
- // if the input error handlers are of type RenderErrorHandler (default) than
- // we also check for a possible configured error styling in the configuration
- // Note: this is currently only implemented in here, as the TextCellEditor is
- // the only editor that supports just in time conversion/validation
- if (this.inputConversionErrorHandler instanceof RenderErrorHandling) {
- IStyle conversionErrorStyle = this.configRegistry.getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, DisplayMode.EDIT, this.labelStack.getLabels());
-
- ((RenderErrorHandling) this.inputConversionErrorHandler).setErrorStyle(conversionErrorStyle);
- }
-
- if (this.inputValidationErrorHandler instanceof RenderErrorHandling) {
- IStyle validationErrorStyle = this.configRegistry.getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, DisplayMode.EDIT, this.labelStack.getLabels());
-
- ((RenderErrorHandling) this.inputValidationErrorHandler).setErrorStyle(validationErrorStyle);
- }
-
- this.text.forceFocus();
-
- return this.text;
- }
-
- @Override
- public Object getEditorValue() {
- return this.text.getText();
- }
-
- @Override
- public void setEditorValue(Object value) {
- this.text.setText(value != null && value.toString().length() > 0 ? value.toString() : ""); //$NON-NLS-1$
- }
-
- @Override
- public Control getEditorControl() {
- return this.text;
- }
-
- @Override
- public StyledText createEditorControl(Composite parent) {
- int style = HorizontalAlignmentEnum.getSWTStyle(this.cellStyle);
- if (this.editMode == EditModeEnum.DIALOG) {
- style = style | SWT.BORDER;
- }
- return createEditorControl(parent, style);
- }
-
- /**
- *
- * @param parent
- * the composite parent
- * @param style
- * the style of the editor
- * @return
- * the created StyledText
- */
- protected StyledText createStyledText(final Composite parent, final int style) {
- return new StyledText(parent, style);
- }
-
- /**
- * Creates the editor control that is wrapped by this ICellEditor.
- * Will use the style configurations in ConfigRegistry for styling the control.
- *
- * @param parent
- * The Composite that will be the parent of the new editor control.
- * Can not be <code>null</code>
- * @param style
- * The SWT style of the text control to create.
- * @return The created editor control that is wrapped by this ICellEditor.
- */
- protected StyledText createEditorControl(final Composite parent, int style) {
- // create the Text control based on the specified style
- final StyledText textControl = createStyledText(parent, style);
-
- // to avoid widget is disposed exception during the closing of the cell editor
- textControl.addVerifyKeyListener(new VerifyKeyListener() {
-
- @Override
- public void verifyKey(VerifyEvent event) {
- if (textControl.isDisposed()) {
- event.doit = false;
- }
- }
- });
-
- // set style information configured in the associated cell style
- textControl.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
- textControl.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
- textControl.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));
-
- textControl.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_IBEAM));
-
- // add a key listener that will commit or close the editor for special key strokes
- // and executes conversion/validation on input to the editor
- textControl.addKeyListener(this);
- // textControl.addKeyListener(new KeyAdapter() {
- //
- // @Override
- // public void keyPressed(KeyEvent event) {
- // if (commitOnEnter && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
- //
- // MoveDirectionEnum move = MoveDirectionEnum.NONE;
- // if (moveSelectionOnEnter && editMode == EditModeEnum.INLINE) {
- // if (event.stateMask == 0) {
- // move = MoveDirectionEnum.DOWN;
- // } else if (event.stateMask == SWT.SHIFT) {
- // move = MoveDirectionEnum.UP;
- // }
- // }
- //
- // commit(move);
- //
- // if (editMode == EditModeEnum.DIALOG) {
- // parent.forceFocus();
- // }
- // } else if (event.keyCode == SWT.ESC && event.stateMask == 0) {
- // close();
- // } else if (commitOnUpDown && editMode == EditModeEnum.INLINE) {
- // if (event.keyCode == SWT.ARROW_UP) {
- // commit(MoveDirectionEnum.UP);
- // } else if (event.keyCode == SWT.ARROW_DOWN) {
- // commit(MoveDirectionEnum.DOWN);
- // }
- // }
- // }
- //
- // @Override
- // public void keyReleased(KeyEvent e) {
- // try {
- // // always do the conversion
- // Object canonicalValue = getCanonicalValue(inputConversionErrorHandler);
- // // and always do the validation
- // // even if for commiting the validation should be skipped, on editing
- // // a validation failure should be made visible
- // // otherwise there would be no need for validation!
- // validateCanonicalValue(canonicalValue, inputValidationErrorHandler);
- // } catch (Exception ex) {
- // // do nothing as exceptions caused by conversion or validation are handled already
- // // we just need this catch block for stopping the process if conversion failed with
- // // an exception
- // }
- // }
- // });
-
- return textControl;
- }
-
-
- /**
- *
- * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
- *
- * @param event
- */
- public void keyPressed(KeyEvent event) {
- if (commitOnEnter && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
-
- MoveDirectionEnum move = MoveDirectionEnum.NONE;
- if (moveSelectionOnEnter && editMode == EditModeEnum.INLINE) {
- if (event.stateMask == 0) {
- move = MoveDirectionEnum.DOWN;
- } else if (event.stateMask == SWT.SHIFT) {
- move = MoveDirectionEnum.UP;
- }
- }
-
- commit(move);
-
- if (editMode == EditModeEnum.DIALOG) {
- parent.forceFocus();
- }
- } else if (event.keyCode == SWT.ESC && event.stateMask == 0) {
- close();
- } else if (commitOnUpDown && editMode == EditModeEnum.INLINE) {
- if (event.keyCode == SWT.ARROW_UP) {
- commit(MoveDirectionEnum.UP);
- } else if (event.keyCode == SWT.ARROW_DOWN) {
- commit(MoveDirectionEnum.DOWN);
- }
- }
- }
-
- /**
- *
- * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
- *
- * @param e
- */
- public void keyReleased(KeyEvent e) {
- try {
- // always do the conversion
- Object canonicalValue = getCanonicalValue(inputConversionErrorHandler);
- // and always do the validation
- // even if for commiting the validation should be skipped, on editing
- // a validation failure should be made visible
- // otherwise there would be no need for validation!
- validateCanonicalValue(canonicalValue, inputValidationErrorHandler);
- } catch (Exception ex) {
- // do nothing as exceptions caused by conversion or validation are handled already
- // we just need this catch block for stopping the process if conversion failed with
- // an exception
- }
- }
-
-
- @Override
- public void close() {
- super.close();
-
- this.decorationProvider.dispose();
- }
-
- /**
- * @return <code>true</code> if the wrapped Text control is editable, <code>false</code> if not.
- */
- public boolean isEditable() {
- return editable;
- }
-
- /**
- *
- * @param editable
- * <code>true</code> if the wrapped Text control should be editable, <code>false</code> if not.
- */
- public void setEditable(boolean editable) {
- this.editable = editable;
- }
-
- /**
- * Returns the current configured selection mode that is used on activating the wrapped
- * text editor control. By default this is <code>null</code> which causes the following
- * default behaviour. If the text editor control is activated with an initial value then
- * the selection is set at the end of the containing text. If it is activated
- * only specifying the original canonical value, the default behaviour is to select
- * the whole text contained in the text editor control.
- *
- * @return The current configured selection mode, <code>null</code> for default behaviour.
- */
- public final EditorSelectionEnum getSelectionMode() {
- return selectionMode;
- }
-
- /**
- * Set the selection mode that should be used on the content of the wrapped text editor control
- * when it gets activated. By setting a value explicitly you configure the selection mode for
- * both cases, activating the wrapped text editor control with and without an initial value.
- * Setting this value to <code>null</code> will reactivate the default behaviour like described
- * here {@link TextCellEditor#getSelectionMode()}.
- *
- * @param selectionMode
- * The selection mode that should be used on the content of the
- * wrapped text editor control when it gets activated.
- */
- public final void setSelectionMode(EditorSelectionEnum selectionMode) {
- this.selectionMode = selectionMode;
- }
-
- /**
- * Will set the selection to the wrapped text control regarding the configured {@link EditorSelectionEnum}.
- *
- * <p>
- * This method is called
- *
- * @see Text#setSelection(int, int)
- */
- private void selectText(EditorSelectionEnum selectionMode) {
- int textLength = this.text.getText().length();
- if (textLength > 0) {
- if (selectionMode == EditorSelectionEnum.ALL) {
- this.text.setSelection(0, textLength);
- } else if (selectionMode == EditorSelectionEnum.END) {
- this.text.setSelection(textLength, textLength);
- } else if (selectionMode == EditorSelectionEnum.START) {
- this.text.setSelection(0);
- }
- }
- }
-
- /**
- * @return The {@link ControlDecorationProvider} responsible for adding a {@link ControlDecoration} to the wrapped editor control.
- */
- public ControlDecorationProvider getDecorationProvider() {
- return this.decorationProvider;
- }
-
- /**
- * Enables/disables the error decoration for the wrapped text control.
- *
- * @param enabled
- * <code>true</code> if an error decoration should be added to
- * the wrapped text control, <code>false</code> if not.
- */
- public void setErrorDecorationEnabled(boolean enabled) {
- this.decorationProvider.setErrorDecorationEnabled(enabled);
- }
-
- /**
- * Set the error description text that will be shown in the decoration hover.
- *
- * @param errorText
- * The text to be shown as a description for the decoration, or <code>null</code> if there should be no description.
- *
- * @see ControlDecoration#setDescriptionText(String)
- */
- public void setErrorDecorationText(String errorText) {
- this.decorationProvider.setErrorDecorationText(errorText);
- }
-
- /**
- * Force the error decoration hover to show immediately.
- *
- * @param customErrorText
- * The text to show in the hover popup.
- *
- * @see ControlDecoration#show()
- * @see ControlDecoration#showHoverText(String)
- */
- public void showErrorDecorationHover(String customErrorText) {
- this.decorationProvider.showErrorDecorationHover(customErrorText);
- }
-
- /**
- * Set the position of the control decoration relative to the control.
- * It should include style bits describing both the vertical and horizontal orientation.
- *
- * @param decorationPositionOverride
- * bit-wise or of position constants (<code>SWT.TOP</code>, <code>SWT.BOTTOM</code>, <code>SWT.LEFT</code>, <code>SWT.RIGHT</code>, and <code>SWT.CENTER</code>).
- *
- * @see ControlDecoration#ControlDecoration(Control, int)
- */
- public void setDecorationPositionOverride(int decorationPositionOverride) {
- this.decorationProvider.setDecorationPositionOverride(decorationPositionOverride);
- }
-
- /**
- * @return The {@link IEditErrorHandler} that is used for showing conversion errors on typing into
- * this editor. By default this is the {@link RenderErrorHandling} which will render the
- * content in the editor red to indicate a conversion error.
- */
- public IEditErrorHandler getInputConversionErrorHandler() {
- return this.inputConversionErrorHandler;
- }
-
- /**
- * @param inputConversionErrorHandler
- * The {@link IEditErrorHandler} that is should be used for showing
- * conversion errors on typing into this editor.
- */
- public void setInputConversionErrorHandler(IEditErrorHandler inputConversionErrorHandler) {
- this.inputConversionErrorHandler = inputConversionErrorHandler;
- }
-
- /**
- * @return The {@link IEditErrorHandler} that is used for showing validation errors on typing into
- * this editor. By default this is the {@link RenderErrorHandling} which will render the
- * content in the editor red to indicate a validation error.
- */
- public IEditErrorHandler getInputValidationErrorHandler() {
- return this.inputValidationErrorHandler;
- }
-
- /**
- * @param inputValidationErrorHandler
- * The {@link IEditErrorHandler} that is should used for showing
- * validation errors on typing into this editor.
- */
- public void setInputValidationErrorHandler(IEditErrorHandler inputValidationErrorHandler) {
- this.inputValidationErrorHandler = inputValidationErrorHandler;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 482790
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.celleditor;
+
+import org.eclipse.jface.fieldassist.ControlDecoration;
+import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
+import org.eclipse.nebula.widgets.nattable.edit.config.RenderErrorHandling;
+import org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor;
+import org.eclipse.nebula.widgets.nattable.edit.editor.ControlDecorationProvider;
+import org.eclipse.nebula.widgets.nattable.edit.editor.EditorSelectionEnum;
+import org.eclipse.nebula.widgets.nattable.edit.editor.IEditErrorHandler;
+import org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor;
+import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
+import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
+import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
+import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
+import org.eclipse.nebula.widgets.nattable.style.IStyle;
+import org.eclipse.nebula.widgets.nattable.widget.EditModeEnum;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.custom.VerifyKeyListener;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * duplicated code from {@link TextCellEditor}. Here we replace Text by StyledText
+ * This code is used with XText Cell Editor
+ */
+public abstract class AbstractStyledTextCellEditor extends AbstractCellEditor implements KeyListener {
+
+ /**
+ * The StyledText control which is the editor wrapped by this TextCellEditor.
+ */
+ private StyledText text = null;
+
+ /**
+ * Flag to configure if the wrapped text editor control is editable or not.
+ */
+ private boolean editable = true;
+
+ /**
+ * Flag to configure whether the editor should commit and move the selection
+ * in the corresponding way if the up or down key is pressed.
+ */
+ private final boolean commitOnUpDown;
+
+ /**
+ * Flag to configure whether the selection should move after a value was
+ * committed after pressing enter.
+ */
+ private final boolean moveSelectionOnEnter;
+
+ /**
+ * The selection mode that should be used on activating the wrapped text control.
+ * By default the behaviour is to set the selection at the end of the containing text
+ * if the text editor control is activated with an initial value. If it is activated
+ * only specifying the original canonical value, the default behaviour is to select
+ * the whole text contained in the text editor control.
+ *
+ * <p>
+ * You can override this default behaviour by setting an {@link EditorSelectionEnum} explicitly. With this you are able e.g. to set the selection at the beginning of the contained text, so writing in the text control will result in prefixing.
+ *
+ * <p>
+ * Note that on overriding the behaviour, you override both activation cases.
+ */
+ private EditorSelectionEnum selectionMode;
+
+ /**
+ * The {@link ControlDecorationProvider} responsible for adding a {@link ControlDecoration} to the wrapped editor control. Can be configured via
+ * convenience methods of this TextCellEditor.
+ */
+ protected final ControlDecorationProvider decorationProvider = new ControlDecorationProvider();
+
+ /**
+ * The {@link IEditErrorHandler} that is used for showing conversion errors on typing into
+ * this editor. By default this is the {@link RenderErrorHandling} which will render the
+ * content in the editor red to indicate a conversion error.
+ */
+ private IEditErrorHandler inputConversionErrorHandler = new RenderErrorHandling(decorationProvider);
+
+ /**
+ * The {@link IEditErrorHandler} that is used for showing validation errors on typing into
+ * this editor. By default this is the {@link RenderErrorHandling} which will render the
+ * content in the editor red to indicate a validation error.
+ */
+ private IEditErrorHandler inputValidationErrorHandler = new RenderErrorHandling(decorationProvider);
+
+ /**
+ * Flag to determine whether this editor should try to commit and close on pressing the enter key.
+ * The default is of course <code>true</code>, but for a multi line text editor, the enter key
+ * should be treated as inserting a new line instead of committing.
+ */
+ protected boolean commitOnEnter = true;
+
+ /**
+ * Creates the default TextCellEditor that does not commit on pressing the up/down arrow keys
+ * and will not move the selection on committing a value by pressing enter.
+ */
+ public AbstractStyledTextCellEditor() {
+ this(false);
+ }
+
+ /**
+ * Creates a TextCellEditor that will not move the selection on committing a value by pressing enter.
+ *
+ * @param commitOnUpDown
+ * Flag to configure whether the editor should commit
+ * and move the selection in the corresponding way if the up or down key is pressed.
+ */
+ public AbstractStyledTextCellEditor(boolean commitOnUpDown) {
+ this(commitOnUpDown, false);
+ }
+
+ /**
+ * Creates a TextCellEditor.
+ *
+ * @param commitOnUpDown
+ * Flag to configure whether the editor should commit
+ * and move the selection in the corresponding way if the up or down key is pressed.
+ * @param moveSelectionOnEnter
+ * Flag to configure whether the selection should move after a value was
+ * committed after pressing enter.
+ */
+ public AbstractStyledTextCellEditor(boolean commitOnUpDown, boolean moveSelectionOnEnter) {
+ this.commitOnUpDown = commitOnUpDown;
+ this.moveSelectionOnEnter = moveSelectionOnEnter;
+ }
+
+ @Override
+ protected Control activateCell(final Composite parent, Object originalCanonicalValue) {
+ this.text = createEditorControl(parent);
+
+ // If the originalCanonicalValue is a Character it is possible the editor is activated by keypress
+ if (originalCanonicalValue instanceof Character) {
+ this.text.setText(originalCanonicalValue.toString());
+ selectText(this.selectionMode != null ? this.selectionMode : EditorSelectionEnum.END);
+ }
+ // if there is no initial value, handle the original canonical value to transfer it to the text control
+ else {
+ setCanonicalValue(originalCanonicalValue);
+ selectText(this.selectionMode != null ? this.selectionMode : EditorSelectionEnum.ALL);
+ }
+
+ if (!isEditable()) {
+ this.text.setEditable(false);
+ }
+
+ // show an error decoration if this is enabled
+ this.decorationProvider.createErrorDecorationIfRequired(this.text);
+
+ // if the input error handlers are of type RenderErrorHandler (default) than
+ // we also check for a possible configured error styling in the configuration
+ // Note: this is currently only implemented in here, as the TextCellEditor is
+ // the only editor that supports just in time conversion/validation
+ if (this.inputConversionErrorHandler instanceof RenderErrorHandling) {
+ IStyle conversionErrorStyle = this.configRegistry.getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, DisplayMode.EDIT, this.labelStack.getLabels());
+
+ ((RenderErrorHandling) this.inputConversionErrorHandler).setErrorStyle(conversionErrorStyle);
+ }
+
+ if (this.inputValidationErrorHandler instanceof RenderErrorHandling) {
+ IStyle validationErrorStyle = this.configRegistry.getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, DisplayMode.EDIT, this.labelStack.getLabels());
+
+ ((RenderErrorHandling) this.inputValidationErrorHandler).setErrorStyle(validationErrorStyle);
+ }
+
+ this.text.forceFocus();
+
+ return this.text;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor#getEditorValue()
+ */
+ @Override
+ public Object getEditorValue() {
+ if(null != this.text){
+ return this.text.getText();
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor#setEditorValue(java.lang.Object)
+ */
+ @Override
+ public void setEditorValue(final Object value) {
+ if(null != this.text){
+ this.text.setText(value != null && value.toString().length() > 0 ? value.toString() : ""); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor#getEditorControl()
+ */
+ @Override
+ public Control getEditorControl() {
+ return this.text;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor#createEditorControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public StyledText createEditorControl(final Composite parent) {
+ int style = HorizontalAlignmentEnum.getSWTStyle(this.cellStyle);
+ if (this.editMode == EditModeEnum.DIALOG) {
+ style = style | SWT.BORDER;
+ }
+ return createEditorControl(parent, style);
+ }
+
+ /**
+ *
+ * @param parent
+ * the composite parent
+ * @param style
+ * the style of the editor
+ * @return
+ * the created StyledText
+ */
+ protected StyledText createStyledText(final Composite parent, final int style) {
+ return new StyledText(parent, style);
+ }
+
+ /**
+ * Creates the editor control that is wrapped by this ICellEditor.
+ * Will use the style configurations in ConfigRegistry for styling the control.
+ *
+ * @param parent
+ * The Composite that will be the parent of the new editor control.
+ * Can not be <code>null</code>
+ * @param style
+ * The SWT style of the text control to create.
+ * @return The created editor control that is wrapped by this ICellEditor.
+ */
+ protected StyledText createEditorControl(final Composite parent, int style) {
+ // create the Text control based on the specified style
+ final StyledText textControl = createStyledText(parent, style);
+
+ // to avoid widget is disposed exception during the closing of the cell editor
+ textControl.addVerifyKeyListener(new VerifyKeyListener() {
+
+ @Override
+ public void verifyKey(VerifyEvent event) {
+ if (textControl.isDisposed()) {
+ event.doit = false;
+ }
+ }
+ });
+
+ // set style information configured in the associated cell style
+ textControl.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
+ textControl.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
+ textControl.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));
+
+ textControl.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_IBEAM));
+
+ // add a key listener that will commit or close the editor for special key strokes
+ // and executes conversion/validation on input to the editor
+ textControl.addKeyListener(this);
+ // textControl.addKeyListener(new KeyAdapter() {
+ //
+ // @Override
+ // public void keyPressed(KeyEvent event) {
+ // if (commitOnEnter && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
+ //
+ // MoveDirectionEnum move = MoveDirectionEnum.NONE;
+ // if (moveSelectionOnEnter && editMode == EditModeEnum.INLINE) {
+ // if (event.stateMask == 0) {
+ // move = MoveDirectionEnum.DOWN;
+ // } else if (event.stateMask == SWT.SHIFT) {
+ // move = MoveDirectionEnum.UP;
+ // }
+ // }
+ //
+ // commit(move);
+ //
+ // if (editMode == EditModeEnum.DIALOG) {
+ // parent.forceFocus();
+ // }
+ // } else if (event.keyCode == SWT.ESC && event.stateMask == 0) {
+ // close();
+ // } else if (commitOnUpDown && editMode == EditModeEnum.INLINE) {
+ // if (event.keyCode == SWT.ARROW_UP) {
+ // commit(MoveDirectionEnum.UP);
+ // } else if (event.keyCode == SWT.ARROW_DOWN) {
+ // commit(MoveDirectionEnum.DOWN);
+ // }
+ // }
+ // }
+ //
+ // @Override
+ // public void keyReleased(KeyEvent e) {
+ // try {
+ // // always do the conversion
+ // Object canonicalValue = getCanonicalValue(inputConversionErrorHandler);
+ // // and always do the validation
+ // // even if for commiting the validation should be skipped, on editing
+ // // a validation failure should be made visible
+ // // otherwise there would be no need for validation!
+ // validateCanonicalValue(canonicalValue, inputValidationErrorHandler);
+ // } catch (Exception ex) {
+ // // do nothing as exceptions caused by conversion or validation are handled already
+ // // we just need this catch block for stopping the process if conversion failed with
+ // // an exception
+ // }
+ // }
+ // });
+
+ return textControl;
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
+ *
+ * @param event
+ */
+ public void keyPressed(KeyEvent event) {
+ if (commitOnEnter && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
+
+ MoveDirectionEnum move = MoveDirectionEnum.NONE;
+ if (moveSelectionOnEnter && editMode == EditModeEnum.INLINE) {
+ if (event.stateMask == 0) {
+ move = MoveDirectionEnum.DOWN;
+ } else if (event.stateMask == SWT.SHIFT) {
+ move = MoveDirectionEnum.UP;
+ }
+ }
+
+ commit(move);
+
+ if (editMode == EditModeEnum.DIALOG) {
+ parent.forceFocus();
+ }
+ } else if (event.keyCode == SWT.ESC && event.stateMask == 0) {
+ close();
+ } else if (commitOnUpDown && editMode == EditModeEnum.INLINE) {
+ if (event.keyCode == SWT.ARROW_UP) {
+ commit(MoveDirectionEnum.UP);
+ } else if (event.keyCode == SWT.ARROW_DOWN) {
+ commit(MoveDirectionEnum.DOWN);
+ }
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
+ *
+ * @param e
+ */
+ public void keyReleased(KeyEvent e) {
+ try {
+ // always do the conversion
+ Object canonicalValue = getCanonicalValue(inputConversionErrorHandler);
+ // and always do the validation
+ // even if for commiting the validation should be skipped, on editing
+ // a validation failure should be made visible
+ // otherwise there would be no need for validation!
+ validateCanonicalValue(canonicalValue, inputValidationErrorHandler);
+ } catch (Exception ex) {
+ // do nothing as exceptions caused by conversion or validation are handled already
+ // we just need this catch block for stopping the process if conversion failed with
+ // an exception
+ }
+ }
+
+
+ @Override
+ public void close() {
+ super.close();
+
+ this.decorationProvider.dispose();
+ }
+
+ /**
+ * @return <code>true</code> if the wrapped Text control is editable, <code>false</code> if not.
+ */
+ public boolean isEditable() {
+ return editable;
+ }
+
+ /**
+ *
+ * @param editable
+ * <code>true</code> if the wrapped Text control should be editable, <code>false</code> if not.
+ */
+ public void setEditable(boolean editable) {
+ this.editable = editable;
+ }
+
+ /**
+ * Returns the current configured selection mode that is used on activating the wrapped
+ * text editor control. By default this is <code>null</code> which causes the following
+ * default behaviour. If the text editor control is activated with an initial value then
+ * the selection is set at the end of the containing text. If it is activated
+ * only specifying the original canonical value, the default behaviour is to select
+ * the whole text contained in the text editor control.
+ *
+ * @return The current configured selection mode, <code>null</code> for default behaviour.
+ */
+ public final EditorSelectionEnum getSelectionMode() {
+ return selectionMode;
+ }
+
+ /**
+ * Set the selection mode that should be used on the content of the wrapped text editor control
+ * when it gets activated. By setting a value explicitly you configure the selection mode for
+ * both cases, activating the wrapped text editor control with and without an initial value.
+ * Setting this value to <code>null</code> will reactivate the default behaviour like described
+ * here {@link TextCellEditor#getSelectionMode()}.
+ *
+ * @param selectionMode
+ * The selection mode that should be used on the content of the
+ * wrapped text editor control when it gets activated.
+ */
+ public final void setSelectionMode(EditorSelectionEnum selectionMode) {
+ this.selectionMode = selectionMode;
+ }
+
+ /**
+ * Will set the selection to the wrapped text control regarding the configured {@link EditorSelectionEnum}.
+ *
+ * <p>
+ * This method is called
+ *
+ * @see Text#setSelection(int, int)
+ */
+ private void selectText(EditorSelectionEnum selectionMode) {
+ int textLength = this.text.getText().length();
+ if (textLength > 0) {
+ if (selectionMode == EditorSelectionEnum.ALL) {
+ this.text.setSelection(0, textLength);
+ } else if (selectionMode == EditorSelectionEnum.END) {
+ this.text.setSelection(textLength, textLength);
+ } else if (selectionMode == EditorSelectionEnum.START) {
+ this.text.setSelection(0);
+ }
+ }
+ }
+
+ /**
+ * @return The {@link ControlDecorationProvider} responsible for adding a {@link ControlDecoration} to the wrapped editor control.
+ */
+ public ControlDecorationProvider getDecorationProvider() {
+ return this.decorationProvider;
+ }
+
+ /**
+ * Enables/disables the error decoration for the wrapped text control.
+ *
+ * @param enabled
+ * <code>true</code> if an error decoration should be added to
+ * the wrapped text control, <code>false</code> if not.
+ */
+ public void setErrorDecorationEnabled(boolean enabled) {
+ this.decorationProvider.setErrorDecorationEnabled(enabled);
+ }
+
+ /**
+ * Set the error description text that will be shown in the decoration hover.
+ *
+ * @param errorText
+ * The text to be shown as a description for the decoration, or <code>null</code> if there should be no description.
+ *
+ * @see ControlDecoration#setDescriptionText(String)
+ */
+ public void setErrorDecorationText(String errorText) {
+ this.decorationProvider.setErrorDecorationText(errorText);
+ }
+
+ /**
+ * Force the error decoration hover to show immediately.
+ *
+ * @param customErrorText
+ * The text to show in the hover popup.
+ *
+ * @see ControlDecoration#show()
+ * @see ControlDecoration#showHoverText(String)
+ */
+ public void showErrorDecorationHover(String customErrorText) {
+ this.decorationProvider.showErrorDecorationHover(customErrorText);
+ }
+
+ /**
+ * Set the position of the control decoration relative to the control.
+ * It should include style bits describing both the vertical and horizontal orientation.
+ *
+ * @param decorationPositionOverride
+ * bit-wise or of position constants (<code>SWT.TOP</code>, <code>SWT.BOTTOM</code>, <code>SWT.LEFT</code>, <code>SWT.RIGHT</code>, and <code>SWT.CENTER</code>).
+ *
+ * @see ControlDecoration#ControlDecoration(Control, int)
+ */
+ public void setDecorationPositionOverride(int decorationPositionOverride) {
+ this.decorationProvider.setDecorationPositionOverride(decorationPositionOverride);
+ }
+
+ /**
+ * @return The {@link IEditErrorHandler} that is used for showing conversion errors on typing into
+ * this editor. By default this is the {@link RenderErrorHandling} which will render the
+ * content in the editor red to indicate a conversion error.
+ */
+ public IEditErrorHandler getInputConversionErrorHandler() {
+ return this.inputConversionErrorHandler;
+ }
+
+ /**
+ * @param inputConversionErrorHandler
+ * The {@link IEditErrorHandler} that is should be used for showing
+ * conversion errors on typing into this editor.
+ */
+ public void setInputConversionErrorHandler(IEditErrorHandler inputConversionErrorHandler) {
+ this.inputConversionErrorHandler = inputConversionErrorHandler;
+ }
+
+ /**
+ * @return The {@link IEditErrorHandler} that is used for showing validation errors on typing into
+ * this editor. By default this is the {@link RenderErrorHandling} which will render the
+ * content in the editor red to indicate a validation error.
+ */
+ public IEditErrorHandler getInputValidationErrorHandler() {
+ return this.inputValidationErrorHandler;
+ }
+
+ /**
+ * @param inputValidationErrorHandler
+ * The {@link IEditErrorHandler} that is should used for showing
+ * validation errors on typing into this editor.
+ */
+ public void setInputValidationErrorHandler(IEditErrorHandler inputValidationErrorHandler) {
+ this.inputValidationErrorHandler = inputValidationErrorHandler;
+ }
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/editor/UMLReferenceTextWithCompletionCellEditor.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/editor/UMLReferenceTextWithCompletionCellEditor.java
index 40a39ba7306..b80a7fd3b7c 100755
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/editor/UMLReferenceTextWithCompletionCellEditor.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/editor/UMLReferenceTextWithCompletionCellEditor.java
@@ -7,19 +7,31 @@
*
* Contributors:
* Vincent Lorenzo (CEA-LIST) - duplicated and adapted code from nattable project.
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue - Bug 482790
*
******************************************************************************/
package org.eclipse.papyrus.uml.nattable.manager.cell.editor;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.jface.window.Window;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.edit.DialogEditHandler;
+import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
+import org.eclipse.nebula.widgets.nattable.edit.EditConfigHelper;
+import org.eclipse.nebula.widgets.nattable.edit.ICellEditHandler;
import org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor;
import org.eclipse.nebula.widgets.nattable.edit.editor.IEditErrorHandler;
+import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
+import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
+import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
+import org.eclipse.nebula.widgets.nattable.widget.EditModeEnum;
import org.eclipse.papyrus.infra.nattable.celleditor.AbstractPapyrusStyledTextCellEditor;
import org.eclipse.papyrus.infra.nattable.converter.StringResolutionProblemPapyrusConverter;
import org.eclipse.papyrus.infra.nattable.manager.table.ITableAxisElementProvider;
@@ -29,6 +41,7 @@ import org.eclipse.papyrus.infra.widgets.editors.StringEditorWithCompletionWrapp
import org.eclipse.papyrus.infra.widgets.util.INameResolutionHelper;
import org.eclipse.papyrus.infra.widgets.util.IPapyrusConverter;
import org.eclipse.papyrus.infra.widgets.util.ISetPapyrusConverter;
+import org.eclipse.papyrus.uml.nattable.editor.SingleReferenceValueCellEditor;
import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils;
import org.eclipse.papyrus.uml.tools.util.UMLReferenceConverter;
import org.eclipse.papyrus.uml.tools.utils.NameResolutionHelper;
@@ -38,15 +51,14 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import org.eclipse.uml2.uml.Element;
-
-
+import org.eclipse.uml2.uml.NamedElement;
/**
* {@link ICellEditor} implementation that wraps a SWT {@link Text} control to
* support text editing. This is also the default editor in NatTable if you
* didn't configure something else.
*
- * duplicated and adapted code from nattable project. Add the method {@link #keyPressed(Composite, KeyEvent)} to allow to ovveride it
+ * duplicated and adapted code from nattable project. Add the method {@link #keyPressed(Composite, KeyEvent)} to allow to override it
*/
public class UMLReferenceTextWithCompletionCellEditor extends AbstractPapyrusStyledTextCellEditor {
@@ -70,122 +82,174 @@ public class UMLReferenceTextWithCompletionCellEditor extends AbstractPapyrusSty
private boolean isMultiValued = false;
/**
- *
+ * The cell editor which allow to use the dialog reference selection.
+ * It must be used when the text completion can't reach the value.
+ */
+ protected SingleReferenceValueCellEditor singleReferenceValueCellEditor;
+
+ /**
* Constructor.
*
- * @param table
- * @param axisElement
- * @param elementProvider
- * @param commitOnUpDown
- * @param moveSelectionOnEnter
+ * @param table The current table.
+ * @param axisElement The axis element to manage.
+ * @param elementProvider The element provider for the current axis to edit.
+ * @param commitOnUpDown Flag to configure whether the editor should commit and move the selection in the corresponding way if the up or down key is pressed.
+ * @param moveSelectionOnEnter Flag to configure whether the selection should move after a value was committed after pressing enter.
*/
- public UMLReferenceTextWithCompletionCellEditor(Table table, Object axisElement, ITableAxisElementProvider elementProvider, boolean commitOnUpDown, boolean moveSelectionOnEnter) {
+ public UMLReferenceTextWithCompletionCellEditor(final Table table, final Object axisElement, final ITableAxisElementProvider elementProvider, final boolean commitOnUpDown, final boolean moveSelectionOnEnter) {
super(table, axisElement, elementProvider, commitOnUpDown, moveSelectionOnEnter);
}
/**
- *
* Constructor.
*
- * @param table
- * @param axisElement
- * @param elementProvider
- * @param commitOnUpDown
+ * @param table The current table.
+ * @param axisElement The axis element to manage.
+ * @param elementProvider The element provider for the current axis to edit.
+ * @param commitOnUpDown Flag to configure whether the editor should commit and move the selection in the corresponding way if the up or down key is pressed.
*/
- public UMLReferenceTextWithCompletionCellEditor(Table table, Object axisElement, ITableAxisElementProvider elementProvider, boolean commitOnUpDown) {
+ public UMLReferenceTextWithCompletionCellEditor(final Table table, final Object axisElement, final ITableAxisElementProvider elementProvider, final boolean commitOnUpDown) {
super(table, axisElement, elementProvider, commitOnUpDown);
}
/**
- *
* Constructor.
*
- * @param table
- * @param axisElement
- * @param elementProvider
+ * @param table The current table.
+ * @param axisElement The axis element to manage.
+ * @param elementProvider The element provider for the current axis to edit.
*/
- public UMLReferenceTextWithCompletionCellEditor(Table table, Object axisElement, ITableAxisElementProvider elementProvider) {
+ public UMLReferenceTextWithCompletionCellEditor(final Table table, final Object axisElement, final ITableAxisElementProvider elementProvider) {
super(table, axisElement, elementProvider);
}
/**
+ * Set the multi valued boolean value.
*
- * @param isMultivalued
+ * @param isMultivalued The multi valued boolean value.
*/
public void setIsMultiValued(boolean isMultivalued) {
this.isMultiValued = isMultivalued;
}
/**
+ * {@inheritDoc}
*
* @see org.eclipse.papyrus.infra.nattable.celleditor.AbstractStyledTextCellEditor#activateCell(org.eclipse.swt.widgets.Composite, java.lang.Object)
- *
- * @param parent
- * @param originalCanonicalValue
- * @return
*/
@Override
- protected Control activateCell(Composite parent, Object originalCanonicalValue) {
- this.helper = createNameResolutionHelper();
- parser = new StringResolutionProblemPapyrusConverter(new UMLReferenceConverter(this.helper, isMultiValued));
- setPapyrusConverter(parser);
- return super.activateCell(parent, originalCanonicalValue);
+ protected Control activateCell(final Composite parent, final Object originalCanonicalValue) {
+ final CrossAxisWrapper<EObject, EStructuralFeature> editedElement = UMLTableUtils.getRealEditedObject(layerCell, elementProvider);
+ final EObject element = editedElement.getFirstAxis();
+
+ Control control = null;
+
+ // Bug 482790: Check if this is not an object with a null namespace
+ if (!(element instanceof NamedElement && null == ((NamedElement) element).getNamespace())) {
+ this.helper = createNameResolutionHelper();
+ parser = new StringResolutionProblemPapyrusConverter(new UMLReferenceConverter(this.helper, isMultiValued));
+ setPapyrusConverter(parser);
+ control = super.activateCell(parent, originalCanonicalValue);
+ }else{
+ // Bug 482790: The parse can't be used because no name resolution helper can't be created
+ // So re-initialize the display converter to null
+ this.displayConverter = null;
+
+ // The reference dialog used is managed by the SingleReferenceValueCellEditor cell editor
+ singleReferenceValueCellEditor = new SingleReferenceValueCellEditor(axisElement, elementProvider) {
+
+ @Override
+ public Control activateCell(Composite parent, Object originalCanonicalValue, EditModeEnum editMode, ICellEditHandler editHandler, ILayerCell cell, IConfigRegistry configRegistry) {
+ this.parent = parent;
+ this.layerCell = cell;
+ this.configRegistry = configRegistry;
+
+ final List<String> configLabels = cell.getConfigLabels().getLabels();
+ this.displayConverter = UMLReferenceTextWithCompletionCellEditor.this.displayConverter;
+ this.dataValidator = configRegistry.getConfigAttribute(
+ EditConfigAttributes.DATA_VALIDATOR,
+ DisplayMode.EDIT,
+ configLabels);
+
+ this.conversionEditErrorHandler = EditConfigHelper.getEditErrorHandler(
+ configRegistry,
+ EditConfigAttributes.CONVERSION_ERROR_HANDLER,
+ configLabels);
+ this.validationEditErrorHandler = EditConfigHelper.getEditErrorHandler(
+ configRegistry,
+ EditConfigAttributes.VALIDATION_ERROR_HANDLER,
+ configLabels);
+
+ this.dialog = createDialogInstance();
+
+ setCanonicalValue(originalCanonicalValue);
+
+ // this method is only needed to initialize the dialog editor, there
+ // will be no control to return
+ return null;
+ }
+
+ };
+ // Activate the cell of the single reference cell editor
+ control = singleReferenceValueCellEditor.activateCell(parent, originalCanonicalValue, EditModeEnum.DIALOG, new DialogEditHandler(), layerCell, configRegistry);
+ // Manage the dialog return
+ if (Window.OK == singleReferenceValueCellEditor.open()) {
+ // The user click on 'OK' button, so set the canonical value
+ setCanonicalValue(singleReferenceValueCellEditor.getEditorValue());
+ // Commit the value
+ commit(MoveDirectionEnum.NONE);
+ } else {
+ singleReferenceValueCellEditor.close();
+ }
+ }
+ return control;
}
/**
+ * This allows to set the parser to the display converter.
*
* @param parser
- * the parser to use to find the references
+ * the parser to use to find the references.
*/
- private void setPapyrusConverter(IPapyrusConverter parser) {
+ private void setPapyrusConverter(final IPapyrusConverter parser) {
if (this.displayConverter instanceof ISetPapyrusConverter) {
((ISetPapyrusConverter) this.displayConverter).setPapyrusConverter(parser);
}
}
/**
+ * {@inheritDoc}
*
- * @return
+ * @see org.eclipse.papyrus.infra.nattable.celleditor.AbstractStyledTextCellEditor#createStyledText(org.eclipse.swt.widgets.Composite, int)
*/
@Override
- public Control getEditorControl() {
- return super.getEditorControl();
- }
-
- /**
- *
- * @param parent
- * @param style
- * @return
- */
- @Override
- protected StyledText createStyledText(Composite parent, int style) {
+ protected StyledText createStyledText(final Composite parent, final int style) {
this.textCompletion = new StringEditorWithCompletionWrapper(parent, this.parser);
return this.textCompletion.getTextViewer().getTextWidget();
}
/**
+ * {@inheritDoc}
+ *
* @see org.eclipse.papyrus.infra.nattable.celleditor.AbstractStyledTextCellEditor#keyPressed(org.eclipse.swt.events.KeyEvent)
- *
- * @param event
*/
@Override
- public void keyPressed(KeyEvent event) {
- if (isMultiValued && textCompletion.isContentAssistOpened()) {
- return;
+ public void keyPressed(final KeyEvent event) {
+ if (!(isMultiValued && textCompletion.isContentAssistOpened())) {
+ super.keyPressed(event);
}
- super.keyPressed(event);
}
/**
+ * This allows to create the name resolution helper managed by the namespace.
*
* @return
- * the created name resolution helper
+ * the created name resolution helper
*/
protected INameResolutionHelper createNameResolutionHelper() {
- CrossAxisWrapper<EObject, EStructuralFeature> editedElement = UMLTableUtils.getRealEditedObject(layerCell, elementProvider);
- EObject element = editedElement.getFirstAxis();
+ final CrossAxisWrapper<EObject, EStructuralFeature> editedElement = UMLTableUtils.getRealEditedObject(layerCell, elementProvider);
+ final EObject element = editedElement.getFirstAxis();
Element scope;
if (element instanceof Element) {
scope = (Element) element;
@@ -194,24 +258,23 @@ public class UMLReferenceTextWithCompletionCellEditor extends AbstractPapyrusSty
scope = org.eclipse.uml2.uml.util.UMLUtil.getBaseElement(element);
}
- EStructuralFeature feature = editedElement.getSecondAxis();
- EClassifier eType = feature.getEType();
+ INameResolutionHelper helper = null;
+
+ final EStructuralFeature feature = editedElement.getSecondAxis();
+ final EClassifier eType = feature.getEType();
if (eType instanceof EClass) {
- INameResolutionHelper helper = new NameResolutionHelper(scope, (EClass) eType);
- return helper;
+ helper = new NameResolutionHelper(scope, (EClass) eType);
}
- return null;
+ return helper;
}
/**
+ * {@inheritDoc}
*
* @see org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor#getCanonicalValue(org.eclipse.nebula.widgets.nattable.edit.editor.IEditErrorHandler)
- *
- * @param conversionErrorHandler
- * @return
*/
@Override
- public Object getCanonicalValue(IEditErrorHandler conversionErrorHandler) {
+ public Object getCanonicalValue(final IEditErrorHandler conversionErrorHandler) {
Object canonnicalValue = super.getCanonicalValue(conversionErrorHandler);
if (canonnicalValue instanceof Collection<?>) {
return canonnicalValue;
@@ -226,34 +289,38 @@ public class UMLReferenceTextWithCompletionCellEditor extends AbstractPapyrusSty
}
/**
+ * {@inheritDoc}
*
- * @see org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor#getCanonicalValue()
- *
- * @return
+ * @see org.eclipse.papyrus.infra.nattable.celleditor.AbstractStyledTextCellEditor#getEditorValue()
*/
@Override
- public Object getCanonicalValue() {
- return super.getCanonicalValue();
+ public Object getEditorValue() {
+ Object result = null;
+ if (null != singleReferenceValueCellEditor) {
+ result = singleReferenceValueCellEditor.getEditorValue();
+ }
+ return null != result ? result : super.getEditorValue();
}
-
+
/**
+ * {@inheritDoc}
*
* @see org.eclipse.papyrus.infra.nattable.celleditor.AbstractStyledTextCellEditor#close()
- *
*/
@Override
public void close() {
- this.textCompletion.getTextWidget().dispose();
+ if (null != this.textCompletion && null != this.textCompletion.getTextWidget() && !this.textCompletion.getTextWidget().isDisposed()) {
+ this.textCompletion.getTextWidget().dispose();
+ }
super.close();
}
-
/**
+ * {@inheritDoc}
*
* @see org.eclipse.papyrus.infra.nattable.celleditor.AbstractPapyrusStyledTextCellEditor#getEditedEObject()
- *
- * @return
*/
+ @Override
protected EObject getEditedEObject() {
return null;
}

Back to the top