Skip to content

Commit

Permalink
Refactor widgets about security lists into separate package
Browse files Browse the repository at this point in the history
Issue: #4431
  • Loading branch information
buchen committed Jan 10, 2025
1 parent 462d29d commit 5cff137
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import name.abuchen.portfolio.ui.views.dashboard.heatmap.InvestmentHeatmapWidget;
import name.abuchen.portfolio.ui.views.dashboard.heatmap.PerformanceHeatmapWidget;
import name.abuchen.portfolio.ui.views.dashboard.heatmap.YearlyPerformanceHeatmapWidget;
import name.abuchen.portfolio.ui.views.dashboard.lists.EventListWidget;
import name.abuchen.portfolio.ui.views.dashboard.lists.FollowUpWidget;
import name.abuchen.portfolio.ui.views.dashboard.lists.LimitExceededWidget;
import name.abuchen.portfolio.ui.views.dataseries.DataSeries;
import name.abuchen.portfolio.ui.views.payments.PaymentsViewModel;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package name.abuchen.portfolio.ui.views.dashboard;
package name.abuchen.portfolio.ui.views.dashboard.lists;

import java.util.List;
import java.util.Objects;
Expand All @@ -25,6 +25,10 @@
import name.abuchen.portfolio.ui.editor.AbstractFinanceView;
import name.abuchen.portfolio.ui.util.swt.StyledLabel;
import name.abuchen.portfolio.ui.views.SecurityListView;
import name.abuchen.portfolio.ui.views.dashboard.ChartHeightConfig;
import name.abuchen.portfolio.ui.views.dashboard.DashboardData;
import name.abuchen.portfolio.ui.views.dashboard.DashboardResources;
import name.abuchen.portfolio.ui.views.dashboard.WidgetDelegate;
import name.abuchen.portfolio.util.TextUtil;

public abstract class AbstractSecurityListWidget<T extends AbstractSecurityListWidget.Item>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package name.abuchen.portfolio.ui.views.dashboard;
package name.abuchen.portfolio.ui.views.dashboard.lists;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
import java.util.function.Supplier;
Expand All @@ -23,6 +22,10 @@
import name.abuchen.portfolio.ui.util.FormDataFactory;
import name.abuchen.portfolio.ui.util.LogoManager;
import name.abuchen.portfolio.ui.util.swt.StyledLabel;
import name.abuchen.portfolio.ui.views.dashboard.ChartHeightConfig;
import name.abuchen.portfolio.ui.views.dashboard.DashboardData;
import name.abuchen.portfolio.ui.views.dashboard.EnumBasedConfig;
import name.abuchen.portfolio.ui.views.dashboard.WidgetDelegate;

public class EventListWidget extends AbstractSecurityListWidget<EventListWidget.EventItem>
{
Expand Down Expand Up @@ -72,41 +75,6 @@ public DateDateConfig(WidgetDelegate<?> delegate)
}
}

public enum SortDirection
{
ASCENDING(Messages.FollowUpWidget_Option_SortingByDateAscending, (r, l) -> r.event.getDate().compareTo(l.event.getDate())), //
DESCENDING(Messages.FollowUpWidget_Option_SortingByDateDescending, (r, l) -> l.event.getDate().compareTo(r.event.getDate()));

private Comparator<EventItem> comparator;
private String label;

private SortDirection(String label, Comparator<EventItem> comparator)
{
this.label = label;
this.comparator = comparator;
}

Comparator<EventItem> getComparator()
{
return comparator;
}

@Override
public String toString()
{
return label;
}
}

static class SortingConfig extends EnumBasedConfig<SortDirection>
{
public SortingConfig(WidgetDelegate<?> delegate)
{
super(delegate, Messages.FollowUpWidget_Option_Sorting, SortDirection.class,
Dashboard.Config.SORT_DIRECTION, Policy.EXACTLY_ONE);
}
}

public EventListWidget(Widget widget, DashboardData data)
{
super(widget, data);
Expand Down Expand Up @@ -135,7 +103,8 @@ public Supplier<List<EventItem>> getUpdateTask()
}
}

Collections.sort(items, get(SortingConfig.class).getValue().getComparator());
var comparator = get(SortingConfig.class).getValue().getComparator();
Collections.sort(items, (r, l) -> comparator.compare(r.event.getDate(), l.event.getDate()));

return items;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package name.abuchen.portfolio.ui.views.dashboard;
package name.abuchen.portfolio.ui.views.dashboard.lists;

