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.basic.MoneyWiseRegion;
22  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
24  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetEncrypted;
25  
26  /**
27   * SheetDataItem extension for Region.
28   */
29  public final class MoneyWiseSheetRegion
30          extends PrometheusSheetEncrypted<MoneyWiseRegion> {
31      /**
32       * NamedArea for regions.
33       */
34      private static final String AREA_REGIONS = MoneyWiseRegion.LIST_NAME;
35  
36      /**
37       * Name column.
38       */
39      private static final int COL_NAME = COL_KEYSETID + 1;
40  
41      /**
42       * Description column.
43       */
44      private static final int COL_DESC = COL_NAME + 1;
45  
46      /**
47       * Constructor for loading a spreadsheet.
48       *
49       * @param pReader the spreadsheet reader
50       */
51      MoneyWiseSheetRegion(final MoneyWiseReader pReader) {
52          /* Call super constructor */
53          super(pReader, AREA_REGIONS);
54  
55          /* Access the Class list */
56          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pReader.getData();
57          setDataList(myData.getRegions());
58      }
59  
60      /**
61       * Constructor for creating a spreadsheet.
62       *
63       * @param pWriter the spreadsheet writer
64       */
65      MoneyWiseSheetRegion(final MoneyWiseWriter pWriter) {
66          /* Call super constructor */
67          super(pWriter, AREA_REGIONS);
68  
69          /* Access the Class list */
70          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pWriter.getData();
71          setDataList(myData.getRegions());
72      }
73  
74      @Override
75      protected PrometheusDataValues loadSecureValues() throws OceanusException {
76          /* Build data values */
77          final PrometheusDataValues myValues = getRowValues(MoneyWiseRegion.OBJECT_NAME);
78          myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, loadBytes(COL_NAME));
79          myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_DESC, loadBytes(COL_DESC));
80  
81          /* Return the values */
82          return myValues;
83      }
84  
85      @Override
86      protected void insertSecureItem(final MoneyWiseRegion pItem) throws OceanusException {
87          /* Set the fields */
88          super.insertSecureItem(pItem);
89          writeBytes(COL_NAME, pItem.getNameBytes());
90          writeBytes(COL_DESC, pItem.getDescBytes());
91      }
92  
93      @Override
94      protected int getLastColumn() {
95          /* Return the last column */
96          return COL_DESC;
97      }
98  }