List of usage examples for org.eclipse.jface.viewers ViewerCell getControl
public Control getControl()
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 a va 2 s. co m } 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:hydrograph.ui.propertywindow.widgets.customwidgets.mapping.tables.inputtable.InputFieldColumnLabelProvider.java
License:Apache License
@Override public void update(ViewerCell cell) { TableItem item = (TableItem) cell.getItem(); Pattern pattern = Pattern.compile("^[a-zA-Z0-9 _]*$"); if (!pattern.matcher(((InputField) cell.getElement()).getFieldName()).matches()) { item.setBackground(cell.getControl().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); item.setForeground(cell.getControl().getDisplay().getSystemColor(SWT.COLOR_RED)); ((InputField) cell.getElement()).getErrorObject() .setErrorMessage("Input field should match regular expression- \"^[a-zA-Z0-9_]*$\" "); ((InputField) cell.getElement()).getErrorObject().setHasError(true); } else {//from www.j av a 2s . c o m if (((InputField) cell.getElement()).getFieldName().trim().equalsIgnoreCase("")) { item.setBackground(cell.getControl().getDisplay().getSystemColor(SWT.COLOR_RED)); ((InputField) cell.getElement()).getErrorObject() .setErrorMessage("Input field should not be empty"); ((InputField) cell.getElement()).getErrorObject().setHasError(true); } else { ((InputField) cell.getElement()).getErrorObject().setHasError(false); } } super.update(cell); }
From source file:net.certiv.fluentmark.tables.FocusBorderCellHighlighter.java
License:Open Source License
@Override protected void focusCellChanged(ViewerCell newCell, ViewerCell oldCell) { super.focusCellChanged(newCell, oldCell); // Redraw new area if (newCell != null) { Rectangle rect = newCell.getBounds(); int x = newCell.getColumnIndex() == 0 ? 0 : rect.x; int width = newCell.getColumnIndex() == 0 ? rect.x + rect.width : rect.width; // 1 is a fix for Linux-GTK newCell.getControl().redraw(x, rect.y - 1, width, rect.height + 1, true); }/* www . j ava 2s . co m*/ if (oldCell != null) { Rectangle rect = oldCell.getBounds(); int x = oldCell.getColumnIndex() == 0 ? 0 : rect.x; int width = oldCell.getColumnIndex() == 0 ? rect.x + rect.width : rect.width; // 1 is a fix for Linux-GTK oldCell.getControl().redraw(x, rect.y - 1, width, rect.height + 1, true); } }
From source file:org.csstudio.alarm.beast.ui.alarmtable.AlarmTableLabelProvider.java
License:Open Source License
/** Update one cell of the table */ @Override//from w w w . j a v a 2 s .c o 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.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 w w w . 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.scan.ui.scantree.gui.CommandTreeLabelProvider.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w w w .j a v a2 s . co m*/ public void update(final ViewerCell cell) { final ScanCommand command = (ScanCommand) cell.getElement(); cell.setText(getText(command)); cell.setImage(getImage(command)); // highlight the currently active command if (active_command.get() == command) cell.setForeground(cell.getControl().getDisplay().getSystemColor(SWT.COLOR_GREEN)); else cell.setForeground(null); }
From source file:org.csstudio.trends.databrowser2.sampleview.SampleView.java
License:Open Source License
/** {@inheritDoc} */ @Override//from www . j a v a 2 s.c om 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.eclipse.andmore.android.emulator.core.emulationui.AbstractEmuLabelProvider.java
License:Apache License
/** * @see org.eclipse.jface.viewers.CellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell) *//* w w w . j av a 2 s . c o m*/ @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.common.component.dialogs.AbstractIconDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { Composite comp = (Composite) super.createDialogArea(parent); getShell().setText(getShellTitle()); setTitle(getDialogTitle());/*from w w w. j a va2 s . c o m*/ setMessage(getDialogMessage()); Composite container = new Composite(comp, SWT.NONE); container.setLayoutData(new GridData(GridData.FILL_BOTH)); container.setLayout(new GridLayout(2, false)); Label l = new Label(container, SWT.NONE); l.setText(Messages.AbstractIconDialog_IconName); final Text t = new Text(container, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH); t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(container, SWT.NONE); viewer = new TableViewer(container); GridData gd = new GridData(GridData.FILL_BOTH); viewer.getControl().setLayoutData(gd); viewer.setContentProvider(new ObservableListContentProvider()); viewer.setLabelProvider(new StyledCellLabelProvider() { @Override public void update(ViewerCell cell) { IFile file = (IFile) cell.getElement(); StyledString styledString = new StyledString(file.getProjectRelativePath().toString(), null); Image img = icons.get(file); if (img == null) { InputStream in = null; try { in = file.getContents(); img = new Image(cell.getControl().getDisplay(), in); icons.put(file, img); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } String bundle = getBundle(file); if (bundle != null) { styledString.append(" - " + bundle, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$ } cell.setImage(img); cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); } }); final WritableList list = new WritableList(); viewer.setInput(list); viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { okPressed(); } }); t.addModifyListener(new ModifyListener() { private IconMatchCallback callback; private Timer timer = new Timer(true); private TimerTask task; public void modifyText(ModifyEvent e) { if (callback != null) { callback.cancel = true; } if (task != null) { task.cancel(); } list.clear(); clearImages(); callback = new IconMatchCallback(list); task = new SearchThread(callback, t.getText(), project); timer.schedule(task, 500); } }); getShell().addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { clearImages(); } }); return comp; }
From source file:org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.AbstractIconDialogWithHardcodedScope.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { Composite comp = (Composite) super.createDialogArea(parent); getShell().setText(getShellTitle()); setTitle(getDialogTitle());//from ww w . j a v a 2 s.c o m setMessage(getDialogMessage()); String bundleFilter = (String) context.get("bundle"); if (E.notEmpty(bundleFilter)) { setMessage("Filtering by bundle " + bundleFilter); //$NON-NLS-1$ } Composite container = new Composite(comp, SWT.NONE); container.setLayoutData(new GridData(GridData.FILL_BOTH)); container.setLayout(new GridLayout(2, false)); Composite compOptions = new Composite(container, SWT.NONE); compOptions.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); compOptions.setLayout(new RowLayout()); if (E.isEmpty(bundleFilter)) { Button btnProject = new Button(compOptions, SWT.RADIO); btnProject.setText("Project"); btnProject.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { searchScope = ResourceSearchScope.PROJECT; textSearch.notifyListeners(SWT.Modify, new Event()); } }); btnProject.setSelection(true); Button btnWorkspace = new Button(compOptions, SWT.RADIO); btnWorkspace.setText("Workspace"); btnWorkspace.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { searchScope = ResourceSearchScope.WORKSPACE; textSearch.notifyListeners(SWT.Modify, new Event()); } }); btnWorkspace.setSelection(searchScope == ResourceSearchScope.WORKSPACE); btnProject.setSelection(searchScope == ResourceSearchScope.PROJECT); } else { searchScope = ResourceSearchScope.WORKSPACE; } Label l = new Label(container, SWT.NONE); l.setText(Messages.AbstractIconDialog_IconName); textSearch = new Text(container, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH); textSearch.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(container, SWT.NONE); viewer = new TableViewer(container, SWT.FULL_SELECTION | SWT.BORDER); GridData gd = new GridData(GridData.FILL_BOTH); viewer.getControl().setLayoutData(gd); viewer.setContentProvider(new ObservableListContentProvider()); viewer.setLabelProvider(new StyledCellLabelProvider() { @Override public void update(ViewerCell cell) { IFile file = (IFile) cell.getElement(); StyledString styledString = new StyledString(file.getProjectRelativePath().toString(), null); Image img = icons.get(file); if (img == null) { InputStream in = null; try { in = file.getContents(); img = new Image(cell.getControl().getDisplay(), in); icons.put(file, img); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } String bundle = getBundle(file); if (bundle != null) { styledString.append(" - " + bundle, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$ } cell.setImage(img); cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); } }); final WritableList list = new WritableList(); viewer.setInput(list); viewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { okPressed(); } }); textSearch.addModifyListener(new ModifyListener() { private IconMatchCallback callback; private Timer timer = new Timer(true); private TimerTask task; @Override public void modifyText(ModifyEvent e) { if (callback != null) { callback.cancel = true; } if (task != null) { task.cancel(); } list.clear(); clearImages(); callback = new IconMatchCallback(list); task = new SearchThread(callback, textSearch.getText(), project, context, searchScope); timer.schedule(task, 500); } }); getShell().addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { clearImages(); } }); textSearch.notifyListeners(SWT.Modify, new Event()); return comp; }