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.service.sheet;
18
19 import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20
21 import java.util.ListIterator;
22
23 /**
24 * Class representing a sheet within a workBook.
25 */
26 public abstract class PrometheusSheetSheet {
27 /**
28 * The WorkBook.
29 */
30 private final PrometheusSheetWorkBook theWorkBook;
31
32 /**
33 * Name of sheet.
34 */
35 private final String theSheetName;
36
37 /**
38 * Is the sheet readOnly?
39 */
40 private final boolean isReadOnly;
41
42 /**
43 * Constructor for Excel Sheet.
44 *
45 * @param pWorkBook the workBook
46 * @param pName the sheet name
47 * @param pReadOnly is the sheet readOnly?
48 */
49 protected PrometheusSheetSheet(final PrometheusSheetWorkBook pWorkBook,
50 final String pName,
51 final boolean pReadOnly) {
52 /* Store parameters */
53 theWorkBook = pWorkBook;
54 theSheetName = pName;
55 isReadOnly = pReadOnly;
56 }
57
58 /**
59 * Obtain the workBook.
60 *
61 * @return the workBook
62 */
63 public PrometheusSheetWorkBook getWorkBook() {
64 return theWorkBook;
65 }
66
67 /**
68 * Obtain the name of the sheet.
69 *
70 * @return the name
71 */
72 public String getName() {
73 return theSheetName;
74 }
75
76 /**
77 * Get sheet index.
78 *
79 * @return the index of the sheet
80 */
81 public abstract int getSheetIndex();
82
83 /**
84 * Is the sheet readOnly?
85 *
86 * @return true/false
87 */
88 public boolean isReadOnly() {
89 return isReadOnly;
90 }
91
92 /**
93 * Is the sheet hidden?
94 *
95 * @return true/false
96 */
97 public abstract boolean isHidden();
98
99 /**
100 * Set sheet hidden status.
101 *
102 * @param isHidden true/false
103 */
104 public abstract void setHidden(boolean isHidden);
105
106 /**
107 * Get row count.
108 *
109 * @return the count of rows
110 */
111 public abstract int getRowCount();
112
113 /**
114 * Obtain the row at required index within the sheet, if it exists.
115 *
116 * @param pRowIndex the requested row index
117 * @return the requested row.
118 */
119 public abstract PrometheusSheetRow getReadOnlyRowByIndex(int pRowIndex);
120
121 /**
122 * Obtain the row at required index within the sheet, create it if it does not exist.
123 *
124 * @param pRowIndex the requested row index
125 * @return the requested row.
126 */
127 public abstract PrometheusSheetRow getMutableRowByIndex(int pRowIndex);
128
129 /**
130 * Obtain the column by index.
131 *
132 * @param pColIndex the column index
133 * @return the column
134 */
135 public abstract PrometheusSheetColumn getReadOnlyColumnByIndex(int pColIndex);
136
137 /**
138 * Obtain the column by index, creating column if it does not exist.
139 *
140 * @param pColIndex the column index
141 * @return the column
142 */
143 public abstract PrometheusSheetColumn getMutableColumnByIndex(int pColIndex);
144
145 /**
146 * Name a range.
147 *
148 * @param pName the name of the range
149 * @param pFirstCell the first cell in the range
150 * @param pLastCell the last cell in the range
151 * @throws OceanusException on error
152 */
153 public abstract void declareRange(String pName,
154 PrometheusSheetCellPosition pFirstCell,
155 PrometheusSheetCellPosition pLastCell) throws OceanusException;
156
157 /**
158 * Name a single cell as a range.
159 *
160 * @param pName the name of the range
161 * @param pSingleCell the cell to name
162 * @throws OceanusException on error
163 */
164 public void declareRange(final String pName,
165 final PrometheusSheetCellPosition pSingleCell) throws OceanusException {
166 /* declare the range */
167 declareRange(pName, pSingleCell, pSingleCell);
168 }
169
170 /**
171 * Apply data validation to a range of cells.
172 *
173 * @param pFirstCell the first cell in the range
174 * @param pLastCell the last cell in the range
175 * @param pName the name of the validation range list
176 * @throws OceanusException on error
177 */
178 public abstract void applyDataValidation(PrometheusSheetCellPosition pFirstCell,
179 PrometheusSheetCellPosition pLastCell,
180 String pName) throws OceanusException;
181
182 /**
183 * Apply data validation to a range of cells.
184 *
185 * @param pBaseCell the first cell in the range
186 * @param pNumRows the number of rows in the filter
187 * @throws OceanusException on error
188 */
189 public abstract void applyDataFilter(PrometheusSheetCellPosition pBaseCell,
190 int pNumRows) throws OceanusException;
191
192 /**
193 * Create freeze panes.
194 *
195 * @param pFreezeCell the cell to freeze at
196 */
197 public abstract void createFreezePane(PrometheusSheetCellPosition pFreezeCell);
198
199 /**
200 * Obtain an iterator of non-null rows for the view.
201 *
202 * @param pFirstIndex the first row in the view
203 * @param pLastIndex the last row in the view
204 * @return the iterator
205 */
206 protected abstract ListIterator<PrometheusSheetRow> iteratorForRange(int pFirstIndex,
207 int pLastIndex);
208 }