Example usage for org.eclipse.jface.viewers ViewerCell setBackground

List of usage examples for org.eclipse.jface.viewers ViewerCell setBackground

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ViewerCell setBackground.

Prototype

public void setBackground(Color background) 

Source Link

Document

Set the background color of the cell.

Usage

From source file:net.tourbook.ui.views.tourDataEditor.TourDataEditorView.java

License:Open Source License

/**
 * column: #/*from  w  w  w  .jav  a  2 s .c o m*/
 */
private void defineColumn_Data_Sequence() {

    final ColumnDefinition colDef = TableColumnFactory.DATA_SEQUENCE.createColumn(_sliceColumnManager, _pc);

    colDef.setIsDefaultColumn();
    colDef.setCanModifyVisibility(false);
    colDef.setIsColumnMoveable(false);
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final int serieIndex = ((TimeSlice) cell.getElement()).serieIndex;
            final int logIndex = ((TimeSlice) cell.getElement()).uniqueCreateIndex;

            // the UI shows the time slice number starting with 1 and not with 0
            cell.setText(Integer.toString(logIndex + 0));

            // mark reference tour with a different background color
            boolean isBgSet = false;

            if (_refTourRange != null) {
                for (final int[] oneRange : _refTourRange) {
                    if ((serieIndex >= oneRange[0]) && (serieIndex <= oneRange[1])) {
                        cell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));
                        isBgSet = true;
                        break;
                    }
                }
            }

            if (isBgSet == false) {
                cell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            }
        }
    });
}

From source file:net.tourbook.ui.views.tourSegmenter.TourSegmenterView.java

License:Open Source License

private void setCellColor(final ViewerCell cell, final double value) {

    if (value == 0) {

        cell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));

    } else if (value > 0) {

        cell.setBackground(_colorCache.get(STATE_COLOR_ALTITUDE_UP));

    } else if (value < 0) {

        cell.setBackground(_colorCache.get(STATE_COLOR_ALTITUDE_DOWN));
    }//  w w w  .  j a  va  2 s .  com
}

From source file:net.tourbook.ui.views.tourSegmenter.TourSegmenterView.java

License:Open Source License

private void setTotalStyle(final ViewerCell cell) {

    //      cell.setFont(_boldFont);
    cell.setBackground(_colorCache.get(STATE_COLOR_TOTALS));
}

From source file:net.tourbook.ui.views.TourSegmenterView.java

License:Open Source License

private void setCellColor(final ViewerCell cell, final int altiDiff) {

    if (altiDiff == 0) {
        cell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    } else if (altiDiff > 0) {
        cell.setBackground(JFaceResources.getColorRegistry().get(UI.VIEW_COLOR_BG_SEGMENTER_UP));
    } else if (altiDiff < 0) {
        cell.setBackground(JFaceResources.getColorRegistry().get(UI.VIEW_COLOR_BG_SEGMENTER_DOWN));
    }//  w ww.jav a 2 s.  c o m
}

From source file:net.zehrer.no2.ui.provider.NoColumnLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {
    cell.setText(table.indexOf((TableItem) cell.getItem()) + 1 + "");
    cell.setBackground(this.color);
}

From source file:org.csstudio.alarm.beast.msghist.gui.SeverityLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {
    final Message message = (Message) cell.getElement();
    final String severity = message.getProperty(property);
    cell.setText(severity);// ww w . java2 s. c om
    final Color color = color_prefs.getColor(severity);
    if (color != null)
        cell.setBackground(color);
}

From source file:org.csstudio.alarm.beast.ui.alarmtable.AlarmTableLabelProvider.java

License:Open Source License

/** Update one cell of the table */
@Override//from   w ww.j  a va  2s .co  m
public void update(final ViewerCell cell) {
    // AlarmTableProvider should always provide "AlarmTreePV" elements
    final AlarmTreePV alarm = (AlarmTreePV) cell.getElement();

    // Special handling of 'info' entry that has no parent
    switch (column) {
    case ACK:
        cell.setImage(
                alarm.getSeverity().isActive() ? CheckBoxImages.getInstance(cell.getControl()).getImage(false)
                        : CheckBoxImages.getInstance(cell.getControl()).getImage(true));
        break;
    case ICON:
        cell.setImage(icon_provider.getIcon(alarm));
        break;
    case PV:
        cell.setText(alarm.getName());
        break;
    case DESCRIPTION: {
        final String annunciation = AnnunciationFormatter.format(alarm.getDescription(),
                alarm.getSeverity().getDisplayName(), alarm.getValue(), true);
        cell.setText(annunciation);
    }

        break;
    case TIME:
        cell.setText(formatter == null ? alarm.getTimestampText()
                : (alarm.getTimestamp() == null ? ""
                        : formatter.format(
                                ZonedDateTime.ofInstant(alarm.getTimestamp(), ZoneId.systemDefault()))));
        break;
    case CURRENT_SEVERITY:
        if (alarm.getParent() == null)
            return;
        cell.setText(alarm.getCurrentSeverity().getDisplayName());
        cell.setBackground(color_provider.getColor(alarm.getCurrentSeverity()));
        break;
    case CURRENT_STATUS:
        if (alarm.getParent() == null)
            return;
        cell.setText(alarm.getCurrentMessage());
        break;
    case SEVERITY:
        if (alarm.getParent() == null)
            return;
        cell.setText(alarm.getSeverity().getDisplayName());
        cell.setBackground(color_provider.getColor(alarm.getSeverity()));
        break;
    case STATUS:
        if (alarm.getParent() == null)
            return;
        cell.setText(alarm.getMessage());
        break;
    case VALUE:
        if (alarm.getParent() == null)
            return;
        cell.setText(alarm.getValue());
        break;
    case ACTION:
        GDCDataStructure[] guidance = alarm.getGuidance();
        if (guidance.length != 0) {
            cell.setText(guidance[0].getDetails());
        }
        break;
    case ID:
        GDCDataStructure[] guidances = alarm.getGuidance();
        if (guidances.length != 0) {
            cell.setText(guidances[0].getTitle());
        }
        break;
    default:
        break;
    }

    if (column == ColumnInfo.ICON)
        return;

    // If enabled, the background color will reflect the severity of the alarm (when in alarm state).
    // If reverse_colors is also enabled, the background/text colors for unacknowledged cleared alarms will be reversed.
    if (!background_color_alarm_sensitive)
        return;

    final SeverityLevel severity = alarm.getSeverity();
    if (severity == SeverityLevel.OK) {
        // if OK, use default colors
        cell.setBackground(null);
        cell.setForeground(null);
        return;
    }

    final SeverityLevel current_severity = alarm.getCurrentSeverity();
    final Color severity_color = color_provider.getColor(severity);
    final Color color_pair = color_pair_provider == null ? null : color_pair_provider.getColor(severity);

    Color bg_color = severity_color, fg_color = color_pair;

    if (reverse_colors && current_severity == SeverityLevel.OK) {
        // the alarm is currently cleared (recovered), and color reversal is enabled
        bg_color = color_pair;
        fg_color = severity_color;
    }

    cell.setBackground(bg_color);
    cell.setForeground(fg_color);
}

