Skip to content

Package: StringBasedCellEditor

StringBasedCellEditor

nameinstructionbranchcomplexitylinemethod
StringBasedCellEditor()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
StringBasedCellEditor(Composite)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
StringBasedCellEditor(Composite, int)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
activate(ColumnViewerEditorActivationEvent)
M: 15 C: 13
46%
M: 5 C: 1
17%
M: 3 C: 1
25%
M: 3 C: 4
57%
M: 0 C: 1
100%
doSetFocus()
M: 0 C: 14
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
fireCancelEditor()
M: 25 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
instantiate(EStructuralFeature, ViewModelContext)
M: 0 C: 14
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
isPrintable(char)
M: 13 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
withPreSetValidation(EStructuralFeature, UpdateValueStrategy)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2017 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Edgar Mueller - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.edit.spi.swt.table;
15:
16: import org.eclipse.core.databinding.UpdateValueStrategy;
17: import org.eclipse.emf.ecore.EStructuralFeature;
18: import org.eclipse.emf.ecp.edit.spi.swt.util.PreSetValidationStrategy;
19: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
20: import org.eclipse.emfforms.spi.swt.core.EMFFormsControlProcessorService;
21: import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
22: import org.eclipse.jface.viewers.TextCellEditor;
23: import org.eclipse.swt.SWT;
24: import org.eclipse.swt.widgets.Composite;
25:
26: /**
27: * Cell editor for string based cell editors that implements a custom
28: * activate method that propagates changes on first key stroke.
29: *
30: * @since 1.14
31: *
32: */
33: public abstract class StringBasedCellEditor extends TextCellEditor implements ECPCellEditor {
34:
35:         private String initialValue;
36:
37:         /**
38:          * Default constructor.
39:          */
40:         public StringBasedCellEditor() {
41:                 super();
42:         }
43:
44:         /**
45:          * Constructor.
46:          *
47:          * @param parent the parent {@link Composite}
48:          */
49:         public StringBasedCellEditor(Composite parent) {
50:                 super(parent);
51:         }
52:
53:         /**
54:          * Constructor.
55:          *
56:          * @param parent the parent {@link Composite}
57:          * @param style SWT styling bits
58:          */
59:         public StringBasedCellEditor(Composite parent, int style) {
60:                 super(parent, style);
61:         }
62:
63:         @Override
64:         public void activate(ColumnViewerEditorActivationEvent event) {
65:                 initialValue = text.getText();
66:•                if (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED
67:•                        && isPrintable(event.character)
68:•                        && (getStyle() & SWT.READ_ONLY) == 0) {
69:
70:                         doSetValue(String.valueOf(event.character));
71:                 }
72:                 super.activate(event);
73:         }
74:
75:         @Override
76:         protected void fireCancelEditor() {
77:•                if (text != null && !text.isDisposed()
78:•                        && text.getText() != null
79:•                        && !text.getText().equals(initialValue)) {
80:                         doSetValue(initialValue);
81:                 }
82:                 super.fireCancelEditor();
83:         }
84:
85:         @Override
86:         protected void doSetFocus() {
87:                 super.doSetFocus();
88:•                if (text.getText() != null) {
89:                         text.setSelection(text.getText().length());
90:                 }
91:         }
92:
93:         /**
94:          * Create a {@link PreSetValidationStrategy}.
95:          *
96:          * @param feature the feature the cell editor is bound against
97:          * @param delegate a delegate {@link UpdateValueStrategy}
98:          *
99:          * @return a {@link PreSetValidationStrategy}
100:          *
101:          */
102:         protected UpdateValueStrategy withPreSetValidation(EStructuralFeature feature, UpdateValueStrategy delegate) {
103:                 return new PreSetValidationStrategy(null, feature, delegate);
104:         }
105:
106:         /**
107:          * Determines whether the given character is printable.
108:          * Mimics behavior of Nebula's LetterOrDigitKeyEventMatcher.
109:          *
110:          *
111:          * @param character the character to be checked
112:          * @return {@code true}, if the character can be printed, {@code false} otherwise
113:          */
114:         protected boolean isPrintable(char character) {
115:•                return Character.isLetterOrDigit(character)
116:                         || Character
117:                                 .valueOf(character)
118:                                 .toString()
119:•                                .matches("[\\.:,;\\-_#\'+*~!?§$%&/()\\[\\]\\{\\}=\\\\\"]"); //$NON-NLS-1$
120:         }
121:
122:         @Override
123:         public void instantiate(EStructuralFeature feature, ViewModelContext viewModelContext) {
124:•                if (viewModelContext.hasService(EMFFormsControlProcessorService.class)) {
125:                         viewModelContext.getService(EMFFormsControlProcessorService.class).process(text, null, viewModelContext);
126:                 }
127:         }
128: }