|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2012 BREDEX GmbH. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* BREDEX GmbH - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jubula.rc.common.caps; |
| 12 |
|
| 13 |
import java.awt.Rectangle; |
| 14 |
import java.util.StringTokenizer; |
| 15 |
|
| 16 |
import org.eclipse.jubula.rc.common.CompSystemConstants; |
| 17 |
import org.eclipse.jubula.rc.common.driver.ClickOptions; |
| 18 |
import org.eclipse.jubula.rc.common.driver.DragAndDropHelper; |
| 19 |
import org.eclipse.jubula.rc.common.driver.IRobot; |
| 20 |
import org.eclipse.jubula.rc.common.exception.StepExecutionException; |
| 21 |
import org.eclipse.jubula.rc.common.implclasses.IndexConverter; |
| 22 |
import org.eclipse.jubula.rc.common.implclasses.MatchUtil; |
| 23 |
import org.eclipse.jubula.rc.common.implclasses.Verifier; |
| 24 |
import org.eclipse.jubula.rc.common.implclasses.table.Cell; |
| 25 |
import org.eclipse.jubula.rc.common.logger.AutServerLogger; |
| 26 |
import org.eclipse.jubula.rc.common.uiadapter.interfaces.ITableAdapter; |
| 27 |
import org.eclipse.jubula.rc.common.util.KeyStrokeUtil; |
| 28 |
import org.eclipse.jubula.tools.constants.InputConstants; |
| 29 |
import org.eclipse.jubula.tools.objects.event.EventFactory; |
| 30 |
import org.eclipse.jubula.tools.objects.event.TestErrorEvent; |
| 31 |
import org.eclipse.jubula.tools.utils.TimeUtil; |
| 32 |
|
| 33 |
/** |
| 34 |
* General implementation for tables. |
| 35 |
* |
| 36 |
* @author BREDEX GmbH |
| 37 |
*/ |
| 38 |
public abstract class AbstractTableCAPs extends AbstractTextInputSupport { |
| 39 |
|
| 40 |
/** the logger */ |
| 41 |
private static AutServerLogger log = new AutServerLogger( |
| 42 |
AbstractMenuCAPs.class); |
| 43 |
|
| 44 |
/** |
| 45 |
* @return the log |
| 46 |
*/ |
| 47 |
public static AutServerLogger getLog() { |
| 48 |
return log; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* This method is mostly needed for clicks |
| 53 |
* @return the real table as object |
| 54 |
*/ |
| 55 |
private Object getRealTable() { |
| 56 |
return getComponent().getRealComponent(); |
| 57 |
} |
| 58 |
/** |
| 59 |
* |
| 60 |
* @return the ITableAdapter of this table |
| 61 |
*/ |
| 62 |
private ITableAdapter getTableAdapter() { |
| 63 |
return (ITableAdapter) getComponent(); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Verifies the rendered text inside the currently selected cell. |
| 68 |
* |
| 69 |
* @param text The cell text to verify. |
| 70 |
* @throws StepExecutionException |
| 71 |
* If there is no selected cell, or if the rendered text cannot |
| 72 |
* be extracted. |
| 73 |
*/ |
| 74 |
public void gdVerifyText(String text) |
| 75 |
throws StepExecutionException { |
| 76 |
|
| 77 |
gdVerifyText(text, MatchUtil.DEFAULT_OPERATOR); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Verifies the rendered text inside the currently selected cell. |
| 82 |
* @param text The cell text to verify. |
| 83 |
* @param operator The operation used to verify |
| 84 |
* @throws StepExecutionException If there is no selected cell, or if the rendered text cannot be extracted. |
| 85 |
*/ |
| 86 |
public void gdVerifyText(String text, String operator) |
| 87 |
throws StepExecutionException { |
| 88 |
ITableAdapter adapter = getTableAdapter(); |
| 89 |
Cell cell = adapter.getSelectedCell(); |
| 90 |
final int implRow = cell.getRow(); |
| 91 |
final int implCol = cell.getCol(); |
| 92 |
checkRowColBounds(implRow, implCol); |
| 93 |
|
| 94 |
adapter.scrollCellToVisible(implRow, implCol); |
| 95 |
final String current = getCellText(implRow, implCol); |
| 96 |
Verifier.match(current, text, operator); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Verifies the rendered text inside the passed cell. |
| 101 |
* @param row The row of the cell. |
| 102 |
* @param rowOperator The row header operator |
| 103 |
* @param col The column of the cell. |
| 104 |
* @param colOperator The column header operator |
| 105 |
* @param text The cell text to verify. |
| 106 |
* @param operator The operation used to verify |
| 107 |
* @throws StepExecutionException If the row or the column is invalid, or if the rendered text cannot be extracted. |
| 108 |
*/ |
| 109 |
public void gdVerifyText(String text, String operator, final String row, |
| 110 |
final String rowOperator, final String col, |
| 111 |
final String colOperator) throws StepExecutionException { |
| 112 |
ITableAdapter adapter = getTableAdapter(); |
| 113 |
final int implRow = adapter.getRowFromString(row, rowOperator); |
| 114 |
final int implCol = adapter.getColumnFromString(col, colOperator); |
| 115 |
String current; |
| 116 |
//if row is header and column is existing |
| 117 |
if (implRow == -1 && implCol > -1) { |
| 118 |
current = adapter.getColumnName(implCol); |
| 119 |
} else { |
| 120 |
checkRowColBounds(implRow, implCol); |
| 121 |
adapter.scrollCellToVisible(implRow, implCol); |
| 122 |
current = getCellText(implRow, implCol); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
Verifier.match(current, text, operator); |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* Selects the cell of the Table.<br> |
| 133 |
* With the xPos, yPos, xunits and yUnits the click position inside the cell can be defined. |
| 134 |
* @param row The row of the cell. |
| 135 |
* @param rowOperator The row header operator |
| 136 |
* @param col The column of the cell. |
| 137 |
* @param colOperator The column header operator |
| 138 |
* @param clickCount The number of clicks with the right mouse button |
| 139 |
* @param xPos what x position |
| 140 |
* @param xUnits should x position be pixel or percent values |
| 141 |
* @param yPos what y position |
| 142 |
* @param yUnits should y position be pixel or percent values |
| 143 |
* @param extendSelection Should this selection be part of a multiple selection |
| 144 |
* @param button what mouse button should be used |
| 145 |
* @throws StepExecutionException If the row or the column is invalid |
| 146 |
*/ |
| 147 |
public void gdSelectCell(final String row, final String rowOperator, |
| 148 |
final String col, final String colOperator, |
| 149 |
final int clickCount, final int xPos, final String xUnits, |
| 150 |
final int yPos, final String yUnits, final String extendSelection, |
| 151 |
int button) |
| 152 |
throws StepExecutionException { |
| 153 |
ITableAdapter adapter = getTableAdapter(); |
| 154 |
final int implRow = adapter.getRowFromString(row, rowOperator); |
| 155 |
final int implCol = adapter.getColumnFromString(col, colOperator); |
| 156 |
final boolean isExtendSelection = extendSelection.equals( |
| 157 |
CompSystemConstants.EXTEND_SELECTION_YES); |
| 158 |
if (log.isDebugEnabled()) { |
| 159 |
log.debug("Selecting row, col: " + row + ", " + col); //$NON-NLS-1$//$NON-NLS-2$ |
| 160 |
} |
| 161 |
|
| 162 |
Rectangle cellBounds; |
| 163 |
//if row is header and col is existing |
| 164 |
if (implRow == -1 && implCol > -1) { |
| 165 |
cellBounds = adapter.getHeaderBounds(implCol); |
| 166 |
} else { |
| 167 |
cellBounds = adapter.scrollCellToVisible(implRow, implCol); |
| 168 |
} |
| 169 |
Object o = getSpecificRectangle(cellBounds); |
| 170 |
ClickOptions clickOptions = ClickOptions.create(); |
| 171 |
clickOptions.setClickCount(clickCount).setScrollToVisible(false); |
| 172 |
clickOptions.setMouseButton(button); |
| 173 |
try { |
| 174 |
if (isExtendSelection) { |
| 175 |
getRobot().keyPress(getRealTable(), |
| 176 |
getExtendSelectionModifier()); |
| 177 |
} |
| 178 |
getRobot().click(getRealTable(), o, clickOptions, |
| 179 |
xPos, xUnits.equalsIgnoreCase(POS_UNIT_PIXEL), |
| 180 |
yPos, yUnits.equalsIgnoreCase(POS_UNIT_PIXEL)); |
| 181 |
} finally { |
| 182 |
if (isExtendSelection) { |
| 183 |
getRobot().keyRelease(getRealTable(), |
| 184 |
getExtendSelectionModifier()); |
| 185 |
} |
| 186 |
} |
| 187 |
} |
| 188 |
/** |
| 189 |
* This is a workaround because the toolkit specific |
| 190 |
* Robot implementation are using different rectangle types. |
| 191 |
* @param rectangle the java.awt.rectangle which needs to |
| 192 |
* casted |
| 193 |
* @return the rectangle in the type for the specific robot |
| 194 |
*/ |
| 195 |
protected Object getSpecificRectangle(Rectangle rectangle) { |
| 196 |
//FIXME changing the Robots might be useful here |
| 197 |
return rectangle; |
| 198 |
} |
| 199 |
/** |
| 200 |
* Verifies, if value exists in column. |
| 201 |
* |
| 202 |
* @param col The column of the cell. |
| 203 |
* @param colOperator the column header operator |
| 204 |
* @param value The cell text to verify. |
| 205 |
* @param operator The operation used to verify |
| 206 |
* @param searchType Determines where the search begins ("relative" or "absolute") |
| 207 |
* @param exists true if value exists, false otherwise |
| 208 |
* @throws StepExecutionException |
| 209 |
* If the row or the column is invalid, or if the rendered text |
| 210 |
* cannot be extracted. |
| 211 |
*/ |
| 212 |
public void gdVerifyValueInColumn(final String col, |
| 213 |
final String colOperator, final String value, |
| 214 |
final String operator, final String searchType, boolean exists) |
| 215 |
throws StepExecutionException { |
| 216 |
ITableAdapter adapter = getTableAdapter(); |
| 217 |
final int implCol = adapter.getColumnFromString(col, colOperator); |
| 218 |
|
| 219 |
|
| 220 |
boolean valueExists = isValueExisting(adapter, implCol, |
| 221 |
value, operator, searchType); |
| 222 |
|
| 223 |
Verifier.equals(exists, valueExists); |
| 224 |
} |
| 225 |
/** |
| 226 |
* Looks if value exists in the Column. |
| 227 |
* |
| 228 |
* @param adapter the teble adapter working on. |
| 229 |
* @param implCol the implementation column of the cell. |
| 230 |
* @param value the cellt text to verify. |
| 231 |
* @param operator The operation used to verify. |
| 232 |
* @param searchType searchType Determines where the search begins ("relative" or "absolute") |
| 233 |
* @return <code>true</code> it the value exists in the column |
| 234 |
*/ |
| 235 |
private boolean isValueExisting(ITableAdapter adapter, int implCol, |
| 236 |
String value, String operator, final String searchType) { |
| 237 |
final int rowCount = adapter.getRowCount(); |
| 238 |
for (int i = getStartingRowIndex(searchType); |
| 239 |
i < rowCount; ++i) { |
| 240 |
if (MatchUtil.getInstance().match(getCellText(i, |
| 241 |
implCol), value, operator)) { |
| 242 |
return true; |
| 243 |
} |
| 244 |
} |
| 245 |
if (adapter.isHeaderVisible()) { |
| 246 |
String header = adapter.getColumnName(implCol); |
| 247 |
if (MatchUtil.getInstance().match(header, value, |
| 248 |
operator)) { |
| 249 |
return true; |
| 250 |
} |
| 251 |
} |
| 252 |
return false; |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
/** |
| 258 |
* Verifies, if value exists in row.. |
| 259 |
* |
| 260 |
* @param row The row of the cell. |
| 261 |
* @param rowOperator the row header operator |
| 262 |
* @param value The cell text to verify. |
| 263 |
* @param operator The operation used to verify |
| 264 |
* @param searchType Determines where the search begins ("relative" or "absolute") |
| 265 |
* @param exists true if value exists, false otherwise |
| 266 |
* @throws StepExecutionException |
| 267 |
* If the row or the column is invalid, or if the rendered text |
| 268 |
* cannot be extracted. |
| 269 |
*/ |
| 270 |
public void gdVerifyValueInRow(final String row, final String rowOperator, |
| 271 |
final String value, final String operator, final String searchType, |
| 272 |
boolean exists) |
| 273 |
throws StepExecutionException { |
| 274 |
final ITableAdapter adapter = getTableAdapter(); |
| 275 |
final int implRow = adapter.getRowFromString(row, rowOperator); |
| 276 |
boolean valueIsExisting = false; |
| 277 |
//if row is header |
| 278 |
if (implRow == -1) { |
| 279 |
|
| 280 |
for (int k = getStartingColIndex(searchType); |
| 281 |
k < adapter.getColumnCount(); ++k) { |
| 282 |
if (MatchUtil.getInstance().match( |
| 283 |
adapter.getColumnName(k), |
| 284 |
value, operator)) { |
| 285 |
valueIsExisting = true; |
| 286 |
break; |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
} else { |
| 292 |
|
| 293 |
final int columnCount = adapter.getColumnCount(); |
| 294 |
if (columnCount > 0) { |
| 295 |
for (int i = getStartingColIndex(searchType); |
| 296 |
i < columnCount; ++i) { |
| 297 |
if (MatchUtil.getInstance().match( |
| 298 |
getCellText(implRow, i), value, operator)) { |
| 299 |
valueIsExisting = true; |
| 300 |
break; |
| 301 |
} |
| 302 |
} |
| 303 |
} else { |
| 304 |
// No columns found. This table is used to present a |
| 305 |
// list-like component. |
| 306 |
if (MatchUtil.getInstance().match( |
| 307 |
adapter.getRowName(implRow), |
| 308 |
value, operator)) { |
| 309 |
valueIsExisting = true; |
| 310 |
|
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
} |
| 315 |
Verifier.equals(exists, valueIsExisting); |
| 316 |
} |
| 317 |
|
| 318 |
/** |
| 319 |
* Verifies the editable property of the given indices. |
| 320 |
* |
| 321 |
* @param editable |
| 322 |
* The editable property to verify. |
| 323 |
* @param row the row to select |
| 324 |
* @param rowOperator the row header operator |
| 325 |
* @param col the column to select |
| 326 |
* @param colOperator the column header operator |
| 327 |
*/ |
| 328 |
public void gdVerifyEditable(boolean editable, String row, |
| 329 |
String rowOperator, String col, String colOperator) { |
| 330 |
//if row is header row |
| 331 |
|
| 332 |
if (getTableAdapter().getRowFromString(row, rowOperator) == -1) { |
| 333 |
throw new StepExecutionException("Unsupported Header Action", //$NON-NLS-1$ |
| 334 |
EventFactory.createActionError( |
| 335 |
TestErrorEvent.UNSUPPORTED_HEADER_ACTION)); |
| 336 |
} |
| 337 |
gdSelectCell(row, rowOperator, col, colOperator, ClickOptions.create(), |
| 338 |
CompSystemConstants.EXTEND_SELECTION_NO); |
| 339 |
gdVerifyEditable(editable); |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
/** |
| 344 |
* Selects a table cell in the given row and column via click in the midle of the cell. |
| 345 |
* @param row The row of the cell. |
| 346 |
* @param rowOperator The row header operator |
| 347 |
* @param col The column of the cell. |
| 348 |
* @param colOperator The column header operator |
| 349 |
* @param co the click options to use |
| 350 |
* @param extendSelection Should this selection be part of a multiple selection |
| 351 |
*/ |
| 352 |
private void gdSelectCell(final String row, final String rowOperator, |
| 353 |
final String col, final String colOperator, |
| 354 |
final ClickOptions co, final String extendSelection) { |
| 355 |
|
| 356 |
gdSelectCell(row, rowOperator, col, colOperator, co.getClickCount(), |
| 357 |
50, POS_UNI_PERCENT, 50, POS_UNI_PERCENT, extendSelection, |
| 358 |
co.getMouseButton()); |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
/** |
| 363 |
* Verifies the rendered text inside cell at the mouse position on screen. |
| 364 |
* |
| 365 |
* @param text The cell text to verify. |
| 366 |
* @param operator The operation used to verify |
| 367 |
* @throws StepExecutionException If there is no selected cell, or if the |
| 368 |
* rendered text cannot be extracted. |
| 369 |
*/ |
| 370 |
public void gdVerifyTextAtMousePosition(String text, String operator) |
| 371 |
throws StepExecutionException { |
| 372 |
if (isMouseOnHeader()) { |
| 373 |
throw new StepExecutionException("Unsupported Header Action", //$NON-NLS-1$ |
| 374 |
EventFactory.createActionError( |
| 375 |
TestErrorEvent.UNSUPPORTED_HEADER_ACTION)); |
| 376 |
} |
| 377 |
Cell cell = getCellAtMousePosition(); |
| 378 |
gdVerifyText(text, operator, |
| 379 |
Integer.toString(IndexConverter.toUserIndex(cell.getRow())), |
| 380 |
MatchUtil.EQUALS, |
| 381 |
Integer.toString(IndexConverter.toUserIndex(cell.getCol())), |
| 382 |
MatchUtil.EQUALS); |
| 383 |
} |
| 384 |
|
| 385 |
/** |
| 386 |
* Verifies the editable property of the selected cell. |
| 387 |
* |
| 388 |
* @param editable the editable property to verify. |
| 389 |
*/ |
| 390 |
public void gdVerifyEditableSelected(boolean editable) { |
| 391 |
gdVerifyEditable(editable); |
| 392 |
} |
| 393 |
|
| 394 |
/** |
| 395 |
* Verifies the editable property of the current selected cell. |
| 396 |
* |
| 397 |
* @param editable The editable property to verify. |
| 398 |
*/ |
| 399 |
public void gdVerifyEditable(boolean editable) { |
| 400 |
Cell cell = getTableAdapter().getSelectedCell(); |
| 401 |
|
| 402 |
Verifier.equals(editable, getTableAdapter() |
| 403 |
.isCellEditable(cell.getRow(), cell.getCol())); |
| 404 |
} |
| 405 |
|
| 406 |
/** |
| 407 |
* Verifies the editable property of the cell under current mouse position. |
| 408 |
* |
| 409 |
* @param editable the editable property to verify. |
| 410 |
*/ |
| 411 |
public void gdVerifyEditableMousePosition(boolean editable) { |
| 412 |
//if row is header row |
| 413 |
if (isMouseOnHeader()) { |
| 414 |
throw new StepExecutionException("Unsupported Header Action", //$NON-NLS-1$ |
| 415 |
EventFactory.createActionError( |
| 416 |
TestErrorEvent.UNSUPPORTED_HEADER_ACTION)); |
| 417 |
} |
| 418 |
Cell cell = getCellAtMousePosition(); |
| 419 |
boolean isEditable = getTableAdapter().isCellEditable( |
| 420 |
cell.getRow(), cell.getCol()); |
| 421 |
Verifier.equals(editable, isEditable); |
| 422 |
} |
| 423 |
/** |
| 424 |
* Finds the first row which contains the value <code>value</code> |
| 425 |
* in column <code>col</code> and selects this row. |
| 426 |
* @param col the column |
| 427 |
* @param colOperator the column header operator |
| 428 |
* @param value the value |
| 429 |
* @param clickCount the number of clicks. |
| 430 |
* @param regexOp the regex operator |
| 431 |
* @param extendSelection Should this selection be part of a multiple selection |
| 432 |
* @param searchType Determines where the search begins ("relative" or "absolute") |
| 433 |
* @param button what mouse button should be used |
| 434 |
*/ |
| 435 |
public void gdSelectRowByValue(String col, String colOperator, |
| 436 |
final String value, final String regexOp, int clickCount, |
| 437 |
final String extendSelection, final String searchType, int button) { |
| 438 |
gdSelectRowByValue(col, colOperator, value, regexOp, extendSelection, |
| 439 |
searchType, ClickOptions.create() |
| 440 |
.setClickCount(clickCount) |
| 441 |
.setMouseButton(button)); |
| 442 |
} |
| 443 |
|
| 444 |
/** |
| 445 |
* Finds the first row which contains the value <code>value</code> |
| 446 |
* in column <code>col</code> and selects this row. |
| 447 |
* |
| 448 |
* @param col the column |
| 449 |
* @param colOperator the column header operator |
| 450 |
* @param value the value |
| 451 |
* @param regexOp the regex operator |
| 452 |
* @param extendSelection Should this selection be part of a multiple selection |
| 453 |
* @param searchType Determines where the search begins ("relative" or "absolute") |
| 454 |
* @param co the clickOptions to use |
| 455 |
*/ |
| 456 |
protected void gdSelectRowByValue(String col, String colOperator, |
| 457 |
final String value, final String regexOp, final String extendSelection, |
| 458 |
final String searchType, ClickOptions co) { |
| 459 |
ITableAdapter adapter = getTableAdapter(); |
| 460 |
final int implCol = adapter.getColumnFromString(col, colOperator); |
| 461 |
Integer implRow = null; |
| 462 |
final int rowCount = adapter.getRowCount(); |
| 463 |
|
| 464 |
for (int i = getStartingRowIndex(searchType); i < rowCount; ++i) { |
| 465 |
if (MatchUtil.getInstance().match(getCellText(i, implCol), |
| 466 |
value, regexOp)) { |
| 467 |
|
| 468 |
implRow = new Integer(i); |
| 469 |
break; |
| 470 |
} |
| 471 |
} |
| 472 |
if (implRow == null) { |
| 473 |
String header = adapter.getColumnName(implCol); |
| 474 |
if (MatchUtil.getInstance().match(header, value, regexOp)) { |
| 475 |
implRow = new Integer(-1); |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
if (implRow == null) { |
| 480 |
throw new StepExecutionException("no such row found", //$NON-NLS-1$ |
| 481 |
EventFactory.createActionError(TestErrorEvent.NOT_FOUND)); |
| 482 |
} |
| 483 |
|
| 484 |
String userIdxRow = new Integer(IndexConverter.toUserIndex( |
| 485 |
implRow.intValue())).toString(); |
| 486 |
String userIdxCol = new Integer(IndexConverter.toUserIndex( |
| 487 |
implCol)).toString(); |
| 488 |
|
| 489 |
gdSelectCell(userIdxRow, MatchUtil.EQUALS, userIdxCol, colOperator, co, |
| 490 |
extendSelection); |
| 491 |
} |
| 492 |
|
| 493 |
/** |
| 494 |
* Finds the first column which contains the value <code>value</code> |
| 495 |
* in the given row and selects the cell. |
| 496 |
* |
| 497 |
* @param row the row to select |
| 498 |
* @param rowOperator the row header operator |
| 499 |
* @param value the value |
| 500 |
* @param clickCount the number of clicks |
| 501 |
* @param regex search using regex |
| 502 |
* @param extendSelection Should this selection be part of a multiple selection |
| 503 |
* @param searchType Determines where the search begins ("relative" or "absolute") |
| 504 |
* @param button what mouse button should be used |
| 505 |
*/ |
| 506 |
public void gdSelectCellByColValue(String row, String rowOperator, |
| 507 |
final String value, final String regex, int clickCount, |
| 508 |
final String extendSelection, final String searchType, int button) { |
| 509 |
gdSelectCellByColValue(row, rowOperator, value, regex, extendSelection, |
| 510 |
searchType, ClickOptions.create() |
| 511 |
.setClickCount(clickCount) |
| 512 |
.setMouseButton(button)); |
| 513 |
} |
| 514 |
|
| 515 |
/** |
| 516 |
* Finds the first column which contains the value <code>value</code> |
| 517 |
* in the given row and selects the cell. |
| 518 |
* |
| 519 |
* @param row the row |
| 520 |
* @param rowOperator the row header operator |
| 521 |
* @param value the value |
| 522 |
* @param regex search using regex |
| 523 |
* @param extendSelection Should this selection be part of a multiple selection |
| 524 |
* @param searchType Determines where the search begins ("relative" or "absolute") |
| 525 |
* @param co the click options to use |
| 526 |
*/ |
| 527 |
protected void gdSelectCellByColValue(String row, String rowOperator, |
| 528 |
final String value, final String regex, final String extendSelection, |
| 529 |
final String searchType, ClickOptions co) { |
| 530 |
ITableAdapter adapter = getTableAdapter(); |
| 531 |
final int implRow = adapter.getRowFromString(row, rowOperator); |
| 532 |
int colCount = adapter.getColumnCount(); |
| 533 |
Integer implCol = null; |
| 534 |
if (implRow == -1) { |
| 535 |
|
| 536 |
for (int i = getStartingColIndex(searchType); i < colCount; ++i) { |
| 537 |
if (MatchUtil.getInstance().match(adapter.getColumnName(i), |
| 538 |
value, regex)) { |
| 539 |
implCol = new Integer(i); |
| 540 |
break; |
| 541 |
} |
| 542 |
} |
| 543 |
} else { |
| 544 |
for (int i = getStartingColIndex(searchType); i < colCount; ++i) { |
| 545 |
if (MatchUtil.getInstance().match(getCellText(implRow, i), |
| 546 |
value, regex)) { |
| 547 |
|
| 548 |
implCol = new Integer(i); |
| 549 |
break; |
| 550 |
} |
| 551 |
} |
| 552 |
} |
| 553 |
if (implCol == null) { |
| 554 |
throw new StepExecutionException("no such cell found", EventFactory //$NON-NLS-1$ |
| 555 |
.createActionError(TestErrorEvent.NOT_FOUND)); |
| 556 |
} |
| 557 |
|
| 558 |
String usrIdxRowStr = new Integer(IndexConverter.toUserIndex( |
| 559 |
implRow)).toString(); |
| 560 |
String usrIdxColStr = new Integer(IndexConverter.toUserIndex( |
| 561 |
implCol.intValue())).toString(); |
| 562 |
|
| 563 |
gdSelectCell(usrIdxRowStr, rowOperator, usrIdxColStr, MatchUtil.EQUALS, |
| 564 |
co, extendSelection); |
| 565 |
|
| 566 |
} |
| 567 |
|
| 568 |
/** |
| 569 |
* Action to read the value of the current selected cell of the JTable |
| 570 |
* to store it in a variable in the Client |
| 571 |
* @param variable the name of the variable |
| 572 |
* @return the text value. |
| 573 |
*/ |
| 574 |
public String gdReadValue(String variable) { |
| 575 |
final Cell selectedCell = getTableAdapter().getSelectedCell(); |
| 576 |
return getCellText(selectedCell.getRow(), selectedCell.getCol()); |
| 577 |
} |
| 578 |
|
| 579 |
/** |
| 580 |
* Action to read the value of the passed cell of the JTable |
| 581 |
* to store it in a variable in the Client |
| 582 |
* @param variable the name of the variable |
| 583 |
* @param row the row to select |
| 584 |
* @param rowOperator the row header operator |
| 585 |
* @param col the column to select |
| 586 |
* @param colOperator the column header operator |
| 587 |
* @return the text value. |
| 588 |
*/ |
| 589 |
public String gdReadValue(String variable, String row, String rowOperator, |
| 590 |
String col, String colOperator) { |
| 591 |
ITableAdapter adapter = getTableAdapter(); |
| 592 |
final int implRow = adapter.getRowFromString(row, rowOperator); |
| 593 |
final int implCol = adapter.getColumnFromString(col, colOperator); |
| 594 |
|
| 595 |
//if row is header and column is existing |
| 596 |
if (implRow == -1 && implCol > -1) { |
| 597 |
return adapter.getColumnName(implCol); |
| 598 |
} |
| 599 |
|
| 600 |
checkRowColBounds(implRow, implCol); |
| 601 |
|
| 602 |
adapter.scrollCellToVisible(implRow, implCol); |
| 603 |
return getCellText(implRow, implCol); |
| 604 |
} |
| 605 |
|
| 606 |
/** |
| 607 |
* {@inheritDoc} |
| 608 |
*/ |
| 609 |
public String gdReadValueAtMousePosition(String variable) { |
| 610 |
Cell cellAtMousePosition = getTableAdapter().getSelectedCell(); |
| 611 |
return getCellText(cellAtMousePosition.getRow(), |
| 612 |
cellAtMousePosition.getCol()); |
| 613 |
} |
| 614 |
|
| 615 |
/** |
| 616 |
* Tries to click in the cell under the mouse position. If the mouse is not |
| 617 |
* over a cell, the current selected cell will be clicked on. If there is no |
| 618 |
* selected cell, the middle of the table is used to click on. |
| 619 |
* @param count Number of clicks |
| 620 |
* @param button The mouse button |
| 621 |
*/ |
| 622 |
public void gdClick(int count, int button) { |
| 623 |
ITableAdapter adapter = getTableAdapter(); |
| 624 |
Cell cell = null; |
| 625 |
if (isMouseOverCell()) { |
| 626 |
cell = getCellAtMousePosition(); |
| 627 |
} else if (adapter.hasCellSelection()) { |
| 628 |
cell = adapter.getSelectedCell(); |
| 629 |
} |
| 630 |
if (cell != null) { |
| 631 |
Rectangle cellRect = |
| 632 |
adapter.scrollCellToVisible(cell.getRow(), cell.getCol()); |
| 633 |
getRobot().click(getRealTable(), cellRect, ClickOptions.create() |
| 634 |
.setClickCount(count).setMouseButton(button)); |
| 635 |
} else { |
| 636 |
super.gdClick(count, button); |
| 637 |
} |
| 638 |
} |
| 639 |
|
| 640 |
/** |
| 641 |
* Selects a cell relative to the cell at the current mouse position. |
| 642 |
* If the mouse is not at any cell, the current selected cell is used. |
| 643 |
* @param direction the direction to move. |
| 644 |
* @param cellCount the amount of cells to move |
| 645 |
* @param clickCount the click count to select the new cell. |
| 646 |
* @param xPos what x position |
| 647 |
* @param xUnits should x position be pixel or percent values |
| 648 |
* @param yPos what y position |
| 649 |
* @param yUnits should y position be pixel or percent values |
| 650 |
* @param extendSelection Should this selection be part of a multiple selection |
| 651 |
* @throws StepExecutionException if any error occurs |
| 652 |
*/ |
| 653 |
public void gdMove(String direction, int cellCount, int clickCount, |
| 654 |
final int xPos, final String xUnits, |
| 655 |
final int yPos, final String yUnits, final String extendSelection) |
| 656 |
throws StepExecutionException { |
| 657 |
if (isMouseOnHeader()) { |
| 658 |
throw new StepExecutionException("Unsupported Header Action", //$NON-NLS-1$ |
| 659 |
EventFactory.createActionError( |
| 660 |
TestErrorEvent.UNSUPPORTED_HEADER_ACTION)); |
| 661 |
} |
| 662 |
Cell currCell = null; |
| 663 |
try { |
| 664 |
currCell = getCellAtMousePosition(); |
| 665 |
} catch (StepExecutionException e) { |
| 666 |
currCell = getTableAdapter().getSelectedCell(); |
| 667 |
} |
| 668 |
int newCol = currCell.getCol(); |
| 669 |
int newRow = currCell.getRow(); |
| 670 |
if (CompSystemConstants.TABLE_MOVE_UP |
| 671 |
.equalsIgnoreCase(direction)) { |
| 672 |
newRow -= cellCount; |
| 673 |
} else if (CompSystemConstants.TABLE_MOVE_DOWN |
| 674 |
.equalsIgnoreCase(direction)) { |
| 675 |
newRow += cellCount; |
| 676 |
} else if (CompSystemConstants.TABLE_MOVE_LEFT |
| 677 |
.equalsIgnoreCase(direction)) { |
| 678 |
newCol -= cellCount; |
| 679 |
} else if (CompSystemConstants.TABLE_MOVE_RIGHT |
| 680 |
.equalsIgnoreCase(direction)) { |
| 681 |
newCol += cellCount; |
| 682 |
} |
| 683 |
newRow = IndexConverter.toUserIndex(newRow); |
| 684 |
newCol = IndexConverter.toUserIndex(newCol); |
| 685 |
String row = Integer.toString(newRow); |
| 686 |
String col = Integer.toString(newCol); |
| 687 |
gdSelectCell(row, MatchUtil.DEFAULT_OPERATOR , col, |
| 688 |
MatchUtil.DEFAULT_OPERATOR, clickCount, xPos, |
| 689 |
xUnits, yPos, yUnits, extendSelection, |
| 690 |
InputConstants.MOUSE_BUTTON_LEFT); |
| 691 |
// gdSelectCell(newRow, newCol, clickCount, |
| 692 |
// xPos, xUnits, yPos, yUnits, extendSelection); |
| 693 |
} |
| 694 |
|
| 695 |
/** |
| 696 |
* Writes the passed text into the currently selected cell. |
| 697 |
* |
| 698 |
* @param text |
| 699 |
* The text. |
| 700 |
* @throws StepExecutionException |
| 701 |
* If there is no selected cell, or if the cell is not editable, |
| 702 |
* or if the table cell editor permits the text to be written. |
| 703 |
*/ |
| 704 |
public void gdInputText(final String text) throws StepExecutionException { |
| 705 |
inputText(text, false); |
| 706 |
} |
| 707 |
|
| 708 |
/** |
| 709 |
* Types the text in the specified cell. |
| 710 |
* @param text The text |
| 711 |
* @param row The row of the cell. |
| 712 |
* @param rowOperator The row operator |
| 713 |
* @param col The column of the cell. |
| 714 |
* @param colOperator The column operator |
| 715 |
* @throws StepExecutionException If the text input fails |
| 716 |
*/ |
| 717 |
public void gdInputText(String text, String row, String rowOperator, |
| 718 |
String col, String colOperator) |
| 719 |
throws StepExecutionException { |
| 720 |
//if row is header row |
| 721 |
if (getTableAdapter().getRowFromString(row, rowOperator) == -1) { |
| 722 |
throw new StepExecutionException("Unsupported Header Action", //$NON-NLS-1$ |
| 723 |
EventFactory.createActionError( |
| 724 |
TestErrorEvent.UNSUPPORTED_HEADER_ACTION)); |
| 725 |
} |
| 726 |
gdSelectCell(row, rowOperator, col, colOperator, |
| 727 |
ClickOptions.create().setClickCount(1), |
| 728 |
CompSystemConstants.EXTEND_SELECTION_NO); |
| 729 |
gdInputText(text); |
| 730 |
} |
| 731 |
|
| 732 |
/** |
| 733 |
* Types <code>text</code> into the component. This replaces the shown |
| 734 |
* content in the current selected cell. |
| 735 |
* |
| 736 |
* @param text the text to type in |
| 737 |
* @throws StepExecutionException |
| 738 |
* If there is no selected cell, or if the cell is not editable, |
| 739 |
* or if the table cell editor permits the text to be written. |
| 740 |
*/ |
| 741 |
public void gdReplaceText(String text) throws StepExecutionException { |
| 742 |
inputText(text, true); |
| 743 |
} |
| 744 |
|
| 745 |
/** |
| 746 |
* Replaces the given text in the given cell coordinates |
| 747 |
* @param text the text to replace |
| 748 |
* @param row The row of the cell. |
| 749 |
* @param rowOperator The row operator |
| 750 |
* @param col The column of the cell. |
| 751 |
* @param colOperator The column operator |
| 752 |
*/ |
| 753 |
public void gdReplaceText(String text, String row, String rowOperator, |
| 754 |
String col, String colOperator) { |
| 755 |
//if row is header row |
| 756 |
if (getTableAdapter().getRowFromString(row, rowOperator) == -1) { |
| 757 |
throw new StepExecutionException("Unsupported Header Action", //$NON-NLS-1$ |
| 758 |
EventFactory.createActionError( |
| 759 |
TestErrorEvent.UNSUPPORTED_HEADER_ACTION)); |
| 760 |
} |
| 761 |
gdSelectCell(row, rowOperator, col, colOperator, |
| 762 |
ClickOptions.create().setClickCount(1), |
| 763 |
CompSystemConstants.EXTEND_SELECTION_NO); |
| 764 |
inputText(text, true); |
| 765 |
} |
| 766 |
|
| 767 |
/** |
| 768 |
* Drags the cell of the Table.<br> |
| 769 |
* With the xPos, yPos, xunits and yUnits the click position inside the |
| 770 |
* cell can be defined. |
| 771 |
* |
| 772 |
* @param mouseButton the mouseButton. |
| 773 |
* @param modifier the modifier. |
| 774 |
* @param row the row to select |
| 775 |
* @param rowOperator the row header operator |
| 776 |
* @param col the column to select |
| 777 |
* @param colOperator the column header operator |
| 778 |
* @param xPos what x position |
| 779 |
* @param xUnits should x position be pixel or percent values |
| 780 |
* @param yPos what y position |
| 781 |
* @param yUnits should y position be pixel or percent values |
| 782 |
* @throws StepExecutionException |
| 783 |
* If the row or the column is invalid |
| 784 |
*/ |
| 785 |
public void gdDragCell(final int mouseButton, final String modifier, |
| 786 |
final String row, final String rowOperator, |
| 787 |
final String col, final String colOperator, final int xPos, |
| 788 |
final String xUnits, final int yPos, final String yUnits) |
| 789 |
throws StepExecutionException { |
| 790 |
|
| 791 |
final DragAndDropHelper dndHelper = DragAndDropHelper.getInstance(); |
| 792 |
dndHelper.setModifier(modifier); |
| 793 |
dndHelper.setMouseButton(mouseButton); |
| 794 |
dndHelper.setDragComponent(null); |
| 795 |
gdSelectCell(row, rowOperator, col, colOperator, 0, xPos, xUnits, yPos, |
| 796 |
yUnits, CompSystemConstants.EXTEND_SELECTION_NO, 1); |
| 797 |
pressOrReleaseModifiers(modifier, true); |
| 798 |
getRobot().mousePress(null, null, mouseButton); |
| 799 |
} |
| 800 |
|
| 801 |
/** |
| 802 |
* Drops on the cell of the JTable.<br> |
| 803 |
* With the xPos, yPos, xunits and yUnits the click position inside the |
| 804 |
* cell can be defined. |
| 805 |
* |
| 806 |
* @param row the row to select |
| 807 |
* @param rowOperator the row header operator |
| 808 |
* @param col the column to select |
| 809 |
* @param colOperator the column header operator |
| 810 |
* @param xPos what x position |
| 811 |
* @param xUnits should x position be pixel or percent values |
| 812 |
* @param yPos what y position |
| 813 |
* @param yUnits should y position be pixel or percent values |
| 814 |
* @param delayBeforeDrop the amount of time (in milliseconds) to wait |
| 815 |
* between moving the mouse to the drop point and |
| 816 |
* releasing the mouse button |
| 817 |
* @throws StepExecutionException |
| 818 |
* If the row or the column is invalid |
| 819 |
*/ |
| 820 |
public void gdDropCell(final String row, final String rowOperator, |
| 821 |
final String col, final String colOperator, final int xPos, |
| 822 |
final String xUnits, final int yPos, final String yUnits, |
| 823 |
int delayBeforeDrop) throws StepExecutionException { |
| 824 |
|
| 825 |
final DragAndDropHelper dndHelper = DragAndDropHelper.getInstance(); |
| 826 |
try { |
| 827 |
gdSelectCell(row, rowOperator, col, colOperator, 0, xPos, xUnits, |
| 828 |
yPos, yUnits, CompSystemConstants.EXTEND_SELECTION_NO, 1); |
| 829 |
waitBeforeDrop(delayBeforeDrop); |
| 830 |
} finally { |
| 831 |
getRobot().mouseRelease(null, null, dndHelper.getMouseButton()); |
| 832 |
pressOrReleaseModifiers(dndHelper.getModifier(), false); |
| 833 |
} |
| 834 |
} |
| 835 |
|
| 836 |
/** |
| 837 |
* Finds the first row which contains the value <code>value</code> |
| 838 |
* in column <code>col</code> and drags this row. |
| 839 |
* |
| 840 |
* @param mouseButton the mouse button |
| 841 |
* @param modifier the modifier |
| 842 |
* @param col the column |
| 843 |
* @param colOperator the column header operator |
| 844 |
* @param value the value |
| 845 |
* @param regexOp the regex operator |
| 846 |
* @param searchType Determines where the search begins ("relative" or "absolute") |
| 847 |
*/ |
| 848 |
public void gdDragRowByValue(int mouseButton, String modifier, String col, |
| 849 |
String colOperator, final String value, final String regexOp, |
| 850 |
final String searchType) { |
| 851 |
|
| 852 |
final DragAndDropHelper dndHelper = DragAndDropHelper.getInstance(); |
| 853 |
dndHelper.setModifier(modifier); |
| 854 |
dndHelper.setMouseButton(mouseButton); |
| 855 |
gdSelectRowByValue(col, colOperator, value, regexOp, 1, |
| 856 |
CompSystemConstants.EXTEND_SELECTION_NO, searchType, 1); |
| 857 |
pressOrReleaseModifiers(modifier, true); |
| 858 |
getRobot().mousePress(null, null, mouseButton); |
| 859 |
} |
| 860 |
|
| 861 |
/** |
| 862 |
* Finds the first row which contains the value <code>value</code> |
| 863 |
* in column <code>col</code> and drops on this row. |
| 864 |
* |
| 865 |
* @param col the column to select |
| 866 |
* @param colOperator the column header operator |
| 867 |
* @param value the value |
| 868 |
* @param regexOp the regex operator |
| 869 |
* @param searchType Determines where the search begins ("relative" or "absolute") |
| 870 |
* @param delayBeforeDrop the amount of time (in milliseconds) to wait |
| 871 |
* between moving the mouse to the drop point and |
| 872 |
* releasing the mouse button |
| 873 |
*/ |
| 874 |
public void gdDropRowByValue(String col, String colOperator, |
| 875 |
final String value, final String regexOp, final String searchType, |
| 876 |
int delayBeforeDrop) { |
| 877 |
|
| 878 |
final DragAndDropHelper dndHelper = DragAndDropHelper.getInstance(); |
| 879 |
try { |
| 880 |
gdSelectRowByValue(col, colOperator, value, regexOp, |
| 881 |
CompSystemConstants.EXTEND_SELECTION_NO, |
| 882 |
searchType, ClickOptions |
| 883 |
.create().setClickCount(0)); |
| 884 |
waitBeforeDrop(delayBeforeDrop); |
| 885 |
} finally { |
| 886 |
getRobot().mouseRelease(null, null, dndHelper.getMouseButton()); |
| 887 |
pressOrReleaseModifiers(dndHelper.getModifier(), false); |
| 888 |
} |
| 889 |
} |
| 890 |
|
| 891 |
/** |
| 892 |
* Finds the first column which contains the value <code>value</code> |
| 893 |
* in the given row and drags the cell. |
| 894 |
* |
| 895 |
* @param mouseButton the mouse button |
| 896 |
* @param modifier the modifiers |
| 897 |
* @param row the row to select |
| 898 |
* @param rowOperator the row header operator |
| 899 |
* @param value the value |
| 900 |
* @param regex search using regex |
| 901 |
* @param searchType Determines where the search begins ("relative" or "absolute") |
| 902 |
*/ |
| 903 |
public void gdDragCellByColValue(int mouseButton, String modifier, |
| 904 |
String row, String rowOperator, final String value, |
| 905 |
final String regex, final String searchType) { |
| 906 |
|
| 907 |
final DragAndDropHelper dndHelper = DragAndDropHelper.getInstance(); |
| 908 |
dndHelper.setModifier(modifier); |
| 909 |
dndHelper.setMouseButton(mouseButton); |
| 910 |
|
| 911 |
gdSelectCellByColValue(row, rowOperator, value, regex, |
| 912 |
CompSystemConstants.EXTEND_SELECTION_NO, searchType, |
| 913 |
ClickOptions.create().setClickCount(0)); |
| 914 |
pressOrReleaseModifiers(modifier, true); |
| 915 |
getRobot().mousePress(null, null, mouseButton); |
| 916 |
} |
| 917 |
|
| 918 |
/** |
| 919 |
* Finds the first column which contains the value <code>value</code> |
| 920 |
* in the given row and drops on the cell. |
| 921 |
* |
| 922 |
* @param row the row to select |
| 923 |
* @param rowOperator the row header operator |
| 924 |
* @param value the value |
| 925 |
* @param regex search using regex |
| 926 |
* @param searchType Determines where the search begins ("relative" or "absolute") |
| 927 |
* @param delayBeforeDrop the amount of time (in milliseconds) to wait |
| 928 |
* between moving the mouse to the drop point and |
| 929 |
* releasing the mouse button |
| 930 |
*/ |
| 931 |
public void gdDropCellByColValue(String row, String rowOperator, |
| 932 |
final String value, final String regex, final String searchType, |
| 933 |
int delayBeforeDrop) { |
| 934 |
|
| 935 |
final DragAndDropHelper dndHelper = DragAndDropHelper.getInstance(); |
| 936 |
try { |
| 937 |
gdSelectCellByColValue(row, rowOperator, value, regex, |
| 938 |
CompSystemConstants.EXTEND_SELECTION_NO, searchType, |
| 939 |
ClickOptions.create().setClickCount(0)); |
| 940 |
waitBeforeDrop(delayBeforeDrop); |
| 941 |
} finally { |
| 942 |
getRobot().mouseRelease(null, null, dndHelper.getMouseButton()); |
| 943 |
pressOrReleaseModifiers(dndHelper.getModifier(), false); |
| 944 |
} |
| 945 |
} |
| 946 |
|
| 947 |
|
| 948 |
/** |
| 949 |
* Gets the text from the specific cell which is given |
| 950 |
* by the row and the column. |
| 951 |
* @param row the zero based index of the row |
| 952 |
* @param column the zero based index of the column |
| 953 |
* @return the text of the cell of the given coordinates |
| 954 |
*/ |
| 955 |
private String getCellText(final int row, final int column) { |
| 956 |
return getTableAdapter().getCellText(row, column); |
| 957 |
|
| 958 |
} |
| 959 |
|
| 960 |
/** |
| 961 |
* Presses or releases the given modifier. |
| 962 |
* @param modifier the modifier. |
| 963 |
* @param press if true, the modifier will be pressed. |
| 964 |
* if false, the modifier will be released. |
| 965 |
*/ |
| 966 |
protected void pressOrReleaseModifiers(String modifier, boolean press) { |
| 967 |
final IRobot robot = getRobot(); |
| 968 |
final StringTokenizer modTok = new StringTokenizer( |
| 969 |
KeyStrokeUtil.getModifierString(modifier), " "); //$NON-NLS-1$ |
| 970 |
while (modTok.hasMoreTokens()) { |
| 971 |
final String mod = modTok.nextToken(); |
| 972 |
final int keyCode = getKeyCode(mod); |
| 973 |
if (press) { |
| 974 |
robot.keyPress(null, keyCode); |
| 975 |
} else { |
| 976 |
robot.keyRelease(null, keyCode); |
| 977 |
} |
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
/** |
| 982 |
* Gets the key code for a specific modifier |
| 983 |
* @param mod the modifier |
| 984 |
* @return the integer key code value |
| 985 |
*/ |
| 986 |
protected abstract int getKeyCode(String mod); |
| 987 |
|
| 988 |
/** |
| 989 |
* Checks whether <code>0 <= value < count</code>. |
| 990 |
* @param value The value to check. |
| 991 |
* @param count The upper bound. |
| 992 |
*/ |
| 993 |
private void checkBounds(int value, int count) { |
| 994 |
if (value < 0 || value >= count) { |
| 995 |
throw new StepExecutionException("Invalid row/column: " + value, //$NON-NLS-1$ |
| 996 |
EventFactory.createActionError( |
| 997 |
TestErrorEvent.INVALID_INDEX_OR_HEADER)); |
| 998 |
} |
| 999 |
} |
| 1000 |
|
| 1001 |
/** |
| 1002 |
* Checks if the passed row and column are inside the bounds of the Table. |
| 1003 |
* @param row The row |
| 1004 |
* @param column The column |
| 1005 |
* @throws StepExecutionException If the row or the column is outside of the Table's bounds. |
| 1006 |
*/ |
| 1007 |
protected void checkRowColBounds(int row, int column) |
| 1008 |
throws StepExecutionException { |
| 1009 |
ITableAdapter adapter = getTableAdapter(); |
| 1010 |
checkBounds(row, adapter.getRowCount()); |
| 1011 |
|
| 1012 |
// Corner case: Only check the bounds if the table is not being |
| 1013 |
// used as a list or anything other than the first column |
| 1014 |
// is being checked. |
| 1015 |
int colCount = adapter.getColumnCount(); |
| 1016 |
if (colCount > 0 || column > 0) { |
| 1017 |
checkBounds(column, colCount); |
| 1018 |
} |
| 1019 |
} |
| 1020 |
|
| 1021 |
/** |
| 1022 |
* @param searchType Determines column where the search begins ("relative" or "absolute") |
| 1023 |
* @return The index from which to begin a search, based on the search type |
| 1024 |
* and (if appropriate) the currently selected cell. |
| 1025 |
*/ |
| 1026 |
private int getStartingColIndex(String searchType) { |
| 1027 |
int startingIndex = 0; |
| 1028 |
if (searchType.equalsIgnoreCase( |
| 1029 |
CompSystemConstants.SEARCH_TYPE_RELATIVE)) { |
| 1030 |
startingIndex = getTableAdapter().getSelectedCell().getCol() + 1; |
| 1031 |
} |
| 1032 |
return startingIndex; |
| 1033 |
} |
| 1034 |
|
| 1035 |
/** |
| 1036 |
* @param searchType Determines the row where the search begins ("relative" or "absolute") |
| 1037 |
* @return The index from which to begin a search, based on the search type |
| 1038 |
* and (if appropriate) the currently selected cell. |
| 1039 |
*/ |
| 1040 |
private int getStartingRowIndex(String searchType) { |
| 1041 |
int startingIndex = 0; |
| 1042 |
if (searchType.equalsIgnoreCase( |
| 1043 |
CompSystemConstants.SEARCH_TYPE_RELATIVE)) { |
| 1044 |
startingIndex = getTableAdapter().getSelectedCell().getRow() + 1; |
| 1045 |
} |
| 1046 |
return startingIndex; |
| 1047 |
} |
| 1048 |
|
| 1049 |
/** |
| 1050 |
* inputs/replaces the given text |
| 1051 |
* @param text the text to input |
| 1052 |
* @param replace wheter to replace or not |
| 1053 |
* @throws StepExecutionException If there is no selected cell, |
| 1054 |
* or if the cell is not editable, or if the table cell editor permits |
| 1055 |
* the text to be written. |
| 1056 |
*/ |
| 1057 |
private void inputText(final String text, boolean replace) |
| 1058 |
throws StepExecutionException { |
| 1059 |
ITableAdapter adapter = getTableAdapter(); |
| 1060 |
|
| 1061 |
final Cell cell = adapter.getSelectedCell(); |
| 1062 |
// Ensure that the cell is visible. |
| 1063 |
Rectangle rectangle = |
| 1064 |
adapter.scrollCellToVisible(cell.getRow(), cell.getCol()); |
| 1065 |
|
| 1066 |
Object editor = activateEditor(cell, rectangle); |
| 1067 |
editor = setEditorToReplaceMode(editor, replace); |
| 1068 |
|
| 1069 |
getRobot().type(editor, text); |
| 1070 |
} |
| 1071 |
|
| 1072 |
/** |
| 1073 |
* @return true if the mouse pointer is over any cell, false otherwise. |
| 1074 |
*/ |
| 1075 |
private boolean isMouseOverCell() { |
| 1076 |
try { |
| 1077 |
getCellAtMousePosition(); |
| 1078 |
} catch (StepExecutionException se) { |
| 1079 |
return false; |
| 1080 |
} |
| 1081 |
return true; |
| 1082 |
} |
| 1083 |
|
| 1084 |
/** |
| 1085 |
* Waits the given amount of time. Logs a drop-related error if interrupted. |
| 1086 |
* |
| 1087 |
* @param delayBeforeDrop the amount of time (in milliseconds) to wait |
| 1088 |
* between moving the mouse to the drop point and |
| 1089 |
* releasing the mouse button |
| 1090 |
*/ |
| 1091 |
static void waitBeforeDrop(int delayBeforeDrop) { |
| 1092 |
TimeUtil.delay(delayBeforeDrop); |
| 1093 |
} |
| 1094 |
|
| 1095 |
/** |
| 1096 |
* Sets the specific editor to an replace mode. Means that the next key |
| 1097 |
* input will override the complete text of the editor. |
| 1098 |
* @param editor |
| 1099 |
* @param replace if <code>true</code> than the editor has to override |
| 1100 |
* the complete text with the next key input. Else the next |
| 1101 |
* key input will append to the end. |
| 1102 |
* @return the editor if it changed |
| 1103 |
*/ |
| 1104 |
protected abstract Object setEditorToReplaceMode(Object editor, |
| 1105 |
boolean replace); |
| 1106 |
|
| 1107 |
/** |
| 1108 |
* Activates the editor of the specific cell. |
| 1109 |
* @param cell |
| 1110 |
* @param rectangle |
| 1111 |
* @return the editor of the cell |
| 1112 |
*/ |
| 1113 |
protected abstract Object activateEditor(Cell cell, Rectangle rectangle); |
| 1114 |
|
| 1115 |
|
| 1116 |
/** |
| 1117 |
* Gets The modifier for an extended selection (more than one item) |
| 1118 |
* @return the modifier |
| 1119 |
*/ |
| 1120 |
protected abstract int getExtendSelectionModifier(); |
| 1121 |
|
| 1122 |
/** |
| 1123 |
* @return the cell under the current mouse position. |
| 1124 |
* @throws StepExecutionException If no cell is found. |
| 1125 |
*/ |
| 1126 |
protected abstract Cell getCellAtMousePosition() |
| 1127 |
throws StepExecutionException; |
| 1128 |
|
| 1129 |
/** |
| 1130 |
* Verifies if mouse is on header. |
| 1131 |
* @return true if mouse is on header |
| 1132 |
*/ |
| 1133 |
protected abstract boolean isMouseOnHeader(); |
| 1134 |
|
| 1135 |
/** |
| 1136 |
* Selects the passed row of the JTable. This is actually a selection of the |
| 1137 |
* cell <code>(row, 0)</code>. |
| 1138 |
* |
| 1139 |
* @param row |
| 1140 |
* The row |
| 1141 |
* @param extendSelection Should this selection be part of a multiple selection |
| 1142 |
* @throws StepExecutionException |
| 1143 |
* If the row is invalid |
| 1144 |
* @deprecated the same as gdSelectCell |
| 1145 |
* Will be removed! |
| 1146 |
*/ |
| 1147 |
public void gdSelectRow(int row, String extendSelection) |
| 1148 |
throws StepExecutionException { |
| 1149 |
// FIXME this is only here for testing purpose (to get all CaA tests running) |
| 1150 |
gdSelectCell(String.valueOf(row), MatchUtil.DEFAULT_OPERATOR, "1", //$NON-NLS-1$ |
| 1151 |
MatchUtil.DEFAULT_OPERATOR, |
| 1152 |
ClickOptions.create().setClickCount(1), extendSelection); |
| 1153 |
} |
| 1154 |
|
| 1155 |
/** |
| 1156 |
* Finds the first column which contains the value <code>value</code> |
| 1157 |
* in the given row and selects the cell. |
| 1158 |
* |
| 1159 |
* @param row the row |
| 1160 |
* @param value the value |
| 1161 |
* @param clickCount the mouse clicks. |
| 1162 |
* @param regex search using regex |
| 1163 |
* @param extendSelection Should this selection be part of a multiple selection |
| 1164 |
* @param searchType Determines where the search begins ("relative" or "absolute") |
| 1165 |
* @deprecated Will be removed with gdSelectCellByColValue with String parameter |
| 1166 |
* for Row/Column |
| 1167 |
*/ |
| 1168 |
public void gdSelectCellByColValue(int row, final String value, |
| 1169 |
final String regex, int clickCount, final String extendSelection, |
| 1170 |
final String searchType) { |
| 1171 |
// FIXME this is only here for testing purpose (to get all CaA tests running) |
| 1172 |
gdSelectCellByColValue(String.valueOf(row), MatchUtil.DEFAULT_OPERATOR, |
| 1173 |
value, regex, clickCount, extendSelection, searchType, 1); |
| 1174 |
|
| 1175 |
} |
| 1176 |
|
| 1177 |
/** |
| 1178 |
* Finds the first row which contains the value <code>value</code> |
| 1179 |
* in column <code>col</code> and selects this row. |
| 1180 |
* @param col the column |
| 1181 |
* @param value the value |
| 1182 |
* @param clickCount the number of clicks. |
| 1183 |
* @param regexOp the regex operator |
| 1184 |
* @param extendSelection Should this selection be part of a multiple selection |
| 1185 |
* @param searchType Determines where the search begins ("relative" or "absolute") |
| 1186 |
* @deprecated Will be removed with gdSelectRowByValue with String parameter |
| 1187 |
* for Row/Column |
| 1188 |
*/ |
| 1189 |
public void gdSelectRowByValue(int col, final String value, |
| 1190 |
int clickCount, final String regexOp, final String extendSelection, |
| 1191 |
final String searchType) { |
| 1192 |
// FIXME this is only here for testing purpose (to get all CaA tests running) |
| 1193 |
gdSelectRowByValue(String.valueOf(col), MatchUtil.DEFAULT_OPERATOR, |
| 1194 |
value, regexOp, clickCount, extendSelection, searchType, 1); |
| 1195 |
} |
| 1196 |
} |