Search in sources :

Example 6 with GridPos

use of org.jkiss.dbeaver.ui.controls.lightgrid.GridPos in project dbeaver by dbeaver.

the class SpreadsheetFindReplaceTarget method replaceSelection.

@Override
public void replaceSelection(String text, boolean regExReplace) {
    GridPos selection = (GridPos) owner.getSelection().getFirstElement();
    if (selection == null) {
        return;
    }
    GridCell cell = owner.getSpreadsheet().posToCell(selection);
    if (cell == null) {
        return;
    }
    String oldValue = CommonUtils.toString(owner.getSpreadsheet().getContentProvider().getCellValue(cell.col, cell.row, true, true));
    String newValue = text;
    if (searchPattern != null) {
        newValue = searchPattern.matcher(oldValue).replaceAll(newValue);
    }
    boolean recordMode = owner.getController().isRecordMode();
    final DBDAttributeBinding attr = (DBDAttributeBinding) (recordMode ? cell.row : cell.col);
    final ResultSetRow row = (ResultSetRow) (recordMode ? cell.col : cell.row);
    owner.getController().getModel().updateCellValue(attr, row, newValue);
    owner.getController().updatePanelsContent(false);
}
Also used : GridPos(org.jkiss.dbeaver.ui.controls.lightgrid.GridPos) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) GridCell(org.jkiss.dbeaver.ui.controls.lightgrid.GridCell)

Example 7 with GridPos

use of org.jkiss.dbeaver.ui.controls.lightgrid.GridPos in project dbeaver by serge-rider.

the class SpreadsheetPresentation method scrollToRow.

public void scrollToRow(@NotNull RowPosition position) {
    boolean recordMode = controller.isRecordMode();
    ResultSetRow curRow = controller.getCurrentRow();
    ResultSetModel model = controller.getModel();
    switch(position) {
        case FIRST:
            if (recordMode) {
                if (model.getRowCount() > 0) {
                    controller.setCurrentRow(model.getRow(0));
                } else {
                    controller.setCurrentRow(null);
                }
            } else {
                spreadsheet.shiftCursor(0, -spreadsheet.getItemCount(), false);
            }
            break;
        case PREVIOUS:
            if (recordMode && curRow != null && curRow.getVisualNumber() > 0) {
                controller.setCurrentRow(model.getRow(curRow.getVisualNumber() - 1));
            } else {
                spreadsheet.shiftCursor(0, -1, false);
            }
            break;
        case NEXT:
            if (recordMode && curRow != null && curRow.getVisualNumber() < model.getRowCount() - 1) {
                controller.setCurrentRow(model.getRow(curRow.getVisualNumber() + 1));
            } else {
                spreadsheet.shiftCursor(0, 1, false);
            }
            break;
        case LAST:
            if (recordMode && model.getRowCount() > 0) {
                controller.setCurrentRow(model.getRow(model.getRowCount() - 1));
            } else {
                spreadsheet.shiftCursor(0, spreadsheet.getItemCount(), false);
            }
            break;
        case CURRENT:
            if (curRow != null) {
                GridPos curPos = spreadsheet.getCursorPosition();
                GridCell newCell = spreadsheet.posToCell(new GridPos(curPos.col, curRow.getVisualNumber()));
                if (newCell != null) {
                    spreadsheet.setCursor(newCell, false);
                }
            }
            break;
    }
    if (controller.isRecordMode()) {
        // Update focus cell
        restoreState(curAttribute);
    }
    // Update controls
    controller.updateEditControls();
    controller.updateStatusMessage();
    if (recordMode) {
        // Refresh meta if we are in record mode
        refreshData(true, false, true);
    }
}
Also used : GridPos(org.jkiss.dbeaver.ui.controls.lightgrid.GridPos) GridCell(org.jkiss.dbeaver.ui.controls.lightgrid.GridCell)

Example 8 with GridPos

use of org.jkiss.dbeaver.ui.controls.lightgrid.GridPos in project dbeaver by serge-rider.

the class SpreadsheetFindReplaceTarget method setSelection.

@Override
public void setSelection(int offset, int length) {
    int columnCount = owner.getSpreadsheet().getColumnCount();
    List<GridPos> selRows = new ArrayList<>();
    for (int rowNum = 0; rowNum < length; rowNum++) {
        for (int col = 0; col < columnCount; col++) {
            selRows.add(new GridPos(col, offset + rowNum));
        }
    }
    owner.setSelection(new StructuredSelection(selRows));
}
Also used : GridPos(org.jkiss.dbeaver.ui.controls.lightgrid.GridPos) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Point(org.eclipse.swt.graphics.Point)

Example 9 with GridPos

use of org.jkiss.dbeaver.ui.controls.lightgrid.GridPos in project dbeaver by serge-rider.

the class SpreadsheetFindReplaceTarget method findAndSelect.

