use of org.jkiss.dbeaver.ui.controls.lightgrid.GridCell in project dbeaver by serge-rider.
the class SpreadsheetPresentation method changeMode.
@Override
public void changeMode(boolean recordMode) {
ResultSetRow oldRow = controller.getCurrentRow();
DBDAttributeBinding oldAttribute = this.curAttribute;
int rowCount = controller.getModel().getRowCount();
if (rowCount > 0) {
// Fix row number if needed
if (oldRow == null) {
oldRow = controller.getModel().getRow(0);
} else if (oldRow.getVisualNumber() >= rowCount) {
oldRow = controller.getModel().getRow(rowCount - 1);
}
}
if (oldAttribute == null && controller.getModel().getVisibleAttributeCount() > 0) {
oldAttribute = controller.getModel().getVisibleAttribute(0);
}
this.columnOrder = recordMode ? SWT.DEFAULT : SWT.NONE;
if (oldRow != null && oldAttribute != null) {
if (!recordMode) {
spreadsheet.setCursor(new GridCell(oldAttribute, oldRow), false);
} else {
spreadsheet.setCursor(new GridCell(oldRow, oldAttribute), false);
}
}
spreadsheet.layout(true, true);
}
use of org.jkiss.dbeaver.ui.controls.lightgrid.GridCell in project dbeaver by serge-rider.
the class SpreadsheetPresentation method setCurrentAttribute.
@Override
public void setCurrentAttribute(@NotNull DBDAttributeBinding attribute) {
this.curAttribute = attribute;
ResultSetRow curRow = controller.getCurrentRow();
if (curRow == null) {
return;
}
GridCell cell = controller.isRecordMode() ? new GridCell(curRow, this.curAttribute) : new GridCell(this.curAttribute, curRow);
this.spreadsheet.setCursor(cell, false);
//this.spreadsheet.showColumn(this.curAttribute);
}
use of org.jkiss.dbeaver.ui.controls.lightgrid.GridCell 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 ? "" : spreadsheet.getContentProvider().getCellText(cell.col, cell.row);
return CommonUtils.toString(value);
}
use of org.jkiss.dbeaver.ui.controls.lightgrid.GridCell 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 = owner.getSpreadsheet().getContentProvider().getCellText(cell.col, cell.row);
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.GridCell in project dbeaver by serge-rider.
the class SpreadsheetPresentation method createPresentation.
@Override
public void createPresentation(@NotNull IResultSetController controller, @NotNull Composite parent) {
super.createPresentation(controller, parent);
this.boldFont = UIUtils.makeBoldFont(parent.getFont());
this.italicFont = UIUtils.modifyFont(parent.getFont(), SWT.ITALIC);
this.foregroundNull = parent.getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
this.spreadsheet = new Spreadsheet(parent, SWT.MULTI | SWT.VIRTUAL | SWT.H_SCROLL | SWT.V_SCROLL, controller.getSite(), this, new ContentProvider(), new GridLabelProvider());
this.spreadsheet.setLayoutData(new GridData(GridData.FILL_BOTH));
this.spreadsheet.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.detail != SWT.DRAG && e.detail != SWT.DROP_DOWN) {
updateGridCursor((GridCell) e.data);
}
fireSelectionChanged(new SpreadsheetSelectionImpl());
}
});
spreadsheet.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
SpreadsheetPresentation.this.controller.updateEditControls();
}
@Override
public void focusLost(FocusEvent e) {
SpreadsheetPresentation.this.controller.updateEditControls();
}
});
this.themeManager = controller.getSite().getWorkbenchWindow().getWorkbench().getThemeManager();
this.themeChangeListener = new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().startsWith(ThemeConstants.RESULTS_PROP_PREFIX)) {
applyThemeSettings();
}
}
};
this.themeManager.addPropertyChangeListener(themeChangeListener);
applyThemeSettings();
this.spreadsheet.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
dispose();
}
});
trackPresentationControl();
UIUtils.enableHostEditorKeyBindingsSupport(controller.getSite(), spreadsheet);
}
Aggregations