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
/*******************************************************************************
 * Copyright (c) 2006 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 Shindl <tom.schindl@bestsolution.at> - initial API and implementation
 * 												  fix for bug 163317
 ******************************************************************************/
package org.eclipse.jface.viewers;
import org.eclipse.jface.util.Policy;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Widget;