use of org.eclipse.jface.viewers.ColumnPixelData in project portfolio by buchen.
the class ReviewExtractedItemsPage method addColumns.
private void addColumns(TableViewer viewer, TableColumnLayout layout) {
TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
column.getColumn().setText(Messages.ColumnStatus);
column.setLabelProvider(new // NOSONAR
FormattedLabelProvider() {
@Override
public Image getImage(ExtractedEntry element) {
Images image = null;
switch(element.getMaxCode()) {
case WARNING:
image = Images.WARNING;
break;
case ERROR:
image = Images.ERROR;
break;
case OK:
default:
}
return image != null ? image.image() : null;
}
@Override
public String getText(ExtractedEntry entry) {
// $NON-NLS-1$
return "";
}
});
layout.setColumnData(column.getColumn(), new ColumnPixelData(22, true));
column = new TableViewerColumn(viewer, SWT.NONE);
column.getColumn().setText(Messages.ColumnDate);
column.setLabelProvider(new // NOSONAR
FormattedLabelProvider() {
@Override
public String getText(ExtractedEntry entry) {
LocalDateTime date = entry.getItem().getDate();
return date != null ? Values.DateTime.format(date) : null;
}
});
layout.setColumnData(column.getColumn(), new ColumnPixelData(80, true));
column = new TableViewerColumn(viewer, SWT.NONE);
column.getColumn().setText(Messages.ColumnTransactionType);
column.setLabelProvider(new // NOSONAR
FormattedLabelProvider() {
@Override
public String getText(ExtractedEntry entry) {
return entry.getItem().getTypeInformation();
}
@Override
public Image getImage(ExtractedEntry entry) {
Annotated subject = entry.getItem().getSubject();
if (subject instanceof AccountTransaction)
return Images.ACCOUNT.image();
else if (subject instanceof PortfolioTransaction)
return Images.PORTFOLIO.image();
else if (subject instanceof Security)
return Images.SECURITY.image();
else if (subject instanceof BuySellEntry)
return Images.PORTFOLIO.image();
else if (subject instanceof AccountTransferEntry)
return Images.ACCOUNT.image();
else if (subject instanceof PortfolioTransferEntry)
return Images.PORTFOLIO.image();
else
return null;
}
});
layout.setColumnData(column.getColumn(), new ColumnPixelData(100, true));
column = new TableViewerColumn(viewer, SWT.RIGHT);
column.getColumn().setText(Messages.ColumnAmount);
column.setLabelProvider(new // NOSONAR
FormattedLabelProvider() {
@Override
public String getText(ExtractedEntry entry) {
Money amount = entry.getItem().getAmount();
return amount != null ? Values.Money.format(amount) : null;
}
});
layout.setColumnData(column.getColumn(), new ColumnPixelData(80, true));
column = new TableViewerColumn(viewer, SWT.RIGHT);
column.getColumn().setText(Messages.ColumnShares);
column.setLabelProvider(new // NOSONAR
FormattedLabelProvider() {
@Override
public String getText(ExtractedEntry entry) {
return Values.Share.formatNonZero(entry.getItem().getShares());
}
});
layout.setColumnData(column.getColumn(), new ColumnPixelData(80, true));
column = new TableViewerColumn(viewer, SWT.NONE);
column.getColumn().setText(Messages.ColumnSecurity);
column.setLabelProvider(new // NOSONAR
FormattedLabelProvider() {
@Override
public String getText(ExtractedEntry entry) {
Security security = entry.getItem().getSecurity();
return security != null ? security.getName() : null;
}
});
layout.setColumnData(column.getColumn(), new ColumnPixelData(250, true));
}
use of org.eclipse.jface.viewers.ColumnPixelData in project portfolio by buchen.
the class CSVImportDefinitionPage method doProcessFile.
private void doProcessFile() {
try {
importer.processFile();
tableViewer.getTable().setRedraw(false);
for (TableColumn column : tableViewer.getTable().getColumns()) column.dispose();
TableColumnLayout layout = (TableColumnLayout) tableViewer.getTable().getParent().getLayout();
for (Column column : importer.getColumns()) {
TableColumn tableColumn = new TableColumn(tableViewer.getTable(), SWT.None);
layout.setColumnData(tableColumn, new ColumnPixelData(80, true));
setColumnLabel(tableColumn, column);
}
List<Object> input = new ArrayList<>();
input.add(importer);
input.addAll(importer.getRawValues());
tableViewer.setInput(input);
tableViewer.refresh();
tableViewer.getTable().pack();
for (TableColumn column : tableViewer.getTable().getColumns()) column.pack();
doUpdateErrorMessages();
} catch (IOException e) {
PortfolioPlugin.log(e);
ErrorDialog.openError(getShell(), Messages.LabelError, e.getMessage(), new Status(Status.ERROR, PortfolioPlugin.PLUGIN_ID, e.getMessage(), e));
} finally {
tableViewer.getTable().setRedraw(true);
}
}
use of org.eclipse.jface.viewers.ColumnPixelData in project jbosstools-hibernate by jbosstools.
the class AutoResizeTableLayout method autoSizeColumns.
private void autoSizeColumns() {
int width = table.getClientArea().width;
if (width <= 1) {
return;
}
TableColumn[] tableColumns = table.getColumns();
int size = Math.min(columns.size(), tableColumns.length);
int[] widths = new int[size];
int fixedWidth = 0;
int numberOfWeightColumns = 0;
int totalWeight = 0;
// First calc space occupied by fixed columns.
for (int i = 0; i < size; i++) {
ColumnLayoutData col = columns.get(i);
if (col instanceof ColumnPixelData) {
int pixels = ((ColumnPixelData) col).width;
widths[i] = pixels;
fixedWidth += pixels;
} else if (col instanceof ColumnWeightData) {
ColumnWeightData cw = (ColumnWeightData) col;
numberOfWeightColumns++;
int weight = cw.weight;
totalWeight += weight;
} else {
throw new IllegalStateException(HibernateConsoleMessages.AutoResizeTableLayout_unknown_column_layout_data);
}
}
// Do we have columns that have a weight?
if (numberOfWeightColumns > 0) {
// Now, distribute the rest
// to the columns with weight.
int rest = width - fixedWidth;
int totalDistributed = 0;
for (int i = 0; i < size; i++) {
ColumnLayoutData col = columns.get(i);
if (col instanceof ColumnWeightData) {
ColumnWeightData cw = (ColumnWeightData) col;
int weight = cw.weight;
int pixels = totalWeight == 0 ? 0 : weight * rest / totalWeight;
totalDistributed += pixels;
widths[i] = pixels;
}
}
// Distribute any remaining pixels
// to columns with weight.
int diff = rest - totalDistributed;
for (int i = 0; diff > 0; i++) {
if (i == size) {
i = 0;
}
ColumnLayoutData col = columns.get(i);
if (col instanceof ColumnWeightData) {
++widths[i];
--diff;
}
}
}
for (int i = 0; i < size; i++) {
if (tableColumns[i].getWidth() != widths[i]) {
tableColumns[i].setWidth(widths[i]);
}
}
}
use of org.eclipse.jface.viewers.ColumnPixelData in project erlide_eclipse by erlang.
the class DebuggerTraceView method createColumns.
private void createColumns() {
final Tree tree = viewer.getTree();
final TableLayout layout = new TableLayout();
TreeViewerColumn column;
final String[] names = { // $NON-NLS-1$ //$NON-NLS-2$
"Kind", // $NON-NLS-1$ //$NON-NLS-2$
"Function", // $NON-NLS-1$
org.erlide.debug.ui.views.ActionMessages.getString("DebuggerTraceView.5") };
for (final String name : names) {
column = new TreeViewerColumn(viewer, SWT.NONE);
final TreeColumn treeColumn = column.getColumn();
treeColumn.setResizable(true);
treeColumn.setMoveable(true);
treeColumn.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
}
@Override
public void widgetSelected(final SelectionEvent e) {
}
});
// column.getColumn().setData(MARKER_FIELD, markerField);
// Show the help in the first column
column.setLabelProvider(new ColumnLabelProvider());
treeColumn.setText(name);
treeColumn.setToolTipText(name);
}
// column = new TreeViewerColumn(viewer, SWT.NONE);
// treeColumn = column.getColumn();
// treeColumn.setResizable(true);
// treeColumn.setMoveable(true);
// column.setLabelProvider(new ColumnLabelProvider());
// column.getColumn().setImage(markerField.getColumnHeaderImage());
// final EditingSupport support = markerField
// .getEditingSupport(viewer);
// if (support != null) {
// column.setEditingSupport(support);
// }
// if (builder.getPrimarySortField().equals(markerField)) {
// updateDirectionIndicator(column.getColumn(), markerField);
// }
int columnWidth = -1;
for (int i = 0; i < names.length; ++i) {
if (i == 0) {
// Compute and store a font metric
final GC gc = new GC(tree);
gc.setFont(tree.getFont());
final FontMetrics fontMetrics = gc.getFontMetrics();
gc.dispose();
columnWidth = (int) Math.max(100, fontMetrics.getAverageCharacterWidth() * 20);
}
// if (columnWidths != null) {
// final Integer value = columnWidths.getInteger(getFieldId(column
// .getColumn()));
//
// // Make sure we get a useful value
// if (value != null && value.intValue() > 0) {
// columnWidth = value.intValue();
// }
// }
// // Take trim into account if we are using the default value, but
// not
// // if it is restored.
// if (columnWidth < 0) {
// layout.addColumnData(new ColumnPixelData(markerField
// .getDefaultColumnWidth(tree), true, true));
// } else {
layout.addColumnData(new ColumnPixelData(columnWidth, true));
// }
}
// }
// Remove extra columns
// if (currentColumns.length > fields.length) {
// for (int i = fields.length; i < currentColumns.length; i++) {
// currentColumns[i].dispose();
//
// }
// }
viewer.getTree().setLayout(layout);
tree.setLinesVisible(true);
tree.setHeaderVisible(true);
tree.layout(true);
}
use of org.eclipse.jface.viewers.ColumnPixelData in project erlide_eclipse by erlang.
the class TableLayoutComposite method layoutTable.
protected void layoutTable(final Table table, final int width, final Rectangle area, final boolean increase) {
if (width <= 1) {
return;
}
final TableColumn[] tableColumns = table.getColumns();
final int size = Math.min(columns.size(), tableColumns.length);
final int[] widths = new int[size];
int fixedWidth = 0;
int numberOfWeightColumns = 0;
int totalWeight = 0;
// First calc space occupied by fixed columns
for (int i = 0; i < size; i++) {
final ColumnLayoutData col = columns.get(i);
if (col instanceof ColumnPixelData) {
final int pixels = ((ColumnPixelData) col).width;
widths[i] = pixels;
fixedWidth += pixels;
} else if (col instanceof ColumnWeightData) {
final ColumnWeightData cw = (ColumnWeightData) col;
numberOfWeightColumns++;
// first time, use the weight specified by the column data,
// otherwise use
// the actual width as the weight
// int weight = firstTime ? cw.weight :
// tableColumns[i].getWidth();
final int weight = cw.weight;
totalWeight += weight;
} else {
// $NON-NLS-1$
Assert.isTrue(false, "Unknown column layout data");
}
}
// Do we have columns that have a weight
if (numberOfWeightColumns > 0) {
// Now distribute the rest to the columns with weight.
final int rest = width - fixedWidth;
int totalDistributed = 0;
for (int i = 0; i < size; ++i) {
final ColumnLayoutData col = columns.get(i);
if (col instanceof ColumnWeightData) {
final ColumnWeightData cw = (ColumnWeightData) col;
// calculate weight as above
// int weight = firstTime ? cw.weight :
// tableColumns[i].getWidth();
final int weight = cw.weight;
int pixels = totalWeight == 0 ? 0 : weight * rest / totalWeight;
if (pixels < cw.minimumWidth) {
pixels = cw.minimumWidth;
}
totalDistributed += pixels;
widths[i] = pixels;
}
}
// Distribute any remaining pixels to columns with weight.
int diff = rest - totalDistributed;
for (int i = 0; diff > 0; ++i) {
if (i == size) {
i = 0;
}
final ColumnLayoutData col = columns.get(i);
if (col instanceof ColumnWeightData) {
++widths[i];
--diff;
}
}
}
if (increase) {
table.setSize(area.width, area.height);
}
for (int i = 0; i < size; i++) {
tableColumns[i].setWidth(widths[i]);
}
if (!increase) {
table.setSize(area.width, area.height);
}
}
Aggregations