List of usage examples for org.eclipse.jface.viewers ViewerCell setBackground
public void setBackground(Color background)
From source file:org.csstudio.display.rdbtable.ui.RDBTableRowLabelProvider.java
License:Open Source License
/** @param cell Cell in table that we need to update with info from * the RDBTableRow/*from www. ja v a 2 s. c o m*/ */ @Override public void update(final ViewerCell cell) { final RDBTableRow row = (RDBTableRow) cell.getElement(); // Display text of corresponding RDBTable column cell.setText(row.getColumn(cell.getColumnIndex())); // Highlight changed or deleted cells final Display display = cell.getControl().getDisplay(); if (row.wasDeleted()) cell.setBackground(display.getSystemColor(SWT.COLOR_GRAY)); else if (row.wasModified()) cell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); else cell.setBackground(null); }
From source file:org.csstudio.trends.databrowser2.sampleview.SampleView.java
License:Open Source License
/** {@inheritDoc} */ @Override/*w w w.j a v a 2 s .com*/ protected void doCreatePartControl(final Composite parent) { final GridLayout layout = new GridLayout(3, false); parent.setLayout(layout); // Item: pvs [Refresh] Label l = new Label(parent, 0); l.setText(Messages.SampleView_Item); l.setLayoutData(new GridData()); items = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY); items.setLayoutData(new GridData(SWT.FILL, 0, true, false)); items.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(final SelectionEvent e) { widgetDefaultSelected(e); } @Override public void widgetDefaultSelected(final SelectionEvent e) { // Configure table to display samples of the selected model item if (items.getSelectionIndex() == 0) { sample_table.setInput(null); return; } final int selected = items.getSelectionIndex() - 1; /// Skip initial "Select item" entry int index = 0; for (ModelItem item : model.getItems()) { if (index == selected) { sample_table.setInput(item); return; } ++index; } Activator.getLogger().log(Level.WARNING, "Invalid item index " + selected); } }); final Button refresh = new Button(parent, SWT.PUSH); refresh.setText(Messages.SampleView_Refresh); refresh.setToolTipText(Messages.SampleView_RefreshTT); refresh.setLayoutData(new GridData()); refresh.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { // Trigger GUI update update(false); } }); // Sample Table // TableColumnLayout requires this to be in its own container final Composite table_parent = new Composite(parent, 0); table_parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1)); final TableColumnLayout table_layout = new MinSizeTableColumnLayout(10); table_parent.setLayout(table_layout); sample_table = new TableViewer(table_parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL); sample_table.setContentProvider(new SampleTableContentProvider()); final Table table = sample_table.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); // Time column TableViewerColumn col = TableHelper.createColumn(table_layout, sample_table, Messages.TimeColumn, 90, 100); col.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final PlotSample sample = (PlotSample) cell.getElement(); cell.setText(TimestampHelper.format(sample.getPosition())); } }); // Value column col = TableHelper.createColumn(table_layout, sample_table, Messages.ValueColumn, 50, 100); col.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final PlotSample sample = (PlotSample) cell.getElement(); cell.setText(format.format(sample.getVType())); } @Override public String getToolTipText(Object element) { final PlotSample sample = (PlotSample) element; final VType value = sample.getVType(); // Show numbers in their 'natural' format which may differ from the Display settings if (value instanceof VStatistics) { final VStatistics mmd = (VStatistics) value; return NLS.bind(Messages.SampleView_MinMaxValueTT, new String[] { Double.toString(mmd.getAverage()), Double.toString(mmd.getMin()), Double.toString(mmd.getMax()) }); } else if (value instanceof VNumber) { final VNumber dbl = (VNumber) value; return Double.toString(dbl.getValue().doubleValue()); } else return VTypeHelper.toString(value); } }); // Severity column col = TableHelper.createColumn(table_layout, sample_table, Messages.SeverityColumn, 90, 50); col.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final PlotSample sample = (PlotSample) cell.getElement(); final VType value = sample.getVType(); final AlarmSeverity severity = VTypeHelper.getSeverity(value); cell.setText(severity.toString()); if (severity == AlarmSeverity.NONE) { cell.setBackground(null); return; } final Display display = cell.getControl().getDisplay(); if (severity == AlarmSeverity.MAJOR) cell.setBackground(display.getSystemColor(SWT.COLOR_RED)); else if (severity == AlarmSeverity.MINOR) cell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); else cell.setBackground(display.getSystemColor(SWT.COLOR_GRAY)); } }); // Status column col = TableHelper.createColumn(table_layout, sample_table, Messages.StatusColumn, 90, 50); col.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final PlotSample sample = (PlotSample) cell.getElement(); final VType value = sample.getVType(); cell.setText(VTypeHelper.getMessage(value)); } }); // Sample Source column col = TableHelper.createColumn(table_layout, sample_table, Messages.SampleView_Source, 90, 10); col.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final PlotSample sample = (PlotSample) cell.getElement(); cell.setText(sample.getSource()); } }); ColumnViewerToolTipSupport.enableFor(sample_table); // Be ignorant of any change of the current model after this view // is disposed. parent.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { if (model != null) model.removeListener(model_listener); } }); }
From source file:org.dawnsci.breadcrumb.navigation.table.AbstractLazyLabelProvider.java
License:Open Source License
public void update(ViewerCell cell) { if (disposed) return;/* www. jav a 2 s . c o m*/ if (cell.getItem().isDisposed()) return; Object element = cell.getElement(); try { final int index = cell.getColumnIndex(); final String fastText = getFastText(element, index - columnOffset); if (fastText != null) { cell.setText(fastText); } else if (allowLazyText) { viewerCellTextQueue.add(new ViewCellBean(cell, element, index)); } else { cell.setText(getSlowText(element, index - columnOffset)); } Image image = getImage(element, index - columnOffset); cell.setImage(image); cell.setBackground(getBackground(element)); //cell.setForeground(getForeground(element)); //cell.setFont(getFont(element)); } catch (Exception ne) { logger.error("Error in table ", ne); } }
From source file:org.dynami.utils.UIUtils.java
License:Apache License
public static void colorize(final ViewerCell cell, final Pair p) { if (p.value.doubleValue() >= 0.0) { cell.setBackground(GREEN); } else {// www .j a v a 2s. c om cell.setBackground(RED); } }
From source file:org.dynami.views.OrdersView.java
License:Apache License
private void colorizeOrder(final ViewerCell cell, final Order order) { switch (order.status) { case STATUS.CANCELLED: cell.setForeground(GREY);/* w w w.j a va 2 s . co m*/ cell.setBackground(getRevertColor(GREY)); break; case STATUS.PARTIALLY_EXECUTED: cell.setForeground(MAGENTA); cell.setBackground(getRevertColor(MAGENTA)); break; case STATUS.PENDING: cell.setForeground(BLUE); cell.setBackground(getRevertColor(BLUE)); break; case STATUS.REFUSED: cell.setForeground(RED); cell.setBackground(getRevertColor(RED)); break; default: break; } }
From source file:org.dynami.views.PortfolioView.java
License:Apache License
@Override public void createPartControl(Composite parent) { Composite container = new Composite(parent, SWT.NONE); container.setLayout(new GridLayout(6, false)); {/* ww w . ja va 2s . c o m*/ Button btnStockFilter = new Button(container, SWT.TOGGLE); btnStockFilter.setSelection(true); btnStockFilter.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (((Button) e.getSource()).getSelection()) { tableViewer.removeFilter(stockFilter); } else { tableViewer.addFilter(stockFilter); } } }); btnStockFilter.setText("Stock"); } { Button btnFutureFilter = new Button(container, SWT.TOGGLE); btnFutureFilter.setSelection(true); btnFutureFilter.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (((Button) e.getSource()).getSelection()) { tableViewer.removeFilter(futureFilter); } else { tableViewer.addFilter(futureFilter); } } }); btnFutureFilter.setText("Future"); } { Button btnOptionFilter = new Button(container, SWT.TOGGLE); btnOptionFilter.setSelection(true); btnOptionFilter.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (((Button) e.getSource()).getSelection()) { tableViewer.removeFilter(optionFilter); } else { tableViewer.addFilter(optionFilter); } } }); btnOptionFilter.setText("Option"); } { txtSearch = new Text(container, SWT.BORDER); txtSearch.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.ITALIC)); txtSearch.setText("Search"); txtSearch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); txtSearch.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { txtSearch.setText(UIUtils.SEARCH_HINT); } @Override public void focusGained(FocusEvent e) { txtSearch.setText(""); } }); txtSearch.addTraverseListener(new TraverseListener() { @Override public void keyTraversed(TraverseEvent event) { if (event.detail == SWT.TRAVERSE_RETURN) { final String search = txtSearch.getText(); if (!UIUtils.SEARCH_HINT.equals(search) && !"".equals(search)) { filter.setSearchText(txtSearch.getText()); tableViewer.addFilter(filter); } else { tableViewer.removeFilter(filter); } } } }); } { Button btnSearch = new Button(container, SWT.NONE); btnSearch.setImage( ResourceManager.getPluginImage("org.eclipse.ui", "/icons/full/etool16/help_search.gif")); } { Button btnRemove = new Button(container, SWT.NONE); btnRemove.setImage(ResourceManager.getPluginImage("org.eclipse.ui", "/icons/full/etool16/clear.gif")); } Composite tbl_composite = new Composite(container, SWT.NONE); tbl_composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 6, 1)); TableColumnLayout tcl_layout = new TableColumnLayout(); tbl_composite.setLayout(tcl_layout); { tableViewer = new TableViewer(tbl_composite, SWT.BORDER | SWT.FULL_SELECTION); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); tableViewer.setUseHashlookup(true); table = tableViewer.getTable(); // table.addMouseListener(new MouseAdapter() { // @Override // public void mouseDoubleClick(MouseEvent e) { // StructuredSelection selection = (StructuredSelection)tableViewer.getSelection(); // if(selection != null){ // Leg leg = (Leg)selection.getFirstElement(); // if(leg != null){ // final Order order = new Order( // leg.getAsset(), // (leg.getQuantity()>0)?OrderCommandType.SELL:OrderCommandType.BUY, // leg.getPrice(), // leg.getQuantity()); // OrderDialog dialog = new OrderDialog(getSite().getShell(), null, order); // dialog.open(); // } // } // } // }); table.setLinesVisible(true); table.setHeaderVisible(true); { TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE); TableColumn tblclmnAsset = tableViewerColumn.getColumn(); tblclmnAsset.setText("Asset"); tcl_layout.setColumnData(tblclmnAsset, new ColumnWeightData(35, true)); //layout.setColumnData(tblclmnAsset, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true)); tableViewerColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { Leg l = (Leg) cell.getElement(); cell.setText(l.asset); if (l.gainLoss >= 0) cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_GREEN)); else cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED)); } }); } { TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE); TableColumn tblclmnType = tableViewerColumn.getColumn(); tblclmnType.setText("Type"); tcl_layout.setColumnData(tblclmnType, new ColumnWeightData(10, true)); tableViewerColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { Leg l = (Leg) cell.getElement(); cell.setText(l.assetType); if (l.gainLoss >= 0) cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_GREEN)); else cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED)); } }); } { TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE); TableColumn tblclmnQuantity = tableViewerColumn.getColumn(); tblclmnQuantity.setAlignment(SWT.RIGHT); tblclmnQuantity.setText("Qt."); tcl_layout.setColumnData(tblclmnQuantity, new ColumnWeightData(5, true)); tableViewerColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { Leg l = (Leg) cell.getElement(); int qt = l.quantity * ((l.orderType == OrderType.BUY.type()) ? 1 : -1); cell.setText(String.valueOf(qt)); if (l.gainLoss >= 0) cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_GREEN)); else cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED)); } }); } { TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE); TableColumn tblclmnGainloss = tableViewerColumn.getColumn(); tblclmnGainloss.setAlignment(SWT.RIGHT); tblclmnGainloss.setText("Profit"); tcl_layout.setColumnData(tblclmnGainloss, new ColumnWeightData(10, true)); tableViewerColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { Leg l = (Leg) cell.getElement(); cell.setText("" + DUtils.EURO_DECIMAL_FORMAT.format(l.gainLoss)); if (l.gainLoss >= 0) cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_GREEN)); else cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED)); } }); } { TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE); TableColumn tblclmnDelta = tableViewerColumn.getColumn(); tblclmnDelta.setAlignment(SWT.RIGHT); tblclmnDelta.setText("Delta"); tcl_layout.setColumnData(tblclmnDelta, new ColumnWeightData(10, true)); tableViewerColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { Leg l = (Leg) cell.getElement(); cell.setText("" + DUtils.DECIMAL_FORMAT.format(l.delta)); if (l.gainLoss >= 0) cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_GREEN)); else cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED)); } }); } { TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE); TableColumn tblclmnGamma = tableViewerColumn.getColumn(); tblclmnGamma.setAlignment(SWT.RIGHT); tblclmnGamma.setText("Gamma"); tcl_layout.setColumnData(tblclmnGamma, new ColumnWeightData(10, true)); tableViewerColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { Leg l = (Leg) cell.getElement(); cell.setText("" + DUtils.DECIMAL_FORMAT.format(l.gamma)); if (l.gainLoss >= 0) cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_GREEN)); else cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED)); } }); } { TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE); TableColumn tblclmnVega = tableViewerColumn.getColumn(); tblclmnVega.setAlignment(SWT.CENTER); tblclmnVega.setText("Vega"); tcl_layout.setColumnData(tblclmnVega, new ColumnWeightData(10, true)); tableViewerColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { Leg l = (Leg) cell.getElement(); cell.setText("" + DUtils.DECIMAL_FORMAT.format(l.vega)); if (l.gainLoss >= 0) cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_GREEN)); else cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED)); } }); } { TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE); TableColumn tblclmnTheta = tableViewerColumn.getColumn(); tblclmnTheta.setAlignment(SWT.RIGHT); tblclmnTheta.setText("Theta"); tcl_layout.setColumnData(tblclmnTheta, new ColumnWeightData(10, true)); tableViewerColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { Leg l = (Leg) cell.getElement(); cell.setText("" + DUtils.DECIMAL_FORMAT.format(l.theta)); if (l.gainLoss >= 0) cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_GREEN)); else cell.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED)); } }); } } portfolioService.dispatch().subscribe(portfolioListener); }
From source file:org.eclipse.acceleo.ui.interpreter.internal.view.VariableLabelProvider.java
License:Open Source License
/** * {@inheritDoc}/*w ww.j av a2s . co m*/ * * @see org.eclipse.jface.viewers.CellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell) */ @Override public void update(ViewerCell cell) { final Object element = cell.getElement(); final String text = getText(element); if (InterpreterMessages.getString("interpreter.view.variable.placeholder").equals(text)) { //$NON-NLS-1$ cell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW)); } else { cell.setBackground(null); } cell.setText(text); cell.setImage(getImage(element)); }
From source file:org.eclipse.andmore.android.emulator.core.emulationui.AbstractEmuLabelProvider.java
License:Apache License
/** * @see org.eclipse.jface.viewers.CellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell) *//*ww w. j a va 2 s . c om*/ @Override public void update(ViewerCell cell) { // The instance column index is set with the current cell column index, // as the logic // contained in this class depends on this information. Then after the // cell is // updated according to the standard procedure, the column index field // is reset so that // it does not interfere with subsequent updates. columnIndex = cell.getColumnIndex(); super.update(cell); columnIndex = firstColumnIndex; // Checks if the cell needs to be highlighted. This will be true if the // values of // alternativeColorHost and alternativeColorBeanId are different from // null and -1 if ((alternativeColorHost != null) && (alternativeColorBeanId != -1)) { Object element = cell.getElement(); // Only leaf nodes can be highlighted if (element instanceof EmuViewerLeafNode) { // The next lines are used to check if the current element is // the one to be // highlighted. For that, the host and bean id needs to be // compared to the // alternativeColorHost and alternativeColorBeanId instance // field values EmuViewerLeafNode node = (EmuViewerLeafNode) element; long beanId = node.getBeanId(); EmuViewerRootNode root = (EmuViewerRootNode) node.getParent().getParent(); String host = root.getEmulatorIdentifier(); if ((beanId == alternativeColorBeanId) && (host.equals(alternativeColorHost))) { // Highlighting the node cell.setBackground(alternativeColor); // Putting the node at the visible part of the tree ViewerRow highlightedRow = cell.getViewerRow(); TreeItem highlightedItem = (TreeItem) highlightedRow.getItem(); Tree tree = (Tree) cell.getControl(); tree.showItem(highlightedItem); } } } }
From source file:org.eclipse.e4.tools.emf.ui.internal.ObservableColumnLabelProvider.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public void update(ViewerCell cell) { M element = (M) cell.getElement();/*from w w w.j a v a2s. com*/ cell.setText(getText(element)); cell.setImage(getImage(element)); cell.setBackground(getBackground(element)); cell.setForeground(getForeground(element)); cell.setFont(getFont(element)); }
From source file:org.eclipse.emf.ecp.edit.internal.swt.controls.ECPFocusCellDrawHighlighter.java
License:Open Source License
private void markFocusedCell(Event event, ViewerCell cell) { Color background = cell.getControl().isFocusControl() ? getSelectedCellBackgroundColor(cell) : getSelectedCellBackgroundColorNoFocus(cell); Color foreground = cell.getControl().isFocusControl() ? getSelectedCellForegroundColor(cell) : getSelectedCellForegroundColorNoFocus(cell); if (foreground != null || background != null || onlyTextHighlighting(cell)) { // GC gc = event.gc; if (background == null) { background = cell.getItem().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION); }//www. j a va 2 s.com if (foreground == null) { foreground = cell.getItem().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT); } // gc.setBackground(background); // gc.setForeground(foreground); // // if (onlyTextHighlighting(cell)) { // Rectangle area = event.getBounds(); // Rectangle rect = cell.getTextBounds(); // if( rect != null ) { // area.x = rect.x; // } // gc.fillRectangle(area); // } else { // gc.fillRectangle(event.getBounds()); // } cell.setBackground(background); cell.setForeground(foreground); // event.detail &= ~SWT.SELECTED; } }