use of org.eclipse.jface.viewers.ViewerCell in project hale by halestudio.
the class AbstractFunctionTableSection method createControls.
/**
* @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls(org.eclipse.swt.widgets.Composite,
* org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
*/
@Override
@SuppressWarnings("unchecked")
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
Composite compparent = getWidgetFactory().createComposite(parent);
compparent.setLayout(new FormLayout());
Composite composite = getWidgetFactory().createComposite(compparent);
TableColumnLayout columnLayout = new TableColumnLayout();
composite.setLayout(columnLayout);
FormData data = new FormData();
data.width = 100;
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, -0);
data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
data.bottom = new FormAttachment(100, -ITabbedPropertyConstants.VSPACE);
composite.setLayoutData(data);
tableViewer = new TableViewer(composite, SWT.FULL_SELECTION);
Table table = tableViewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
TableViewerColumn nameviewercol = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn namecol = nameviewercol.getColumn();
columnLayout.setColumnData(namecol, new ColumnWeightData(20));
namecol.setText("Name");
nameviewercol.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((P) cell.getElement()).getName());
}
});
TableViewerColumn lableviewercol = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn lablecol = lableviewercol.getColumn();
columnLayout.setColumnData(lablecol, new ColumnWeightData(20));
lablecol.setText("Lable");
lableviewercol.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((P) cell.getElement()).getDisplayName());
}
});
TableViewerColumn occurenceviewercol = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn occurencecol = occurenceviewercol.getColumn();
columnLayout.setColumnData(occurencecol, new ColumnWeightData(20));
occurencecol.setText("Occurence");
occurenceviewercol.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
P cellparameter = ((P) cell.getElement());
cell.setText(String.valueOf(cellparameter.getMinOccurrence()) + ".." + (String.valueOf(cellparameter.getMaxOccurrence())));
}
});
TableViewerColumn descriptionviewercol = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn descriptioncol = descriptionviewercol.getColumn();
columnLayout.setColumnData(descriptioncol, new ColumnWeightData(20));
descriptioncol.setText("Description");
descriptionviewercol.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(String.valueOf(((P) cell.getElement()).getDescription()));
}
});
}
use of org.eclipse.jface.viewers.ViewerCell in project yamcs-studio by yamcs.
the class SpreadSheetTable method getRowColumnIndex.
/**
*Get row and column index under given point.
* @param point the widget-relative coordinates
* @return int[0] is row index, int[1] is column index.
* null if no cell was found under given point.
*/
public int[] getRowColumnIndex(Point point) {
Table table = tableViewer.getTable();
ViewerCell cell = tableViewer.getCell(point);
if (cell == null)
return null;
int col = cell.getColumnIndex();
// int row = table.indexOf((TableItem) cell.getItem());
// return new int[]{row, col};
int row = -1;
// get row index
Rectangle clientArea = table.getClientArea();
int index = table.getTopIndex();
while (index < table.getItemCount()) {
boolean visible = false;
TableItem item = table.getItem(index);
Rectangle rect = item.getBounds(col);
if (rect.contains(point)) {
row = index;
return new int[] { row, col };
}
if (!visible && rect.intersects(clientArea)) {
visible = true;
}
if (!visible)
return new int[] { row, col };
index++;
}
return new int[] { row, col };
}
use of org.eclipse.jface.viewers.ViewerCell in project archi by archimatetool.
the class RelationshipsMatrixDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
setTitle(Messages.RelationshipsMatrixDialog_0);
setMessage(Messages.RelationshipsMatrixDialog_1);
Composite composite = (Composite) super.createDialogArea(parent);
Composite client = new Composite(composite, SWT.NULL);
GridLayout layout = new GridLayout(2, false);
client.setLayout(layout);
client.setLayoutData(new GridData(GridData.FILL_BOTH));
GridData gd;
GridTableViewer viewer = new GridTableViewer(client);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 800;
gd.heightHint = 500;
viewer.getControl().setLayoutData(gd);
viewer.getGrid().setHeaderVisible(true);
viewer.getGrid().setRowHeaderVisible(true);
viewer.getGrid().setRowsResizeable(true);
viewer.getGrid().setCellSelectionEnabled(true);
// viewer.setColumnProperties(new String[] {"1", "2", "3"});
viewer.setRowHeaderLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(ArchiLabelProvider.INSTANCE.getDefaultName((EClass) cell.getElement()));
cell.setImage(ArchiLabelProvider.INSTANCE.getImage(cell.getElement()));
}
});
for (EClass eClass : getData()) {
GridColumn column = new GridColumn(viewer.getGrid(), SWT.NONE);
column.setWidth(70);
column.setImage(ArchiLabelProvider.INSTANCE.getImage(eClass));
column.setHeaderTooltip(ArchiLabelProvider.INSTANCE.getDefaultName(eClass));
}
viewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return getData().toArray();
}
});
viewer.setLabelProvider(new MyLabelProvider());
// hookContextMenu(viewer);
viewer.setInput(getData());
// $NON-NLS-1$
String text = "";
for (Entry<EClass, Character> entry : RelationshipsMatrix.INSTANCE.getRelationshipsValueMap().entrySet()) {
// $NON-NLS-1$ //$NON-NLS-2$
text += entry.getValue() + ": " + ArchiLabelProvider.INSTANCE.getDefaultName(entry.getKey()) + "\n";
}
Label label = new Label(client, SWT.NULL);
label.setText(text);
label.setLayoutData(new GridData(SWT.TOP, SWT.TOP, false, true));
return composite;
}
use of org.eclipse.jface.viewers.ViewerCell in project webtools.sourceediting by eclipse.
the class AttributesBlock method createControl.
public void createControl(Composite parent) {
TabItem item = new TabItem((TabFolder) parent, SWT.NONE);
// $NON-NLS-1$
item.setText(Messages.getString("AttributesBlock.0"));
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginBottom = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
item.setControl(composite);
table = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.MULTI);
table.setHeaderVisible(true);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
table.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (event.character == SWT.DEL && event.stateMask == 0) {
performRemove();
}
}
});
TableColumn tc1 = new TableColumn(table, SWT.NONE);
// $NON-NLS-1$
tc1.setText(Messages.getString("AttributesBlock.2"));
tc1.setWidth(350);
tc1.setResizable(true);
TableColumn tc2 = new TableColumn(table, SWT.NONE);
// $NON-NLS-1$
tc2.setText(Messages.getString("AttributesBlock.7"));
tc2.setWidth(50);
tc2.setResizable(true);
Composite buttonComp = new Composite(composite, SWT.FILL);
buttonComp.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
GridLayout gl = new GridLayout();
gl.marginWidth = 0;
buttonComp.setLayout(gl);
Button addButton = new Button(buttonComp, SWT.PUSH);
// $NON-NLS-1$
addButton.setText(Messages.getString("AttributesBlock.8"));
addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
addButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
AttributeDialog dialog = new AttributeDialog(getShell(), attributes);
if (dialog.open() == Window.OK) {
List<IAttribute> newAttributes = dialog.getAttributes();
LaunchAttribute first = null;
for (IAttribute attribute : newAttributes) {
// $NON-NLS-1$
LaunchAttribute att = new LaunchAttribute(attribute.getURI(), "string", null);
if (first == null)
first = att;
attributes.addAttribute(att);
}
if (newAttributes.size() > 0) {
tViewer.refresh();
tViewer.setSelection(new StructuredSelection(first), true);
tViewer.editElement(first, 1);
updateLaunchConfigurationDialog();
}
}
}
});
removeButton = new Button(buttonComp, SWT.PUSH);
// $NON-NLS-1$
removeButton.setText(Messages.getString("AttributesBlock.14"));
removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
removeButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
performRemove();
}
});
setControl(table);
tViewer = new TableViewer(table);
tViewer.setContentProvider(new IStructuredContentProvider() {
public Object[] getElements(Object inputElement) {
return attributes.getAttributes().toArray(new LaunchAttribute[0]);
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
attributes = (LaunchAttributes) newInput;
}
});
tViewer.setSorter(new ViewerSorter() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
LaunchAttribute a1 = (LaunchAttribute) e1;
LaunchAttribute a2 = (LaunchAttribute) e2;
return a1.uri.compareTo(a2.uri);
}
});
tViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
updateRemoveButton();
}
});
TableViewerColumn tvc1 = new TableViewerColumn(tViewer, tc1);
tvc1.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
LaunchAttribute tv = (LaunchAttribute) cell.getElement();
cell.setText(tv.uri);
}
@Override
public int getToolTipTimeDisplayed(Object object) {
return 5000;
}
@Override
public String getToolTipText(Object element) {
LaunchAttribute tv = (LaunchAttribute) element;
return attributeUris.get(tv.uri).getDescription();
}
});
// ColumnViewerToolTipSupport.enableFor(tViewer);
TableViewerColumn tvc2 = new TableViewerColumn(tViewer, tc2);
tvc2.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
LaunchAttribute tv = (LaunchAttribute) cell.getElement();
cell.setText(tv.value);
}
});
tvc2.setEditingSupport(new EditingSupport(tViewer) {
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected CellEditor getCellEditor(Object element) {
return new TextCellEditor(table);
}
@Override
protected Object getValue(Object element) {
LaunchAttribute tv = (LaunchAttribute) element;
// $NON-NLS-1$
return tv.value == null ? "" : tv.value;
}
@Override
protected void setValue(Object element, Object value) {
LaunchAttribute tv = (LaunchAttribute) element;
tv.setValue((String) value);
updateLaunchConfigurationDialog();
tViewer.update(tv, null);
}
});
restoreColumnSettings();
}
use of org.eclipse.jface.viewers.ViewerCell in project org.csstudio.display.builder by kasemir.
the class SampleView method doCreatePartControl.
/**
* {@inheritDoc}
*/
@Override
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;
}
// / Skip initial "Select item" entry
final int selected = items.getSelectionIndex() - 1;
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);
}
});
}
Aggregations