Skip to content

Commit

Permalink
save and retrieve Filter for Trades view
Browse files Browse the repository at this point in the history
  • Loading branch information
mierin12 committed Apr 7, 2024
1 parent 9435785 commit a2d1b59
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
Expand Down Expand Up @@ -218,6 +219,19 @@ 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);

Expand Down Expand Up @@ -251,6 +265,19 @@ private void addFilterButton(ToolBarManager manager)
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);
}

Expand Down

0 comments on commit a2d1b59

Please sign in to comment.