use of org.jkiss.dbeaver.ui.controls.lightgrid.GridPos in project dbeaver by serge-rider.
the class SpreadsheetPresentation method getCursorLocation.
@Override
public Point getCursorLocation() {
GridPos focusPos = spreadsheet.getFocusPos();
Rectangle columnBounds = spreadsheet.getColumnBounds(focusPos.col);
if (columnBounds != null) {
columnBounds.y += spreadsheet.getHeaderHeight();
return new Point(columnBounds.x, columnBounds.y);
}
return super.getCursorLocation();
}
use of org.jkiss.dbeaver.ui.controls.lightgrid.GridPos in project dbeaver by dbeaver.
the class DatabaseProducerPageExtractSettings method createControl.
@Override
public void createControl(Composite parent) {
initializeDialogUnits(parent);
Composite composite = new Composite(parent, SWT.NULL);
GridLayout gl = new GridLayout();
gl.marginHeight = 0;
gl.marginWidth = 0;
composite.setLayout(gl);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
final DatabaseProducerSettings settings = getWizard().getPageSettings(this, DatabaseProducerSettings.class);
{
Group generalSettings = UIUtils.createControlGroup(composite, CoreMessages.data_transfer_wizard_output_group_progress, 4, GridData.FILL_HORIZONTAL, 0);
Label threadsNumLabel = UIUtils.createControlLabel(generalSettings, CoreMessages.data_transfer_wizard_output_label_max_threads);
threadsNumText = new Spinner(generalSettings, SWT.BORDER);
threadsNumText.setMinimum(1);
threadsNumText.setMaximum(10);
threadsNumText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
try {
getWizard().getSettings().setMaxJobCount(Integer.parseInt(threadsNumText.getText()));
} catch (NumberFormatException e1) {
// do nothing
}
}
});
if (getWizard().getSettings().getDataPipes().size() < 2) {
threadsNumLabel.setEnabled(false);
threadsNumText.setEnabled(false);
}
threadsNumText.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_BEGINNING, false, false, 3, 1));
{
UIUtils.createControlLabel(generalSettings, CoreMessages.data_transfer_wizard_output_label_extract_type);
rowsExtractType = new Combo(generalSettings, SWT.DROP_DOWN | SWT.READ_ONLY);
rowsExtractType.setItems(new String[] { CoreMessages.data_transfer_wizard_output_combo_extract_type_item_single_query, CoreMessages.data_transfer_wizard_output_combo_extract_type_item_by_segments });
rowsExtractType.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
switch(rowsExtractType.getSelectionIndex()) {
case EXTRACT_TYPE_SEGMENTS:
settings.setExtractType(DatabaseProducerSettings.ExtractType.SEGMENTS);
break;
case EXTRACT_TYPE_SINGLE_QUERY:
settings.setExtractType(DatabaseProducerSettings.ExtractType.SINGLE_QUERY);
break;
}
updatePageCompletion();
}
});
segmentSizeLabel = UIUtils.createControlLabel(generalSettings, CoreMessages.data_transfer_wizard_output_label_segment_size);
segmentSizeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END, GridData.VERTICAL_ALIGN_BEGINNING, false, false, 1, 1));
segmentSizeText = new Text(generalSettings, SWT.BORDER);
segmentSizeText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
try {
settings.setSegmentSize(Integer.parseInt(segmentSizeText.getText()));
} catch (NumberFormatException e1) {
// just skip it
}
}
});
segmentSizeText.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END, GridData.VERTICAL_ALIGN_BEGINNING, false, false, 1, 1));
}
newConnectionCheckbox = UIUtils.createCheckbox(generalSettings, CoreMessages.data_transfer_wizard_output_checkbox_new_connection, null, true, 4);
newConnectionCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
settings.setOpenNewConnections(newConnectionCheckbox.getSelection());
}
});
rowCountCheckbox = UIUtils.createCheckbox(generalSettings, CoreMessages.data_transfer_wizard_output_checkbox_select_row_count, null, true, 4);
rowCountCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
settings.setQueryRowCount(rowCountCheckbox.getSelection());
}
});
IStructuredSelection curSelection = getWizard().getCurrentSelection();
boolean hasSelection = curSelection != null && !curSelection.isEmpty() && curSelection.getFirstElement() instanceof GridPos;
if (hasSelection) {
Button selectedColumnsOnlyCheckbox = UIUtils.createCheckbox(generalSettings, CoreMessages.data_transfer_wizard_output_checkbox_selected_columns_only, null, false, 4);
selectedColumnsOnlyCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
settings.setSelectedColumnsOnly(selectedColumnsOnlyCheckbox.getSelection());
}
});
Button selectedRowsOnlyCheckbox = UIUtils.createCheckbox(generalSettings, CoreMessages.data_transfer_wizard_output_checkbox_selected_rows_only, null, false, 4);
selectedRowsOnlyCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
settings.setSelectedRowsOnly(selectedRowsOnlyCheckbox.getSelection());
}
});
SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean selection = selectedColumnsOnlyCheckbox.getSelection() || selectedRowsOnlyCheckbox.getSelection();
newConnectionCheckbox.setEnabled(!selection);
}
};
selectedColumnsOnlyCheckbox.addSelectionListener(listener);
selectedRowsOnlyCheckbox.addSelectionListener(listener);
}
}
setControl(composite);
}
use of org.jkiss.dbeaver.ui.controls.lightgrid.GridPos in project dbeaver by serge-rider.
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);
}
use of org.jkiss.dbeaver.ui.controls.lightgrid.GridPos in project dbeaver by serge-rider.
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);
}
use of org.jkiss.dbeaver.ui.controls.lightgrid.GridPos in project dbeaver by dbeaver.
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;
}
}
}
Aggregations