KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > viewers > EditingSupport


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
11  * fix in bug 151295,167325,200558
12  *******************************************************************************/

13
14 package org.eclipse.jface.viewers;
15
16 import org.eclipse.core.runtime.Assert;
17
18 /**
19  * EditingSupport is the abstract superclass of the support for cell editing.
20  *
21  * @since 3.3
22  *
23  */

24 public abstract class EditingSupport {
25
26     private ColumnViewer viewer;
27
28     /**
29      * @param viewer
30      * a new viewer
31      */

32     public EditingSupport(ColumnViewer viewer) {
33         Assert.isNotNull(viewer, "Viewer is not allowed to be null"); //$NON-NLS-1$
34
this.viewer = viewer;
35     }
36
37     /**
38      * The editor to be shown
39      *
40      * @param element
41      * the model element
42      * @return the CellEditor
43      */

44     protected abstract CellEditor getCellEditor(Object JavaDoc element);
45
46     /**
47      * Is the cell editable
48      *
49      * @param element
50      * the model element
51      * @return true if editable
52      */

53     protected abstract boolean canEdit(Object JavaDoc element);
54
55     /**
56      * Get the value to set to the editor
57      *
58      * @param element
59      * the model element
60      * @return the value shown
61      */

62     protected abstract Object JavaDoc getValue(Object JavaDoc element);
63
64     /**
65      * Restore the value from the CellEditor
66      *
67      * <p>
68      * <b>Subclasses should overwrite!</b>
69      * </p>
70      *
71      * @param element
72      * the model element
73      * @param value
74      * the new value
75      */

76     protected abstract void setValue(Object JavaDoc element, Object JavaDoc value);
77
78     /**
79      * @return the viewer this editing support works for
80      */

81     public ColumnViewer getViewer() {
82         return viewer;
83     }
84
85     /**
86      * Initialize the editor. Frameworks like Databinding can hook in here and provide
87      * a customized implementation. <p><b>Standard customers should not overwrite this method but {@link #getValue(Object)}</b></p>
88      *
89      * @param cellEditor
90      * the cell editor
91      * @param cell
92      * the cell the editor is working for
93      */

94     protected void initializeCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
95         Object JavaDoc value = getValue(cell.getElement());
96         cellEditor.setValue(value);
97     }
98
99     /**
100      * Save the value of the cell editor back to the model. Frameworks like Databinding can hook in here and provide
101      * a customized implementation. <p><b>Standard customers should not overwrite this method but {@link #setValue(Object, Object)} </b></p>
102      * @param cellEditor
103      * the cell-editor
104      * @param cell
105      * the cell the editor is working for
106      */

107     protected void saveCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
108         Object JavaDoc value = cellEditor.getValue();
109         setValue(cell.getElement(), value);
110     }
111
112     boolean isLegacySupport() {
113         return false;
114     }
115 }
116
Popular Tags