Search in sources :

Example 1 with ListSelectionDialog

use of name.abuchen.portfolio.ui.dialogs.ListSelectionDialog in project portfolio by buchen.

the class ClientFilterMenu method createCustomFilter.

private void createCustomFilter() {
    LabelProvider labelProvider = new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            return element instanceof Account ? Images.ACCOUNT.image() : Images.PORTFOLIO.image();
        }
    };
    ListSelectionDialog dialog = new ListSelectionDialog(Display.getDefault().getActiveShell(), labelProvider);
    dialog.setTitle(Messages.LabelClientFilterDialogTitle);
    dialog.setMessage(Messages.LabelClientFilterDialogMessage);
    List<Object> elements = new ArrayList<>();
    elements.addAll(client.getPortfolios());
    elements.addAll(client.getAccounts());
    dialog.setElements(elements);
    if (dialog.open() == ListSelectionDialog.OK) {
        Object[] selected = dialog.getResult();
        if (selected.length > 0) {
            Item newItem = buildItem(selected);
            selectedItem = newItem;
            customItems.addFirst(newItem);
            if (customItems.size() > MAXIMUM_NO_CUSTOM_ITEMS)
                customItems.removeLast();
            preferences.putValue(ClientFilterDropDown.class.getSimpleName(), // $NON-NLS-1$
            String.join(// $NON-NLS-1$
            ";", customItems.stream().map(i -> i.uuids).collect(Collectors.toList())));
            listeners.forEach(l -> l.accept(newItem.filter));
        }
    }
}
Also used : Arrays(java.util.Arrays) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Messages(name.abuchen.portfolio.ui.Messages) Map(java.util.Map) ListSelectionDialog(name.abuchen.portfolio.ui.dialogs.ListSelectionDialog) LinkedList(java.util.LinkedList) Portfolio(name.abuchen.portfolio.model.Portfolio) Separator(org.eclipse.jface.action.Separator) Account(name.abuchen.portfolio.model.Account) ClientFilter(name.abuchen.portfolio.snapshot.filter.ClientFilter) Action(org.eclipse.jface.action.Action) Display(org.eclipse.swt.widgets.Display) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) IMenuManager(org.eclipse.jface.action.IMenuManager) Collections(java.util.Collections) IMenuListener(org.eclipse.jface.action.IMenuListener) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Account(name.abuchen.portfolio.model.Account) ArrayList(java.util.ArrayList) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ListSelectionDialog(name.abuchen.portfolio.ui.dialogs.ListSelectionDialog)

Example 2 with ListSelectionDialog

use of name.abuchen.portfolio.ui.dialogs.ListSelectionDialog in project portfolio by buchen.

the class DataSeriesConfig method doAddSeries.

private void doAddSeries(boolean showOnlyBenchmark) {
    List<DataSeries> list = delegate.getDashboardData().getDataSeriesSet().getAvailableSeries().stream().filter(ds -> ds.isBenchmark() == showOnlyBenchmark).collect(Collectors.toList());
    ListSelectionDialog dialog = new ListSelectionDialog(Display.getDefault().getActiveShell(), new DataSeriesLabelProvider());
    dialog.setTitle(Messages.ChartSeriesPickerTitle);
    dialog.setMessage(Messages.ChartSeriesPickerTitle);
    dialog.setElements(list);
    dialog.setMultiSelection(false);
    if (dialog.open() != ListSelectionDialog.OK)
        return;
    Object[] result = dialog.getResult();
    if (result == null || result.length == 0)
        return;
    dataSeries = (DataSeries) result[0];
    delegate.getWidget().getConfiguration().put(Dashboard.Config.DATA_SERIES.name(), dataSeries.getUUID());
    // construct label to indicate the data series (user can manually change
    // the label later)
    // $NON-NLS-1$
    String label = WidgetFactory.valueOf(delegate.getWidget().getType()).getLabel() + ", " + dataSeries.getLabel();
    delegate.getWidget().setLabel(label);
    delegate.getClient().markDirty();
}
Also used : Separator(org.eclipse.jface.action.Separator) Dashboard(name.abuchen.portfolio.model.Dashboard) MenuManager(org.eclipse.jface.action.MenuManager) DataSeries(name.abuchen.portfolio.ui.views.dataseries.DataSeries) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Display(org.eclipse.swt.widgets.Display) Collectors(java.util.stream.Collectors) List(java.util.List) IMenuManager(org.eclipse.jface.action.IMenuManager) Messages(name.abuchen.portfolio.ui.Messages) ListSelectionDialog(name.abuchen.portfolio.ui.dialogs.ListSelectionDialog) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) DataSeriesLabelProvider(name.abuchen.portfolio.ui.views.dataseries.DataSeriesLabelProvider) DataSeries(name.abuchen.portfolio.ui.views.dataseries.DataSeries) ListSelectionDialog(name.abuchen.portfolio.ui.dialogs.ListSelectionDialog) DataSeriesLabelProvider(name.abuchen.portfolio.ui.views.dataseries.DataSeriesLabelProvider)

Example 3 with ListSelectionDialog

use of name.abuchen.portfolio.ui.dialogs.ListSelectionDialog in project portfolio by buchen.

the class DataSeriesConfigurator method doAddSeries.

private void doAddSeries(boolean showOnlyBenchmark) {
    List<DataSeries> list = new ArrayList<>(dataSeriesSet.getAvailableSeries());
    // remove items if that do not match the benchmark flag
    Iterator<DataSeries> iter = list.iterator();
    while (iter.hasNext()) if (iter.next().isBenchmark() != showOnlyBenchmark)
        iter.remove();
    // remove already selected items
    for (DataSeries s : selectedSeries) list.remove(s);
    ListSelectionDialog dialog = new ListSelectionDialog(Display.getDefault().getActiveShell(), new DataSeriesLabelProvider());
    dialog.setTitle(Messages.ChartSeriesPickerTitle);
    dialog.setMessage(Messages.ChartSeriesPickerTitle);
    dialog.setElements(list);
    if (dialog.open() != ListSelectionDialog.OK)
        return;
    Object[] result = dialog.getResult();
    if (result == null || result.length == 0)
        return;
    for (Object object : result) selectedSeries.add((DataSeries) object);
    fireUpdate();
}
Also used : ArrayList(java.util.ArrayList) ListSelectionDialog(name.abuchen.portfolio.ui.dialogs.ListSelectionDialog)

Aggregations

ListSelectionDialog (name.abuchen.portfolio.ui.dialogs.ListSelectionDialog)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Messages (name.abuchen.portfolio.ui.Messages)2 IMenuManager (org.eclipse.jface.action.IMenuManager)2 Separator (org.eclipse.jface.action.Separator)2 Display (org.eclipse.swt.widgets.Display)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Consumer (java.util.function.Consumer)1 Stream (java.util.stream.Stream)1 Account (name.abuchen.portfolio.model.Account)1 Client (name.abuchen.portfolio.model.Client)1 Dashboard (name.abuchen.portfolio.model.Dashboard)1 Portfolio (name.abuchen.portfolio.model.Portfolio)1