Search in sources :

Example 21 with Column

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);
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IMenuListener(org.eclipse.jface.action.IMenuListener) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport) MonthEditingSupport(name.abuchen.portfolio.ui.util.viewers.MonthEditingSupport) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) ConsumerPriceIndex(name.abuchen.portfolio.model.ConsumerPriceIndex) Column(name.abuchen.portfolio.ui.util.viewers.Column) IMenuManager(org.eclipse.jface.action.IMenuManager) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 22 with Column

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);
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Column(name.abuchen.portfolio.ui.util.viewers.Column) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) Image(org.eclipse.swt.graphics.Image)

Example 23 with 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;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ContextMenu(name.abuchen.portfolio.ui.util.ContextMenu) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) Image(org.eclipse.swt.graphics.Image) CTabItem(org.eclipse.swt.custom.CTabItem) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) Column(name.abuchen.portfolio.ui.util.viewers.Column) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 24 with Column

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);
}
Also used : Named(name.abuchen.portfolio.model.Named) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Image(org.eclipse.swt.graphics.Image) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn)

Example 25 with Column

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);
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Column(name.abuchen.portfolio.ui.util.viewers.Column) Color(org.eclipse.swt.graphics.Color) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Security(name.abuchen.portfolio.model.Security) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition) SharesLabelProvider(name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider)

Aggregations

Column (name.abuchen.portfolio.ui.util.viewers.Column)47 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)43 NoteColumn (name.abuchen.portfolio.ui.views.columns.NoteColumn)38 Image (org.eclipse.swt.graphics.Image)33 Composite (org.eclipse.swt.widgets.Composite)32 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)31 TableViewer (org.eclipse.jface.viewers.TableViewer)31 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)30 Security (name.abuchen.portfolio.model.Security)26 Values (name.abuchen.portfolio.money.Values)24 Messages (name.abuchen.portfolio.ui.Messages)24 IMenuManager (org.eclipse.jface.action.IMenuManager)24 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 SWT (org.eclipse.swt.SWT)24 Images (name.abuchen.portfolio.ui.Images)23 ColumnViewerSorter (name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter)23 Color (org.eclipse.swt.graphics.Color)23 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)21 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)21 NameColumn (name.abuchen.portfolio.ui.views.columns.NameColumn)20