Search in sources :

Example 1 with BookmarkMenu

use of name.abuchen.portfolio.ui.util.BookmarkMenu 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 BookmarkMenu

use of name.abuchen.portfolio.ui.util.BookmarkMenu in project portfolio by buchen.

the class AbstractNodeTreeViewer method fillContextMenu.

protected // NOSONAR
void fillContextMenu(// NOSONAR
IMenuManager manager) {
    // do not show context menu if multiple nodes are selected
    IStructuredSelection selection = (IStructuredSelection) nodeViewer.getSelection();
    if (selection.isEmpty() || selection.size() > 1)
        return;
    TaxonomyNode node = (TaxonomyNode) selection.getFirstElement();
    if (node.isUnassignedCategory())
        return;
    // allow inherited views to contribute to the context menu
    manager.add(new Separator(MENU_GROUP_CUSTOM_ACTIONS));
    manager.add(new Separator(MENU_GROUP_DEFAULT_ACTIONS));
    if (node.isClassification()) {
        manager.add(new SimpleAction(Messages.MenuTaxonomyClassificationCreate, a -> doAddClassification(node)));
        TaxonomyNode unassigned = getModel().getUnassignedNode();
        if (!unassigned.getChildren().isEmpty()) {
            MenuManager subMenu = new MenuManager(Messages.MenuTaxonomyMakeAssignment);
            addAvailableAssignments(subMenu, node);
            manager.add(subMenu);
        }
        manager.add(new Separator());
        MenuManager sorting = new MenuManager(Messages.MenuTaxonomySortTreeBy);
        sorting.add(new SimpleAction(Messages.MenuTaxonomySortByTypName, a -> doSort(node, true)));
        sorting.add(new SimpleAction(Messages.MenuTaxonomySortByName, a -> doSort(node, false)));
        manager.add(sorting);
        if (!node.isRoot()) {
            manager.add(new Separator(MENU_GROUP_DELETE_ACTIONS));
            manager.add(new SimpleAction(Messages.MenuTaxonomyClassificationDelete, a -> doDeleteClassification(node)));
        }
    } else {
        // node is assignment, but not in unassigned category
        if (!node.getParent().isUnassignedCategory()) {
            manager.add(new SimpleAction(Messages.MenuTaxonomyAssignmentRemove, a -> {
                int oldWeight = node.getWeight();
                node.setWeight(0);
                doChangeAssignmentWeight(node, oldWeight);
                onTaxnomyNodeEdited(getModel().getVirtualRootNode());
            }));
        }
        Security security = node.getBackingSecurity();
        if (security != null) {
            manager.add(new Separator());
            manager.add(new BookmarkMenu(part, security));
        }
    }
}
Also used : NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) Arrays(java.util.Arrays) DND(org.eclipse.swt.dnd.DND) Classification(name.abuchen.portfolio.model.Classification) ModificationListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.ModificationListener) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) Composite(org.eclipse.swt.widgets.Composite) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) UIConstants(name.abuchen.portfolio.ui.UIConstants) Separator(org.eclipse.jface.action.Separator) Predicate(java.util.function.Predicate) MenuManager(org.eclipse.jface.action.MenuManager) Set(java.util.Set) Security(name.abuchen.portfolio.model.Security) UUID(java.util.UUID) Display(org.eclipse.swt.widgets.Display) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) Transfer(org.eclipse.swt.dnd.Transfer) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) List(java.util.List) Colors(name.abuchen.portfolio.ui.util.Colors) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SecurityTransfer(name.abuchen.portfolio.ui.dnd.SecurityTransfer) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TransferData(org.eclipse.swt.dnd.TransferData) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) ContextMenu(name.abuchen.portfolio.ui.util.ContextMenu) Values(name.abuchen.portfolio.money.Values) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) BookmarkMenu(name.abuchen.portfolio.ui.util.BookmarkMenu) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) Messages(name.abuchen.portfolio.ui.Messages) TreeSelection(org.eclipse.jface.viewers.TreeSelection) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) LinkedList(java.util.LinkedList) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport) Viewer(org.eclipse.jface.viewers.Viewer) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Column(name.abuchen.portfolio.ui.util.viewers.Column) Action(org.eclipse.jface.action.Action) TreeViewerCSVExporter(name.abuchen.portfolio.ui.util.TreeViewerCSVExporter) Preference(org.eclipse.e4.core.di.extensions.Preference) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) Named(name.abuchen.portfolio.model.Named) StringJoiner(java.util.StringJoiner) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) ToolTip(org.eclipse.jface.window.ToolTip) Collections(java.util.Collections) Control(org.eclipse.swt.widgets.Control) Assignment(name.abuchen.portfolio.model.Classification.Assignment) BookmarkMenu(name.abuchen.portfolio.ui.util.BookmarkMenu) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Security(name.abuchen.portfolio.model.Security) Separator(org.eclipse.jface.action.Separator)

Example 3 with BookmarkMenu

use of name.abuchen.portfolio.ui.util.BookmarkMenu in project portfolio by buchen.

the class SecuritiesTable method fillContextMenu.

