Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/EStructuralFeatureEditorConfig.java4
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/provider/EMFFeatureHeaderLabelProvider.java9
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/MultiLineTextCellEditor.java90
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/MultiLineTextCellEditorEx.java107
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/TextCellEditor.java457
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/listener/NatTableDropListener.java24
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java2
7 files changed, 677 insertions, 16 deletions
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/EStructuralFeatureEditorConfig.java b/extraplugins/table/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/EStructuralFeatureEditorConfig.java
index bd4b3073ac1..845a33a53fd 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/EStructuralFeatureEditorConfig.java
+++ b/extraplugins/table/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/EStructuralFeatureEditorConfig.java
@@ -32,13 +32,13 @@ import org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor;
import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor;
import org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor;
import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider;
-import org.eclipse.nebula.widgets.nattable.edit.editor.MultiLineTextCellEditor;
import org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor;
import org.eclipse.nebula.widgets.nattable.painter.cell.ComboBoxPainter;
import org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter;
import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.nattable.celleditor.MultiLineTextCellEditorEx;
import org.eclipse.papyrus.infra.nattable.celleditor.config.AbstractCellEditorConfiguration;
import org.eclipse.papyrus.infra.nattable.manager.table.ITableAxisElementProvider;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
@@ -98,7 +98,7 @@ public class EStructuralFeatureEditorConfig extends AbstractCellEditorConfigurat
ICellEditor editor = null;
switch(editorKind) {
case SINGLE_STRING:
- editor = new MultiLineTextCellEditor(true);
+ editor = new MultiLineTextCellEditorEx(true);
break;
case SINGLE_INTEGER:
editor = new TextCellEditor();
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/provider/EMFFeatureHeaderLabelProvider.java b/extraplugins/table/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/provider/EMFFeatureHeaderLabelProvider.java
index dc801b897db..3c7eb83fcd9 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/provider/EMFFeatureHeaderLabelProvider.java
+++ b/extraplugins/table/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/provider/EMFFeatureHeaderLabelProvider.java
@@ -155,8 +155,8 @@ public class EMFFeatureHeaderLabelProvider extends EMFEObjectHeaderLabelProvider
if(value instanceof EStructuralFeatureAxis) {
feature = ((EStructuralFeatureAxis)value).getElement();
alias = ((EStructuralFeatureAxis)value).getAlias();
- } else if(feature instanceof EStructuralFeature) {
- feature = (EStructuralFeature)((ILabelProviderContextElementWrapper)element).getObject();
+ } else if(value instanceof EStructuralFeature) {
+ feature = (EStructuralFeature)value;
}
String returnedValue = null;
@@ -201,7 +201,7 @@ public class EMFFeatureHeaderLabelProvider extends EMFEObjectHeaderLabelProvider
if(object instanceof EStructuralFeatureAxis) {
feature = ((EStructuralFeatureAxis)object).getElement();
} else if(object instanceof EStructuralFeature) {
- feature = (EStructuralFeature)((ILabelProviderContextElementWrapper)element).getObject();
+ feature = (EStructuralFeature)object;
}
if(feature instanceof EAttribute) {
return EStructuralFeatureImageRegistry.getAttributeIcon();
@@ -209,6 +209,9 @@ public class EMFFeatureHeaderLabelProvider extends EMFEObjectHeaderLabelProvider
} else if(feature instanceof EReference) {
return getEReferenceImage((EReference)feature);
}
+ if(feature==null){
+ return null;
+ }
return super.getImage(feature);
}
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/MultiLineTextCellEditor.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/MultiLineTextCellEditor.java
new file mode 100644
index 00000000000..604c258a822
--- /dev/null
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/MultiLineTextCellEditor.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Dirk Fauth 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:
+ * Dirk Fauth <dirk.fauth@gmail.com> - initial API and implementation
+ * Vincent Lorenzo (vincent.lorenzo@cea.fr) - duplicate this class from nattable (change super class)
+ *******************************************************************************/
+package org.eclipse.papyrus.infra.nattable.celleditor;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
+import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * A specialization of {@link TextCellEditor} that uses a multi line text editor as
+ * editor control. To support multi line editing correctly, the behaviour to commit
+ * on pressing the enter key is disabled.
+ * <p>
+ * A multi line editor usually needs some space. Therefore it might be a good decision
+ * to set the configuration attribute {@link EditConfigAttributes#OPEN_IN_DIALOG} to
+ * <code>true</code> for this editor, so the editor always opens in a subdialog.
+ * </p>
+ * <p>
+ * As some table layouts may support enough space for an inline cell editor, this editor
+ * does not specify {@link ICellEditor#openInline(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry,
+ * java.util.List)} to always return <code>false</code>.
+ * </p>
+ * @author Dirk Fauth
+ *
+ */
+public class MultiLineTextCellEditor extends TextCellEditor {
+
+ /**
+ * Flag to configure whether the text control should enable automatic line wrap behaviour
+ * or not. By default this editor will support automatic line wrapping.
+ */
+ private boolean lineWrap = true;
+
+ /**
+ * Create a new multi line text editor that ensures to not commit the editor
+ * value in case enter is typed. The text control will support automatic line wrapping.
+ */
+ public MultiLineTextCellEditor() {
+ this(true);
+ }
+
+ /**
+ * Create a new multi line text editor that ensures to not commit the editor
+ * value in case enter is typed.
+ * @param lineWrap Flag to configure whether the text control should enable automatic line
+ * wrap behaviour or not.
+ */
+ public MultiLineTextCellEditor(boolean lineWrap) {
+ this.commitOnEnter = false;
+ this.lineWrap = lineWrap;
+ }
+
+ @Override
+ public Text createEditorControl(Composite parent) {
+ int style = HorizontalAlignmentEnum.getSWTStyle(this.cellStyle) | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL;
+ if (lineWrap) {
+ style = style | SWT.WRAP;
+ } else {
+ style = style | SWT.H_SCROLL;
+ }
+ final Text textControl = super.createEditorControl(parent, style);
+
+ if (!openInline(this.configRegistry, this.labelStack.getLabels())) {
+ //add the layout data directly so it will not be layouted by the CellEditDialog
+ GridDataFactory.fillDefaults().grab(true, true).hint(100, 50).applyTo(textControl);
+ }
+
+ return textControl;
+ }
+
+ /**
+ * @param lineWrap <code>true</code> if the text control should enable automatic line
+ * wrap behaviour, <code>false</code> if not
+ */
+ public void setLineWrap(boolean lineWrap) {
+ this.lineWrap = lineWrap;
+ }
+}
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/MultiLineTextCellEditorEx.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/MultiLineTextCellEditorEx.java
new file mode 100644
index 00000000000..e0f9f1be5ee
--- /dev/null
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/MultiLineTextCellEditorEx.java
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ * 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:
+ * Vincent Lorenzo (CEA-LIST) - vincent.lorenzo@cea.fr
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.celleditor;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.keys.IBindingService;
+
+/**
+ *
+ * @author VL222926
+ * This multi line cell editor has the same behavior than spreadsheet (ALT+ENTER (Excel)for new line and ENTER to commit).
+ * To get this behavior, we desactivate the filtering done by org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher. This class
+ * set event.doit==false if the keypressed are binding for eclipse command (ALT-ENTER is registered to show property view)
+ *
+ * //TODO : the next version of nattable seems support this behavior with ALT-ENTER,
+ */
+public class MultiLineTextCellEditorEx extends MultiLineTextCellEditor {
+
+ /**
+ * boolean indicating if the eclipse filter was activated when the editor has been created
+ */
+ private boolean initialValueForFilteringKeyPress;
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public MultiLineTextCellEditorEx() {
+ super();
+ this.commitOnEnter = true;
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param lineWrap
+ */
+ public MultiLineTextCellEditorEx(boolean lineWrap) {
+ super(lineWrap);
+ this.commitOnEnter = true;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.celleditor.MultiLineTextCellEditor#createEditorControl(org.eclipse.swt.widgets.Composite)
+ *
+ * @param parent
+ * @return
+ */
+ @Override
+ public Text createEditorControl(Composite parent) {
+ IBindingService service = (IBindingService)PlatformUI.getWorkbench().getService(IBindingService.class);
+ this.initialValueForFilteringKeyPress = service.isKeyFilterEnabled();
+ if(this.initialValueForFilteringKeyPress) {
+ service.setKeyFilterEnabled(false);
+ }
+ return super.createEditorControl(parent);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.celleditor.TextCellEditor#close()
+ *
+ */
+ @Override
+ public void close() {
+ if(this.initialValueForFilteringKeyPress) {
+ IBindingService service = (IBindingService)PlatformUI.getWorkbench().getService(IBindingService.class);
+ service.setKeyFilterEnabled(this.initialValueForFilteringKeyPress);
+ }
+ super.close();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.celleditor.TextCellEditor#keyPressed(org.eclipse.swt.widgets.Composite, org.eclipse.swt.widgets.Text,
+ * org.eclipse.swt.events.KeyEvent)
+ *
+ * @param parent
+ * @param text
+ * @param event
+ */
+ @Override
+ protected void keyPressed(Composite parent, Text text, KeyEvent event) {
+ if(event.stateMask == SWT.ALT && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
+ text.insert(text.getLineDelimiter());
+ } else {
+ super.keyPressed(parent, text, event);
+ }
+ }
+}
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/TextCellEditor.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/TextCellEditor.java
new file mode 100644
index 00000000000..e9a9152b352
--- /dev/null
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/TextCellEditor.java
@@ -0,0 +1,457 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Original authors 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:
+ * Vincent Lorenzo (CEA-LIST) - duplicated and adapted code from nattable project.
+ *
+ ******************************************************************************/
+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.ICellEditor;
+import org.eclipse.nebula.widgets.nattable.edit.editor.IEditErrorHandler;
+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.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+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;
+
+/**
+ * {@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
+ */
+public class TextCellEditor extends AbstractCellEditor {
+
+ /**
+ * The Text control which is the editor wrapped by this TextCellEditor.
+ */
+ private Text 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 TextCellEditor() {
+ 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 TextCellEditor(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 TextCellEditor(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 String 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 Text getEditorControl() {
+ return this.text;
+ }
+
+ @Override
+ public Text createEditorControl(Composite parent) {
+ int style = HorizontalAlignmentEnum.getSWTStyle(this.cellStyle);
+ if(this.editMode == EditModeEnum.DIALOG) {
+ style = style | SWT.BORDER;
+ }
+ return createEditorControl(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 Text createEditorControl(final Composite parent, int style) {
+ //create the Text control based on the specified style
+ final Text textControl = new Text(parent, style);
+
+ //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(new KeyAdapter() {
+
+ @Override
+ public void keyPressed(KeyEvent event) {
+ TextCellEditor.this.keyPressed(parent, textControl, event);
+ }
+
+ @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;
+ }
+
+ protected void keyPressed(Composite parent, Text text, 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 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/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/listener/NatTableDropListener.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/listener/NatTableDropListener.java
index ee8754c0734..1ea0f87088c 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/listener/NatTableDropListener.java
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/listener/NatTableDropListener.java
@@ -73,12 +73,13 @@ public class NatTableDropListener implements DropTargetListener {
public void dragEnter(final DropTargetEvent event) {
//nothing to do
}
-/**
- *
- * @see org.eclipse.swt.dnd.DropTargetListener#dragLeave(org.eclipse.swt.dnd.DropTargetEvent)
- *
- * @param event
- */
+
+ /**
+ *
+ * @see org.eclipse.swt.dnd.DropTargetListener#dragLeave(org.eclipse.swt.dnd.DropTargetEvent)
+ *
+ * @param event
+ */
public void dragLeave(final DropTargetEvent event) {
//nothing to do
}
@@ -86,7 +87,7 @@ public class NatTableDropListener implements DropTargetListener {
/**
*
* @see org.eclipse.swt.dnd.DropTargetListener#dragOperationChanged(org.eclipse.swt.dnd.DropTargetEvent)
- *
+ *
* @param event
*/
public void dragOperationChanged(final DropTargetEvent event) {
@@ -96,7 +97,7 @@ public class NatTableDropListener implements DropTargetListener {
/**
*
* @see org.eclipse.swt.dnd.DropTargetListener#dragOver(org.eclipse.swt.dnd.DropTargetEvent)
- *
+ *
* @param event
*/
public void dragOver(final DropTargetEvent event) {
@@ -107,6 +108,9 @@ public class NatTableDropListener implements DropTargetListener {
if(data instanceof IStructuredSelection) {
structuredSelection = (IStructuredSelection)data;
}
+ if(structuredSelection == null) {
+ return;
+ }
final List<Object> droppedElements = new ArrayList<Object>((Collection<?>)structuredSelection.toList());
this.dropKindValue = this.manager.getLocationInTheTable(new Point(event.x, event.y));
int drop = DND.DROP_NONE;
@@ -189,7 +193,7 @@ public class NatTableDropListener implements DropTargetListener {
/**
*
* @see org.eclipse.swt.dnd.DropTargetListener#drop(org.eclipse.swt.dnd.DropTargetEvent)
- *
+ *
* @param event
*/
public void drop(final DropTargetEvent event) {
@@ -198,7 +202,7 @@ public class NatTableDropListener implements DropTargetListener {
Object data = localTransfer.nativeToJava(event.currentDataType);
if(data instanceof StructuredSelection) {
final IStructuredSelection selection = (IStructuredSelection)data;
- final List< Object> droppedElements = new ArrayList<Object>((Collection<?>)selection.toList());
+ final List<Object> droppedElements = new ArrayList<Object>((Collection<?>)selection.toList());
if(this.dropKindValue != null) {
switch(this.dropKindValue.getKind()) {
case AFTER_COLUMN_HEADER:
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
index b3166a86baa..98d45525bbe 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
@@ -396,7 +396,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
updateToggleCommandState(command, getTable().isInvertAxis());
} else {
- throw new RuntimeException(String.format("The Eclipse service {0} has not been found", ICommandService.class)); //$NON-NLS-1$
+ throw new RuntimeException(String.format("The Eclipse service %s has not been found", ICommandService.class)); //$NON-NLS-1$
}
}

Back to the top