Search in sources :

Example 1 with ConvertDeliveryToBuySellAction

use of name.abuchen.portfolio.ui.views.actions.ConvertDeliveryToBuySellAction in project portfolio by buchen.

the class PortfolioTransactionsViewer method fillTransactionsContextMenu.

private void fillTransactionsContextMenu(IMenuManager manager) {
    if (portfolio == null)
        return;
    IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
    PortfolioTransaction firstTransaction = (PortfolioTransaction) selection.getFirstElement();
    if (firstTransaction != null && selection.size() == 1) {
        Action editAction = createEditAction(firstTransaction);
        editAction.setAccelerator(SWT.MOD1 | 'E');
        manager.add(editAction);
        manager.add(new Separator());
        if (fullContextMenu && (firstTransaction.getType() == PortfolioTransaction.Type.BUY || firstTransaction.getType() == PortfolioTransaction.Type.SELL)) {
            manager.add(new ConvertBuySellToDeliveryAction(owner.getClient(), new TransactionPair<>(portfolio, firstTransaction)));
            manager.add(new Separator());
        }
        if (fullContextMenu && (firstTransaction.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND || firstTransaction.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND)) {
            manager.add(new ConvertDeliveryToBuySellAction(owner.getClient(), new TransactionPair<>(portfolio, firstTransaction)));
            manager.add(new Separator());
        }
        if (fullContextMenu)
            new SecurityContextMenu(owner).menuAboutToShow(manager, firstTransaction.getSecurity(), portfolio);
        else
            manager.add(new BookmarkMenu(owner.getPart(), firstTransaction.getSecurity()));
    } else if (firstTransaction == null) {
        new SecurityContextMenu(owner).menuAboutToShow(manager, null, portfolio);
    }
    if (firstTransaction != null) {
        manager.add(new Separator());
        manager.add(new Action(Messages.MenuTransactionDelete) {

            @Override
            public void run() {
                Object[] transactions = selection.toArray();
                for (Object transaction : transactions) portfolio.deleteTransaction((PortfolioTransaction) transaction, owner.getClient());
                owner.markDirty();
                owner.notifyModelUpdated();
            }
        });
    }
}
Also used : TransactionPair(name.abuchen.portfolio.model.TransactionPair) ConvertDeliveryToBuySellAction(name.abuchen.portfolio.ui.views.actions.ConvertDeliveryToBuySellAction) BookmarkMenu(name.abuchen.portfolio.ui.util.BookmarkMenu) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) ConvertBuySellToDeliveryAction(name.abuchen.portfolio.ui.views.actions.ConvertBuySellToDeliveryAction) ConvertDeliveryToBuySellAction(name.abuchen.portfolio.ui.views.actions.ConvertDeliveryToBuySellAction) Action(org.eclipse.jface.action.Action) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) ConvertBuySellToDeliveryAction(name.abuchen.portfolio.ui.views.actions.ConvertBuySellToDeliveryAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Separator(org.eclipse.jface.action.Separator)

Example 2 with ConvertDeliveryToBuySellAction

use of name.abuchen.portfolio.ui.views.actions.ConvertDeliveryToBuySellAction in project portfolio by buchen.

the class SecurityListView method transactionMenuAboutToShow.

private // NOSONAR
void transactionMenuAboutToShow(// NOSONAR
IMenuManager manager) {
    Security security = (Security) prices.getData(Security.class.toString());
    if (security == null)
        return;
    TransactionPair<?> pair = (TransactionPair<?>) ((IStructuredSelection) transactions.getSelection()).getFirstElement();
    if (pair != null) {
        Action action = createEditAction(pair);
        action.setAccelerator(SWT.MOD1 | 'E');
        manager.add(action);
        manager.add(new Separator());
        if (pair.getTransaction() instanceof PortfolioTransaction) {
            Portfolio p = (Portfolio) pair.getOwner();
            PortfolioTransaction t = (PortfolioTransaction) pair.getTransaction();
            if (t.getType() == PortfolioTransaction.Type.BUY || t.getType() == PortfolioTransaction.Type.SELL) {
                manager.add(new ConvertBuySellToDeliveryAction(getClient(), new TransactionPair<>(p, t)));
                manager.add(new Separator());
            }
            if (t.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND || t.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND) {
                manager.add(new ConvertDeliveryToBuySellAction(getClient(), new TransactionPair<>(p, t)));
                manager.add(new Separator());
            }
        }
    }
    new SecurityContextMenu(SecurityListView.this).menuAboutToShow(manager, security);
    manager.add(new Separator());
    manager.add(new Action(Messages.MenuTransactionDelete) {

        @Override
        public void run() {
            TransactionPair<?> pair = (TransactionPair<?>) ((IStructuredSelection) transactions.getSelection()).getFirstElement();
            if (pair == null)
                return;
            pair.deleteTransaction(getClient());
            getClient().markDirty();
        }
    });
}
Also used : TransactionPair(name.abuchen.portfolio.model.TransactionPair) ConvertDeliveryToBuySellAction(name.abuchen.portfolio.ui.views.actions.ConvertDeliveryToBuySellAction) ConvertBuySellToDeliveryAction(name.abuchen.portfolio.ui.views.actions.ConvertBuySellToDeliveryAction) ConvertDeliveryToBuySellAction(name.abuchen.portfolio.ui.views.actions.ConvertDeliveryToBuySellAction) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) ConvertBuySellToDeliveryAction(name.abuchen.portfolio.ui.views.actions.ConvertBuySellToDeliveryAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Security(name.abuchen.portfolio.model.Security) Separator(org.eclipse.jface.action.Separator)

Aggregations

PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)2 TransactionPair (name.abuchen.portfolio.model.TransactionPair)2 OpenDialogAction (name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction)2 ConvertBuySellToDeliveryAction (name.abuchen.portfolio.ui.views.actions.ConvertBuySellToDeliveryAction)2 ConvertDeliveryToBuySellAction (name.abuchen.portfolio.ui.views.actions.ConvertDeliveryToBuySellAction)2 Action (org.eclipse.jface.action.Action)2 Separator (org.eclipse.jface.action.Separator)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Portfolio (name.abuchen.portfolio.model.Portfolio)1 Security (name.abuchen.portfolio.model.Security)1 BookmarkMenu (name.abuchen.portfolio.ui.util.BookmarkMenu)1 SimpleAction (name.abuchen.portfolio.ui.util.SimpleAction)1