Discussion:
[nebula-dev] New topic in forum Nebula, called TableComboViewer and changing the Background color of a row item, by Douglas Carter
f***@eclipse.org
2018-08-14 20:42:48 UTC
Permalink
I'm trying to create a dropdown box in which I can change the background color of individual rows based on what that row contains. I had hoped that the TableComboViewer as it can be given a LabelProvider that implements ITableColorProvider, therefore allowing you to what I had assumed was set the background color per row. No matter what I try though nothing appears to apply the changes to the background color of the TableCombo, in the Text area or in the drop down.

Label Provider Below


public class ViewGroupLabelProvider extends LabelProvider implements ITableLabelProvider, ITableColorProvider, ITableFontProvider {

public String getText(Object element) {
if (element instanceof String) {
return (String) element;
}
return "Unk";
}

@Override
public Font getFont(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;
}

@Override
public Color getForeground(Object element, int columnIndex) {
return Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
}

@Override
public Color getBackground(Object element, int columnIndex) {
if (element instanceof String) {
String item = (String) element;
switch (item) {
case "Brand":
return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED);
case "Make":
return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN);
case "Requested Part Number":
return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE);
}
}
return new Color(new Shell().getDisplay(), 255,0,0);
}

@Override
public Image getColumnImage(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;
}

@Override
public String getColumnText(Object element, int columnIndex) {
if (element instanceof String) {
return (String) element;
}
return "Unk";
}
}

To participate in the discussion, go here: https://www.eclipse.org/forums/index.php?t=rview&frm_id=64
Loading...