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

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

Introduction

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

Prototype

public void setForeground(Color foreground) 

Source Link

Document

Set the foreground color of the cell.

Usage

From source file:gov.redhawk.sca.internal.ui.wizards.ValueColumnLabelProvider.java

License:Open Source License

@Override
public void update(final ViewerCell cell) {
    final Object element = cell.getElement();
    if (element instanceof Simple) {
        final Simple simple = (Simple) element;
        final SimpleRef ref = Util.getRef(simple, getComponentInstantiation());
        final DataType override = getOverride(simple.getId());
        if (override == null) {
            cell.setForeground(getDefaultColor(cell.getControl()));
            if (ref == null) {
                if (simple.getValue() != null) {
                    cell.setText(getText(simple.getEnumerations(), simple.getValue()));
                } else {
                    cell.setText("");
                }/*from  w  w w  .j ava  2  s .com*/
            } else {
                cell.setText(ref.getValue());
            }
        } else {
            cell.setText(AnyUtils.convertAny(override.value).toString());
            cell.setForeground(null);
        }
        Image image = null;
        if (PropertiesUtil.canOverride(simple)) {
            image = getImage(element);
        }
        cell.setImage(image);
    } else if (element instanceof SimpleSequence) {
        final SimpleSequence simple = (SimpleSequence) element;
        final SimpleSequenceRef ref = Util.getRef(simple, getComponentInstantiation());
        final DataType override = getOverride(simple.getId());
        if (override == null) {
            cell.setForeground(getDefaultColor(cell.getControl()));
            if (ref == null) {
                if (simple.getValues() != null) {
                    cell.setText(Arrays.toString(simple.getValues().getValue().toArray()));
                } else {
                    cell.setText("");
                }
            } else {
                cell.setText(Arrays.toString(ref.getValues().getValue().toArray()));
            }
        } else {
            cell.setText(
                    Arrays.toString((Object[]) AnyUtils.convertAny(override.value, override.value.type())));
            cell.setForeground(null);
        }
        Image image = null;
        if (PropertiesUtil.canOverride(simple)) {
            image = getImage(element);
        }
        cell.setImage(image);
    }

}

From source file:net.sf.smbt.ui.ableton.views.AbletonLiveView.java

License:LGPL

private TreeViewerColumn createTableViewerColumn(String title, int bound) {
    final TreeViewerColumn viewerColumn = new TreeViewerColumn(subDetailsViewer, SWT.NONE);
    final TreeColumn column = viewerColumn.getColumn();
    column.setText(title);//  www  .ja  v  a  2  s  .  co  m
    column.setWidth(bound);
    column.setResizable(true);
    column.setMoveable(true);
    viewerColumn.setLabelProvider(new StyledCellLabelProvider() {
        @Override
        protected void paint(Event event, Object element) {
            if (element instanceof LiveScene) {
                TreeItem treeItem = (TreeItem) event.item;
                Object obj = treeItem.getData(viewerColumn.getColumn().getText() + "#clip");
                if (obj != null) {
                    LiveClip c = (LiveClip) obj;
                    super.paint(event, element);
                    if (((LiveScene) element).getSceneID() == lastSceneID) {
                        int width = 0;
                        int height = event.height - 4;
                        int x = event.x;
                        int y = event.y + 2;
                        float l = c.getLength();
                        float p = c.getPosition();

                        if (p > 0 && l > 0) {
                            float ratio = p / l;
                            width = Float.valueOf(ratio * (float) viewerColumn.getColumn().getWidth())
                                    .intValue();
                            event.gc.setAlpha(100);
                            event.gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
                            event.gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
                            event.gc.fillRoundRectangle(x, y, width, height, 2, 2);
                            event.gc.setAlpha(255);
                            event.gc.drawRoundRectangle(x, y, width, height, 2, 2);
                        }
                    }
                } else {
                    super.paint(event, element);
                }
            } else {
                super.paint(event, element);
            }
        }

        @Override
        public void update(ViewerCell cell) {
            super.update(cell);
            if (cell.getElement() instanceof LiveScene) {
                LiveScene scene = (LiveScene) cell.getElement();
                int idx = cell.getColumnIndex();
                if (liveController.getLiveApp().getTracks().size() > idx) {
                    LiveTrack track = liveController.getLiveApp().getTracks().get(idx);
                    for (LiveClip c : track.getClips()) {
                        if (scene.getSceneID() == c.getClipID()) {
                            cell.setText(c.getClipName());
                            //cell.getStyleRanges();
                            /*
                            switch(c.getClipState()) {
                               case PLAYING:
                               case TRIGGERED:
                                  cell.setImage(playImage);
                                  //break;
                               case STOP:
                                  cell.setImage(stopImage);
                                  break;
                               default:
                                  cell.setImage(stopImage);
                                  break;
                            };*/

                            cell.setImage(lastSceneID == scene.getSceneID() ? playImage : stopImage);

                            if (c.getColor() != null) {
                                cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
                                cell.setBackground(c.getColor());
                            }

                            cell.getItem().setData(track.getTrackName() + "#clip", c);
                            break;
                        } else {
                            cell.setForeground(GUIToolkit.FG);
                            cell.setBackground(GUIToolkit.BG);
                        }
                    }
                }
            }
        }
    });
    return viewerColumn;
}

