View Javadoc
1   /*
2    * MoneyWise: Finance Application
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.moneywise.ui.dialog;
18  
19  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20  import io.github.tonywasher.joceanus.oceanus.date.OceanusDate;
21  import io.github.tonywasher.joceanus.oceanus.decimal.OceanusMoney;
22  import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataFieldId;
23  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicDataType;
24  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicResource;
25  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDeposit;
26  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDeposit.MoneyWiseDepositList;
27  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDepositCategory;
28  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDepositCategory.MoneyWiseDepositCategoryList;
29  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayee;
30  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayee.MoneyWisePayeeList;
31  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseAccountInfoClass;
32  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseAssetCategory;
33  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseCurrency;
34  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseCurrency.MoneyWiseCurrencyList;
35  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseDepositCategoryClass;
36  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseStaticDataType;
37  import io.github.tonywasher.joceanus.moneywise.ui.MoneyWiseIcon;
38  import io.github.tonywasher.joceanus.moneywise.ui.MoneyWiseUIResource;
39  import io.github.tonywasher.joceanus.moneywise.ui.base.MoneyWiseAssetTable;
40  import io.github.tonywasher.joceanus.moneywise.views.MoneyWiseView;
41  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
42  import io.github.tonywasher.joceanus.prometheus.ui.fieldset.PrometheusFieldSet;
43  import io.github.tonywasher.joceanus.prometheus.ui.fieldset.PrometheusFieldSetEvent;
44  import io.github.tonywasher.joceanus.prometheus.views.PrometheusEditSet;
45  import io.github.tonywasher.joceanus.tethys.api.control.TethysUIControl.TethysUIIconMapSet;
46  import io.github.tonywasher.joceanus.tethys.api.factory.TethysUIFactory;
47  import io.github.tonywasher.joceanus.tethys.api.field.TethysUIDataEditField.TethysUICharArrayEditField;
48  import io.github.tonywasher.joceanus.tethys.api.field.TethysUIDataEditField.TethysUICharArrayTextAreaField;
49  import io.github.tonywasher.joceanus.tethys.api.field.TethysUIDataEditField.TethysUIDateButtonField;
50  import io.github.tonywasher.joceanus.tethys.api.field.TethysUIDataEditField.TethysUIIconButtonField;
51  import io.github.tonywasher.joceanus.tethys.api.field.TethysUIDataEditField.TethysUIMoneyEditField;
52  import io.github.tonywasher.joceanus.tethys.api.field.TethysUIDataEditField.TethysUIScrollButtonField;
53  import io.github.tonywasher.joceanus.tethys.api.field.TethysUIDataEditField.TethysUIStringEditField;
54  import io.github.tonywasher.joceanus.tethys.api.field.TethysUIFieldFactory;
55  import io.github.tonywasher.joceanus.tethys.api.menu.TethysUIScrollItem;
56  import io.github.tonywasher.joceanus.tethys.api.menu.TethysUIScrollMenu;
57  import io.github.tonywasher.joceanus.tethys.api.menu.TethysUIScrollSubMenu;
58  
59  import java.util.HashMap;
60  import java.util.Iterator;
61  import java.util.Map;
62  
63  /**
64   * Panel to display/edit/create a Deposit.
65   */
66  public class MoneyWiseDepositDialog
67          extends MoneyWiseAssetDialog<MoneyWiseDeposit> {
68      /**
69       * Rates Tab Title.
70       */
71      private static final String TAB_RATES = MoneyWiseUIResource.DEPOSITPANEL_TAB_RATES.getValue();
72  
73      /**
74       * The fieldSet.
75       */
76      private final PrometheusFieldSet<MoneyWiseDeposit> theFieldSet;
77  
78      /**
79       * DepositRate Table.
80       */
81      private final MoneyWiseDepositRateTable theRates;
82  
83      /**
84       * The Closed State.
85       */
86      private Boolean theClosedState = Boolean.FALSE;
87  
88      /**
89       * Constructor.
90       *
91       * @param pFactory the GUI factory
92       * @param pView    the data view
93       * @param pEditSet the edit set
94       * @param pOwner   the owning table
95       */
96      public MoneyWiseDepositDialog(final TethysUIFactory<?> pFactory,
97                                    final MoneyWiseView pView,
98                                    final PrometheusEditSet pEditSet,
99                                    final MoneyWiseAssetTable<MoneyWiseDeposit> pOwner) {
100         /* Initialise the panel */
101         super(pFactory, pEditSet, pOwner);
102 
103         /* Access the fieldSet */
104         theFieldSet = getFieldSet();
105         theFieldSet.setReporter(pOwner::showValidateError);
106 
107         /* Build the main panel */
108         buildMainPanel(pFactory);
109 
110         /* Build the account panel */
111         buildAccountPanel(pFactory);
112 
113         /* Build the notes panel */
114         buildNotesPanel(pFactory);
115 
116         /* Create the DepositRates table and add to fieldSet */
117         theRates = new MoneyWiseDepositRateTable(pView, getEditSet(), pOwner.getErrorPanel());
118         theFieldSet.newTable(TAB_RATES, theRates);
119 
120         /* Create the listeners */
121         theRates.getEventRegistrar().addEventListener(e -> {
122             updateActions();
123             fireStateChanged();
124         });
125     }
126 
127     /**
128      * Build Main subPanel.
129      *
130      * @param pFactory the GUI factory
131      */
132     private void buildMainPanel(final TethysUIFactory<?> pFactory) {
133         /* Create the text fields */
134         final TethysUIFieldFactory myFields = pFactory.fieldFactory();
135         final TethysUIStringEditField myName = myFields.newStringField();
136         final TethysUIStringEditField myDesc = myFields.newStringField();
137 
138         /* Create the buttons */
139         final TethysUIScrollButtonField<MoneyWiseAssetCategory> myCategoryButton = myFields.newScrollField(MoneyWiseAssetCategory.class);
140         final TethysUIScrollButtonField<MoneyWisePayee> myParentButton = myFields.newScrollField(MoneyWisePayee.class);
141         final TethysUIScrollButtonField<MoneyWiseCurrency> myCurrencyButton = myFields.newScrollField(MoneyWiseCurrency.class);
142         final TethysUIIconButtonField<Boolean> myClosedButton = myFields.newIconField(Boolean.class);
143 
144         /* Assign the fields to the panel */
145         theFieldSet.addField(PrometheusDataResource.DATAITEM_FIELD_NAME, myName, MoneyWiseDeposit::getName);
146         theFieldSet.addField(PrometheusDataResource.DATAITEM_FIELD_DESC, myDesc, MoneyWiseDeposit::getDesc);
147         theFieldSet.addField(MoneyWiseBasicResource.CATEGORY_NAME, myCategoryButton, MoneyWiseDeposit::getCategory);
148         theFieldSet.addField(MoneyWiseBasicResource.ASSET_PARENT, myParentButton, MoneyWiseDeposit::getParent);
149         theFieldSet.addField(MoneyWiseStaticDataType.CURRENCY, myCurrencyButton, MoneyWiseDeposit::getAssetCurrency);
150         theFieldSet.addField(MoneyWiseBasicResource.ASSET_CLOSED, myClosedButton, MoneyWiseDeposit::isClosed);
151 
152         /* Configure the menuBuilders */
153         myCategoryButton.setMenuConfigurator(c -> buildCategoryMenu(c, getItem()));
154         myParentButton.setMenuConfigurator(c -> buildParentMenu(c, getItem()));
155         myCurrencyButton.setMenuConfigurator(c -> buildCurrencyMenu(c, getItem()));
156         final Map<Boolean, TethysUIIconMapSet<Boolean>> myMapSets = MoneyWiseIcon.configureLockedIconButton(pFactory);
157         myClosedButton.setIconMapSet(() -> myMapSets.get(theClosedState));
158 
159         /* Configure validation checks */
160         myName.setValidator(this::isValidName);
161         myDesc.setValidator(this::isValidDesc);
162     }
163 
164     /**
165      * Build account subPanel.
166      *
167      * @param pFactory the GUI factory
168      */
169     private void buildAccountPanel(final TethysUIFactory<?> pFactory) {
170         /* Create a new panel */
171         theFieldSet.newPanel(TAB_ACCOUNT);
172 
173         /* Allocate fields */
174         final TethysUIFieldFactory myFields = pFactory.fieldFactory();
175         final TethysUIDateButtonField myMaturity = myFields.newDateField();
176         final TethysUICharArrayEditField mySortCode = myFields.newCharArrayField();
177         final TethysUICharArrayEditField myAccount = myFields.newCharArrayField();
178         final TethysUICharArrayEditField myReference = myFields.newCharArrayField();
179         final TethysUIMoneyEditField myOpening = myFields.newMoneyField();
180 
181         /* Assign the fields to the panel */
182         theFieldSet.addField(MoneyWiseAccountInfoClass.MATURITY, myMaturity, MoneyWiseDeposit::getMaturity);
183         theFieldSet.addField(MoneyWiseAccountInfoClass.SORTCODE, mySortCode, MoneyWiseDeposit::getSortCode);
184         theFieldSet.addField(MoneyWiseAccountInfoClass.ACCOUNT, myAccount, MoneyWiseDeposit::getAccount);
185         theFieldSet.addField(MoneyWiseAccountInfoClass.REFERENCE, myReference, MoneyWiseDeposit::getReference);
186         theFieldSet.addField(MoneyWiseAccountInfoClass.OPENINGBALANCE, myOpening, MoneyWiseDeposit::getOpeningBalance);
187 
188         /* Configure the currency */
189         myOpening.setDeemedCurrency(() -> getItem().getCurrency());
190 
191         /* Configure validation checks */
192         mySortCode.setValidator(this::isValidSortCode);
193         myAccount.setValidator(this::isValidAccount);
194         myReference.setValidator(this::isValidReference);
195     }
196 
197     /**
198      * Build Notes subPanel.
199      *
200      * @param pFactory the GUI factory
201      */
202     private void buildNotesPanel(final TethysUIFactory<?> pFactory) {
203         /* Allocate fields */
204         final TethysUIFieldFactory myFields = pFactory.fieldFactory();
205         final TethysUICharArrayTextAreaField myNotes = myFields.newCharArrayAreaField();
206 
207         /* Assign the fields to the panel */
208         theFieldSet.newTextArea(TAB_NOTES, MoneyWiseAccountInfoClass.NOTES, myNotes, MoneyWiseDeposit::getNotes);
209 
210         /* Configure validation checks */
211         myNotes.setValidator(this::isValidNotes);
212     }
213 
214     @Override
215     public void refreshData() {
216         /* If we have an item */
217         final MoneyWiseDeposit myItem = getItem();
218         if (myItem != null) {
219             final MoneyWiseDepositList myDeposits = getDataList(MoneyWiseBasicDataType.DEPOSIT, MoneyWiseDepositList.class);
220             setItem(myDeposits.findItemById(myItem.getIndexedId()));
221         }
222 
223         /* Refresh the rates */
224         theRates.refreshData();
225 
226         /* Make sure that the item is not editable */
227         setEditable(false);
228     }
229 
230     @Override
231     protected void adjustFields(final boolean isEditable) {
232         /* Access the item */
233         final MoneyWiseDeposit myDeposit = getItem();
234         final boolean bIsClosed = myDeposit.isClosed();
235         final boolean bIsActive = myDeposit.isActive();
236         final boolean bIsRelevant = myDeposit.isRelevant();
237         final boolean bIsChangeable = !bIsActive && isEditable;
238 
239         /* Determine whether the closed button should be visible */
240         final boolean bShowClosed = bIsClosed || (bIsActive && !bIsRelevant);
241         theFieldSet.setFieldVisible(MoneyWiseBasicResource.ASSET_CLOSED, bShowClosed);
242 
243         /* Determine the state of the closed button */
244         final boolean bEditClosed = bIsClosed
245                 ? !myDeposit.getParent().isClosed()
246                 : !bIsRelevant;
247         theFieldSet.setFieldEditable(MoneyWiseBasicResource.ASSET_CLOSED, isEditable && bEditClosed);
248         theClosedState = bEditClosed;
249 
250         /* Determine whether the description field should be visible */
251         final boolean bShowDesc = isEditable || myDeposit.getDesc() != null;
252         theFieldSet.setFieldVisible(PrometheusDataResource.DATAITEM_FIELD_DESC, bShowDesc);
253 
254         /* Determine whether the account details should be visible */
255         final boolean bShowSortCode = isEditable || myDeposit.getSortCode() != null;
256         theFieldSet.setFieldVisible(MoneyWiseAccountInfoClass.SORTCODE, bShowSortCode);
257         final boolean bShowAccount = isEditable || myDeposit.getAccount() != null;
258         theFieldSet.setFieldVisible(MoneyWiseAccountInfoClass.ACCOUNT, bShowAccount);
259         final boolean bShowReference = isEditable || myDeposit.getReference() != null;
260         theFieldSet.setFieldVisible(MoneyWiseAccountInfoClass.REFERENCE, bShowReference);
261         final boolean bHasOpening = myDeposit.getOpeningBalance() != null;
262         final boolean bShowOpening = bIsChangeable || bHasOpening;
263         theFieldSet.setFieldVisible(MoneyWiseAccountInfoClass.OPENINGBALANCE, bShowOpening);
264         final boolean bShowNotes = isEditable || myDeposit.getNotes() != null;
265         theFieldSet.setFieldVisible(MoneyWiseAccountInfoClass.NOTES, bShowNotes);
266 
267         /* Maturity is only visible if the item is a bond */
268         final boolean bShowMaturity = MoneyWiseDepositCategoryClass.BOND.equals(myDeposit.getCategoryClass());
269         theFieldSet.setFieldVisible(MoneyWiseAccountInfoClass.MATURITY, bShowMaturity);
270         theFieldSet.setFieldEditable(MoneyWiseAccountInfoClass.MATURITY, isEditable && !bIsClosed);
271 
272         /* Category, Currency, and OpeningBalance cannot be changed if the item is active */
273         theFieldSet.setFieldEditable(MoneyWiseBasicResource.CATEGORY_NAME, bIsChangeable);
274         theFieldSet.setFieldEditable(MoneyWiseStaticDataType.CURRENCY, bIsChangeable && !bHasOpening);
275         theFieldSet.setFieldEditable(MoneyWiseAccountInfoClass.OPENINGBALANCE, bIsChangeable);
276 
277         /* Set editable value for parent */
278         theFieldSet.setFieldEditable(MoneyWiseBasicResource.ASSET_PARENT, isEditable && !bIsClosed);
279     }
280 
281     @Override
282     protected void updateField(final PrometheusFieldSetEvent pUpdate) throws OceanusException {
283         /* Access the field */
284         final MetisDataFieldId myField = pUpdate.getFieldId();
285         final MoneyWiseDeposit myDeposit = getItem();
286 
287         /* Process updates */
288         if (PrometheusDataResource.DATAITEM_FIELD_NAME.equals(myField)) {
289             /* Update the Name */
290             myDeposit.setName(pUpdate.getValue(String.class));
291         } else if (PrometheusDataResource.DATAITEM_FIELD_DESC.equals(myField)) {
292             /* Update the Description */
293             myDeposit.setDescription(pUpdate.getValue(String.class));
294         } else if (MoneyWiseBasicResource.CATEGORY_NAME.equals(myField)) {
295             /* Update the Category */
296             myDeposit.setCategory(pUpdate.getValue(MoneyWiseDepositCategory.class));
297             myDeposit.autoCorrect();
298         } else if (MoneyWiseBasicResource.ASSET_PARENT.equals(myField)) {
299             /* Update the Parent */
300             myDeposit.setParent(pUpdate.getValue(MoneyWisePayee.class));
301         } else if (MoneyWiseStaticDataType.CURRENCY.equals(myField)) {
302             /* Update the Currency */
303             myDeposit.setAssetCurrency(pUpdate.getValue(MoneyWiseCurrency.class));
304         } else if (MoneyWiseBasicResource.ASSET_CLOSED.equals(myField)) {
305             /* Update the Closed indication */
306             myDeposit.setClosed(pUpdate.getValue(Boolean.class));
307         } else if (MoneyWiseAccountInfoClass.MATURITY.equals(myField)) {
308             /* Update the Maturity */
309             myDeposit.setMaturity(pUpdate.getValue(OceanusDate.class));
310         } else if (MoneyWiseAccountInfoClass.SORTCODE.equals(myField)) {
311             /* Update the SortCode */
312             myDeposit.setSortCode(pUpdate.getValue(char[].class));
313         } else if (MoneyWiseAccountInfoClass.ACCOUNT.equals(myField)) {
314             /* Update the Account */
315             myDeposit.setAccount(pUpdate.getValue(char[].class));
316         } else if (MoneyWiseAccountInfoClass.REFERENCE.equals(myField)) {
317             /* Update the Reference */
318             myDeposit.setReference(pUpdate.getValue(char[].class));
319         } else if (MoneyWiseAccountInfoClass.OPENINGBALANCE.equals(myField)) {
320             /* Update the OpeningBalance */
321             myDeposit.setOpeningBalance(pUpdate.getValue(OceanusMoney.class));
322         } else if (MoneyWiseAccountInfoClass.NOTES.equals(myField)) {
323             /* Update the Notes */
324             myDeposit.setNotes(pUpdate.getValue(char[].class));
325         }
326     }
327 
328     @Override
329     protected void declareGoToItems(final boolean pUpdates) {
330         final MoneyWiseDeposit myItem = getItem();
331         final MoneyWisePayee myParent = myItem.getParent();
332         if (!pUpdates) {
333             final MoneyWiseDepositCategory myCategory = myItem.getCategory();
334             final MoneyWiseCurrency myCurrency = myItem.getAssetCurrency();
335             declareGoToItem(myCategory);
336             declareGoToItem(myCurrency);
337         }
338         declareGoToItem(myParent);
339     }
340 
341     @Override
342     public void setEditable(final boolean isEditable) {
343         /* Update the rates */
344         theRates.setEditable(isEditable);
345 
346         /* Pass call onwards */
347         super.setEditable(isEditable);
348     }
349 
350     @Override
351     protected void refreshAfterUpdate() {
352         /* Pass call onwards */
353         super.refreshAfterUpdate();
354 
355         /* Refresh the rates */
356         theRates.refreshAfterUpdate();
357     }
358 
359     /**
360      * Build the category type menu for an item.
361      *
362      * @param pMenu    the menu
363      * @param pDeposit the deposit to build for
364      */
365     public void buildCategoryMenu(final TethysUIScrollMenu<MoneyWiseAssetCategory> pMenu,
366                                   final MoneyWiseDeposit pDeposit) {
367         /* Clear the menu */
368         pMenu.removeAllItems();
369 
370         /* Record active item */
371         final MoneyWiseDepositCategory myCurr = pDeposit.getCategory();
372         TethysUIScrollItem<MoneyWiseAssetCategory> myActive = null;
373 
374         /* Access Deposit Categories */
375         final MoneyWiseDepositCategoryList myCategories = getDataList(MoneyWiseBasicDataType.DEPOSITCATEGORY, MoneyWiseDepositCategoryList.class);
376 
377         /* Create a simple map for top-level categories */
378         final Map<String, TethysUIScrollSubMenu<MoneyWiseAssetCategory>> myMap = new HashMap<>();
379 
380         /* Loop through the available category values */
381         final Iterator<MoneyWiseDepositCategory> myIterator = myCategories.iterator();
382         while (myIterator.hasNext()) {
383             final MoneyWiseDepositCategory myCategory = myIterator.next();
384 
385             /* Ignore deleted or parent */
386             final boolean bIgnore = myCategory.isDeleted() || myCategory.isCategoryClass(MoneyWiseDepositCategoryClass.PARENT);
387             if (bIgnore) {
388                 continue;
389             }
390 
391             /* Determine menu to add to */
392             final MoneyWiseDepositCategory myParent = myCategory.getParentCategory();
393             final String myParentName = myParent.getName();
394             final TethysUIScrollSubMenu<MoneyWiseAssetCategory> myMenu = myMap.computeIfAbsent(myParentName, pMenu::addSubMenu);
395 
396             /* Create a new MenuItem and add it to the popUp */
397             final TethysUIScrollItem<MoneyWiseAssetCategory> myItem = myMenu.getSubMenu().addItem(myCategory, myCategory.getSubCategory());
398 
399             /* Note active category */
400             if (myCategory.equals(myCurr)) {
401                 myActive = myItem;
402             }
403         }
404 
405         /* Ensure active item is visible */
406         if (myActive != null) {
407             myActive.scrollToItem();
408         }
409     }
410 
411     /**
412      * Build the parent menu for an item.
413      *
414      * @param pMenu    the menu
415      * @param pDeposit the deposit to build for
416      */
417     public void buildParentMenu(final TethysUIScrollMenu<MoneyWisePayee> pMenu,
418                                 final MoneyWiseDeposit pDeposit) {
419         /* Clear the menu */
420         pMenu.removeAllItems();
421 
422         /* Record active item */
423         final MoneyWiseDepositCategoryClass myType = pDeposit.getCategoryClass();
424         final MoneyWisePayee myCurr = pDeposit.getParent();
425         TethysUIScrollItem<MoneyWisePayee> myActive = null;
426 
427         /* Access Payees */
428         final MoneyWisePayeeList myPayees = getDataList(MoneyWiseBasicDataType.PAYEE, MoneyWisePayeeList.class);
429 
430         /* Loop through the Payees */
431         final Iterator<MoneyWisePayee> myIterator = myPayees.iterator();
432         while (myIterator.hasNext()) {
433             final MoneyWisePayee myPayee = myIterator.next();
434 
435             /* Ignore deleted or non-owner */
436             boolean bIgnore = myPayee.isDeleted() || !myPayee.getCategoryClass().canParentDeposit(myType);
437             bIgnore |= myPayee.isClosed();
438             if (bIgnore) {
439                 continue;
440             }
441 
442             /* Create a new action for the payee */
443             final TethysUIScrollItem<MoneyWisePayee> myItem = pMenu.addItem(myPayee);
444 
445             /* If this is the active parent */
446             if (myPayee.equals(myCurr)) {
447                 /* Record it */
448                 myActive = myItem;
449             }
450         }
451 
452         /* Ensure active item is visible */
453         if (myActive != null) {
454             myActive.scrollToItem();
455         }
456     }
457 
458     /**
459      * Build the currency menu for an item.
460      *
461      * @param pMenu    the menu
462      * @param pDeposit the deposit to build for
463      */
464     public void buildCurrencyMenu(final TethysUIScrollMenu<MoneyWiseCurrency> pMenu,
465                                   final MoneyWiseDeposit pDeposit) {
466         /* Clear the menu */
467         pMenu.removeAllItems();
468 
469         /* Record active item */
470         final MoneyWiseCurrency myCurr = pDeposit.getAssetCurrency();
471         TethysUIScrollItem<MoneyWiseCurrency> myActive = null;
472 
473         /* Access Currencies */
474         final MoneyWiseCurrencyList myCurrencies = getDataList(MoneyWiseStaticDataType.CURRENCY, MoneyWiseCurrencyList.class);
475 
476         /* Loop through the AccountCurrencies */
477         final Iterator<MoneyWiseCurrency> myIterator = myCurrencies.iterator();
478         while (myIterator.hasNext()) {
479             final MoneyWiseCurrency myCurrency = myIterator.next();
480 
481             /* Ignore deleted or disabled */
482             final boolean bIgnore = myCurrency.isDeleted() || !myCurrency.getEnabled();
483             if (bIgnore) {
484                 continue;
485             }
486 
487             /* Create a new action for the currency */
488             final TethysUIScrollItem<MoneyWiseCurrency> myItem = pMenu.addItem(myCurrency);
489 
490             /* If this is the active currency */
491             if (myCurrency.equals(myCurr)) {
492                 /* Record it */
493                 myActive = myItem;
494             }
495         }
496 
497         /* Ensure active item is visible */
498         if (myActive != null) {
499             myActive.scrollToItem();
500         }
501     }
502 }