Search in sources :

Example 16 with SimpleAction

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);
    });
}
Also used : NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) TableViewer(org.eclipse.jface.viewers.TableViewer) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) ToolBar(org.eclipse.swt.widgets.ToolBar) Images(name.abuchen.portfolio.ui.Images) ListEditingSupport(name.abuchen.portfolio.ui.util.viewers.ListEditingSupport) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Inject(javax.inject.Inject) ModificationListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.ModificationListener) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) Portfolio(name.abuchen.portfolio.model.Portfolio) Separator(org.eclipse.jface.action.Separator) Account(name.abuchen.portfolio.model.Account) CTabFolder(org.eclipse.swt.custom.CTabFolder) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) MenuManager(org.eclipse.jface.action.MenuManager) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) Action(org.eclipse.jface.action.Action) Display(org.eclipse.swt.widgets.Display) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) PortfolioSnapshot(name.abuchen.portfolio.snapshot.PortfolioSnapshot) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) CTabItem(org.eclipse.swt.custom.CTabItem) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Separator(org.eclipse.jface.action.Separator)

Example 17 with SimpleAction

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));
        }
    }));
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) Separator(org.eclipse.jface.action.Separator) MessageFormat(com.ibm.icu.text.MessageFormat) IMenuManager(org.eclipse.jface.action.IMenuManager) Messages(name.abuchen.portfolio.ui.Messages) LocalDate(java.time.LocalDate) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) ToolBar(org.eclipse.swt.widgets.ToolBar) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) Display(org.eclipse.swt.widgets.Display) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) InputDialog(org.eclipse.jface.dialogs.InputDialog) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Separator(org.eclipse.jface.action.Separator) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 18 with SimpleAction

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);
}
Also used : SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction)

Example 19 with SimpleAction

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);
}
Also used : Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) ToolBar(org.eclipse.swt.widgets.ToolBar) Images(name.abuchen.portfolio.ui.Images) Inject(javax.inject.Inject) Composite(org.eclipse.swt.widgets.Composite) AbstractFinanceView(name.abuchen.portfolio.ui.AbstractFinanceView) Messages(name.abuchen.portfolio.ui.Messages) ClientFilterDropDown(name.abuchen.portfolio.ui.util.ClientFilterDropDown) Separator(org.eclipse.jface.action.Separator) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) DateSelectionDialog(name.abuchen.portfolio.ui.dialogs.DateSelectionDialog) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) TableViewerCSVExporter(name.abuchen.portfolio.ui.util.TableViewerCSVExporter) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) IMenuManager(org.eclipse.jface.action.IMenuManager) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) Collections(java.util.Collections) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) Control(org.eclipse.swt.widgets.Control) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) ClientFilterDropDown(name.abuchen.portfolio.ui.util.ClientFilterDropDown) IMenuManager(org.eclipse.jface.action.IMenuManager) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) TableViewerCSVExporter(name.abuchen.portfolio.ui.util.TableViewerCSVExporter)

Example 20 with SimpleAction

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());
        }));
    });
}
Also used : Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) ToolBar(org.eclipse.swt.widgets.ToolBar) Images(name.abuchen.portfolio.ui.Images) Inject(javax.inject.Inject) Composite(org.eclipse.swt.widgets.Composite) AbstractFinanceView(name.abuchen.portfolio.ui.AbstractFinanceView) Messages(name.abuchen.portfolio.ui.Messages) ClientFilterDropDown(name.abuchen.portfolio.ui.util.ClientFilterDropDown) Separator(org.eclipse.jface.action.Separator) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) DateSelectionDialog(name.abuchen.portfolio.ui.dialogs.DateSelectionDialog) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) TableViewerCSVExporter(name.abuchen.portfolio.ui.util.TableViewerCSVExporter) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) IMenuManager(org.eclipse.jface.action.IMenuManager) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) Collections(java.util.Collections) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) Control(org.eclipse.swt.widgets.Control) DateSelectionDialog(name.abuchen.portfolio.ui.dialogs.DateSelectionDialog) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Separator(org.eclipse.jface.action.Separator)

Aggregations

SimpleAction (name.abuchen.portfolio.ui.util.SimpleAction)26 Action (org.eclipse.jface.action.Action)20 IMenuManager (org.eclipse.jface.action.IMenuManager)20 Messages (name.abuchen.portfolio.ui.Messages)17 Separator (org.eclipse.jface.action.Separator)16 MenuManager (org.eclipse.jface.action.MenuManager)14 Display (org.eclipse.swt.widgets.Display)13 Inject (javax.inject.Inject)11 SWT (org.eclipse.swt.SWT)11 Images (name.abuchen.portfolio.ui.Images)10 AbstractDropDown (name.abuchen.portfolio.ui.util.AbstractDropDown)9 Composite (org.eclipse.swt.widgets.Composite)9 List (java.util.List)8 LocalDate (java.time.LocalDate)7 Control (org.eclipse.swt.widgets.Control)7 LabelOnly (name.abuchen.portfolio.ui.util.LabelOnly)6 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)6 Image (org.eclipse.swt.graphics.Image)6 Client (name.abuchen.portfolio.model.Client)5 Values (name.abuchen.portfolio.money.Values)5