Mercurial > projects > dwt-addons
annotate dwtx/jface/viewers/EditingSupport.d @ 70:46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 22 May 2008 01:36:46 +0200 |
parents | b6c35faf97c8 |
children |
rev | line source |
---|---|
10 | 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 | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
11 * fix in bug 151295,167325,201905 |
10 | 12 * Port to the D programming language: |
13 * Frank Benoit <benoit@tionex.de> | |
14 *******************************************************************************/ | |
15 | |
16 module dwtx.jface.viewers.EditingSupport; | |
17 | |
18 import dwtx.jface.viewers.ColumnViewer; | |
19 import dwtx.jface.viewers.CellEditor; | |
20 import dwtx.jface.viewers.ViewerCell; | |
21 | |
22 import dwtx.core.runtime.Assert; | |
23 | |
24 import dwt.dwthelper.utils; | |
25 | |
26 /** | |
27 * EditingSupport is the abstract superclass of the support for cell editing. | |
28 * | |
29 * @since 3.3 | |
30 * | |
31 */ | |
32 public abstract class EditingSupport { | |
33 | |
34 private ColumnViewer viewer; | |
35 | |
36 /** | |
37 * @param viewer | |
38 * a new viewer | |
39 */ | |
40 public this(ColumnViewer viewer) { | |
41 Assert.isNotNull(viewer, "Viewer is not allowed to be null"); //$NON-NLS-1$ | |
42 this.viewer = viewer; | |
43 } | |
44 | |
45 /** | |
46 * The editor to be shown | |
47 * | |
48 * @param element | |
49 * the model element | |
50 * @return the CellEditor | |
51 */ | |
52 protected abstract CellEditor getCellEditor(Object element); | |
53 package CellEditor getCellEditor_package(Object element){ | |
54 return getCellEditor(element); | |
55 } | |
56 | |
57 /** | |
58 * Is the cell editable | |
59 * | |
60 * @param element | |
61 * the model element | |
62 * @return true if editable | |
63 */ | |
64 protected abstract bool canEdit(Object element); | |
65 package bool canEdit_package(Object element){ | |
66 return canEdit(element); | |
67 } | |
68 | |
69 /** | |
70 * Get the value to set to the editor | |
71 * | |
72 * @param element | |
73 * the model element | |
74 * @return the value shown | |
75 */ | |
76 protected abstract Object getValue(Object element); | |
77 | |
78 /** | |
79 * Restore the value from the CellEditor | |
80 * | |
81 * <p> | |
82 * <b>Subclasses should overwrite!</b> | |
83 * </p> | |
84 * | |
85 * @param element | |
86 * the model element | |
87 * @param value | |
88 * the new value | |
89 */ | |
90 protected abstract void setValue(Object element, Object value); | |
91 | |
92 /** | |
93 * @return the viewer this editing support works for | |
94 */ | |
95 public ColumnViewer getViewer() { | |
96 return viewer; | |
97 } | |
98 | |
99 /** | |
100 * Initialize the editor. Frameworks like Databinding can hook in here and provide | |
101 * a customized implementation. <p><b>Standard customers should not overwrite this method but {@link #getValue(Object)}</b></p> | |
102 * | |
103 * @param cellEditor | |
104 * the cell editor | |
105 * @param cell | |
106 * the cell the editor is working for | |
107 */ | |
108 protected void initializeCellEditorValue(CellEditor cellEditor, ViewerCell cell) { | |
109 Object value = getValue(cell.getElement()); | |
110 cellEditor.setValue(value); | |
111 } | |
112 package void initializeCellEditorValue_package(CellEditor cellEditor, ViewerCell cell) { | |
113 initializeCellEditorValue(cellEditor, cell); | |
114 } | |
115 | |
116 /** | |
117 * Save the value of the cell editor back to the model. Frameworks like Databinding can hook in here and provide | |
118 * a customized implementation. <p><b>Standard customers should not overwrite this method but {@link #setValue(Object, Object)} </b></p> | |
119 * @param cellEditor | |
120 * the cell-editor | |
121 * @param cell | |
122 * the cell the editor is working for | |
123 */ | |
124 protected void saveCellEditorValue(CellEditor cellEditor, ViewerCell cell) { | |
125 Object value = cellEditor.getValue(); | |
126 setValue(cell.getElement(), value); | |
127 } | |
128 package void saveCellEditorValue_package(CellEditor cellEditor, ViewerCell cell) { | |
129 saveCellEditorValue(cellEditor, cell); | |
130 } | |
131 | |
132 bool isLegacySupport() { | |
133 return false; | |
134 } | |
135 } |