use of org.eclipse.jface.viewers.ColumnPixelData in project eclipse-cs by checkstyle.
the class EnhancedTableViewer method restoreState.
/**
* Restores the sorting state from the dialog settings.
*/
private void restoreState() {
IDialogSettings settings = mSettingsProvider != null ? mSettingsProvider.getTableSettings() : null;
if (settings == null) {
return;
}
try {
mSortedColumnIndex = settings.getInt(TAG_COLUMN_INDEX);
} catch (NumberFormatException e) {
mSortedColumnIndex = 0;
}
try {
mSortDirection = settings.getInt(TAG_SORT_DIRECTION);
} catch (NumberFormatException e) {
mSortDirection = DIRECTION_FORWARD;
}
TableLayout layout = new TableLayout();
boolean allColumnsHaveStoredData = true;
// store the column widths
TableColumn[] columns = this.getTable().getColumns();
for (int i = 0, size = columns.length; i < size; i++) {
try {
int width = settings.getInt(TAG_COLUMN_WIDTH + i);
columns[i].setWidth(width);
layout.addColumnData(new ColumnPixelData(width));
} catch (NumberFormatException e) {
// probably a new column
allColumnsHaveStoredData = false;
}
}
// weighted layout
if (allColumnsHaveStoredData) {
this.getTable().setLayout(layout);
}
// restore the selection
try {
this.getTable().select(settings.getInt(TAG_CURRENT_SELECTION));
} catch (NumberFormatException e) {
// NOOP
}
resort();
}
use of org.eclipse.jface.viewers.ColumnPixelData in project tdq-studio-se by Talend.
the class EditSortMatchRuleNamesDialog method createTableViewer.
/**
* create Table Viewer.
*
* @param parent
* @return
*/
private void createTableViewer(Composite parent) {
tableViewer = new TableViewer(parent, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
Table table_1 = tableViewer.getTable();
GridData gd_table_1 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
gd_table_1.heightHint = 217;
table_1.setLayoutData(gd_table_1);
Table table = (Table) tableViewer.getControl();
TableLayout tableLayout = new TableLayout();
tableLayout.addColumnData(new ColumnPixelData(350));
table.setLayout(tableLayout);
tableViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
return (OrderMatchRule[]) inputElement;
}
@Override
public void dispose() {
// do nothing here, until now
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// do nothing here, until now
}
});
createMatchRuleNameColumn();
table.setHeaderVisible(true);
table.setLinesVisible(true);
tableViewer.setInput(orderMatchRuleList.toArray(new OrderMatchRule[orderMatchRuleList.size()]));
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
// when the selection changed, update the up/down buttons status
updateButtonsStatus();
}
});
}
use of org.eclipse.jface.viewers.ColumnPixelData in project tdq-studio-se by Talend.
the class AbstractMatchAnalysisTableViewer method initTable.
/**
* DOC zshen Comment method "initTable".
*
* @param headers the name of column
* @param columnMap all of columns which can be used by current Table
* @param pixelDataOfHeaders the width of the column
*/
public void initTable(List<String> headers, List<MetadataColumn> columnMap, boolean withSorter) {
TableLayout tLayout = new TableLayout();
innerTable.setLayout(tLayout);
innerTable.setHeaderVisible(true);
innerTable.setLinesVisible(true);
GridData gd = new GridData(GridData.FILL_BOTH);
innerTable.setLayoutData(gd);
for (int index = 0; index < headers.size(); index++) {
final int sortIndex = index;
String columnTechnologyLabel = headers.get(index);
String columnLabel = getInternationalizedLabel(columnTechnologyLabel);
if (columnLabel != null) {
if (columnLabel.length() == 1) {
columnLabel = columnLabel + PluginConstant.SPACE_STRING + PluginConstant.SPACE_STRING;
}
tLayout.addColumnData(new ColumnPixelData(columnLabel.length() * getHeaderDisplayWeight(index)));
final TableViewerColumn tableColumn = new TableViewerColumn(this, SWT.LEFT);
tableColumn.getColumn().setText(columnLabel);
addEditingSupportForColumn(tableColumn, columnTechnologyLabel);
if (withSorter) {
final ViewerComparator comparator = getComparator();
tableColumn.getColumn().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
((GroupStatisticsRowCompartor) comparator).setColumn(sortIndex);
int dir = getTable().getSortDirection();
if (getTable().getSortColumn() == tableColumn.getColumn()) {
dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
} else {
dir = SWT.DOWN;
}
getTable().setSortDirection(dir);
getTable().setSortColumn(tableColumn.getColumn());
refresh();
}
});
}
}
}
CellEditor[] editors = getCellEditor(headers, columnMap);
// add menu
addContextMenu();
AbstractMatchCellModifier<T> cellModifier = getTableCellModifier();
if (cellModifier != null) {
cellModifier.setColumnMap(columnMap);
this.setCellModifier(cellModifier);
}
this.setCellEditors(editors);
this.setColumnProperties(headers.toArray(new String[headers.size()]));
this.setContentProvider(getTableContentProvider());
this.setLabelProvider(getTableLabelProvider());
GridData tableGD = new GridData(GridData.FILL_BOTH);
tableGD.heightHint = getTableHeightHint();
innerTable.setLayoutData(tableGD);
}
use of org.eclipse.jface.viewers.ColumnPixelData in project portfolio by buchen.
the class PerformanceView method createCalculationItem.
private void createCalculationItem(CTabFolder folder, String title) {
Composite container = new Composite(folder, SWT.NONE);
TreeColumnLayout layout = new TreeColumnLayout();
container.setLayout(layout);
calculation = new TreeViewer(container, SWT.FULL_SELECTION);
calculation.addSelectionChangedListener(event -> {
Object selection = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (selection != null && selection instanceof ClientPerformanceSnapshot.Position && ((ClientPerformanceSnapshot.Position) selection).getSecurity() != null)
selectionService.setSelection(new SecuritySelection(getClient(), ((ClientPerformanceSnapshot.Position) selection).getSecurity()));
});
final Font boldFont = JFaceResources.getFontRegistry().getBold(container.getFont().getFontData()[0].getName());
TreeViewerColumn column = new TreeViewerColumn(calculation, SWT.NONE);
column.getColumn().setText(Messages.ColumnLable);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ClientPerformanceSnapshot.Category) {
ClientPerformanceSnapshot.Category cat = (ClientPerformanceSnapshot.Category) element;
return cat.getLabel();
} else if (element instanceof ClientPerformanceSnapshot.Position) {
ClientPerformanceSnapshot.Position pos = (ClientPerformanceSnapshot.Position) element;
return pos.getLabel();
}
return null;
}
@Override
public Image getImage(Object element) {
if (element instanceof ClientPerformanceSnapshot.Category) {
return Images.CATEGORY.image();
} else if (element instanceof ClientPerformanceSnapshot.Position) {
ClientPerformanceSnapshot.Position position = (ClientPerformanceSnapshot.Position) element;
if (position.getSecurity() != null) {
ClientPerformanceSnapshot snapshot = ((PerformanceContentProvider) calculation.getContentProvider()).getSnapshot();
boolean hasHoldings = snapshot.getEndClientSnapshot().getPositionsByVehicle().get(position.getSecurity()) != null;
return hasHoldings ? Images.SECURITY.image() : Images.SECURITY_RETIRED.image();
} else {
return null;
}
}
return null;
}
@Override
public Font getFont(Object element) {
if (element instanceof ClientPerformanceSnapshot.Category)
return boldFont;
return null;
}
});
layout.setColumnData(column.getColumn(), new ColumnPixelData(350));
column = new TreeViewerColumn(calculation, SWT.RIGHT);
column.getColumn().setText(Messages.ColumnValue);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ClientPerformanceSnapshot.Category) {
ClientPerformanceSnapshot.Category cat = (ClientPerformanceSnapshot.Category) element;
return Values.Money.format(cat.getValuation(), getClient().getBaseCurrency());
} else if (element instanceof ClientPerformanceSnapshot.Position) {
ClientPerformanceSnapshot.Position pos = (ClientPerformanceSnapshot.Position) element;
return Values.Money.format(pos.getValuation(), getClient().getBaseCurrency());
}
return null;
}
@Override
public Font getFont(Object element) {
if (element instanceof ClientPerformanceSnapshot.Category)
return boldFont;
return null;
}
});
layout.setColumnData(column.getColumn(), new ColumnPixelData(80));
calculation.getTree().setHeaderVisible(true);
calculation.getTree().setLinesVisible(true);
calculation.setContentProvider(new PerformanceContentProvider());
CTabItem item = new CTabItem(folder, SWT.NONE);
item.setText(title);
item.setControl(container);
hookContextMenu(calculation.getTree(), this::fillContextMenu);
}
use of org.eclipse.jface.viewers.ColumnPixelData in project portfolio by buchen.
the class ErrorLogPart method createComposite.
@PostConstruct
public void createComposite(Composite parent, LogEntryCache cache) {
this.entries = cache.getEntries();
Composite container = new Composite(parent, SWT.NONE);
TreeColumnLayout layout = new TreeColumnLayout();
container.setLayout(layout);
logViewer = new TreeViewer(container, SWT.FULL_SELECTION);
TreeViewerColumn column = new TreeViewerColumn(logViewer, SWT.NONE);
column.getColumn().setText(Messages.ColumnDate);
layout.setColumnData(column.getColumn(), new ColumnPixelData(140));
column.setLabelProvider(new ColumnLabelProvider() {
private DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
@Override
public String getText(Object element) {
return dateFormat.format(((LogEntry) element).getDate());
}
});
column = new TreeViewerColumn(logViewer, SWT.NONE);
column.getColumn().setText(Messages.ColumnMessage);
layout.setColumnData(column.getColumn(), new ColumnPixelData(500));
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((LogEntry) element).getMessage();
}
@Override
public Image getImage(Object element) {
LogEntry entry = (LogEntry) element;
switch(entry.getSeverity()) {
case IStatus.ERROR:
return Images.ERROR.image();
case IStatus.WARNING:
return Images.WARNING.image();
default:
return Images.INFO.image();
}
}
});
logViewer.getTree().setHeaderVisible(true);
logViewer.getTree().setLinesVisible(true);
logViewer.setContentProvider(new LogEntryContentProvider());
logViewer.setInput(entries);
logViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
LogEntry entry = (LogEntry) ((IStructuredSelection) event.getSelection()).getFirstElement();
DisplayTextDialog dialog = new DisplayTextDialog(Display.getCurrent().getActiveShell(), entry.getText());
dialog.open();
}
});
}
Aggregations