package com.log4jviewer.ui.preferences.additional;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColorCellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.graphics.RGB;
/**
* Editor for choosing log background color from the log display table preferences.
*
* @author <a href="mailto:rd.ryly@gmail.com">Ruslan Diachenko</a>
*/
public class LogBackgroundCellEditor extends EditingSupport {
private final TableViewer tableViewer;
public LogBackgroundCellEditor(final TableViewer tableViewer) {
super(tableViewer);
this.tableViewer = tableViewer;
}
@Override
protected CellEditor getCellEditor(final Object element) {
return new ColorCellEditor(tableViewer.getTable());
}
@Override
protected boolean canEdit(final Object element) {
return true;
}
@Override
protected Object getValue(final Object element) {
return ((LogLevelDisplayModel) element).getBackground();
}
@Override
protected void setValue(final Object element, final Object value) {
LogLevelDisplayModel levelDisplayModel = (LogLevelDisplayModel) element;
levelDisplayModel.setBackground((RGB) value);
tableViewer.update(element, null);
}
}