|
| 1 | +using System.Collections.Generic; |
| 2 | +using sapfewse; |
| 3 | + |
| 4 | +namespace RoboSAPiens |
| 5 | +{ |
| 6 | + public class AbapList : ITable |
| 7 | + { |
| 8 | + CellRepository cells; |
| 9 | + public List<string> columnTitles; |
| 10 | + public string id { get; } |
| 11 | + public int rowCount; |
| 12 | + |
| 13 | + public AbapList(GuiSimpleContainer container) |
| 14 | + { |
| 15 | + this.cells = new CellRepository(); |
| 16 | + this.columnTitles = getColumnTitles(container); |
| 17 | + this.id = container.Id; |
| 18 | + this.rowCount = getRowCount(container); |
| 19 | + } |
| 20 | + |
| 21 | + public void classifyCells(GuiSession session) |
| 22 | + { |
| 23 | + var table = (GuiSimpleContainer)session.FindById(id); |
| 24 | + |
| 25 | + for (int i = 0; i < table.Children.Length; i++) |
| 26 | + { |
| 27 | + var component = table.Children.ElementAt(i); |
| 28 | + |
| 29 | + if (component.Type == "GuiSimpleContainer") |
| 30 | + { |
| 31 | + var container = (GuiSimpleContainer)component; |
| 32 | + classifyRow(container); |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + public void classifyRow(GuiSimpleContainer container) |
| 38 | + { |
| 39 | + var containerType = container.GetListProperty("ContainerType"); |
| 40 | + |
| 41 | + for (int i = 0; i < container.Children.Length; i++) |
| 42 | + { |
| 43 | + var element = container.Children.ElementAt(i); |
| 44 | + |
| 45 | + if (element.Type == "GuiLabel") |
| 46 | + { |
| 47 | + var label = (GuiLabel)element; |
| 48 | + var colTitle = label.GetListProperty("FieldHeader").Trim(); |
| 49 | + var labels = new List<string>(); |
| 50 | + |
| 51 | + if (label.Text != "") |
| 52 | + labels.Add(label.Text.Trim()); |
| 53 | + |
| 54 | + if (label.Tooltip != "") |
| 55 | + labels.Add(label.Tooltip.Trim()); |
| 56 | + |
| 57 | + int rowNumber = -1; |
| 58 | + |
| 59 | + if (containerType == "G") |
| 60 | + { |
| 61 | + var groupNo = label.GetListProperty("GroupNo"); |
| 62 | + rowNumber = int.Parse(groupNo); |
| 63 | + } |
| 64 | + |
| 65 | + if (containerType == "R") |
| 66 | + { |
| 67 | + var rowNo = label.GetListProperty("RowNo"); |
| 68 | + rowNumber = int.Parse(rowNo); |
| 69 | + } |
| 70 | + |
| 71 | + if (colTitle != "") |
| 72 | + { |
| 73 | + var colIndex = columnTitles.IndexOf(colTitle); |
| 74 | + |
| 75 | + cells.Add(new ListCell( |
| 76 | + label.Id, |
| 77 | + rowNumber, |
| 78 | + colIndex, |
| 79 | + new List<string> { colTitle }, |
| 80 | + CellType.Text, |
| 81 | + labels |
| 82 | + )); |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + public Cell? findCell(ILocator locator, GuiSession session) |
| 89 | + { |
| 90 | + if (cells.Count == 0) classifyCells(session); |
| 91 | + |
| 92 | + return locator switch |
| 93 | + { |
| 94 | + LabelColumnLocator(string label, string column, int offset) => |
| 95 | + cells.findCellByLabelAndColumn(label, column), |
| 96 | + RowColumnLocator(int row, string column, int offset) => |
| 97 | + cells.findCellByRowAndColumn(row, column), |
| 98 | + _ => null |
| 99 | + }; |
| 100 | + } |
| 101 | + |
| 102 | + List<string> getColumnTitles(GuiSimpleContainer container) |
| 103 | + { |
| 104 | + var columnTitles = new List<string>(); |
| 105 | + var containerType = container.GetListProperty("ContainerType"); |
| 106 | + |
| 107 | + if (containerType == "T") |
| 108 | + { |
| 109 | + for (int i = 0; i < container.Children.Length; i++) |
| 110 | + { |
| 111 | + var component = container.Children.ElementAt(i); |
| 112 | + |
| 113 | + if (component.Type == "GuiLabel") |
| 114 | + { |
| 115 | + var label = (GuiLabel)component; |
| 116 | + string columnTitle = ""; |
| 117 | + |
| 118 | + if (label.Text != "") |
| 119 | + { |
| 120 | + columnTitle = label.Text.Trim(); |
| 121 | + } |
| 122 | + else |
| 123 | + { |
| 124 | + if (label.Tooltip != "") |
| 125 | + { |
| 126 | + columnTitle = label.Tooltip.Trim(); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + var tableGroupsTotal = container.GetListProperty("TableGroupsTotal"); |
| 131 | + var labelType = label.GetListProperty("LabelType"); |
| 132 | + |
| 133 | + if (tableGroupsTotal != "") |
| 134 | + { |
| 135 | + if (labelType == "A") columnTitles.Add(columnTitle); |
| 136 | + } |
| 137 | + else |
| 138 | + { |
| 139 | + if (labelType == "N") columnTitles.Add(columnTitle); |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + if (containerType == "G") |
| 146 | + { |
| 147 | + for (int i = 0; i < container.Children.Length; i++) |
| 148 | + { |
| 149 | + var component = container.Children.ElementAt(i); |
| 150 | + |
| 151 | + if (component.Type == "GuiSimpleContainer") |
| 152 | + { |
| 153 | + var cont = (GuiSimpleContainer)component; |
| 154 | + var contType = cont.GetListProperty("ContainerType"); |
| 155 | + |
| 156 | + if (contType == "R") |
| 157 | + { |
| 158 | + for (int colIndex = 0; colIndex < cont.Children.Length; colIndex++) |
| 159 | + { |
| 160 | + var col = cont.Children.ElementAt(colIndex); |
| 161 | + |
| 162 | + if (col.Type == "GuiLabel") |
| 163 | + { |
| 164 | + var label = (GuiLabel)col; |
| 165 | + var colTitle = label.GetListProperty("FieldHeader").Trim(); |
| 166 | + |
| 167 | + if (colTitle != "") |
| 168 | + { |
| 169 | + columnTitles.Add(colTitle); |
| 170 | + } |
| 171 | + } |
| 172 | + } |
| 173 | + break; |
| 174 | + } |
| 175 | + } |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + return columnTitles; |
| 180 | + } |
| 181 | + |
| 182 | + public int getNumRows(GuiSession session) |
| 183 | + { |
| 184 | + return rowCount; |
| 185 | + } |
| 186 | + |
| 187 | + int getRowCount(GuiSimpleContainer container) |
| 188 | + { |
| 189 | + var containerType = container.GetListProperty("ContainerType"); |
| 190 | + int rowCount = 0; |
| 191 | + |
| 192 | + if (containerType == "G") |
| 193 | + { |
| 194 | + var rowsTotal = container.GetListProperty("RowsTotal"); |
| 195 | + if (rowsTotal != "") |
| 196 | + { |
| 197 | + rowCount = int.Parse(rowsTotal); |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + if (containerType == "T") |
| 202 | + { |
| 203 | + var tableGroupsTotal = container.GetListProperty("TableGroupsTotal"); |
| 204 | + |
| 205 | + if (tableGroupsTotal != "") |
| 206 | + { |
| 207 | + rowCount = int.Parse(tableGroupsTotal); |
| 208 | + } |
| 209 | + else |
| 210 | + { |
| 211 | + var rowsTotal = container.GetListProperty("RowsTotal"); |
| 212 | + |
| 213 | + if (rowsTotal != "") |
| 214 | + { |
| 215 | + rowCount = int.Parse(rowsTotal); |
| 216 | + } |
| 217 | + } |
| 218 | + } |
| 219 | + |
| 220 | + return rowCount; |
| 221 | + } |
| 222 | + |
| 223 | + public bool hasColumn(string column) |
| 224 | + { |
| 225 | + return columnTitles.Contains(column); |
| 226 | + } |
| 227 | + |
| 228 | + public bool rowIsAbove(GuiSession session, int rowIndex) |
| 229 | + { |
| 230 | + return false; |
| 231 | + } |
| 232 | + |
| 233 | + public bool rowIsBelow(GuiSession session, int rowIndex) |
| 234 | + { |
| 235 | + return false; |
| 236 | + } |
| 237 | + |
| 238 | + public bool scrollOnePage(GuiSession session) |
| 239 | + { |
| 240 | + return false; |
| 241 | + } |
| 242 | + |
| 243 | + public void selectColumn(string column, GuiSession session) |
| 244 | + { |
| 245 | + var table = (GuiSimpleContainer)session.FindById(id); |
| 246 | + |
| 247 | + for (int i = 0; i < table.Children.Length; i++) |
| 248 | + { |
| 249 | + var component = table.Children.ElementAt(i); |
| 250 | + |
| 251 | + if (component.Type == "GuiLabel") |
| 252 | + { |
| 253 | + var label = (GuiLabel)component; |
| 254 | + |
| 255 | + if (label.Text.Trim() == column || label.Tooltip.Trim() == column) |
| 256 | + { |
| 257 | + label.SetFocus(); |
| 258 | + session.ActiveWindow.SendVKey(2); |
| 259 | + return; |
| 260 | + } |
| 261 | + } |
| 262 | + } |
| 263 | + } |
| 264 | + |
| 265 | + public void selectRow(int rowNumber0, GuiSession session) |
| 266 | + { |
| 267 | + var table = (GuiSimpleContainer)session.FindById(id); |
| 268 | + |
| 269 | + for (int i = 0; i < table.Children.Length; i++) |
| 270 | + { |
| 271 | + var component = table.Children.ElementAt(i); |
| 272 | + |
| 273 | + if (component.Type == "GuiSimpleContainer") |
| 274 | + { |
| 275 | + var container = (GuiSimpleContainer)component; |
| 276 | + var containerType = container.GetListProperty("ContainerType"); |
| 277 | + |
| 278 | + if (containerType == "R" || containerType == "G") |
| 279 | + { |
| 280 | + var row = container; |
| 281 | + var firstColumn = row.Children.ElementAt(0); |
| 282 | + |
| 283 | + if (firstColumn.Type == "GuiLabel") |
| 284 | + { |
| 285 | + var firstCell = (GuiLabel)firstColumn; |
| 286 | + |
| 287 | + int rowIndex = -1; |
| 288 | + |
| 289 | + if (containerType == "R") |
| 290 | + { |
| 291 | + var rowNo = firstCell.GetListProperty("RowNo"); |
| 292 | + if (rowNo != "") rowIndex = int.Parse(rowNo); |
| 293 | + } |
| 294 | + |
| 295 | + if (containerType == "G") |
| 296 | + { |
| 297 | + var groupNo = firstCell.GetListProperty("GroupNo"); |
| 298 | + if (groupNo != "") rowIndex = int.Parse(groupNo); |
| 299 | + } |
| 300 | + |
| 301 | + if (rowIndex == rowNumber0 + 1) |
| 302 | + { |
| 303 | + firstCell.SetFocus(); |
| 304 | + session.ActiveWindow.SendVKey(2); |
| 305 | + return; |
| 306 | + } |
| 307 | + } |
| 308 | + } |
| 309 | + } |
| 310 | + } |
| 311 | + } |
| 312 | + |
| 313 | + public void selectRows(List<int> rowIndices, GuiSession session) |
| 314 | + { |
| 315 | + } |
| 316 | + } |
| 317 | +} |
0 commit comments