001: /*******************************************************************************
002: * Copyright (c) 2006, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
011: * fix in bug 151295,167325,201905
012: *******************************************************************************/package org.eclipse.jface.viewers;
013:
014: import org.eclipse.core.runtime.Assert;
015:
016: /**
017: * EditingSupport is the abstract superclass of the support for cell editing.
018: *
019: * @since 3.3
020: *
021: */
022: public abstract class EditingSupport {
023:
024: private ColumnViewer viewer;
025:
026: /**
027: * @param viewer
028: * a new viewer
029: */
030: public EditingSupport(ColumnViewer viewer) {
031: Assert.isNotNull(viewer, "Viewer is not allowed to be null"); //$NON-NLS-1$
032: this .viewer = viewer;
033: }
034:
035: /**
036: * The editor to be shown
037: *
038: * @param element
039: * the model element
040: * @return the CellEditor
041: */
042: protected abstract CellEditor getCellEditor(Object element);
043:
044: /**
045: * Is the cell editable
046: *
047: * @param element
048: * the model element
049: * @return true if editable
050: */
051: protected abstract boolean canEdit(Object element);
052:
053: /**
054: * Get the value to set to the editor
055: *
056: * @param element
057: * the model element
058: * @return the value shown
059: */
060: protected abstract Object getValue(Object element);
061:
062: /**
063: * Restore the value from the CellEditor
064: *
065: * <p>
066: * <b>Subclasses should overwrite!</b>
067: * </p>
068: *
069: * @param element
070: * the model element
071: * @param value
072: * the new value
073: */
074: protected abstract void setValue(Object element, Object value);
075:
076: /**
077: * @return the viewer this editing support works for
078: */
079: public ColumnViewer getViewer() {
080: return viewer;
081: }
082:
083: /**
084: * Initialize the editor. Frameworks like Databinding can hook in here and provide
085: * a customized implementation. <p><b>Standard customers should not overwrite this method but {@link #getValue(Object)}</b></p>
086: *
087: * @param cellEditor
088: * the cell editor
089: * @param cell
090: * the cell the editor is working for
091: */
092: protected void initializeCellEditorValue(CellEditor cellEditor,
093: ViewerCell cell) {
094: Object value = getValue(cell.getElement());
095: cellEditor.setValue(value);
096: }
097:
098: /**
099: * Save the value of the cell editor back to the model. Frameworks like Databinding can hook in here and provide
100: * a customized implementation. <p><b>Standard customers should not overwrite this method but {@link #setValue(Object, Object)} </b></p>
101: * @param cellEditor
102: * the cell-editor
103: * @param cell
104: * the cell the editor is working for
105: */
106: protected void saveCellEditorValue(CellEditor cellEditor,
107: ViewerCell cell) {
108: Object value = cellEditor.getValue();
109: setValue(cell.getElement(), value);
110: }
111:
112: boolean isLegacySupport() {
113: return false;
114: }
115: }
|