private void fillContextMenu(IMenuManager manager) {
    IStructuredSelection selection = (IStructuredSelection) securities.getSelection();
    if (selection.isEmpty())
        return;
    if (selection.size() == 1) {
        Security security = (Security) selection.getFirstElement();
        // only if the security has a currency code, it can be bought
        if (security.getCurrencyCode() != null)
            fillTransactionContextMenu(manager, security);
        manager.add(new EditSecurityAction());
        manager.add(new Separator());
        new QuotesContextMenu(this.view).menuAboutToShow(manager, security);
        manager.add(new Separator());
        manager.add(new BookmarkMenu(view.getPart(), security));
    }
    manager.add(new Separator());
    if (watchlist == null) {
        manager.add(new DeleteSecurityAction(selection));
    } else {
        manager.add(new Action(MessageFormat.format(Messages.SecurityMenuRemoveFromWatchlist, watchlist.getName())) {

            @Override
            public void run() {
                for (Object security : selection.toArray()) watchlist.getSecurities().remove(security);
                markDirty();
                securities.setInput(watchlist.getSecurities());
            }
        });
    }
}
Also used : BookmarkMenu(name.abuchen.portfolio.ui.util.BookmarkMenu) Action(org.eclipse.jface.action.Action) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Security(name.abuchen.portfolio.model.Security) Separator(org.eclipse.jface.action.Separator)

Example 4 with BookmarkMenu

use of name.abuchen.portfolio.ui.util.BookmarkMenu in project portfolio by buchen.

the class SecurityContextMenu method menuAboutToShow.

public void menuAboutToShow(IMenuManager manager, final Security security, final Portfolio portfolio) {
    if (owner.getClient().getSecurities().isEmpty())
        return;
    // menus to create transactions
    if (security != null && security.getCurrencyCode() == null) {
        manager.add(new BookmarkMenu(owner.getPart(), security));
        return;
    }
    // $NON-NLS-1$
    new OpenDialogAction(owner, Messages.SecurityMenuBuy + "...").type(// 
    SecurityTransactionDialog.class).parameters(// 
    PortfolioTransaction.Type.BUY).with(// 
    portfolio).with(// 
    security).addTo(manager);
    // $NON-NLS-1$
    new OpenDialogAction(owner, Messages.SecurityMenuSell + "...").type(// 
    SecurityTransactionDialog.class).parameters(// 
    PortfolioTransaction.Type.SELL).with(// 
    portfolio).with(// 
    security).addTo(manager);
    // $NON-NLS-1$
    new OpenDialogAction(owner, Messages.SecurityMenuDividends + "...").type(// 
    AccountTransactionDialog.class).parameters(// 
    AccountTransaction.Type.DIVIDENDS).with(// 
    portfolio != null ? portfolio.getReferenceAccount() : null).with(// 
    security).addTo(manager);
    // $NON-NLS-1$
    new OpenDialogAction(owner, AccountTransaction.Type.TAX_REFUND + "...").type(// 
    AccountTransactionDialog.class).parameters(// 
    AccountTransaction.Type.TAX_REFUND).with(// 
    portfolio != null ? portfolio.getReferenceAccount() : null).with(// 
    security).addTo(manager);
    manager.add(new Action(Messages.SecurityMenuStockSplit) {

        @Override
        public void run() {
            StockSplitWizard wizard = new StockSplitWizard(owner.getClient(), security);
            WizardDialog dialog = new WizardDialog(owner.getActiveShell(), wizard);
            if (dialog.open() == Dialog.OK) {
                owner.markDirty();
                owner.notifyModelUpdated();
            }
        }
    });
    if (owner.getClient().getActivePortfolios().size() > 1) {
        manager.add(new Separator());
        // 
        new OpenDialogAction(owner, Messages.SecurityMenuTransfer).type(// 
        SecurityTransferDialog.class).with(// 
        portfolio).with(// 
        security).addTo(manager);
    }
    manager.add(new Separator());
    // $NON-NLS-1$
    new OpenDialogAction(owner, PortfolioTransaction.Type.DELIVERY_INBOUND.toString() + "...").type(// 
    SecurityTransactionDialog.class).parameters(// 
    PortfolioTransaction.Type.DELIVERY_INBOUND).with(// 
    portfolio).with(// 
    security).addTo(manager);
    // $NON-NLS-1$
    new OpenDialogAction(owner, PortfolioTransaction.Type.DELIVERY_OUTBOUND.toString() + "...").type(// 
    SecurityTransactionDialog.class).parameters(// 
    PortfolioTransaction.Type.DELIVERY_OUTBOUND).with(// 
    portfolio).with(// 
    security).addTo(manager);
    if (security != null) {
        manager.add(new Separator());
        manager.add(new BookmarkMenu(owner.getPart(), security));
    }
}
Also used : BookmarkMenu(name.abuchen.portfolio.ui.util.BookmarkMenu) Action(org.eclipse.jface.action.Action) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) StockSplitWizard(name.abuchen.portfolio.ui.wizards.splits.StockSplitWizard) SecurityTransferDialog(name.abuchen.portfolio.ui.dialogs.transactions.SecurityTransferDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Separator(org.eclipse.jface.action.Separator) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction)

Aggregations

BookmarkMenu (name.abuchen.portfolio.ui.util.BookmarkMenu)4 Action (org.eclipse.jface.action.Action)4 Separator (org.eclipse.jface.action.Separator)4 OpenDialogAction (name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 Security (name.abuchen.portfolio.model.Security)2 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 StringJoiner (java.util.StringJoiner)1 UUID (java.util.UUID)1 Predicate (java.util.function.Predicate)1 Inject (javax.inject.Inject)1 Classification (name.abuchen.portfolio.model.Classification)1 Assignment (name.abuchen.portfolio.model.Classification.Assignment)1