From source file:net.sf.smbt.ui.btc.views.MTGoxView.java

License:LGPL

private TreeViewerColumn createHistoryTableViewerColumn(String title, int bound) {
    final TreeViewerColumn viewerColumn = new TreeViewerColumn(hitoryTreeViewer, SWT.NONE);
    final TreeColumn column = viewerColumn.getColumn();
    column.setText(title);/*from   www  .  j  ava 2s.c om*/
    column.setWidth(bound);
    column.setResizable(true);
    column.setMoveable(true);
    viewerColumn.setLabelProvider(new StyledCellLabelProvider() {
        @Override
        protected void paint(Event event, Object element) {
            super.paint(event, element);
        }

        @Override
        public void update(ViewerCell cell) {
            super.update(cell);
            if (cell.getElement() instanceof WalletRecord) {
                WalletRecord v = (WalletRecord) cell.getElement();
                String cellText = "???";
                switch (cell.getColumnIndex()) {
                case 0:
                    cellText = "" + v.getIndex();
                    break;
                case 1:
                    cellText = "" + v.getInfo();
                    break;
                case 2:
                    cellText = "" + v.getType();
                    break;
                case 3:
                    cellText = "" + v.getBalance().getDisplay_short();
                    break;
                case 4:
                    cellText = "" + v.getDate();
                    break;
                case 5:
                    cellText = "" + v.getValue().getDisplay_short();
                    break;
                }
                cell.setText(cellText);
                cell.setForeground(GUIToolkit.FG);
                cell.setBackground(GUIToolkit.BG);
            }
        }
    });
    return viewerColumn;
}

From source file:net.sf.smbt.ui.btc.views.MTGoxView.java

License:LGPL

private TreeViewerColumn createTableViewerColumn(String title, int bound) {
    final TreeViewerColumn viewerColumn = new TreeViewerColumn(transactionTreeViewer, SWT.NONE);
    final TreeColumn column = viewerColumn.getColumn();
    column.setText(title);//from  w  ww  .  j  a v  a  2s  . c o  m
    column.setWidth(bound);
    column.setResizable(true);
    column.setMoveable(true);
    viewerColumn.setLabelProvider(new StyledCellLabelProvider() {
        @Override
        protected void paint(Event event, Object element) {
            super.paint(event, element);
        }

        @Override
        public void update(ViewerCell cell) {
            super.update(cell);
            if (cell.getElement() instanceof Order) {
                Order v = (Order) cell.getElement();
                String cellText = "???";
                switch (cell.getColumnIndex()) {
                case 0:
                    cellText = "" + v.getOid();
                    break;
                case 1:
                    cellText = "" + v.getType();
                    break;
                case 2:
                    cellText = "" + v.getAmount().getDisplay_short();
                    break;
                case 3:
                    cellText = "" + v.getPrice().getDisplay_short();
                    break;
                case 4:
                    cellText = "" + v.getStatus();
                    break;
                case 5:
                    cellText = "" + v.getDate();
                    break;
                }
                cell.setText(cellText);
                cell.setForeground(GUIToolkit.FG);
                cell.setBackground(GUIToolkit.BG);
            }
        }
    });
    return viewerColumn;
}

