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