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.sheets;
18  
19  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDataSet;
20  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseCurrency;
21  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseStaticResource;
22  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
24  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetReader;
25  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetStaticData;
26  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetWriter;
27  
28  /**
29   * SheetStaticData extension for AccountCurrency.
30   *
31   * @author Tony Washer
32   */
33  public final class MoneyWiseSheetCurrency
34          extends PrometheusSheetStaticData<MoneyWiseCurrency> {
35      /**
36       * NamedArea for AccountCurrencies.
37       */
38      private static final String AREA_ACCOUNTCURRENCIES = MoneyWiseCurrency.LIST_NAME;
39  
40      /**
41       * Default column.
42       */
43      private static final int COL_DEFAULT = COL_DESC + 1;
44  
45      /**
46       * Constructor for loading a spreadsheet.
47       *
48       * @param pReader the spreadsheet reader
49       */
50      MoneyWiseSheetCurrency(final PrometheusSheetReader pReader) {
51          /* Call super-constructor */
52          super(pReader, AREA_ACCOUNTCURRENCIES);
53  
54          /* Access the list */
55          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pReader.getData();
56          setDataList(myData.getAccountCurrencies());
57      }
58  
59      /**
60       * Constructor for creating a spreadsheet.
61       *
62       * @param pWriter the spreadsheet writer
63       */
64      MoneyWiseSheetCurrency(final PrometheusSheetWriter pWriter) {
65          /* Call super-constructor */
66          super(pWriter, AREA_ACCOUNTCURRENCIES);
67  
68          /* Access the list */
69          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pWriter.getData();
70          setDataList(myData.getAccountCurrencies());
71      }
72  
73      @Override
74      protected PrometheusDataValues loadSecureValues() throws OceanusException {
75          /* Build data values */
76          final PrometheusDataValues myValues = getRowValues(MoneyWiseCurrency.OBJECT_NAME);
77          myValues.addValue(MoneyWiseStaticResource.CURRENCY_REPORTING, loadBoolean(COL_DEFAULT));
78  
79          /* Return the values */
80          return myValues;
81      }
82  
83      @Override
84      protected void insertSecureItem(final MoneyWiseCurrency pItem) throws OceanusException {
85          /* Insert standard fields */
86          super.insertSecureItem(pItem);
87  
88          /* Set default indication */
89          writeBoolean(COL_DEFAULT, pItem.isReporting());
90      }
91  
92      @Override
93      protected int getLastColumn() {
94          /* Return the last column */
95          return COL_DEFAULT;
96      }
97  }