Skip to content

Package: StringCellEditor$1

StringCellEditor$1

nameinstructionbranchcomplexitylinemethod
convert(Object)
M: 2 C: 17
89%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 1 C: 4
80%
M: 0 C: 1
100%
{...}
M: 0 C: 6
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-2014 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: * Eugen Neufeld - initial API and implementation
13: *******************************************************************************/
14: package org.eclipse.emf.ecp.edit.spi.swt.table;
15:
16: import org.eclipse.core.databinding.DataBindingContext;
17: import org.eclipse.core.databinding.UpdateValueStrategy;
18: import org.eclipse.core.databinding.property.value.IValueProperty;
19: import org.eclipse.emf.ecore.EStructuralFeature;
20: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
21: import org.eclipse.emf.edit.command.SetCommand;
22: import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
23: import org.eclipse.jface.databinding.viewers.CellEditorProperties;
24: import org.eclipse.swt.SWT;
25: import org.eclipse.swt.graphics.Image;
26: import org.eclipse.swt.widgets.Composite;
27:
28: /**
29: * A String cell editor which displays strings.
30: *
31: * @author Eugen Neufeld
32: * @since 1.5
33: *
34: */
35: public class StringCellEditor extends StringBasedCellEditor {
36:
37:         private EStructuralFeature eStructuralFeature;
38:
39:         /**
40:          * Default constructor.
41:          */
42:         public StringCellEditor() {
43:                 super();
44:         }
45:
46:         /**
47:          * A constructor which takes only a parent.
48:          *
49:          * @param parent the {@link Composite} to use as a parent.
50:          */
51:         public StringCellEditor(Composite parent) {
52:                 super(parent);
53:         }
54:
55:         /**
56:          * A constructor which takes the parent and the style.
57:          *
58:          * @param parent the {@link Composite} to use as a parent
59:          * @param style the Style to set
60:          */
61:         public StringCellEditor(Composite parent, int style) {
62:                 super(parent, style);
63:         }
64:
65:         @Override
66:         public IValueProperty getValueProperty() {
67:                 return CellEditorProperties.control().value(WidgetProperties.text(SWT.FocusOut));
68:         }
69:
70:         @Override
71:         public void instantiate(EStructuralFeature feature, ViewModelContext viewModelContext) {
72:                 super.instantiate(feature, viewModelContext);
73:                 eStructuralFeature = feature;
74:         }
75:
76:         @Override
77:         public String getFormatedString(Object value) {
78:                 if (value == null) {
79:                         return ""; //$NON-NLS-1$
80:                 }
81:                 return String.valueOf(value);
82:         }
83:
84:         @Override
85:         public int getColumnWidthWeight() {
86:                 return 100;
87:         }
88:
89:         @Override
90:         public UpdateValueStrategy getTargetToModelStrategy(DataBindingContext databindingContext) {
91:                 return withPreSetValidation(eStructuralFeature, new UpdateValueStrategy() {
92:
93:                         @Override
94:                         public Object convert(Object value) {
95:•                                if ("".equals(value)) { //$NON-NLS-1$
96:                                         value = null;
97:                                 }
98:•                                if (value == null && eStructuralFeature.isUnsettable()) {
99:                                         return SetCommand.UNSET_VALUE;
100:                                 }
101:                                 return super.convert(value);
102:                         }
103:
104:                 });
105:         }
106:
107:         @Override
108:         public UpdateValueStrategy getModelToTargetStrategy(DataBindingContext databindingContext) {
109:                 return null;
110:         }
111:
112:         @Override
113:         public void setEditable(boolean editable) {
114:                 if (text != null) {
115:                         text.setEditable(editable);
116:                 }
117:         }
118:
119:         @Override
120:         public Image getImage(Object value) {
121:                 return null;
122:         }
123:
124:         @Override
125:         public int getMinWidth() {
126:                 return 0;
127:         }
128:
129: }