View Javadoc
1   /*
2    * Prometheus: Application Framework
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.prometheus.sheets;
18  
19  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20  import io.github.tonywasher.joceanus.prometheus.data.PrometheusControlData;
21  import io.github.tonywasher.joceanus.prometheus.data.PrometheusCryptographyDataType;
22  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataSet;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
25  
26  /**
27   * SheetDataItem extension for ControlData.
28   *
29   * @author Tony Washer
30   */
31  public class PrometheusSheetControlData
32          extends PrometheusSheetDataItem<PrometheusControlData> {
33      /**
34       * SheetName for ControlData.
35       */
36      private static final String SHEET_NAME = PrometheusControlData.class.getSimpleName();
37  
38      /**
39       * Version column.
40       */
41      private static final int COL_VERSION = COL_ID + 1;
42  
43      /**
44       * ControlKey column.
45       */
46      private static final int COL_CONTROLID = COL_VERSION + 1;
47  
48      /**
49       * Constructor.
50       *
51       * @param pControl the spreadsheet control
52       */
53      protected PrometheusSheetControlData(final PrometheusSheetControl pControl) {
54          /* Call super constructor */
55          super(pControl, SHEET_NAME);
56  
57          /* Access the Lists */
58          final PrometheusDataSet myData = pControl.getData();
59          setDataList(myData.getControlData());
60      }
61  
62      @Override
63      protected PrometheusDataValues loadSecureValues() throws OceanusException {
64          /* Build data values */
65          final PrometheusDataValues myValues = getRowValues(PrometheusControlData.OBJECT_NAME);
66          myValues.addValue(PrometheusDataResource.CONTROLDATA_VERSION, loadInteger(COL_VERSION));
67          myValues.addValue(PrometheusCryptographyDataType.CONTROLKEY, loadInteger(COL_CONTROLID));
68  
69          /* Return the values */
70          return myValues;
71      }
72  
73      @Override
74      protected void insertSecureItem(final PrometheusControlData pItem) throws OceanusException {
75          /* Set the fields */
76          super.insertSecureItem(pItem);
77          writeInteger(COL_VERSION, pItem.getDataVersion());
78          writeInteger(COL_CONTROLID, pItem.getControlKeyId());
79      }
80  
81      @Override
82      protected int getLastColumn() {
83          /* Return the last column */
84          return COL_CONTROLID;
85      }
86  }