ILayer contextLayer = getContextLayer();
if (!(contextLayer instanceof SelectionLayer)) {
throw new RuntimeException(
"For the GridSearchStrategy to work it needs the selectionLayer to be passed as the contextLayer."); //$NON-NLS-1$
}
SelectionLayer selectionLayer = (SelectionLayer) contextLayer;
PositionCoordinate selectionAnchor = selectionLayer
.getSelectionAnchor();
boolean hadSelectionAnchor = selectionAnchor.columnPosition >= 0
&& selectionAnchor.rowPosition >= 0;
if (!hadSelectionAnchor) {
selectionAnchor.columnPosition = 0;
selectionAnchor.rowPosition = 0;
}
// Pick a first and second dimension based on whether it's a column or
// row-first search.
int firstDimPosition;
int firstDimCount;
int secondDimPosition;
int secondDimCount;
if (columnFirst) {
firstDimPosition = selectionAnchor.columnPosition;
firstDimCount = selectionLayer.getColumnCount();
secondDimPosition = selectionAnchor.rowPosition;
secondDimCount = selectionLayer.getRowCount();
} else {
firstDimPosition = selectionAnchor.rowPosition;
firstDimCount = selectionLayer.getRowCount();
secondDimPosition = selectionAnchor.columnPosition;
secondDimCount = selectionLayer.getColumnCount();
}
// Pick start and end values depending on the direction of the search.
int direction = searchDirection.equals(ISearchDirection.SEARCH_FORWARD) ? 1
: -1;