1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*******************************************************************************
* Copyright (c) 2006, 2008 IBM Corporation 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:
* IBM Corporation - initial API and implementation
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* fix in bug 151295,167325,201905
*******************************************************************************/
package org.eclipse.jface.viewers;
import org.eclipse.core.runtime.Assert;
/**
* EditingSupport is the abstract superclass of the support for cell editing.
*
* @since 3.3
*
*/
public abstract class EditingSupport {
private ColumnViewer viewer;
/**
* @param viewer
* a new viewer
*/
public EditingSupport(ColumnViewer viewer) {
Assert.isNotNull(viewer, "Viewer is not allowed to be null"); //$NON-NLS-1$
this.viewer = viewer;
}
/**
* The editor to be shown
*
* @param element
* the model element
* @return the CellEditor
*/
protected abstract CellEditor getCellEditor(Object element);
/**
* Is the cell editable
*
* @param element
* the model element
* @return true if editable
*/
protected abstract boolean canEdit(Object element);
/**
* Get the value to set to the editor
*
* @param element
* the model element
* @return the value shown
*/
protected abstract Object getValue(Object element);
/**
* Sets the new value on the given element. Note that implementers need to
* ensure that <code>getViewer().update(element, null)</code> or similar
* methods are called, either directly or through some kind of listener
* mechanism on the implementer's model, to cause the new value to appear in
* the viewer.
*
* <p>
* <b>Subclasses should overwrite.</b>
* </p>
*
* @param element
* the model element
* @param value
* the new value
*/
protected abstract void setValue(Object element, Object value);
/**
* @return the viewer this editing support works for
*/
public ColumnViewer getViewer() {
return viewer;
}
/**
* Initialize the editor. Frameworks like Databinding can hook in here and provide
* a customized implementation. <p><b>Standard customers should not overwrite this method but {@link #getValue(Object)}</b></p>
*
* @param cellEditor
* the cell editor
* @param cell
* the cell the editor is working for
*/
protected void initializeCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
Object value = getValue(cell.getElement());
cellEditor.setValue(value);
}
/**
* Save the value of the cell editor back to the model. Frameworks like Databinding can hook in here and provide
* a customized implementation. <p><b>Standard customers should not overwrite this method but {@link #setValue(Object, Object)} </b></p>
* @param cellEditor
* the cell-editor
* @param cell
* the cell the editor is working for
*/
protected void saveCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
Object value = cellEditor.getValue();
setValue(cell.getElement(), value);
}
boolean isLegacySupport() {
return false;
}
}
|