1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.moneywise.ui.panel;
18
19 import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20 import io.github.tonywasher.joceanus.oceanus.event.OceanusEvent;
21 import io.github.tonywasher.joceanus.oceanus.event.OceanusEventManager;
22 import io.github.tonywasher.joceanus.oceanus.event.OceanusEventRegistrar;
23 import io.github.tonywasher.joceanus.oceanus.event.OceanusEventRegistrar.OceanusEventProvider;
24 import io.github.tonywasher.joceanus.oceanus.profile.OceanusProfile;
25 import io.github.tonywasher.joceanus.metis.ui.MetisErrorPanel;
26 import io.github.tonywasher.joceanus.metis.viewer.MetisViewerEntry;
27 import io.github.tonywasher.joceanus.metis.viewer.MetisViewerManager;
28 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseAssetBase;
29 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicDataType;
30 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseCash;
31 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDeposit;
32 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseLoan;
33 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayee;
34 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePortfolio;
35 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseSecurity;
36 import io.github.tonywasher.joceanus.moneywise.ui.MoneyWiseGoToId;
37 import io.github.tonywasher.joceanus.moneywise.ui.MoneyWiseUIResource;
38 import io.github.tonywasher.joceanus.moneywise.views.MoneyWiseView;
39 import io.github.tonywasher.joceanus.prometheus.ui.PrometheusActionButtons;
40 import io.github.tonywasher.joceanus.prometheus.ui.PrometheusGoToEvent;
41 import io.github.tonywasher.joceanus.prometheus.views.PrometheusDataEvent;
42 import io.github.tonywasher.joceanus.prometheus.views.PrometheusEditSet;
43 import io.github.tonywasher.joceanus.prometheus.views.PrometheusUIEvent;
44 import io.github.tonywasher.joceanus.prometheus.views.PrometheusViewerEntryId;
45 import io.github.tonywasher.joceanus.tethys.api.base.TethysUIComponent;
46 import io.github.tonywasher.joceanus.tethys.api.base.TethysUIEvent;
47 import io.github.tonywasher.joceanus.tethys.api.button.TethysUIButtonFactory;
48 import io.github.tonywasher.joceanus.tethys.api.button.TethysUIScrollButtonManager;
49 import io.github.tonywasher.joceanus.tethys.api.control.TethysUIControlFactory;
50 import io.github.tonywasher.joceanus.tethys.api.control.TethysUILabel;
51 import io.github.tonywasher.joceanus.tethys.api.factory.TethysUIFactory;
52 import io.github.tonywasher.joceanus.tethys.api.menu.TethysUIScrollMenu;
53 import io.github.tonywasher.joceanus.tethys.api.pane.TethysUIBorderPaneManager;
54 import io.github.tonywasher.joceanus.tethys.api.pane.TethysUIBoxPaneManager;
55 import io.github.tonywasher.joceanus.tethys.api.pane.TethysUICardPaneManager;
56 import io.github.tonywasher.joceanus.tethys.api.pane.TethysUIPaneFactory;
57
58
59
60
61 public class MoneyWiseAccountPanel
62 implements OceanusEventProvider<PrometheusDataEvent>, TethysUIComponent {
63
64
65
66 protected static final int STRUT_WIDTH = 5;
67
68
69
70
71 private static final String NLS_DATAENTRY = MoneyWiseUIResource.ASSET_DATAENTRY.getValue();
72
73
74
75
76 private static final String NLS_SELECT = MoneyWiseUIResource.ASSET_TITLE_SELECT.getValue();
77
78
79
80
81 private static final String NLS_DATA = MoneyWiseUIResource.ASSET_PROMPT_SELECT.getValue();
82
83
84
85
86 private final OceanusEventManager<PrometheusDataEvent> theEventManager;
87
88
89
90
91 private final MoneyWiseView theView;
92
93
94
95
96 private final TethysUIBorderPaneManager thePanel;
97
98
99
100
101 private final TethysUIScrollButtonManager<PanelName> theSelectButton;
102
103
104
105
106 private final TethysUICardPaneManager<TethysUIComponent> theCardPanel;
107
108
109
110
111 private final TethysUIBorderPaneManager theSelectPanel;
112
113
114
115
116 private final TethysUICardPaneManager<TethysUIComponent> theFilterCardPanel;
117
118
119
120
121 private final MoneyWiseDepositTable theDepositTable;
122
123
124
125
126 private final MoneyWiseCashTable theCashTable;
127
128
129
130
131 private final MoneyWiseLoanTable theLoanTable;
132
133
134
135
136 private final MoneyWisePortfolioTable thePortfolioTable;
137
138
139
140
141 private final MoneyWiseSecurityTable theSecurityTable;
142
143
144
145
146 private final MoneyWisePayeeTable thePayeeTable;
147
148
149
150
151 private final PrometheusEditSet theEditSet;
152
153
154
155
156 private final MetisViewerEntry theViewerEntry;
157
158
159
160
161 private final MetisErrorPanel theError;
162
163
164
165
166 private final PrometheusActionButtons theActionButtons;
167
168
169
170
171 private boolean isRefreshing;
172
173
174
175
176 private PanelName theActive;
177
178
179
180
181
182
183 MoneyWiseAccountPanel(final MoneyWiseView pView) {
184
185 theView = pView;
186
187
188 final TethysUIFactory<?> myFactory = pView.getGuiFactory();
189 final MetisViewerManager myViewer = pView.getViewerManager();
190
191
192 theEventManager = new OceanusEventManager<>();
193
194
195 theEditSet = new PrometheusEditSet(pView);
196
197
198 final TethysUIPaneFactory myPanes = myFactory.paneFactory();
199 thePanel = myPanes.newBorderPane();
200
201
202 final MetisViewerEntry mySection = pView.getViewerEntry(PrometheusViewerEntryId.MAINTENANCE);
203 theViewerEntry = myViewer.newEntry(mySection, NLS_DATAENTRY);
204 theViewerEntry.setTreeObject(theEditSet);
205
206
207 theError = pView.getToolkit().getToolkit().newErrorPanel(theViewerEntry);
208
209
210 theActionButtons = new PrometheusActionButtons(myFactory, theEditSet);
211
212
213 thePayeeTable = new MoneyWisePayeeTable(pView, theEditSet, theError);
214 theSecurityTable = new MoneyWiseSecurityTable(pView, theEditSet, theError);
215 theDepositTable = new MoneyWiseDepositTable(pView, theEditSet, theError);
216 theCashTable = new MoneyWiseCashTable(pView, theEditSet, theError);
217 theLoanTable = new MoneyWiseLoanTable(pView, theEditSet, theError);
218 thePortfolioTable = new MoneyWisePortfolioTable(pView, theEditSet, theError);
219
220
221 final TethysUIControlFactory myControls = myFactory.controlFactory();
222 final TethysUIButtonFactory<?> myButtons = myFactory.buttonFactory();
223 final TethysUILabel myLabel = myControls.newLabel(NLS_DATA);
224 theSelectButton = myButtons.newScrollButton(PanelName.class);
225 buildSelectMenu();
226
227
228 theCardPanel = myPanes.newCardPane();
229
230
231 theCardPanel.addCard(PanelName.DEPOSITS.toString(), theDepositTable);
232 theCardPanel.addCard(PanelName.CASH.toString(), theCashTable);
233 theCardPanel.addCard(PanelName.LOANS.toString(), theLoanTable);
234 theCardPanel.addCard(PanelName.PORTFOLIOS.toString(), thePortfolioTable);
235 theCardPanel.addCard(PanelName.SECURITIES.toString(), theSecurityTable);
236 theCardPanel.addCard(PanelName.PAYEES.toString(), thePayeeTable);
237 theActive = PanelName.DEPOSITS;
238 theSelectButton.setFixedText(theActive.toString());
239
240
241 theFilterCardPanel = myPanes.newCardPane();
242
243
244 theFilterCardPanel.addCard(PanelName.DEPOSITS.toString(), theDepositTable.getFilterPanel());
245 theFilterCardPanel.addCard(PanelName.CASH.toString(), theCashTable.getFilterPanel());
246 theFilterCardPanel.addCard(PanelName.LOANS.toString(), theLoanTable.getFilterPanel());
247 theFilterCardPanel.addCard(PanelName.PORTFOLIOS.toString(), thePortfolioTable.getFilterPanel());
248 theFilterCardPanel.addCard(PanelName.SECURITIES.toString(), theSecurityTable.getFilterPanel());
249 theFilterCardPanel.addCard(PanelName.PAYEES.toString(), thePayeeTable.getFilterPanel());
250
251
252 final TethysUIBoxPaneManager mySelect = myPanes.newHBoxPane();
253 mySelect.addNode(myLabel);
254 mySelect.addNode(theSelectButton);
255
256
257 theSelectPanel = myPanes.newBorderPane();
258 theSelectPanel.setBorderTitle(NLS_SELECT);
259 theSelectPanel.setWest(mySelect);
260 theSelectPanel.setCentre(theFilterCardPanel);
261
262
263 final TethysUIBorderPaneManager myHeader = myPanes.newBorderPane();
264 myHeader.setCentre(theSelectPanel);
265 myHeader.setNorth(theError);
266 myHeader.setEast(theActionButtons);
267
268
269 thePanel.setNorth(myHeader);
270 thePanel.setCentre(theCardPanel);
271
272
273 theActionButtons.setVisible(false);
274
275
276 theSelectButton.getEventRegistrar().addEventListener(TethysUIEvent.NEWVALUE, e -> handleSelection());
277 theError.getEventRegistrar().addEventListener(e -> handleErrorPane());
278 theActionButtons.getEventRegistrar().addEventListener(this::handleActionButtons);
279 setChildListeners(theDepositTable.getEventRegistrar());
280 setChildListeners(theCashTable.getEventRegistrar());
281 setChildListeners(theLoanTable.getEventRegistrar());
282 setChildListeners(thePayeeTable.getEventRegistrar());
283 setChildListeners(thePortfolioTable.getEventRegistrar());
284 setChildListeners(theSecurityTable.getEventRegistrar());
285 }
286
287 @Override
288 public TethysUIComponent getUnderlying() {
289 return thePanel;
290 }
291
292 @Override
293 public OceanusEventRegistrar<PrometheusDataEvent> getEventRegistrar() {
294 return theEventManager.getEventRegistrar();
295 }
296
297
298
299
300
301
302 private void setChildListeners(final OceanusEventRegistrar<PrometheusDataEvent> pRegistrar) {
303 pRegistrar.addEventListener(PrometheusDataEvent.ADJUSTVISIBILITY, e -> {
304 if (!isRefreshing) {
305 setVisibility();
306 }
307 });
308 pRegistrar.addEventListener(PrometheusDataEvent.GOTOWINDOW, this::handleGoToEvent);
309 }
310
311 @Override
312 public void setEnabled(final boolean pEnabled) {
313 theSelectButton.setEnabled(pEnabled);
314 theCardPanel.setEnabled(pEnabled);
315 theFilterCardPanel.setEnabled(pEnabled);
316 }
317
318 @Override
319 public void setVisible(final boolean pVisible) {
320 thePanel.setVisible(pVisible);
321 }
322
323
324
325
326 private void buildSelectMenu() {
327
328 final TethysUIScrollMenu<PanelName> myMenu = theSelectButton.getMenu();
329
330
331 for (PanelName myPanel : PanelName.values()) {
332
333 myMenu.addItem(myPanel);
334 }
335 }
336
337
338
339
340
341
342 public void showLocked(final boolean pShow) {
343
344 thePayeeTable.setShowAll(pShow);
345 theSecurityTable.setShowAll(pShow);
346 theDepositTable.setShowAll(pShow);
347 theCashTable.setShowAll(pShow);
348 theLoanTable.setShowAll(pShow);
349 thePortfolioTable.setShowAll(pShow);
350 }
351
352
353
354
355 private void cancelEditing() {
356
357 thePayeeTable.cancelEditing();
358 theSecurityTable.cancelEditing();
359 theDepositTable.cancelEditing();
360 theCashTable.cancelEditing();
361 theLoanTable.cancelEditing();
362 thePortfolioTable.cancelEditing();
363 }
364
365
366
367
368
369
370 public void refreshData() throws OceanusException {
371
372 OceanusProfile myTask = theView.getActiveTask();
373 myTask = myTask.startTask("Accounts");
374
375
376 isRefreshing = true;
377 theEditSet.setDataSet(theView.getData());
378
379
380 thePayeeTable.refreshData();
381 theSecurityTable.refreshData();
382 theDepositTable.refreshData();
383 theCashTable.refreshData();
384 theLoanTable.refreshData();
385 thePortfolioTable.refreshData();
386
387
388 isRefreshing = false;
389 setVisibility();
390
391
392 theViewerEntry.setTreeObject(theEditSet);
393
394
395 myTask.end();
396 }
397
398
399
400
401 public void determineFocus() {
402
403 switch (theActive) {
404 case DEPOSITS:
405 theDepositTable.determineFocus(theViewerEntry);
406 break;
407 case CASH:
408 theCashTable.determineFocus(theViewerEntry);
409 break;
410 case LOANS:
411 theLoanTable.determineFocus(theViewerEntry);
412 break;
413 case PORTFOLIOS:
414 thePortfolioTable.determineFocus(theViewerEntry);
415 break;
416 case SECURITIES:
417 theSecurityTable.determineFocus(theViewerEntry);
418 break;
419 case PAYEES:
420 thePayeeTable.determineFocus(theViewerEntry);
421 break;
422 default:
423 break;
424 }
425 }
426
427
428
429
430
431
432 public boolean hasUpdates() {
433
434 boolean hasUpdates = theDepositTable.hasUpdates();
435 if (!hasUpdates) {
436 hasUpdates = theCashTable.hasUpdates();
437 }
438 if (!hasUpdates) {
439 hasUpdates = theLoanTable.hasUpdates();
440 }
441 if (!hasUpdates) {
442 hasUpdates = thePortfolioTable.hasUpdates();
443 }
444 if (!hasUpdates) {
445 hasUpdates = theSecurityTable.hasUpdates();
446 }
447 if (!hasUpdates) {
448 hasUpdates = thePayeeTable.hasUpdates();
449 }
450
451
452 return hasUpdates;
453 }
454
455
456
457
458
459
460 public boolean hasSession() {
461
462 boolean hasSession = theDepositTable.hasSession();
463 if (!hasSession) {
464 hasSession = theCashTable.hasSession();
465 }
466 if (!hasSession) {
467 hasSession = theLoanTable.hasSession();
468 }
469 if (!hasSession) {
470 hasSession = thePortfolioTable.hasSession();
471 }
472 if (!hasSession) {
473 hasSession = theSecurityTable.hasSession();
474 }
475 if (!hasSession) {
476 hasSession = thePayeeTable.hasSession();
477 }
478
479
480 return hasSession;
481 }
482
483
484
485
486
487
488 public boolean hasErrors() {
489
490 boolean hasErrors = theDepositTable.hasErrors();
491 if (!hasErrors) {
492 hasErrors = theCashTable.hasErrors();
493 }
494 if (!hasErrors) {
495 hasErrors = theLoanTable.hasErrors();
496 }
497 if (!hasErrors) {
498 hasErrors = thePortfolioTable.hasErrors();
499 }
500 if (!hasErrors) {
501 hasErrors = theSecurityTable.hasErrors();
502 }
503 if (!hasErrors) {
504 hasErrors = thePayeeTable.hasErrors();
505 }
506
507
508 return hasErrors;
509 }
510
511
512
513
514
515
516 public boolean isItemEditing() {
517
518 boolean isEditing = theDepositTable.isItemEditing();
519 if (!isEditing) {
520 isEditing = theCashTable.isItemEditing();
521 }
522 if (!isEditing) {
523 isEditing = theLoanTable.isItemEditing();
524 }
525 if (!isEditing) {
526 isEditing = thePortfolioTable.isItemEditing();
527 }
528 if (!isEditing) {
529 isEditing = theSecurityTable.isItemEditing();
530 }
531 if (!isEditing) {
532 isEditing = thePayeeTable.isItemEditing();
533 }
534
535
536 return isEditing;
537 }
538
539
540
541
542
543
544 public void selectAccount(final MoneyWiseAssetBase pAccount) {
545
546 if (pAccount instanceof MoneyWiseDeposit myDeposit) {
547 theDepositTable.selectDeposit(myDeposit);
548 showPanel(PanelName.DEPOSITS);
549 } else if (pAccount instanceof MoneyWiseCash myCash) {
550 theCashTable.selectCash(myCash);
551 showPanel(PanelName.CASH);
552 } else if (pAccount instanceof MoneyWiseLoan myLoan) {
553 theLoanTable.selectLoan(myLoan);
554 showPanel(PanelName.LOANS);
555 } else if (pAccount instanceof MoneyWisePortfolio myPortfolio) {
556 thePortfolioTable.selectPortfolio(myPortfolio);
557 showPanel(PanelName.PORTFOLIOS);
558 } else if (pAccount instanceof MoneyWiseSecurity mySecurity) {
559 theSecurityTable.selectSecurity(mySecurity);
560 showPanel(PanelName.SECURITIES);
561 } else if (pAccount instanceof MoneyWisePayee myPayee) {
562 thePayeeTable.selectPayee(myPayee);
563 showPanel(PanelName.PAYEES);
564 }
565 }
566
567
568
569
570
571
572 private void showPanel(final PanelName pName) {
573
574 final String myName = pName.toString();
575
576
577 theCardPanel.selectCard(myName);
578 theFilterCardPanel.selectCard(myName);
579
580
581 theActive = pName;
582 theSelectButton.setFixedText(myName);
583
584
585 determineFocus();
586 }
587
588
589
590
591 protected void setVisibility() {
592
593 final boolean hasUpdates = hasUpdates();
594 final boolean isItemEditing = isItemEditing();
595
596
597 theActionButtons.setEnabled(true);
598 theActionButtons.setVisible(hasUpdates && !isItemEditing);
599
600
601 theSelectButton.setEnabled(!isItemEditing);
602 theFilterCardPanel.setEnabled(!isItemEditing);
603
604
605 theEventManager.fireEvent(PrometheusDataEvent.ADJUSTVISIBILITY);
606 }
607
608
609
610
611 private void handleErrorPane() {
612
613 final boolean isError = theError.hasError();
614
615
616 theSelectPanel.setVisible(!isError);
617
618
619 theCardPanel.setEnabled(!isError);
620
621
622 theActionButtons.setEnabled(!isError);
623 }
624
625
626
627
628 private void handleSelection() {
629
630 cancelEditing();
631
632
633 showPanel(theSelectButton.getValue());
634 }
635
636
637
638
639
640
641 private void handleActionButtons(final OceanusEvent<PrometheusUIEvent> pEvent) {
642
643 cancelEditing();
644
645
646 theEditSet.processCommand(pEvent.getEventId(), theError);
647 }
648
649
650
651
652
653
654 private void handleGoToEvent(final OceanusEvent<PrometheusDataEvent> pEvent) {
655
656 @SuppressWarnings("unchecked") final PrometheusGoToEvent<MoneyWiseGoToId> myEvent = pEvent.getDetails(PrometheusGoToEvent.class);
657
658
659 switch (myEvent.getId()) {
660
661 case STATEMENT:
662 case CATEGORY:
663 case REGION:
664 case TAG:
665 case STATIC:
666 theEventManager.cascadeEvent(pEvent);
667 break;
668
669
670 case ACCOUNT:
671 selectAccount(myEvent.getDetails(MoneyWiseAssetBase.class));
672 break;
673 default:
674 break;
675 }
676 }
677
678
679
680
681 private enum PanelName {
682
683
684
685 DEPOSITS(MoneyWiseBasicDataType.DEPOSIT),
686
687
688
689
690 CASH(MoneyWiseBasicDataType.CASH),
691
692
693
694
695 LOANS(MoneyWiseBasicDataType.LOAN),
696
697
698
699
700 PORTFOLIOS(MoneyWiseBasicDataType.PORTFOLIO),
701
702
703
704
705 SECURITIES(MoneyWiseBasicDataType.SECURITY),
706
707
708
709
710 PAYEES(MoneyWiseBasicDataType.PAYEE);
711
712
713
714
715 private String theName;
716
717
718
719
720
721
722 PanelName(final MoneyWiseBasicDataType pDataType) {
723 theName = pDataType.getListName();
724 }
725
726 @Override
727 public String toString() {
728
729 return theName;
730 }
731 }
732 }
733