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();
}
});
}
}
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));
}
}
}
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());
}
});
}
}
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));
}
}
Aggregations