package com.log4jviewer.ui.preferences.additional;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
/**
* Editor for the column with display preferences.
*
* @author <a href="mailto:rd.ryly@gmail.com">Ruslan Diachenko</a>
*/
public class ColumnDisplayCellEditor extends EditingSupport {
private final TableViewer tableViewer;
public ColumnDisplayCellEditor(final TableViewer tableViewer) {
super(tableViewer);
this.tableViewer = tableViewer;
}
@Override
protected CellEditor getCellEditor(final Object element) {
return new CheckboxCellEditor(tableViewer.getTable(), SWT.CHECK | SWT.CENTER);
}
@Override
protected boolean canEdit(final Object element) {
return true;
}
@Override
protected Object getValue(final Object element) {
return ((ColumnModel) element).isDisplay();
}
@Override
protected void setValue(final Object element, final Object value) {
ColumnModel columnModel = (ColumnModel) element;
columnModel.setDisplay((Boolean) value);
tableViewer.update(element, null);
}
}