Bug 168709 [Viewers] Request to open up ViewerColumn#setEditingSupport
setEditingSupport is now marked final. I would like to override this method to handle a very specific situation. The Grid can contain a checkbox in any column as opposed to Table which can only contain a checkbox in the first column. The new viewer API allows us to easily populate these checkboxes, but there is currently nothing that propogates any changes from the widget back to the model - i.e. if someone checks a checkbox the model currently doesn't get updated because this happens without an editor. So I designed a new CheckEditingSupport class. This is essentially a marker interface that lets me know that the user has set this as a check cell. The only method used from CheckEditingSupport is setValue. Here is my setEditingSupport implementation for reference: public void setEditingSupport(EditingSupport editingSupport) { if (editingSupport instanceof CheckEditingSupport) { if (checkEditingSupport == null) { final int colIndex = getColumn().getParent().indexOf(getColumn()); getColumn().getParent().addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { if (event.detail == SWT.CHECK && event.index == colIndex) { GridItem item = (GridItem)event.item; Object element = viewer.getElementAt(viewer.getGrid().indexOf(item)); checkEditingSupport.setValue(element, new Boolean(item.getChecked(colIndex))); } } }); } checkEditingSupport = (CheckEditingSupport)editingSupport; } else { super.setEditingSupport(editingSupport); } }
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerColumn.java
/**
 * Instances of this class represent a column of a {@link ColumnViewer}. Label
 * providers and editing support can be configured for each column separately.
 * Concrete subclasses of {@link ColumnViewer} should implement a matching
 * concrete subclass of {@link ViewerColumn}.
 * 
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as part
 * of a work in progress. This API may change at any given time. Please do not
 * use this API without consulting with the Platform/UI team.
 * 
 * @since 3.3
 * 
 */
public abstract class ViewerColumn {
	private CellLabelProvider labelProvider;
	static String COLUMN_VIEWER_KEY = Policy.JFACE + ".columnViewer";
	private EditingSupport editingSupport;
	private ILabelProviderListener listener;
	private boolean listenerRegistered = false;
	/**
	 * Create a new instance of the receiver at columnIndex.
	 * 
	 * @param viewer
	 *            the viewer the column is part of
	 * @param columnOwner
	 *            the widget owning the viewer in case the widget has no columns
	 *            this could be the widget itself
	 */
	protected ViewerColumn(final ColumnViewer viewer, Widget columnOwner) {
		columnOwner.setData(ViewerColumn.COLUMN_VIEWER_KEY, this);