import java.text.MessageFormat;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
import java.util.function.Supplier;
Expand All @@ -24,6 +23,11 @@
import name.abuchen.portfolio.ui.util.FormDataFactory;
import name.abuchen.portfolio.ui.util.LogoManager;
import name.abuchen.portfolio.ui.util.swt.StyledLabel;
import name.abuchen.portfolio.ui.views.dashboard.AttributesConfig;
import name.abuchen.portfolio.ui.views.dashboard.ChartHeightConfig;
import name.abuchen.portfolio.ui.views.dashboard.DashboardData;
import name.abuchen.portfolio.ui.views.dashboard.EnumBasedConfig;
import name.abuchen.portfolio.ui.views.dashboard.WidgetDelegate;
import name.abuchen.portfolio.ui.views.settings.AttributeFieldType;
import name.abuchen.portfolio.ui.views.settings.SettingsView;

Expand All @@ -32,7 +36,7 @@ public class FollowUpWidget extends AbstractSecurityListWidget<FollowUpWidget.Fo
public static class FollowUpItem extends AbstractSecurityListWidget.Item
{
private AttributeType type;
private LocalDate date;
LocalDate date;

public FollowUpItem(Security security, AttributeType type, LocalDate date)
{
Expand Down Expand Up @@ -77,41 +81,6 @@ public DateDateConfig(WidgetDelegate<?> delegate)
}
}

public enum SortDirection
{
ASCENDING(Messages.FollowUpWidget_Option_SortingByDateAscending, (r, l) -> r.date.compareTo(l.date)), //
DESCENDING(Messages.FollowUpWidget_Option_SortingByDateDescending, (r, l) -> l.date.compareTo(r.date));

private Comparator<FollowUpItem> comparator;
private String label;

private SortDirection(String label, Comparator<FollowUpItem> comparator)
{
this.label = label;
this.comparator = comparator;
}

Comparator<FollowUpItem> getComparator()
{
return comparator;
}

@Override
public String toString()
{
return label;
}
}

static class SortingConfig extends EnumBasedConfig<SortDirection>
{
public SortingConfig(WidgetDelegate<?> delegate)
{
super(delegate, Messages.FollowUpWidget_Option_Sorting, SortDirection.class,
Dashboard.Config.SORT_DIRECTION, Policy.EXACTLY_ONE);
}
}

public FollowUpWidget(Widget widget, DashboardData data)
{
super(widget, data);
Expand Down Expand Up @@ -146,7 +115,8 @@ public Supplier<List<FollowUpItem>> getUpdateTask()
}
}

Collections.sort(items, get(SortingConfig.class).getValue().getComparator());
var comparator = get(SortingConfig.class).getValue().getComparator();
Collections.sort(items, (r, l) -> comparator.compare(r.date, l.date));

return items;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package name.abuchen.portfolio.ui.views.dashboard;
package name.abuchen.portfolio.ui.views.dashboard.lists;

import java.text.MessageFormat;
import java.time.LocalDate;
Expand Down Expand Up @@ -28,6 +28,9 @@
import name.abuchen.portfolio.ui.util.swt.ColoredLabel;
import name.abuchen.portfolio.ui.util.swt.StyledLabel;
import name.abuchen.portfolio.ui.views.columns.AttributeColumn;
import name.abuchen.portfolio.ui.views.dashboard.AttributesConfig;
import name.abuchen.portfolio.ui.views.dashboard.ChartHeightConfig;
import name.abuchen.portfolio.ui.views.dashboard.DashboardData;
import name.abuchen.portfolio.ui.views.settings.AttributeFieldType;
import name.abuchen.portfolio.ui.views.settings.SettingsView;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package name.abuchen.portfolio.ui.views.dashboard.lists;

import java.time.LocalDate;
import java.util.Comparator;

import name.abuchen.portfolio.ui.Messages;

public enum SortDirection
{
ASCENDING(Messages.FollowUpWidget_Option_SortingByDateAscending, Comparable::compareTo), //
DESCENDING(Messages.FollowUpWidget_Option_SortingByDateDescending, (r, l) -> l.compareTo(r));

private Comparator<LocalDate> comparator;
private String label;

private SortDirection(String label, Comparator<LocalDate> comparator)
{
this.label = label;
this.comparator = comparator;
}

public Comparator<LocalDate> getComparator()
{
return comparator;
}

@Override
public String toString()
{
return label;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package name.abuchen.portfolio.ui.views.dashboard.lists;

import name.abuchen.portfolio.model.Dashboard;
import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.views.dashboard.EnumBasedConfig;
import name.abuchen.portfolio.ui.views.dashboard.WidgetDelegate;

public class SortingConfig extends EnumBasedConfig<SortDirection>
{
public SortingConfig(WidgetDelegate<?> delegate)
{
super(delegate, Messages.FollowUpWidget_Option_Sorting, SortDirection.class,
Dashboard.Config.SORT_DIRECTION, Policy.EXACTLY_ONE);
}
}

0 comments on commit 5cff137

Please sign in to comment.