Search in sources :

Example 1 with Images

use of name.abuchen.portfolio.ui.Images in project portfolio by buchen.

the class ReviewExtractedItemsPage method showContextMenu.

private void showContextMenu(IMenuManager manager) {
    IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
    boolean atLeastOneImported = false;
    boolean atLeastOneNotImported = false;
    for (Object element : selection.toList()) {
        ExtractedEntry entry = (ExtractedEntry) element;
        // an entry will be imported if it is marked as to be
        // imported *and* not a duplicate
        atLeastOneImported = atLeastOneImported || entry.isImported();
        // an entry will not be imported if it marked as not to be
        // imported *or* if it is marked as duplicate
        atLeastOneNotImported = atLeastOneNotImported || !entry.isImported();
    }
    // provide a hint to the user why the entry is struck out
    if (selection.size() == 1) {
        ExtractedEntry entry = (ExtractedEntry) selection.getFirstElement();
        // 
        entry.getStatus().filter(// 
        s -> s.getCode() != ImportAction.Status.Code.OK).forEach(s -> {
            Images image = // 
            s.getCode() == ImportAction.Status.Code.WARNING ? Images.WARNING : Images.ERROR;
            manager.add(new LabelOnly(s.getMessage(), image.descriptor()));
        });
    }
    if (atLeastOneImported) {
        manager.add(new Action(Messages.LabelDoNotImport) {

            @Override
            public void run() {
                for (Object element : ((IStructuredSelection) tableViewer.getSelection()).toList()) ((ExtractedEntry) element).setImported(false);
                tableViewer.refresh();
            }
        });
    }
    if (atLeastOneNotImported) {
        manager.add(new Action(Messages.LabelDoImport) {

            @Override
            public void run() {
                for (Object element : ((IStructuredSelection) tableViewer.getSelection()).toList()) ((ExtractedEntry) element).setImported(true);
                tableViewer.refresh();
            }
        });
    }
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) TableViewer(org.eclipse.jface.viewers.TableViewer) StyledString(org.eclipse.jface.viewers.StyledString) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) AbstractWizardPage(name.abuchen.portfolio.ui.wizards.AbstractWizardPage) IStatus(org.eclipse.core.runtime.IStatus) Extractor(name.abuchen.portfolio.datatransfer.Extractor) ViewerCell(org.eclipse.jface.viewers.ViewerCell) Composite(org.eclipse.swt.widgets.Composite) ImportAction(name.abuchen.portfolio.datatransfer.ImportAction) AbstractClientJob(name.abuchen.portfolio.ui.AbstractClientJob) CheckCurrenciesAction(name.abuchen.portfolio.datatransfer.actions.CheckCurrenciesAction) Button(org.eclipse.swt.widgets.Button) Account(name.abuchen.portfolio.model.Account) MenuManager(org.eclipse.jface.action.MenuManager) Status(org.eclipse.core.runtime.Status) Security(name.abuchen.portfolio.model.Security) Display(org.eclipse.swt.widgets.Display) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Collectors(java.util.stream.Collectors) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) Styler(org.eclipse.jface.viewers.StyledString.Styler) SWT(org.eclipse.swt.SWT) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) IntStream(java.util.stream.IntStream) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) LocalDateTime(java.time.LocalDateTime) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) TextStyle(org.eclipse.swt.graphics.TextStyle) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Table(org.eclipse.swt.widgets.Table) OptionalInt(java.util.OptionalInt) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ArrayList(java.util.ArrayList) Annotated(name.abuchen.portfolio.model.Annotated) Messages(name.abuchen.portfolio.ui.Messages) CheckValidTypesAction(name.abuchen.portfolio.datatransfer.actions.CheckValidTypesAction) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) DetectDuplicatesAction(name.abuchen.portfolio.datatransfer.actions.DetectDuplicatesAction) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) Portfolio(name.abuchen.portfolio.model.Portfolio) Combo(org.eclipse.swt.widgets.Combo) FormLayout(org.eclipse.swt.layout.FormLayout) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Action(org.eclipse.jface.action.Action) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) PortfolioPlugin(name.abuchen.portfolio.ui.PortfolioPlugin) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) FormDataFactory(name.abuchen.portfolio.ui.util.FormDataFactory) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) Collections(java.util.Collections) LabelProvider(org.eclipse.jface.viewers.LabelProvider) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) ImportAction(name.abuchen.portfolio.datatransfer.ImportAction) CheckCurrenciesAction(name.abuchen.portfolio.datatransfer.actions.CheckCurrenciesAction) CheckValidTypesAction(name.abuchen.portfolio.datatransfer.actions.CheckValidTypesAction) DetectDuplicatesAction(name.abuchen.portfolio.datatransfer.actions.DetectDuplicatesAction) Action(org.eclipse.jface.action.Action) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) Images(name.abuchen.portfolio.ui.Images) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with Images

use of name.abuchen.portfolio.ui.Images 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));
}
Also used : LocalDateTime(java.time.LocalDateTime) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Images(name.abuchen.portfolio.ui.Images) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) StyledString(org.eclipse.jface.viewers.StyledString) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Image(org.eclipse.swt.graphics.Image) Security(name.abuchen.portfolio.model.Security) Annotated(name.abuchen.portfolio.model.Annotated) Money(name.abuchen.portfolio.money.Money) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry)

Aggregations

LocalDateTime (java.time.LocalDateTime)2 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)2 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)2 Annotated (name.abuchen.portfolio.model.Annotated)2 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)2 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)2 PortfolioTransferEntry (name.abuchen.portfolio.model.PortfolioTransferEntry)2 Security (name.abuchen.portfolio.model.Security)2 Money (name.abuchen.portfolio.money.Money)2 Images (name.abuchen.portfolio.ui.Images)2 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)2 StyledString (org.eclipse.jface.viewers.StyledString)2 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)2 Image (org.eclipse.swt.graphics.Image)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 OptionalInt (java.util.OptionalInt)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1