use of name.abuchen.portfolio.ui.util.viewers.Column 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);
}
});
}
use of name.abuchen.portfolio.ui.util.viewers.Column in project portfolio by buchen.
the class AttributeListTab method addColumns.
private void addColumns(ShowHideColumnHelper support) {
Column column = new Column(Messages.ColumnName, SWT.None, 250);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((AttributeType) element).getName();
}
@Override
public Image getImage(Object element) {
return Images.TEXT.image();
}
});
// $NON-NLS-1$
new StringEditingSupport(AttributeType.class, "name").addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnColumnLabel, SWT.None, 150);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((AttributeType) element).getColumnLabel();
}
});
// $NON-NLS-1$
new StringEditingSupport(AttributeType.class, "columnLabel").addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnFieldType, SWT.None, 150);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return AttributeFieldType.of((AttributeType) element).toString();
}
});
support.addColumn(column);
}
use of name.abuchen.portfolio.ui.util.viewers.Column in project portfolio by buchen.
the class BookmarksListTab method createTab.
@Override
public CTabItem createTab(CTabFolder folder) {
Composite container = new Composite(folder, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
bookmarks = new TableViewer(container, SWT.FULL_SELECTION | SWT.MULTI);
ColumnEditingSupport.prepare(bookmarks);
ShowHideColumnHelper support = new // $NON-NLS-1$
ShowHideColumnHelper(// $NON-NLS-1$
BookmarksListTab.class.getSimpleName() + "@bottom", preferences, bookmarks, layout);
// Create Column for Bookmark
Column column = new Column(Messages.BookmarksListView_bookmark, SWT.None, 150);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((Bookmark) element).getLabel();
}
@Override
public Image getImage(Object element) {
return Images.TEXT.image();
}
});
// $NON-NLS-1$
new StringEditingSupport(Bookmark.class, "label").addListener(this).attachTo(column);
support.addColumn(column);
// Create Column for URL
column = new Column(Messages.BookmarksListView_url, SWT.None, 500);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((Bookmark) element).getPattern();
}
});
// $NON-NLS-1$
new StringEditingSupport(Bookmark.class, "pattern").addListener(this).attachTo(column);
support.addColumn(column);
support.createColumns();
bookmarks.getTable().setHeaderVisible(true);
bookmarks.getTable().setLinesVisible(true);
bookmarks.setContentProvider(ArrayContentProvider.getInstance());
bookmarks.setInput(client.getSettings().getBookmarks());
bookmarks.refresh();
new ContextMenu(bookmarks.getTable(), this::fillContextMenu).hook();
CTabItem item = new CTabItem(folder, SWT.NONE);
item.setText(Messages.BookmarksListView_title);
item.setControl(container);
return item;
}
use of name.abuchen.portfolio.ui.util.viewers.Column in project portfolio by buchen.
the class AbstractNodeTreeViewer method addDimensionColumn.
protected void addDimensionColumn(ShowHideColumnHelper support) {
// $NON-NLS-1$
Column column = new NameColumn("txname", Messages.ColumnLevels, SWT.NONE, 400);
column.setLabelProvider(new // NOSONAR
NameColumnLabelProvider() {
@Override
public Image getImage(Object e) {
if (((TaxonomyNode) e).isUnassignedCategory())
return Images.UNASSIGNED_CATEGORY.image();
return super.getImage(e);
}
});
new // $NON-NLS-1$
StringEditingSupport(// $NON-NLS-1$
Named.class, // $NON-NLS-1$
"name") {
@Override
public boolean canEdit(Object element) {
if (((TaxonomyNode) element).isUnassignedCategory())
return false;
else
return super.canEdit(element);
}
}.setMandatory(true).addListener(this).attachTo(column);
column.setRemovable(false);
// drag & drop sorting does not work well with auto sorting
column.setSorter(null);
support.addColumn(column);
column = new IsinColumn();
column.getEditingSupport().addListener(this);
column.setSorter(null);
column.setVisible(false);
support.addColumn(column);
column = new NoteColumn();
column.getEditingSupport().addListener(this);
column.setSorter(null);
column.setVisible(false);
support.addColumn(column);
addWeightColumn(support);
}
use of name.abuchen.portfolio.ui.util.viewers.Column in project portfolio by buchen.
the class ReBalancingViewer method addColumns.
@Override
protected void addColumns(ShowHideColumnHelper support) {
addDimensionColumn(support);
addDesiredAllocationColumn(support);
// $NON-NLS-1$
Column column = new Column("targetvalue", Messages.ColumnTargetValue, SWT.RIGHT, 100);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
return node.isClassification() ? Values.Money.format(node.getTarget(), getModel().getCurrencyCode()) : null;
}
});
support.addColumn(column);
addActualColumns(support);
// $NON-NLS-1$
column = new Column("delta%", Messages.ColumnDeltaPercent, SWT.RIGHT, 60);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
if (node.getTarget() == null)
return null;
return Values.Percent.format(((double) node.getActual().getAmount() / (double) node.getTarget().getAmount()) - 1);
}
@Override
public Color getForeground(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
if (node.getTarget() == null)
return null;
return Display.getCurrent().getSystemColor(node.getActual().isGreaterOrEqualThan(node.getTarget()) ? SWT.COLOR_DARK_GREEN : SWT.COLOR_DARK_RED);
}
});
support.addColumn(column);
// $NON-NLS-1$
column = new Column("delta", Messages.ColumnDeltaValue, SWT.RIGHT, 100);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
if (node.getTarget() == null)
return null;
return Values.Money.format(node.getActual().subtract(node.getTarget()), getModel().getCurrencyCode());
}
@Override
public Color getForeground(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
if (node.getTarget() == null)
return null;
return Display.getCurrent().getSystemColor(node.getActual().isGreaterOrEqualThan(node.getTarget()) ? SWT.COLOR_DARK_GREEN : SWT.COLOR_DARK_RED);
}
});
support.addColumn(column);
// $NON-NLS-1$
column = new Column("quote", Messages.ColumnQuote, SWT.RIGHT, 60);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
Security security = node.getBackingSecurity();
if (security == null || security.getCurrencyCode() == null)
return null;
SecurityPrice price = security.getSecurityPrice(LocalDate.now());
return Values.Quote.format(security.getCurrencyCode(), price.getValue(), getModel().getCurrencyCode());
}
});
support.addColumn(column);
// $NON-NLS-1$
column = new Column("shares", Messages.ColumnSharesOwned, SWT.RIGHT, 60);
column.setLabelProvider(new SharesLabelProvider() {
@Override
public Long getValue(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
Security security = node.getBackingSecurity();
if (security == null || security.getCurrencyCode() == null)
return null;
AssetPosition position = getModel().getClientSnapshot().getPositionsByVehicle().get(security);
if (position == null)
return null;
return Math.round(position.getPosition().getShares() * node.getWeight() / (double) Classification.ONE_HUNDRED_PERCENT);
}
});
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("deltashares", Messages.ColumnDeltaShares, SWT.RIGHT, 100);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
// no delta shares for unassigned securities
if (node.getParent() != null && node.getParent().isUnassignedCategory())
return null;
Security security = node.getBackingSecurity();
if (security == null || security.getCurrencyCode() == null)
return null;
String priceCurrency = security.getCurrencyCode();
long price = security.getSecurityPrice(LocalDate.now()).getValue();
long weightedPrice = Math.round(node.getWeight() * price / (double) Classification.ONE_HUNDRED_PERCENT);
if (weightedPrice == 0L)
return Values.Share.format(0L);
String deltaCurrency = node.getActual().getCurrencyCode();
long delta = node.getParent().getTarget().getAmount() - node.getParent().getActual().getAmount();
// delta in order to know how many shares need to bought or sold
if (!deltaCurrency.equals(priceCurrency)) {
delta = getModel().getCurrencyConverter().with(priceCurrency).convert(LocalDate.now(), Money.of(deltaCurrency, delta)).getAmount();
}
long shares = Math.round(delta * Values.Share.divider() * Values.Quote.dividerToMoney() / weightedPrice);
return Values.Share.format(shares);
}
});
support.addColumn(column);
addAdditionalColumns(support);
}
Aggregations