Search in sources :

Example 1 with GridCell

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);
}
Also used : GridCell(org.jkiss.dbeaver.ui.controls.lightgrid.GridCell)

Example 2 with GridCell

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);
}
Also used : GridCell(org.jkiss.dbeaver.ui.controls.lightgrid.GridCell)

Example 3 with GridCell

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);
}
Also used : GridPos(org.jkiss.dbeaver.ui.controls.lightgrid.GridPos) GridCell(org.jkiss.dbeaver.ui.controls.lightgrid.GridCell)

Example 4 with GridCell

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);
}
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 5 with GridCell

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);
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) IGridContentProvider(org.jkiss.dbeaver.ui.controls.lightgrid.IGridContentProvider) GridCell(org.jkiss.dbeaver.ui.controls.lightgrid.GridCell) IGridLabelProvider(org.jkiss.dbeaver.ui.controls.lightgrid.IGridLabelProvider) GridData(org.eclipse.swt.layout.GridData)

Aggregations

GridCell (org.jkiss.dbeaver.ui.controls.lightgrid.GridCell)10 GridPos (org.jkiss.dbeaver.ui.controls.lightgrid.GridPos)4 Nullable (org.jkiss.code.Nullable)2 IGridLabelProvider (org.jkiss.dbeaver.ui.controls.lightgrid.IGridLabelProvider)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 IFindReplaceTarget (org.eclipse.jface.text.IFindReplaceTarget)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 Point (org.eclipse.swt.graphics.Point)1 GridData (org.eclipse.swt.layout.GridData)1 IPropertySource (org.eclipse.ui.views.properties.IPropertySource)1 IPropertySourceProvider (org.eclipse.ui.views.properties.IPropertySourceProvider)1 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)1 PropertyCollector (org.jkiss.dbeaver.runtime.properties.PropertyCollector)1 PropertyPageStandard (org.jkiss.dbeaver.ui.controls.PropertyPageStandard)1 IGridContentProvider (org.jkiss.dbeaver.ui.controls.lightgrid.IGridContentProvider)1 ResultSetModel (org.jkiss.dbeaver.ui.controls.resultset.ResultSetModel)1 ResultSetRow (org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow)1