diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/Messages.java b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/Messages.java index 94fccbc259..3dcf68aa8d 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/Messages.java +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/Messages.java @@ -893,6 +893,7 @@ public class Messages extends NLS public static String MenuChartYZoomOut; public static String MenuChangeUrl; public static String MenuChooseClientFilter; + public static String MenuChooseClientFilterWithoutReferenceAccount; public static String MenuConfigureChart; public static String MenuConfigureCurrentDashboard; public static String MenuConfigureDashboards; diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages.properties index 00272a2491..5243c55a88 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages.properties @@ -1788,6 +1788,8 @@ MenuChartYZoomOut = Zoom out MenuChooseClientFilter = Filter data by portfolio and reference account +MenuChooseClientFilterWithoutReferenceAccount = Filter data by portfolio + MenuConfigureChart = Configure chart MenuConfigureCurrentDashboard = Configure dashboard diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_cs.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_cs.properties index 1dab218c65..fb82b25b20 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_cs.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_cs.properties @@ -1780,6 +1780,8 @@ MenuChartYZoomOut = Odd\u00E1lit MenuChooseClientFilter = Filtrov\u00E1n\u00ED dat podle portfolia a referen\u010Dn\u00EDho \u00FA\u010Dtu +MenuChooseClientFilterWithoutReferenceAccount = Filtrov\u00E1n\u00ED dat podle portfolia + MenuConfigureChart = Nastaven\u00ED grafu MenuConfigureCurrentDashboard = Nastaven\u00ED dashboard diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_da.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_da.properties index 0384b323a5..445629216b 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_da.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_da.properties @@ -1779,6 +1779,8 @@ MenuChartYZoomOut = Zoom ud MenuChooseClientFilter = Filtrer data efter portef\u00F8lje og referencekonto +MenuChooseClientFilterWithoutReferenceAccount = Filtrer data efter portef\u00F8lje + MenuConfigureChart = Konfigurer diagram MenuConfigureCurrentDashboard = Konfigurer brugergr\u00E6nseflade diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_de.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_de.properties index e9f7bab8c0..80e6f54bf8 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_de.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_de.properties @@ -1781,6 +1781,8 @@ MenuChartYZoomOut = Y-Achse verkleinern MenuChooseClientFilter = Daten nach Depot und Referenzkonto filtern +MenuChooseClientFilterWithoutReferenceAccount = Daten nach Depot filtern + MenuConfigureChart = Diagramm konfigurieren MenuConfigureCurrentDashboard = Dashboard konfigurieren diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_es.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_es.properties index f8a757360e..d453563fd4 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_es.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_es.properties @@ -1781,6 +1781,8 @@ MenuChartYZoomOut = Alejar MenuChooseClientFilter = Filtrar por cartera y cuenta +MenuChooseClientFilterWithoutReferenceAccount = Filtrar por cartera + MenuConfigureChart = Configurar gr\u00E1fico MenuConfigureCurrentDashboard = Configurar Dashboard diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_fr.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_fr.properties index 28ece5e00a..33a779805f 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_fr.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_fr.properties @@ -1782,6 +1782,8 @@ MenuChartYZoomOut = Zoom arri\u00E8re MenuChooseClientFilter = Filtrer les donn\u00E9es par portefeuille et compte de r\u00E9f\u00E9rence +MenuChooseClientFilterWithoutReferenceAccount = Filtrer les donn\u00E9es par portefeuille + MenuConfigureChart = Configurer le graphique MenuConfigureCurrentDashboard = Configurer le tableau de bord diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_it.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_it.properties index d2f647de7d..d86abe55f6 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_it.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_it.properties @@ -1781,6 +1781,8 @@ MenuChartYZoomOut = Riduci MenuChooseClientFilter = Filtra i dati per portafoglio e conto di riferimento +MenuChooseClientFilterWithoutReferenceAccount = Filtra i dati per portafoglio + MenuConfigureChart = Configura grafico MenuConfigureCurrentDashboard = Configura dashboard diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_nl.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_nl.properties index ee141214ab..49ce94f651 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_nl.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_nl.properties @@ -1781,6 +1781,8 @@ MenuChartYZoomOut = Uitzoomen MenuChooseClientFilter = Gegevens filteren op portefeuilles en tegenrekeningen +MenuChooseClientFilterWithoutReferenceAccount = Gegevens filteren op portefeuilles + MenuConfigureChart = Grafiek configureren MenuConfigureCurrentDashboard = Dashboard configureren diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pl.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pl.properties index 4d22a4c4c3..73b0f9f3f0 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pl.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pl.properties @@ -1779,6 +1779,8 @@ MenuChartYZoomOut = Oddal MenuChooseClientFilter = Filtruj dane wed\u0142ug portfela i konta odniesienia +MenuChooseClientFilterWithoutReferenceAccount = Filtruj dane wed\u0142ug portfela + MenuConfigureChart = Skonfiguruj wykres MenuConfigureCurrentDashboard = Skonfiguruj panel diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt.properties index de3243a791..a9e810974c 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt.properties @@ -1779,6 +1779,8 @@ MenuChartYZoomOut = Diminuir zoom MenuChooseClientFilter = Filtre dados por portf\u00F3lio e conta de refer\u00EAncia +MenuChooseClientFilterWithoutReferenceAccount = Filtre dados por portf\u00F3lio + MenuConfigureChart = Configurar gr\u00E1fico MenuConfigureCurrentDashboard = Configurar painel diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt_BR.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt_BR.properties index 7a6c45999f..7d3f293c9b 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt_BR.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt_BR.properties @@ -1779,6 +1779,8 @@ MenuChartYZoomOut = Diminuir zoom MenuChooseClientFilter = Filtre dados por portf\u00F3lio e conta de refer\u00EAncia +MenuChooseClientFilterWithoutReferenceAccount = Filtre dados por portf\u00F3lio + MenuConfigureChart = Configurar gr\u00E1fico MenuConfigureCurrentDashboard = Configurar painel diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_ru.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_ru.properties index cb3a4ce746..b542293574 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_ru.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_ru.properties @@ -1779,6 +1779,8 @@ MenuChartYZoomOut = \u0423\u043C\u0435\u043D\u044C\u0448\u0438\u0442\u044C MenuChooseClientFilter = \u0424\u0438\u043B\u044C\u0442\u0440\u0430\u0446\u0438\u044F \u0434\u0430\u043D\u043D\u044B\u0445 \u043F\u043E \u043F\u043E\u0440\u0442\u0444\u043E\u043B\u0438\u043E \u0438 \u044D\u0442\u0430\u043B\u043E\u043D\u043D\u043E\u043C\u0443 \u0441\u0447\u0435\u0442\u0443 +MenuChooseClientFilterWithoutReferenceAccount = \u0424\u0438\u043B\u044C\u0442\u0440\u0430\u0446\u0438\u044F \u0434\u0430\u043D\u043D\u044B\u0445 \u043F\u043E \u043F\u043E\u0440\u0442\u0444\u043E\u043B\u0438\u043E + MenuConfigureChart = \u041D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0430 \u0433\u0440\u0430\u0444\u0438\u043A\u0430 MenuConfigureCurrentDashboard = \u041D\u0430\u0441\u0442\u0440\u043E\u0438\u0442\u044C \u0438\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u043E\u043D\u043D\u0443\u044E \u043F\u0430\u043D\u0435\u043B\u044C diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_sk.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_sk.properties index f25df8764c..28a425a61a 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_sk.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_sk.properties @@ -1781,6 +1781,8 @@ MenuChartYZoomOut = Oddiali\u0165 MenuChooseClientFilter = Filtrovanie \u00FAdajov pod\u013Ea portf\u00F3lia a referen\u010Dn\u00E9ho \u00FA\u010Dtu +MenuChooseClientFilterWithoutReferenceAccount = Filtrovanie \u00FAdajov pod\u013Ea portf\u00F3lia + MenuConfigureChart = Nastavenie grafu MenuConfigureCurrentDashboard = Nastavenie pr\u00EDstrojovej dosky diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh.properties index cf66ed5160..b16f98eb50 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh.properties @@ -1781,6 +1781,8 @@ MenuChartYZoomOut = \u7F29\u5C0F MenuChooseClientFilter = \u4EE5\u6295\u8D44\u7EC4\u5408\u4E0E\u5173\u8054\u8D26\u6237\u8FC7\u6EE4\u6570\u636E +MenuChooseClientFilterWithoutReferenceAccount = \u6309\u6295\u8D44\u7EC4\u5408\u7B5B\u9009\u6570\u636E + MenuConfigureChart = \u914D\u7F6E\u56FE\u8868 MenuConfigureCurrentDashboard = \u914D\u7F6E\u62A5\u8868 diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh_TW.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh_TW.properties index 920e99714c..528dc29f17 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh_TW.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh_TW.properties @@ -1779,6 +1779,8 @@ MenuChartYZoomOut = \u7E2E\u5C0F MenuChooseClientFilter = \u6309\u6295\u8CC7\u7D44\u5408\u548C\u53C3\u8003\u5E33\u6236\u5C07\u6578\u64DA\u904E\u6FFE +MenuChooseClientFilterWithoutReferenceAccount = \u6309\u6295\u8CC7\u7D44\u5408\u904E\u6FFE\u6578\u64DA + MenuConfigureChart = \u8A2D\u5B9A\u5716\u8868 MenuConfigureCurrentDashboard = \u8A2D\u5B9A\u5831\u8868 diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/util/ClientFilterMenu.java b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/util/ClientFilterMenu.java index 49268bae02..73b2ff9307 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/util/ClientFilterMenu.java +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/util/ClientFilterMenu.java @@ -132,12 +132,52 @@ public ClientFilterMenu(Client client, IPreferenceStore preferences) loadCustomItems(); } + public ClientFilterMenu(Client client, IPreferenceStore preferences, boolean withReferenceAccount) + { + this.client = client; + this.preferences = preferences; + this.filterConfig = client.getSettings() + .getConfigurationSet(WellKnownConfigurationSets.CLIENT_FILTER_DEFINITIONS); + + selectedItem = new Item("", Messages.PerformanceChartLabelEntirePortfolio, "", //$NON-NLS-1$ //$NON-NLS-2$ + ClientFilter.NO_FILTER); + defaultItems.add(selectedItem); + if (withReferenceAccount) + { + client.getActivePortfolios().forEach(portfolio -> { + defaultItems.add(new Item(portfolio.getUUID(), portfolio.getName(), portfolio.getUUID(), + new PortfolioClientFilter(portfolio))); + defaultItems.add(new Item(portfolio.getUUID() + "," + portfolio.getReferenceAccount().getUUID(), //$NON-NLS-1$ + portfolio.getName() + " + " + portfolio.getReferenceAccount().getName(), //$NON-NLS-1$ + portfolio.getUUID() + "," + portfolio.getReferenceAccount().getUUID(), //$NON-NLS-1$ + new PortfolioClientFilter(portfolio, portfolio.getReferenceAccount()))); + }); + } + else // do not fetch ReferenceAccount + { + client.getActivePortfolios().forEach(portfolio -> { + defaultItems.add(new Item(portfolio.getUUID(), portfolio.getName(), portfolio.getUUID(), + new PortfolioClientFilter(portfolio))); + }); + + } + + loadCustomItems(); + + } + public ClientFilterMenu(Client client, IPreferenceStore preferences, Consumer listener) { this(client, preferences); this.listeners.add(listener); } + public ClientFilterMenu(Client client, IPreferenceStore preferences, Consumer listener, + boolean withReferenceAccount) + { + this(client, preferences, withReferenceAccount); + this.listeners.add(listener); + } private void loadCustomItems() { filterConfig.getConfigurations().forEach(conf -> { diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/trades/TradeDetailsView.java b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/trades/TradeDetailsView.java index 605593e747..3b69561b6f 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/trades/TradeDetailsView.java +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/trades/TradeDetailsView.java @@ -14,6 +14,7 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.ControlContribution; +import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.action.ToolBarManager; @@ -32,6 +33,7 @@ import name.abuchen.portfolio.money.CurrencyConverter; import name.abuchen.portfolio.money.CurrencyConverterImpl; import name.abuchen.portfolio.money.ExchangeRateProviderFactory; +import name.abuchen.portfolio.snapshot.filter.ClientFilter; import name.abuchen.portfolio.snapshot.trades.Trade; import name.abuchen.portfolio.snapshot.trades.TradeCollector; import name.abuchen.portfolio.snapshot.trades.TradeCollectorException; @@ -39,8 +41,10 @@ import name.abuchen.portfolio.ui.Messages; import name.abuchen.portfolio.ui.UIConstants; import name.abuchen.portfolio.ui.editor.AbstractFinanceView; +import name.abuchen.portfolio.ui.util.ClientFilterMenu; import name.abuchen.portfolio.ui.util.ContextMenu; import name.abuchen.portfolio.ui.util.DropDown; +import name.abuchen.portfolio.ui.util.LabelOnly; import name.abuchen.portfolio.ui.util.SimpleAction; import name.abuchen.portfolio.ui.util.TableViewerCSVExporter; import name.abuchen.portfolio.ui.views.SecurityContextMenu; @@ -112,42 +116,6 @@ public boolean isTrue() } } - private class FilterAction extends Action - { - private MutableBoolean criterion; - - private DropDown theMenu; - private FilterAction counterpart; - - public FilterAction(String label, MutableBoolean criterion, DropDown theMenu) - { - super(label); - this.criterion = criterion; - this.theMenu = theMenu; - this.setChecked(criterion.isTrue()); - } - - public void setCounterpart(FilterAction counterpart) - { - this.counterpart = counterpart; - } - - @Override - public void run() - { - criterion.invert(); - - if (counterpart != null && criterion.isTrue()) - { - counterpart.criterion.setValue(false); - counterpart.setChecked(false); - } - - update(); - updateFilterButtonImage(theMenu); - } - } - private static final String ID_WARNING_TOOL_ITEM = "warning"; //$NON-NLS-1$ private Input input; @@ -169,7 +137,10 @@ protected String getDefaultTitle() private MutableBoolean onlyProfitable = new MutableBoolean(false); private MutableBoolean onlyLossMaking = new MutableBoolean(false); + private boolean isOn; + private Pattern filterPattern; + private ClientFilter clientFilter; @Inject @Optional @@ -208,7 +179,7 @@ protected void addButtons(ToolBarManager toolBarManager) toolBarManager.add(new Separator()); - addFilterButton(toolBarManager); + toolBarManager.add(new FilterDropDown(getPreferenceStore())); toolBarManager.add(new DropDown(Messages.MenuExportData, Images.EXPORT, SWT.NONE, manager -> manager.add(new SimpleAction(Messages.LabelTrades + " (CSV)", //$NON-NLS-1$ @@ -220,13 +191,6 @@ protected void addButtons(ToolBarManager toolBarManager) manager -> table.getShowHideColumnHelper().menuAboutToShow(manager))); } - private void updateFilterButtonImage(DropDown dropDown) - { - boolean isOn = usePreselectedTrades.isTrue() || onlyOpen.isTrue() || onlyClosed.isTrue() - || onlyProfitable.isTrue() || onlyLossMaking.isTrue(); - dropDown.setImage(isOn ? Images.FILTER_ON : Images.FILTER_OFF); - } - private void addSearchButton(ToolBarManager toolBar) { toolBar.add(new ControlContribution("searchbox") //$NON-NLS-1$ @@ -264,72 +228,6 @@ protected int computeWidth(Control control) }); } - private void addFilterButton(ToolBarManager manager) - { - boolean hasPreselectedTrades = input != null; - - // retrieve existing filter - int savedFilters = 0; - IPreferenceStore preferenceStore = getPreferenceStore(); - savedFilters = preferenceStore.getInt(this.getClass().getSimpleName() + "-filterSettingsTrade"); //$NON-NLS-1$ - if ((savedFilters & (1 << 1)) != 0) - onlyOpen.setValue(true); - if ((savedFilters & (1 << 2)) != 0) - onlyClosed.setValue(true); - if ((savedFilters & (1 << 3)) != 0) - onlyProfitable.setValue(true); - if ((savedFilters & (1 << 4)) != 0) - onlyLossMaking.setValue(true); - - DropDown filterDropDowMenu = new DropDown(Messages.MenuFilterTrades, Images.FILTER_OFF, SWT.NONE); - updateFilterButtonImage(filterDropDowMenu); - - filterDropDowMenu.setMenuListener(mgr -> { - - if (hasPreselectedTrades) - { - mgr.add(new FilterAction(input.getInterval().toString(), usePreselectedTrades, filterDropDowMenu)); - mgr.add(new Separator()); - } - - FilterAction onlyOpenAction = new FilterAction(Messages.FilterOnlyOpenTrades, onlyOpen, filterDropDowMenu); - FilterAction onlyClosedAction = new FilterAction(Messages.FilterOnlyClosedTrades, onlyClosed, - filterDropDowMenu); - - onlyOpenAction.setCounterpart(onlyClosedAction); - onlyClosedAction.setCounterpart(onlyOpenAction); - - FilterAction onlyProfitableAction = new FilterAction(Messages.FilterOnlyProfitableTrades, onlyProfitable, - filterDropDowMenu); - FilterAction onlyLossMakingAction = new FilterAction(Messages.FilterOnlyLossMakingTrades, onlyLossMaking, - filterDropDowMenu); - - onlyProfitableAction.setCounterpart(onlyLossMakingAction); - onlyLossMakingAction.setCounterpart(onlyProfitableAction); - - mgr.add(onlyOpenAction); - mgr.add(onlyClosedAction); - mgr.add(new Separator()); - mgr.add(onlyProfitableAction); - mgr.add(onlyLossMakingAction); - }); - - filterDropDowMenu.addDisposeListener(e -> { - int savedFilter = 0; - if (onlyOpen.isTrue()) - savedFilter += (1 << 1); - if (onlyClosed.isTrue()) - savedFilter += (1 << 2); - if (onlyProfitable.isTrue()) - savedFilter += (1 << 3); - if (onlyLossMaking.isTrue()) - savedFilter += (1 << 4); - preferenceStore.setValue(this.getClass().getSimpleName() + "-filterSettingsTrade", savedFilter); //$NON-NLS-1$ - }); - - manager.add(filterDropDowMenu); - } - @Override protected Control createBody(Composite parent) { @@ -353,7 +251,8 @@ public boolean select(Viewer viewer, Object parentElement, Object element) String[] properties = new String[] { security.getName(), // security.getIsin(), // security.getTickerSymbol(), // - security.getWkn() // + security.getWkn(), // + trade.getPortfolio().getName() }; for (String property : properties) @@ -399,6 +298,8 @@ private void update() Input data = usePreselectedTrades.isTrue() ? input : collectAllTrades(); Stream filteredTrades = data.getTrades().stream(); + filteredTrades = filteredTrades.filter(t -> clientFilter.filter(getClient()).getPortfolios().toString() + .contains(t.getPortfolio().getName())); if (onlyClosed.isTrue()) filteredTrades = filteredTrades.filter(Trade::isClosed); @@ -452,4 +353,125 @@ private Input collectAllTrades() return new Input(null, trades, errors); } + + private class FilterDropDown extends DropDown implements IMenuListener + { + private ClientFilterMenu clientFilterMenu; + + public FilterDropDown(IPreferenceStore preferenceStore) + { + super(Messages.MenuFilterTrades, Images.FILTER_OFF, SWT.NONE); + + // retrieve existing filter + int savedFilters = 0; + savedFilters = preferenceStore.getInt(TradeDetailsView.class.getSimpleName() + "-filterSettingsTrade"); //$NON-NLS-1$ + if ((savedFilters & (1 << 1)) != 0) + onlyOpen.setValue(true); + if ((savedFilters & (1 << 2)) != 0) + onlyClosed.setValue(true); + if ((savedFilters & (1 << 3)) != 0) + onlyProfitable.setValue(true); + if ((savedFilters & (1 << 4)) != 0) + onlyLossMaking.setValue(true); + + isOn = usePreselectedTrades.isTrue() || onlyOpen.isTrue() || onlyClosed.isTrue() + || onlyProfitable.isTrue() || onlyLossMaking.isTrue(); + + clientFilterMenu = new ClientFilterMenu(getClient(), preferenceStore, f -> { + setImage(!isOn && !clientFilterMenu.hasActiveFilter() ? Images.FILTER_OFF : Images.FILTER_ON); + + clientFilter = f; + notifyModelUpdated(); + }, false); + + clientFilterMenu.trackSelectedFilterConfigurationKey(TradeDetailsView.class.getSimpleName()); + clientFilter = clientFilterMenu.getSelectedFilter(); + + if (isOn || clientFilterMenu.hasActiveFilter()) + setImage(Images.FILTER_ON); + + setMenuListener(this); + + addDisposeListener(e -> { + int savedFilter = 0; + if (onlyOpen.isTrue()) + savedFilter += (1 << 1); + if (onlyClosed.isTrue()) + savedFilter += (1 << 2); + if (onlyProfitable.isTrue()) + savedFilter += (1 << 3); + if (onlyLossMaking.isTrue()) + savedFilter += (1 << 4); + preferenceStore.setValue(TradeDetailsView.class.getSimpleName() + "-filterSettingsTrade", savedFilter); //$NON-NLS-1$ + + }); + } + + @Override + public void menuAboutToShow(IMenuManager manager) + { + FilterAction onlyOpenAction = new FilterAction(Messages.FilterOnlyOpenTrades, onlyOpen); + FilterAction onlyClosedAction = new FilterAction(Messages.FilterOnlyClosedTrades, onlyClosed); + FilterAction onlyProfitableAction = new FilterAction(Messages.FilterOnlyProfitableTrades, onlyProfitable); + FilterAction onlyLossMakingAction = new FilterAction(Messages.FilterOnlyLossMakingTrades, onlyLossMaking); + + onlyOpenAction.setCounterpart(onlyClosedAction); + onlyClosedAction.setCounterpart(onlyOpenAction); + onlyProfitableAction.setCounterpart(onlyLossMakingAction); + onlyLossMakingAction.setCounterpart(onlyProfitableAction); + + boolean hasPreselectedTrades = input != null; + if (hasPreselectedTrades) + { + manager.add(new FilterAction(input.getInterval().toString(), usePreselectedTrades)); + manager.add(new Separator()); + } + + manager.add(onlyOpenAction); + manager.add(onlyClosedAction); + manager.add(new Separator()); + manager.add(onlyProfitableAction); + manager.add(onlyLossMakingAction); + + manager.add(new Separator()); + manager.add(new LabelOnly(Messages.MenuChooseClientFilterWithoutReferenceAccount)); + clientFilterMenu.menuAboutToShow(manager); + } + + private class FilterAction extends Action + { + private MutableBoolean criterion; + private FilterAction counterpart; + + public FilterAction(String label, MutableBoolean criterion) + { + super(label); + this.criterion = criterion; + this.setChecked(criterion.isTrue()); + } + + public void setCounterpart(FilterAction counterpart) + { + this.counterpart = counterpart; + } + + @Override + public void run() + { + criterion.invert(); + + if (counterpart != null && criterion.isTrue()) + { + counterpart.criterion.setValue(false); + counterpart.setChecked(false); + } + TradeDetailsView.this.update(); + + isOn = usePreselectedTrades.isTrue() || onlyOpen.isTrue() || onlyClosed.isTrue() + || onlyProfitable.isTrue() || onlyLossMaking.isTrue(); + setImage(!isOn && !clientFilterMenu.hasActiveFilter() ? Images.FILTER_OFF : Images.FILTER_ON); + + } + } + } }