use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.
the class SecurityListView method createPricesTable.
// //////////////////////////////////////////////////////////////
// tab item: prices
// //////////////////////////////////////////////////////////////
protected Composite createPricesTable(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
prices = new TableViewer(container, SWT.FULL_SELECTION | SWT.MULTI);
ColumnEditingSupport.prepare(prices);
ShowHideColumnHelper support = new // $NON-NLS-1$
ShowHideColumnHelper(// $NON-NLS-1$
SecurityListView.class.getSimpleName() + "@prices", getPreferenceStore(), prices, layout);
Column column = new Column(Messages.ColumnDate, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return Values.Date.format(((SecurityPrice) element).getDate());
}
@Override
public Color getBackground(Object element) {
SecurityPrice current = (SecurityPrice) element;
List<?> all = (List<?>) prices.getInput();
int index = all.indexOf(current);
if (index == 0)
return null;
SecurityPrice previous = (SecurityPrice) all.get(index - 1);
int days = Dates.daysBetween(previous.getDate(), current.getDate());
return days > 3 ? Colors.WARNING : null;
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(SecurityPrice.class, "date").attachTo(column, SWT.UP);
// $NON-NLS-1$
new DateEditingSupport(SecurityPrice.class, "date").addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnQuote, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Security security = (Security) prices.getData(Security.class.toString());
SecurityPrice price = (SecurityPrice) element;
return Values.Quote.format(security.getCurrencyCode(), price.getValue(), getClient().getBaseCurrency());
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(SecurityPrice.class, "value").attachTo(column);
// $NON-NLS-1$
new ValueEditingSupport(SecurityPrice.class, "value", Values.Quote).addListener(this).attachTo(column);
support.addColumn(column);
support.createColumns();
prices.getTable().setHeaderVisible(true);
prices.getTable().setLinesVisible(true);
prices.setContentProvider(ArrayContentProvider.getInstance());
hookContextMenu(prices.getTable(), this::fillPricesContextMenu);
return container;
}
use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.
the class InvestmentPlanListView method createTopTable.
@Override
protected void createTopTable(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
plans = new TableViewer(container, SWT.FULL_SELECTION);
ColumnEditingSupport.prepare(plans);
planColumns = new // $NON-NLS-1$
ShowHideColumnHelper(// $NON-NLS-1$
InvestmentPlanListView.class.getSimpleName() + "@top", getPreferenceStore(), plans, layout);
addColumns(planColumns);
planColumns.createColumns();
plans.getTable().setHeaderVisible(true);
plans.getTable().setLinesVisible(true);
plans.setContentProvider(ArrayContentProvider.getInstance());
plans.setInput(getClient().getPlans());
plans.addSelectionChangedListener(event -> {
InvestmentPlan plan = (InvestmentPlan) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (plan != null)
transactions.setInput(plan.getPortfolio(), plan.getTransactions());
else
transactions.setInput(null, null);
transactions.refresh();
});
hookContextMenu(plans.getTable(), this::fillPlansContextMenu);
}
use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.
the class PerformanceView method createTransactionViewer.
private TableViewer createTransactionViewer(CTabFolder folder, String title) {
Composite container = new Composite(folder, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
TableViewer transactionViewer = new TableViewer(container, SWT.FULL_SELECTION);
transactionViewer.addSelectionChangedListener(event -> {
TransactionPair<?> tx = ((TransactionPair<?>) ((IStructuredSelection) event.getSelection()).getFirstElement());
if (tx != null && tx.getTransaction().getSecurity() != null)
selectionService.setSelection(new SecuritySelection(getClient(), tx.getTransaction().getSecurity()));
});
ShowHideColumnHelper support = new // $NON-NLS-1$
ShowHideColumnHelper(// $NON-NLS-1$
PerformanceView.class.getSimpleName() + "@2" + title, getPreferenceStore(), transactionViewer, layout);
Column column = new Column(Messages.ColumnDate, SWT.None, 100);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return Values.DateTime.format(((TransactionPair<?>) element).getTransaction().getDateTime());
}
});
column.setSorter(ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getDateTime()), SWT.UP);
support.addColumn(column);
column = new Column(Messages.ColumnTransactionType, SWT.LEFT, 100);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Transaction t = ((TransactionPair<?>) element).getTransaction();
return t instanceof AccountTransaction ? ((AccountTransaction) t).getType().toString() : ((PortfolioTransaction) t).getType().toString();
}
});
column.setSorter(ColumnViewerSorter.create(e -> {
Transaction t = ((TransactionPair<?>) e).getTransaction();
return t instanceof AccountTransaction ? ((AccountTransaction) t).getType().toString() : ((PortfolioTransaction) t).getType().toString();
}));
support.addColumn(column);
column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return Values.Money.format(((TransactionPair<?>) element).getTransaction().getMonetaryAmount(), getClient().getBaseCurrency());
}
});
column.setSorter(ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getMonetaryAmount()));
support.addColumn(column);
addTaxesColumn(support);
addFeesColumn(support);
addSecurityColumn(support);
addPortfolioColumn(support);
addAccountColumn(support);
column = new NoteColumn();
column.setEditingSupport(null);
support.addColumn(column);
support.createColumns();
transactionViewer.getTable().setHeaderVisible(true);
transactionViewer.getTable().setLinesVisible(true);
transactionViewer.setContentProvider(ArrayContentProvider.getInstance());
CTabItem item = new CTabItem(folder, SWT.NONE);
item.setText(title);
item.setControl(container);
return transactionViewer;
}
use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.
the class StatementOfAssetsViewer method createColumns.
private // NOSONAR
Control createColumns(// NOSONAR
Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
assets = new TableViewer(container, SWT.FULL_SELECTION);
ColumnViewerToolTipSupport.enableFor(assets, ToolTip.NO_RECREATE);
ColumnEditingSupport.prepare(assets);
assets.addSelectionChangedListener(event -> {
Element element = (Element) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (element != null && element.isSecurity())
selectionService.setSelection(new SecuritySelection(client, element.getSecurity()));
});
support = new ShowHideColumnHelper(StatementOfAssetsViewer.class.getName(), client, preference, assets, layout);
// $NON-NLS-1$
Column column = new Column("0", Messages.ColumnSharesOwned, SWT.RIGHT, 80);
column.setLabelProvider(new // NOSONAR
SharesLabelProvider() {
@Override
public Long getValue(Object e) {
Element element = (Element) e;
return element.isSecurity() ? element.getSecurityPosition().getShares() : null;
}
});
column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurityPosition().getShares() : null)));
support.addColumn(column);
// $NON-NLS-1$
column = new NameColumn("1");
column.setLabelProvider(new // NOSONAR
NameColumnLabelProvider() {
@Override
public String getText(Object e) {
if (((Element) e).isGroupByTaxonomy())
return Messages.LabelTotalSum;
return super.getText(e);
}
@Override
public Font getFont(Object e) {
return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
}
@Override
public Image getImage(Object e) {
if (((Element) e).isCategory())
return null;
return super.getImage(e);
}
});
column.setEditingSupport(new // $NON-NLS-1$
StringEditingSupport(// $NON-NLS-1$
Named.class, // $NON-NLS-1$
"name") {
@Override
public boolean canEdit(Object element) {
boolean isCategory = ((Element) element).isCategory();
boolean isUnassignedCategory = isCategory && Classification.UNASSIGNED_ID.equals(((Element) element).getCategory().getClassification().getId());
return !isUnassignedCategory ? super.canEdit(element) : false;
}
}.setMandatory(true).addListener(new MarkDirtyListener(this.owner)));
column.getSorter().wrap(ElementComparator::new);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("2", Messages.ColumnTicker, SWT.None, 60);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
return element.isSecurity() ? element.getSecurity().getTickerSymbol() : null;
}
});
column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurity().getTickerSymbol() : null)));
support.addColumn(column);
// $NON-NLS-1$
column = new Column("12", Messages.ColumnWKN, SWT.None, 60);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
return element.isSecurity() ? element.getSecurity().getWkn() : null;
}
});
column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurity().getWkn() : null)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new IsinColumn("3");
column.getEditingSupport().addListener(new MarkDirtyListener(this.owner));
column.getSorter().wrap(ElementComparator::new);
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("4", Messages.ColumnQuote, SWT.RIGHT, 60);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
if (!element.isSecurity())
return null;
Security security = element.getSecurity();
return Values.Quote.format(security.getCurrencyCode(), element.getSecurityPosition().getPrice().getValue(), client.getBaseCurrency());
}
});
column.setComparator(new ElementComparator(new AttributeComparator(e -> {
Element element = (Element) e;
if (!element.isSecurity())
return null;
return Money.of(element.getSecurity().getCurrencyCode(), element.getSecurityPosition().getPrice().getValue());
})));
support.addColumn(column);
// $NON-NLS-1$
column = new Column("qdate", Messages.ColumnDateOfQuote, SWT.LEFT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
return element.isSecurity() ? Values.Date.format(element.getSecurityPosition().getPrice().getDate()) : null;
}
});
column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurityPosition().getPrice().getDate() : null)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("5", Messages.ColumnMarketValue, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
return Values.Money.format(element.getValuation(), client.getBaseCurrency());
}
@Override
public Font getFont(Object e) {
return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(Element.class, "valuation").wrap(ElementComparator::new));
support.addColumn(column);
// $NON-NLS-1$
column = new Column("6", Messages.ColumnShareInPercent, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
if (element.isGroupByTaxonomy())
return Values.Percent.format(1d);
if (element.isCategory())
return Values.Percent.format(element.getCategory().getShare());
else
return Values.Percent.format(element.getPosition().getShare());
}
@Override
public Font getFont(Object e) {
return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(Element.class, "valuation").wrap(ElementComparator::new));
support.addColumn(column);
// $NON-NLS-1$
column = new Column("7", Messages.ColumnPurchasePrice, SWT.RIGHT, 60);
column.setDescription(Messages.ColumnPurchasePrice_Description);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
if (element.isSecurity()) {
Money purchasePrice = element.getSecurityPosition().getFIFOPurchasePrice();
return Values.Money.formatNonZero(purchasePrice, client.getBaseCurrency());
}
return null;
}
});
column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurityPosition().getFIFOPurchasePrice() : null)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("ppmvavg", Messages.ColumnPurchasePriceMovingAverage, SWT.RIGHT, 60);
column.setDescription(Messages.ColumnPurchasePriceMovingAverage_Description);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
if (element.isSecurity()) {
Money purchasePrice = element.getSecurityPosition().getMovingAveragePurchasePrice();
return Values.Money.formatNonZero(purchasePrice, client.getBaseCurrency());
}
return null;
}
});
column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurityPosition().getMovingAveragePurchasePrice() : null)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("8", Messages.ColumnPurchaseValue, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnPurchaseValue_Description);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
Money purchaseValue = element.getFIFOPurchaseValue();
return Values.Money.formatNonZero(purchaseValue, client.getBaseCurrency());
}
@Override
public Font getFont(Object e) {
return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
}
});
column.setVisible(false);
column.setSorter(// $NON-NLS-1$
ColumnViewerSorter.create(Element.class, "FIFOPurchaseValue").wrap(ElementComparator::new));
support.addColumn(column);
// $NON-NLS-1$
column = new Column("pvmvavg", Messages.ColumnPurchaseValueMovingAverage, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnPurchaseValueMovingAverage_Description);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
Money purchaseValue = element.getMovingAveragePurchaseValue();
return Values.Money.formatNonZero(purchaseValue, client.getBaseCurrency());
}
@Override
public Font getFont(Object e) {
return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
}
});
column.setVisible(false);
column.setSorter(// $NON-NLS-1$
ColumnViewerSorter.create(Element.class, "MovingAveragePurchaseValue").wrap(ElementComparator::new));
support.addColumn(column);
// $NON-NLS-1$
column = new Column("9", Messages.ColumnProfitLoss, SWT.RIGHT, 80);
column.setLabelProvider(new // NOSONAR
ColumnLabelProvider() {
@Override
public String getText(Object e) {
Money profitLoss = ((Element) e).getProfitLoss();
return Values.Money.formatNonZero(profitLoss, client.getBaseCurrency());
}
@Override
public Color getForeground(Object e) {
Money profitLoss = ((Element) e).getProfitLoss();
return Display.getCurrent().getSystemColor(profitLoss.isNegative() ? SWT.COLOR_DARK_RED : SWT.COLOR_DARK_GREEN);
}
@Override
public Image getImage(Object e) {
Money profitLoss = ((Element) e).getProfitLoss();
if (profitLoss.isZero())
return null;
return profitLoss.isNegative() ? Images.RED_ARROW.image() : Images.GREEN_ARROW.image();
}
@Override
public Font getFont(Object e) {
return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
}
});
column.setVisible(false);
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(Element.class, "profitLoss").wrap(ElementComparator::new));
support.addColumn(column);
column = new NoteColumn();
column.getEditingSupport().addListener(new MarkDirtyListener(this.owner));
column.getSorter().wrap(ElementComparator::new);
support.addColumn(column);
// create a modifiable copy as all menus share the same list of
// reporting periods
List<ReportingPeriod> options = new ArrayList<>(owner.getPart().loadReportingPeriods());
addPerformanceColumns(options);
addDividendColumns(options);
addTaxonomyColumns();
addAttributeColumns();
addCurrencyColumns();
support.createColumns();
assets.getTable().setHeaderVisible(true);
assets.getTable().setLinesVisible(true);
assets.setContentProvider(new StatementOfAssetsContentProvider());
//
assets.addDragSupport(//
DND.DROP_MOVE, //
new Transfer[] { SecurityTransfer.getTransfer() }, new SecurityDragListener(assets));
LocalResourceManager resources = new LocalResourceManager(JFaceResources.getResources(), assets.getTable());
boldFont = resources.createFont(FontDescriptor.createFrom(assets.getTable().getFont()).setStyle(SWT.BOLD));
return container;
}
use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.
the class ConsumerPriceIndexListView method createTopTable.
@Override
protected void createTopTable(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
indices = new TableViewer(container, SWT.FULL_SELECTION);
ColumnEditingSupport.prepare(indices);
ShowHideColumnHelper support = new ShowHideColumnHelper(// $NON-NLS-1$
ConsumerPriceIndexListView.class.getSimpleName() + "@bottom", // $NON-NLS-1$
getPreferenceStore(), // $NON-NLS-1$
indices, layout);
Column column = new Column(Messages.ColumnYear, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return String.valueOf(((ConsumerPriceIndex) element).getYear());
}
});
// $NON-NLS-1$ //$NON-NLS-2$
ColumnViewerSorter.create(ConsumerPriceIndex.class, "year", "month").attachTo(column, SWT.DOWN);
// $NON-NLS-1$
new ValueEditingSupport(ConsumerPriceIndex.class, "year", Values.Year).addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnMonth, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
int month = ((ConsumerPriceIndex) element).getMonth();
return Month.of(month).getDisplayName(TextStyle.FULL, Locale.getDefault());
}
});
// $NON-NLS-1$ //$NON-NLS-2$
ColumnViewerSorter.create(ConsumerPriceIndex.class, "month", "year").attachTo(column);
// $NON-NLS-1$
new MonthEditingSupport(ConsumerPriceIndex.class, "month").addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnIndex, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return Values.Index.format(((ConsumerPriceIndex) element).getIndex());
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(ConsumerPriceIndex.class, "index").attachTo(column);
// $NON-NLS-1$
new ValueEditingSupport(ConsumerPriceIndex.class, "index", Values.Index).addListener(this).attachTo(column);
support.addColumn(column);
support.createColumns();
indices.getTable().setHeaderVisible(true);
indices.getTable().setLinesVisible(true);
indices.setContentProvider(ArrayContentProvider.getInstance());
indices.setInput(getClient().getConsumerPriceIndices());
indices.refresh();
hookContextMenu(indices.getTable(), new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
fillContextMenu(manager);
}
});
}
Aggregations