@Override
public int findAndSelect(int offset, String findString, boolean searchForward, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
    searchPattern = null;
    ResultSetModel model = owner.getController().getModel();
    if (model.isEmpty()) {
        return -1;
    }
    Spreadsheet spreadsheet = owner.getSpreadsheet();
    int rowCount = spreadsheet.getItemCount();
    int columnCount = spreadsheet.getColumnCount();
    Collection<GridPos> selection = spreadsheet.getSelection();
    int firstRow = owner.getHighlightScopeFirstLine();
    if (firstRow < 0)
        firstRow = 0;
    int lastRow = owner.getHighlightScopeLastLine();
    if (lastRow >= rowCount || lastRow < 0)
        lastRow = rowCount - 1;
    GridPos startPosition = selection.isEmpty() ? null : selection.iterator().next();
    if (startPosition == null) {
        int startRow = searchForward ? firstRow : lastRow;
        if (startRow >= 0) {
            startPosition = new GridPos(0, startRow);
        } else {
            // From the beginning
            startPosition = new GridPos(0, 0);
        }
    }
    Pattern findPattern;
    if (regExSearch) {
        try {
            findPattern = Pattern.compile(findString, caseSensitive ? 0 : Pattern.CASE_INSENSITIVE);
        } catch (PatternSyntaxException e) {
            log.warn("Bad regex pattern: " + findString);
            return -1;
        }
    } else {
        findPattern = Pattern.compile(Pattern.quote(findString), caseSensitive ? 0 : Pattern.CASE_INSENSITIVE);
    }
    int minColumnNum = owner.getController().isRecordMode() ? -1 : 0;
    for (GridPos curPosition = new GridPos(startPosition); ; ) {
        // Object element = contentProvider.getElement(curPosition);
        if (searchForward) {
            curPosition.col++;
            if (curPosition.col >= columnCount) {
                curPosition.col = minColumnNum;
                curPosition.row++;
            }
        } else {
            curPosition.col--;
            if (curPosition.col < minColumnNum) {
                curPosition.col = columnCount - 1;
                curPosition.row--;
            }
        }
        if ((firstRow >= 0 && curPosition.row < firstRow) || (lastRow >= 0 && curPosition.row > lastRow)) {
            if (offset == -1) {
                // Wrap search - redo search one more time
                offset = 0;
                if (searchForward) {
                    curPosition = new GridPos(0, firstRow);
                } else {
                    curPosition = new GridPos(columnCount - 1, lastRow);
                }
            } else {
                // Not found
                return -1;
            }
        }
        String cellText;
        if (owner.getController().isRecordMode() && curPosition.col == minColumnNum) {
            // Header
            cellText = spreadsheet.getLabelProvider().getText(spreadsheet.getRowElement(curPosition.row));
        } else {
            GridCell cell = spreadsheet.posToCell(curPosition);
            if (cell != null) {
                cellText = CommonUtils.toString(spreadsheet.getContentProvider().getCellValue(cell.col, cell.row, true, true));
            } else {
                continue;
            }
        }
        Matcher matcher = findPattern.matcher(cellText);
        if (wholeWord ? matcher.matches() : matcher.find()) {
            if (curPosition.col == minColumnNum) {
                curPosition.col = 0;
            }
            spreadsheet.setFocusColumn(curPosition.col);
            spreadsheet.setFocusItem(curPosition.row);
            spreadsheet.setCellSelection(curPosition);
            if (!owner.getController().isHasMoreData() || !replaceAll || (curPosition.row >= spreadsheet.getTopIndex() && curPosition.row < spreadsheet.getBottomIndex())) {
                // Do not scroll to invisible rows to avoid scrolling and slow update
                spreadsheet.showSelection();
            }
            searchPattern = findPattern;
            return curPosition.row;
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) ResultSetModel(org.jkiss.dbeaver.ui.controls.resultset.ResultSetModel) Matcher(java.util.regex.Matcher) GridPos(org.jkiss.dbeaver.ui.controls.lightgrid.GridPos) Point(org.eclipse.swt.graphics.Point) PatternSyntaxException(java.util.regex.PatternSyntaxException) GridCell(org.jkiss.dbeaver.ui.controls.lightgrid.GridCell)

Example 10 with GridPos

use of org.jkiss.dbeaver.ui.controls.lightgrid.GridPos in project dbeaver by dbeaver.

the class SpreadsheetFindReplaceTarget method getSelectionText.

@Override
public String getSelectionText() {
    GridPos selection = (GridPos) owner.getSelection().getFirstElement();
    if (selection == null) {
        return "";
    }
    Spreadsheet spreadsheet = owner.getSpreadsheet();
    GridCell cell = spreadsheet.posToCell(selection);
    String value = cell == null ? "" : CommonUtils.toString(spreadsheet.getContentProvider().getCellValue(cell.col, cell.row, true, true));
    return CommonUtils.toString(value);
}
Also used : GridPos(org.jkiss.dbeaver.ui.controls.lightgrid.GridPos) GridCell(org.jkiss.dbeaver.ui.controls.lightgrid.GridCell)

Aggregations

GridPos (org.jkiss.dbeaver.ui.controls.lightgrid.GridPos)11 GridCell (org.jkiss.dbeaver.ui.controls.lightgrid.GridCell)7 Point (org.eclipse.swt.graphics.Point)4 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)2 ResultSetModel (org.jkiss.dbeaver.ui.controls.resultset.ResultSetModel)2 ResultSetRow (org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1