|
@@ -24,11 +24,15 @@ package uk.co.md87.evetool.ui.pages;
|
24
|
24
|
|
25
|
25
|
import java.awt.event.ActionEvent;
|
26
|
26
|
import java.awt.event.ActionListener;
|
|
27
|
+import java.util.ArrayList;
|
27
|
28
|
import java.util.Collections;
|
28
|
29
|
import java.util.List;
|
29
|
30
|
|
|
31
|
+import java.util.concurrent.ExecutionException;
|
|
32
|
+import javax.swing.JLabel;
|
30
|
33
|
import javax.swing.JSeparator;
|
31
|
34
|
|
|
35
|
+import javax.swing.SwingWorker;
|
32
|
36
|
import net.miginfocom.swing.MigLayout;
|
33
|
37
|
|
34
|
38
|
import uk.co.md87.evetool.AccountManager;
|
|
@@ -94,47 +98,94 @@ public abstract class ListablePage<T extends Listable> extends Page implements A
|
94
|
98
|
protected void updatePage() {
|
95
|
99
|
removeAll();
|
96
|
100
|
|
97
|
|
- final List<T> list = getListables();
|
98
|
|
- final ListableParser parser = new ListableParser(list.get(0).getClass());
|
|
101
|
+ add(new JLabel("Loading..."));
|
99
|
102
|
|
100
|
|
- if (config.sortOrder != null) {
|
101
|
|
- Collections.sort(list, new ListableComparator(config.sortOrder, parser));
|
|
103
|
+ new UpdateWorker().execute();
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ protected abstract List<T> getListables();
|
|
107
|
+
|
|
108
|
+ /** {@inheritDoc} */
|
|
109
|
+ @Override
|
|
110
|
+ public void actionPerformed(final ActionEvent e) {
|
|
111
|
+ new ListableConfigDialog(window, this, config, getListables().get(0)).setVisible(true);
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ protected class UpdateResult {
|
|
115
|
+
|
|
116
|
+ private final List<T> list;
|
|
117
|
+ private final ListableParser parser;
|
|
118
|
+
|
|
119
|
+ public UpdateResult(List<T> list, ListableParser parser) {
|
|
120
|
+ this.list = list;
|
|
121
|
+ this.parser = parser;
|
102
|
122
|
}
|
103
|
123
|
|
104
|
|
- String lastGroup = null;
|
105
|
|
- boolean first = true;
|
|
124
|
+ public List<T> getList() {
|
|
125
|
+ return list;
|
|
126
|
+ }
|
106
|
127
|
|
107
|
|
- for (T listable : list) {
|
108
|
|
- if (config.group != null &&
|
109
|
|
- (!(config.group instanceof CompoundConfigElement)
|
110
|
|
- || ((CompoundConfigElement) config.group).getElements().length > 0)) {
|
111
|
|
- final String thisGroup = config.group.getValue(listable, parser);
|
|
128
|
+ public ListableParser getParser() {
|
|
129
|
+ return parser;
|
|
130
|
+ }
|
|
131
|
+ }
|
112
|
132
|
|
113
|
|
- if (lastGroup == null || !thisGroup.equals(lastGroup)) {
|
114
|
|
- first = true;
|
115
|
|
- lastGroup = thisGroup;
|
116
|
|
- add(new HeaderPanel(lastGroup), "growx, pushx");
|
117
|
|
- }
|
118
|
|
- }
|
|
133
|
+ protected class UpdateWorker extends SwingWorker<UpdateResult, Void> {
|
|
134
|
+
|
|
135
|
+ @Override
|
|
136
|
+ protected UpdateResult doInBackground() throws Exception {
|
|
137
|
+ final List<T> list = new ArrayList<T>(getListables());
|
|
138
|
+ final ListableParser parser = new ListableParser(list.get(0).getClass());
|
119
|
139
|
|
120
|
|
- if (first) {
|
121
|
|
- first = false;
|
122
|
|
- } else {
|
123
|
|
- add(new JSeparator(), "growx, pushx");
|
|
140
|
+ if (config.sortOrder != null) {
|
|
141
|
+ Collections.sort(list, new ListableComparator(config.sortOrder, parser));
|
124
|
142
|
}
|
125
|
143
|
|
126
|
|
- add(new ListablePanel(listable, parser, config), "growx, pushx");
|
|
144
|
+ return new UpdateResult(list, parser);
|
127
|
145
|
}
|
128
|
146
|
|
129
|
|
- revalidate();
|
130
|
|
- }
|
|
147
|
+ @Override
|
|
148
|
+ protected void done() {
|
|
149
|
+ try {
|
|
150
|
+ final UpdateResult res = get();
|
|
151
|
+
|
|
152
|
+ removeAll();
|
|
153
|
+
|
|
154
|
+ String lastGroup = null;
|
|
155
|
+ boolean first = true;
|
|
156
|
+
|
|
157
|
+ for (T listable : res.getList()) {
|
|
158
|
+ if (config.group != null &&
|
|
159
|
+ (!(config.group instanceof CompoundConfigElement)
|
|
160
|
+ || ((CompoundConfigElement) config.group)
|
|
161
|
+ .getElements().length > 0)) {
|
|
162
|
+ final String thisGroup = config.group.getValue(listable,
|
|
163
|
+ res.getParser());
|
|
164
|
+
|
|
165
|
+ if (lastGroup == null || !thisGroup.equals(lastGroup)) {
|
|
166
|
+ first = true;
|
|
167
|
+ lastGroup = thisGroup;
|
|
168
|
+ add(new HeaderPanel(lastGroup), "growx, pushx");
|
|
169
|
+ }
|
|
170
|
+ }
|
|
171
|
+
|
|
172
|
+ if (first) {
|
|
173
|
+ first = false;
|
|
174
|
+ } else {
|
|
175
|
+ add(new JSeparator(), "growx, pushx");
|
|
176
|
+ }
|
|
177
|
+
|
|
178
|
+ add(new ListablePanel(listable, res.getParser(), config), "growx, pushx");
|
|
179
|
+ }
|
131
|
180
|
|
132
|
|
- protected abstract List<T> getListables();
|
|
181
|
+ revalidate();
|
|
182
|
+ } catch (ExecutionException ex) {
|
|
183
|
+
|
|
184
|
+ } catch (InterruptedException ex) {
|
|
185
|
+
|
|
186
|
+ }
|
|
187
|
+ }
|
133
|
188
|
|
134
|
|
- /** {@inheritDoc} */
|
135
|
|
- @Override
|
136
|
|
- public void actionPerformed(final ActionEvent e) {
|
137
|
|
- new ListableConfigDialog(window, this, config, getListables().get(0)).setVisible(true);
|
138
|
189
|
}
|
139
|
190
|
|
140
|
191
|
}
|