From source file:net.sf.smbt.ui.btc.views.TradesView.java

License:LGPL

private TreeViewerColumn createBidTradeTableViewerColumn(String title, int bound, TreeViewer tv) {
    final TreeViewerColumn viewerColumn = new TreeViewerColumn(tv, SWT.NONE);
    final TreeColumn column = viewerColumn.getColumn();
    column.setText(title);/*from   w w  w  .j a v  a  2s. c o m*/
    column.setWidth(bound);
    column.setResizable(true);
    column.setMoveable(true);
    viewerColumn.setLabelProvider(new StyledCellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            super.update(cell);
            if (cell.getElement() instanceof DepthValue) {
                DepthValue v = (DepthValue) cell.getElement();
                String cellText = "???";
                cell.setForeground(GUIToolkit.FG);
                cell.setBackground(GUIToolkit.BG);
                long now = System.currentTimeMillis();
                switch (cell.getColumnIndex()) {
                case 0: // Bid Sum
                    if (v instanceof DepthValue) {
                        cellText = "" + v.getSum();
                    }
                    break;
                case 1: // Size
                    if (v instanceof DepthValue) {
                        cellText = "" + v.getAmount();
                    }
                    break;
                case 2: // Bid
                    if (v instanceof DepthValue) {
                        cellText = "" + v.getPrice();
                    }
                    break;
                }
                cell.setText(cellText);
                if (v instanceof DepthValue && (cell.getColumnIndex() == 0 || cell.getColumnIndex() == 1
                        || cell.getColumnIndex() == 2)) {
                    if (v.getLastLocalStatus() + 12000l > now) {
                        if (v.getStatus().equals(DepthStatus.ADD)) {
                            cell.setForeground(GUIToolkit.lightGreen);
                        } else if (v.getStatus().equals(DepthStatus.REM)) {
                            cell.setForeground(GUIToolkit.lightRed);
                        } else if (v.getStatus().equals(DepthStatus.UPDATE)) {
                            cell.setForeground(GUIToolkit.orange);
                        }
                    }
                }
            }
        }
    });
    return viewerColumn;
}

From source file:net.sf.smbt.ui.btc.views.TradesView.java

License:LGPL

private TreeViewerColumn createAskTradeTableViewerColumn(String title, int bound, TreeViewer tv) {
    final TreeViewerColumn viewerColumn = new TreeViewerColumn(tv, SWT.NONE);
    final TreeColumn column = viewerColumn.getColumn();
    column.setText(title);//  w w  w.  j  ava  2 s .  c  o m
    column.setWidth(bound);
    column.setResizable(true);
    column.setMoveable(true);
    viewerColumn.setLabelProvider(new StyledCellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            super.update(cell);
            if (cell.getElement() instanceof DepthValue) {
                DepthValue v = (DepthValue) cell.getElement();
                String cellText = "???";
                cell.setForeground(GUIToolkit.FG);
                cell.setBackground(GUIToolkit.BG);
                long now = System.currentTimeMillis();
                switch (cell.getColumnIndex()) {
                case 2: // Bid Sum
                    if (v instanceof DepthValue) {
                        cellText = "" + v.getSum();
                    }
                    break;
                case 1: // Size
                    if (v instanceof DepthValue) {
                        cellText = "" + v.getAmount();
                    }
                    break;
                case 0: // Bid
                    if (v instanceof DepthValue) {
                        cellText = "" + v.getPrice();
                    }
                    break;
                }
                cell.setText(cellText);
                if (v instanceof DepthValue && (cell.getColumnIndex() == 0 || cell.getColumnIndex() == 1
                        || cell.getColumnIndex() == 2)) {
                    if (v.getLastLocalStatus() + 12000l > now) {
                        if (v.getStatus().equals(DepthStatus.ADD)) {
                            cell.setForeground(GUIToolkit.lightGreen);
                        } else if (v.getStatus().equals(DepthStatus.REM)) {
                            cell.setForeground(GUIToolkit.lightRed);
                        } else if (v.getStatus().equals(DepthStatus.UPDATE)) {
                            cell.setForeground(GUIToolkit.orange);
                        }
                    }
                }
            }
        }
    });
    return viewerColumn;
}

From source file:net.sf.smbt.ui.btc.views.TradesView.java