From source file:org.csstudio.alarm.beast.ui.alarmtree.AlarmTreeLabelProvider.java

License:Open Source License

/** Set a cell's text and color from alarm tree item */
@Override//from w ww.  j a v a2  s .com
public void update(final ViewerCell cell) {
    final AlarmTreeItem item = (AlarmTreeItem) cell.getElement();
    // Text
    String text = getText(item);
    if (!text.equals(cell.getText()))
        cell.setText(text);

    // Provide icon that represents the item's severity
    if (item instanceof AlarmTreePV && !((AlarmTreePV) item).isEnabled()) {
        cell.setImage(icon_provider.getDisabledIcon());
        cell.setBackground(null);
        cell.setForeground(null);
        return; // done, skip the color coding
    } else
        cell.setImage(icon_provider.getIcon(item.getCurrentSeverity(), item.getSeverity(),
                item.getDisabledChildCount() > 0));

    // Color-code AlarmTreePV based on severity.
    final SeverityLevel severity = item.getSeverity();
    //  'OK' severity isn't color-coded.
    if (severity == SeverityLevel.OK) {
        cell.setBackground(null);
        cell.setForeground(null);
        return;
    }
    //  Generally, the foreground (text) color is set,
    //  but for PV items with active alarms, the background
    //  color is set to make it stand out even more.
    final Color color = color_provider.getColor(severity);
    if ((item instanceof AlarmTreePV) && severity.isActive()) {
        cell.setBackground(color);
        cell.setForeground(null);
    } else {
        cell.setForeground(color);
        cell.setBackground(null);
    }
}

From source file:org.csstudio.diag.pvfields.gui.GUI.java

License:Open Source License

/** Create table for {@link PVField}s
 *  @param box Container/*  w w w.ja va2 s.c o m*/
 *  @return {@link TableViewer}
 */
private static TableViewer createFieldTable(final Composite box) {
    final TableColumnLayout table_layout = new TableColumnLayout();
    box.setLayout(table_layout);

    final TableViewer viewer = new TableViewer(box, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    final Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    ColumnViewerToolTipSupport.enableFor(viewer);
    viewer.setContentProvider(new ArrayContentProvider());

    final Display display = viewer.getTable().getDisplay();
    createColumn(viewer, table_layout, "Field", 40, new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            final PVField field = (PVField) cell.getElement();
            cell.setText(PVHelper.getField(field.getName()));
        }
    });
    createColumn(viewer, table_layout, "Original Value", 60, new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            final PVField field = (PVField) cell.getElement();
            cell.setText(field.getOriginalValue());
            if (field.isChanged())
                cell.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
            else
                cell.setBackground(null);
        }
    });
    createColumn(viewer, table_layout, "Current Value", 60, new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            final PVField field = (PVField) cell.getElement();
            cell.setText(field.getCurrentValue());
            if (field.isChanged())
                cell.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
            else
                cell.setBackground(null);
        }
    });
    return viewer;
}

From source file:org.csstudio.display.pace.gui.InstanceLabelProvider.java

License:Open Source License

/** @param gui_cell Cell in GUI that we need to update with info
 *                  from the corresponding cell in the Model
 *///from  w w w . j av  a2 s.  com
@Override
public void update(final ViewerCell gui_cell) {
    // ModelInstanceProvider should always provided "Instance" elements
    final Instance instance = (Instance) gui_cell.getElement();

    // Special name column? See comments in constructor
    if (column < 0) {
        gui_cell.setText(instance.getName());
        return;
    }
    // Cell column
    final Cell cell = instance.getCell(column);
    gui_cell.setText(cell.getValue());

    // Highlight edited cells with yellow background
    if (cell.isEdited()) {
        final Display display = Display.getCurrent();
        gui_cell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
    } else
        gui_cell.setBackground(null);
    // Highlight read-only cells with "inactive" background, usually
    // a light grey.
    // This is for cells configured to be read-only.
    // Those meant to be writable, but PV doesn't allow it,
    // for example because of Channel Access security,
    // say so in the tool tip.
    if (cell.isReadOnly()) {
        final Display display = Display.getCurrent();
        gui_cell.setBackground(display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND));
    }
}