final FindWindow win = new FindWindow(sh);
UXWindowsUtil.screenCenter(win);
win.setFindAction(new UXAbstractAction() {
@Override
public void doAction() {
TabItem tab = TabPanelManager.instance().getActiveTab();
SearchEntity sEntity = new SearchEntity(
tab.getText(),
win.getPattern(),
win.isRegx(),
win.isCaseSensitive());
SearchResult rs;
try {
rs = SearchService.instance().compileSearch(sEntity);
} catch (ServiceException e) {
BaseController.instance().showErrorMessage(e);
return;
}
int ccPos = tab.getCarretPosition();
SearchResult.SearchRangeResult srr = null;
Iterator<SearchRangeResult> it = rs.getIterator();
if (!it.hasNext()) {
BaseController.instance().showWarningMessage("String not found");
return;
}
boolean wasFound = false;
while (it.hasNext()) {
srr = it.next();
if (win.getDirection() == FindWindow.DIRECTION_UP) {
if (srr.start < ccPos) {
wasFound = true;
tab.select(srr.start, srr.end);
break;
}
} else {
if (srr.start >= ccPos) {
wasFound = true;
tab.select(srr.start, srr.end);
break;
}
}
}