aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Weigelt2012-03-26 11:31:27 (EDT)
committerMichael Jastram2012-04-05 06:23:33 (EDT)
commit2e3b24de1f1bf6af3e763cb5944e82772450927d (patch)
tree1933f854e0104c31389161030ea2a4b38d4e6bc4
parent7e57db969d0d6cfc7f5d4b93ec5b3987f0f02772 (diff)
downloadorg.eclipse.rmf-2e3b24de1f1bf6af3e763cb5944e82772450927d.zip
org.eclipse.rmf-2e3b24de1f1bf6af3e763cb5944e82772450927d.tar.gz
org.eclipse.rmf-2e3b24de1f1bf6af3e763cb5944e82772450927d.tar.bz2
fixed Bug 375240:
Capture the first character when starting to edit in SpecEditor
-rw-r--r--org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGridViewer.java2
-rw-r--r--org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrCellEditor.java52
2 files changed, 54 insertions, 0 deletions
diff --git a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGridViewer.java b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGridViewer.java
index 263cc7d..9d126ff 100644
--- a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGridViewer.java
+++ b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGridViewer.java
@@ -19,6 +19,7 @@ import java.util.Set;
import org.agilemore.agilegrid.AgileGrid;
import org.agilemore.agilegrid.Cell;
import org.agilemore.agilegrid.CellResizeAdapter;
+import org.agilemore.agilegrid.EditorActivationStrategy;
import org.agilemore.agilegrid.ICellResizeListener;
import org.agilemore.agilegrid.ISelectionChangedListener;
import org.agilemore.agilegrid.SWTX;
@@ -122,6 +123,7 @@ public class ProrAgileGridViewer extends Viewer {
| SWTX.FILL_WITH_LASTCOL | SWT.MULTI | SWT.DOUBLE_BUFFERED);
agileGrid.setLayoutAdvisor(new ProrLayoutAdvisor(agileGrid));
// agileGrid.setAgileGridEditor(new ProrAgileGridEditor(agileGrid));
+ agileGrid.setEditorActivationStrategy(new EditorActivationStrategy(agileGrid, true));
this.editingDomain = editingDomain;
this.adapterFactory = adapterFactory;
enableDragNDrop();
diff --git a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrCellEditor.java b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrCellEditor.java
index 69d91ef..dfbb942 100644
--- a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrCellEditor.java
+++ b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrCellEditor.java
@@ -11,6 +11,7 @@
package org.eclipse.rmf.pror.reqif10.editor.agilegrid;
import org.agilemore.agilegrid.AgileGrid;
+import org.agilemore.agilegrid.EditorActivationEvent;
import org.agilemore.agilegrid.editors.TextCellEditor;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.jface.action.IStatusLineManager;
@@ -19,6 +20,7 @@ import org.eclipse.rmf.reqif10.Identifiable;
import org.eclipse.rmf.reqif10.SpecHierarchy;
import org.eclipse.rmf.reqif10.util.Reqif10Util;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorSite;
@@ -128,4 +130,54 @@ public abstract class ProrCellEditor extends TextCellEditor {
*/
@Override
abstract protected Object doGetValue();
+
+ /**
+ * Changes the TextCellEditor behavior to capture the first character when
+ * starting to edit. I.e. if one activates the edit mode by pressing a
+ * character key, the current text is replaced by that character.
+ */
+ @Override
+ public void activate(EditorActivationEvent activationEvent) {
+ if (activationEvent.sourceEvent instanceof KeyEvent) {
+ KeyEvent keyEvent = (KeyEvent) activationEvent.sourceEvent;
+ if (isValidCellEditorCharacter(keyEvent)) {
+ text.setText("" + keyEvent.character);
+ // this.fireApplyEditorValue();
+ super.activate(activationEvent);
+ text.setSelection(1, 1);
+ return;
+ }
+ }
+ super.activate(activationEvent);
+ text.selectAll();
+ }
+
+ /**
+ * Helper function to determine if a keypress that already triggered editor
+ * activation is a valid character that can be displayed in the text field.
+ *
+ * @param keyEvent
+ * @return
+ */
+ protected boolean isValidCellEditorCharacter(KeyEvent keyEvent) {
+ System.out.println(keyEvent.keyCode);
+ switch (keyEvent.character) {
+ case ' ':
+ case '\r':
+ case SWT.DEL:
+ case SWT.BS:
+ return false;
+ }
+
+ if ((Character.isLetterOrDigit(keyEvent.character) || keyEvent.keyCode > 32
+ && keyEvent.keyCode < 254 && keyEvent.keyCode != 127)
+ && keyEvent.keyCode != SWT.CTRL
+ && keyEvent.keyCode != SWT.ALT
+ && (keyEvent.stateMask & SWT.CONTROL) == 0
+ && (keyEvent.stateMask & SWT.ALT) == 0) {
+ return true;
+ }
+
+ return false;
+ }
}