License:LGPL

private TreeViewerColumn createSalesTableViewerColumn(String title, int bound, TreeViewer tv) {
    final TreeViewerColumn viewerColumn = new TreeViewerColumn(tv, SWT.NONE);
    final TreeColumn column = viewerColumn.getColumn();
    column.setText(title);//from  w w  w. j  av  a 2  s  .  co m
    column.setWidth(bound);
    column.setResizable(true);
    column.setMoveable(true);
    viewerColumn.setLabelProvider(new StyledCellLabelProvider() {
        @Override
        protected void paint(Event event, Object element) {
            super.paint(event, element);
        }

        @Override
        public void update(ViewerCell cell) {
            super.update(cell);
            if (cell.getElement() instanceof DepthValue) {
                DepthValue v = (DepthValue) cell.getElement();
                String cellText = "???";
                switch (cell.getColumnIndex()) {
                case 0: // Amount
                    cellText = "" + v.getAmount();
                    cell.setForeground(GUIToolkit.FG);
                    cell.setBackground(GUIToolkit.BG);
                    break;
                case 1: // Price
                    String symbol = BTCUtils.INSTANCE.getCurrencySymbol(v.getCurrency());
                    cellText = "" + v.getPrice() + " " + symbol;
                    cell.setForeground(
                            v.getKind().equals(FetchKind.ASK) ? GUIToolkit.lightRed : GUIToolkit.lightGreen);
                    cell.setBackground(GUIToolkit.dark_gray);
                    break;
                case 2: // Date
                    cell.setForeground(GUIToolkit.FG);
                    cell.setBackground(GUIToolkit.BG);
                    cellText = "" + HH_MM_SS_DATE_FORMAT.format(new Date(v.getStamp()));
                    break;
                }
                cell.setText(cellText);
            }
        }
    });
    return viewerColumn;
}

From source file:net.ssehub.easy.producer.ui.productline_editor.configuration.AbstractConfigurationLabelProvider.java

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    int index = cell.getVisualIndex();
    String text = getColumnText(element, index);
    cell.setText(text);/*from w  w w.ja v  a2 s  . c  o  m*/
    cell.setImage(getColumnImage(element, index));
    if (ColumnType.ERROR == columType(index) && null != text) {
        cell.setForeground(ERROR_COLOR);
    } else {
        cell.setForeground(getForeground(element));
    }
    cell.setBackground(getBackground(element));
}

From source file:net.tourbook.common.util.DialogModifyColumns.java

License:Open Source License

private void setColor(final ViewerCell cell, final ColumnDefinition colDef) {

    // paint columns in a different color which can't be hidden
    if (colDef.canModifyVisibility() == false) {
        cell.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
    }//from  ww w  . j  a  va2 s  .c  o m
}

From source file:net.tourbook.importdata.DialogEasyImportConfig.java

License:Open Source License

/**
 * Column: Delete device files//from   w  w w.  j  ava2  s  .com
 */
private void defineColumnIC_90_DeleteDeviceFiles() {

    final TableColumnDefinition colDef = new TableColumnDefinition(_icColumnManager, "deleteFiles", SWT.CENTER); //$NON-NLS-1$

    colDef.setColumnLabel(Messages.Dialog_ImportConfig_Column_DeleteFiles_Label);
    colDef.setColumnHeaderText(Messages.Dialog_ImportConfig_Column_DeleteFiles_Header);
    colDef.setColumnHeaderToolTipText(Messages.Dialog_ImportConfig_Column_DeleteFiles_Tooltip);

    colDef.setDefaultColumnWidth(_pc.convertWidthInCharsToPixels(12));

    colDef.setIsDefaultColumn();

    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final ImportConfig importConfig = (ImportConfig) cell.getElement();

            final boolean isDeleteDeviceFiles = importConfig.isDeleteDeviceFiles;

            if (importConfig.isCreateBackup) {

                cell.setText(isDeleteDeviceFiles //
                        ? Messages.App_Label_BooleanYes
                        : Messages.App_Label_BooleanNo);

                cell.setForeground(isDeleteDeviceFiles //
                        ? COLOR_RED
                        : COLOR_FOREGROUND);
            } else {

                cell.setText(UI.EMPTY_STRING);
            }
        }
    });
}