use of name.abuchen.portfolio.ui.util.SimpleAction in project portfolio by buchen.
the class PortfolioListView method addNewButton.
private void addNewButton(ToolBar toolBar) {
SimpleAction.Runnable newPortfolioAction = a -> {
Portfolio portfolio = new Portfolio();
portfolio.setName(Messages.LabelNoName);
if (!getClient().getAccounts().isEmpty()) {
portfolio.setReferenceAccount(getClient().getAccounts().get(0));
} else {
Account account = new Account();
account.setName(Messages.LabelDefaultReferenceAccountName);
getClient().addAccount(account);
portfolio.setReferenceAccount(account);
}
getClient().addPortfolio(portfolio);
markDirty();
setInput();
portfolios.editElement(portfolio, 0);
};
AbstractDropDown.create(toolBar, Messages.MenuCreatePortfolioOrTransaction, Images.PLUS.image(), SWT.NONE, (dd, manager) -> {
manager.add(new SimpleAction(Messages.PortfolioMenuAdd, newPortfolioAction));
manager.add(new Separator());
Portfolio portfolio = (Portfolio) portfolios.getStructuredSelection().getFirstElement();
new SecurityContextMenu(PortfolioListView.this).menuAboutToShow(manager, null, portfolio);
});
}
use of name.abuchen.portfolio.ui.util.SimpleAction in project portfolio by buchen.
the class StartYearSelectionDropDown method menuAboutToShow.
@Override
public void menuAboutToShow(IMenuManager manager) {
int now = LocalDate.now().getYear();
for (int ii = 0; ii < 10; ii++) {
int year = now - ii;
Action action = new Action(String.valueOf(year)) {
@Override
public void run() {
model.updateWith(year);
setLabel(String.valueOf(year));
}
};
action.setChecked(year == model.getStartYear());
manager.add(action);
}
manager.add(new Separator());
manager.add(new SimpleAction(Messages.LabelSelectYear, a -> {
IInputValidator validator = newText -> {
try {
int year = Integer.parseInt(newText);
return year >= 1900 && year <= now ? null : MessageFormat.format(Messages.MsgErrorDividendsYearBetween1900AndNow, String.valueOf(now));
} catch (NumberFormatException nfe) {
return MessageFormat.format(Messages.MsgErrorDividendsYearBetween1900AndNow, String.valueOf(now));
}
};
InputDialog dialog = new InputDialog(Display.getDefault().getActiveShell(), Messages.LabelYear, Messages.LabelDividendsSelectStartYear, String.valueOf(model.getStartYear()), validator);
if (dialog.open() == InputDialog.OK) {
int year = Integer.parseInt(dialog.getValue());
model.updateWith(year);
setLabel(String.valueOf(year));
}
}));
}
use of name.abuchen.portfolio.ui.util.SimpleAction in project portfolio by buchen.
the class AbstractChartPage method configMenuAboutToShow.
@Override
public void configMenuAboutToShow(IMenuManager manager) {
Action action = new SimpleAction(Messages.LabelIncludeUnassignedCategoryInCharts, a -> {
getModel().setExcludeUnassignedCategoryInCharts(!getModel().isUnassignedCategoryInChartsExcluded());
onConfigChanged();
});
action.setChecked(!getModel().isUnassignedCategoryInChartsExcluded());
manager.add(action);
}
use of name.abuchen.portfolio.ui.util.SimpleAction in project portfolio by buchen.
the class StatementOfAssetsView method addButtons.
@Override
protected void addButtons(final ToolBar toolBar) {
AbstractDropDown dropdown = new AbstractDropDown(toolBar, getClient().getBaseCurrency()) {
@Override
public void menuAboutToShow(IMenuManager manager) {
List<CurrencyUnit> available = CurrencyUnit.getAvailableCurrencyUnits();
Collections.sort(available);
for (final CurrencyUnit unit : available) {
Action action = new SimpleAction(unit.getLabel(), a -> {
setLabel(unit.getCurrencyCode());
getClient().setBaseCurrency(unit.getCurrencyCode());
});
action.setChecked(getClient().getBaseCurrency().equals(unit.getCurrencyCode()));
manager.add(action);
}
}
};
currencyChangeListener = e -> dropdown.setLabel(e.getNewValue().toString());
// $NON-NLS-1$
getClient().addPropertyChangeListener("baseCurrency", currencyChangeListener);
addCalendarButton(toolBar);
this.clientFilter = new ClientFilterDropDown(toolBar, getClient(), getPreferenceStore(), StatementOfAssetsView.class.getSimpleName(), filter -> notifyModelUpdated());
Action export = new SimpleAction(null, action -> new TableViewerCSVExporter(assetViewer.getTableViewer()).export(// $NON-NLS-1$
Messages.LabelStatementOfAssets + ".csv"));
export.setImageDescriptor(Images.EXPORT.descriptor());
export.setToolTipText(Messages.MenuExportData);
new ActionContributionItem(export).fill(toolBar, -1);
Action save = new SimpleAction(null, a -> assetViewer.showSaveMenu(getActiveShell()));
save.setImageDescriptor(Images.SAVE.descriptor());
save.setToolTipText(Messages.MenuSaveColumns);
new ActionContributionItem(save).fill(toolBar, -1);
Action config = new SimpleAction(null, a -> assetViewer.showConfigMenu(toolBar.getShell()));
config.setImageDescriptor(Images.CONFIG.descriptor());
config.setToolTipText(Messages.MenuShowHideColumns);
new ActionContributionItem(config).fill(toolBar, -1);
}
use of name.abuchen.portfolio.ui.util.SimpleAction in project portfolio by buchen.
the class StatementOfAssetsView method addCalendarButton.
private void addCalendarButton(ToolBar toolBar) {
AbstractDropDown.create(toolBar, Messages.LabelPortfolioTimeMachine, Images.CALENDAR_OFF.image(), SWT.NONE, (dropDown, manager) -> {
manager.add(new LabelOnly(Values.Date.format(snapshotDate)));
manager.add(new Separator());
SimpleAction action = new SimpleAction(Messages.LabelToday, a -> {
snapshotDate = LocalDate.now();
notifyModelUpdated();
dropDown.getToolItem().setImage(Images.CALENDAR_OFF.image());
});
action.setEnabled(!snapshotDate.equals(LocalDate.now()));
manager.add(action);
manager.add(new SimpleAction(Messages.MenuPickOtherDate, a -> {
DateSelectionDialog dialog = new DateSelectionDialog(getActiveShell());
dialog.setSelection(snapshotDate);
if (dialog.open() != DateSelectionDialog.OK)
return;
if (snapshotDate.equals(dialog.getSelection()))
return;
snapshotDate = dialog.getSelection();
notifyModelUpdated();
dropDown.getToolItem().setImage(LocalDate.now().equals(snapshotDate) ? Images.CALENDAR_OFF.image() : Images.CALENDAR_ON.image());
}));
});
}
Aggregations