Search in sources :

Example 1 with ResultSetValueController

use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController in project dbeaver by serge-rider.

the class FilterValueEditDialog method createSingleValueEditor.

private void createSingleValueEditor(Composite composite) {
    Composite editorPlaceholder = UIUtils.createPlaceholder(composite, 1);
    editorPlaceholder.setLayoutData(new GridData(GridData.FILL_BOTH));
    editorPlaceholder.setLayout(new FillLayout());
    ResultSetRow singleRow = handler.getRows()[0];
    final ResultSetValueController valueController = new ResultSetValueController(handler.getViewer(), handler.getAttribute(), singleRow, IValueController.EditType.INLINE, editorPlaceholder) {

        @Override
        public boolean isReadOnly() {
            // Filter value is never read-only
            return false;
        }
    };
    IValueEditor editor = null;
    try {
        editor = valueController.getValueManager().createEditor(valueController);
    } catch (Exception e) {
        log.error("Can't create inline value editor", e);
    }
    if (editor == null) {
        editor = new StringInlineEditor(valueController);
    }
    handler.setEditor(editor);
    editor.createControl();
    try {
        editor.primeEditorValue(valueController.getValue());
    } catch (DBException e) {
        log.error("Error populating filter value", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) ResultSetValueController(org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController) StringInlineEditor(org.jkiss.dbeaver.ui.data.editors.StringInlineEditor) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) FillLayout(org.eclipse.swt.layout.FillLayout) IValueEditor(org.jkiss.dbeaver.ui.data.IValueEditor) DBException(org.jkiss.dbeaver.DBException)

Example 2 with ResultSetValueController

use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController in project dbeaver by serge-rider.

the class GenerateUUIDHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart == null) {
        return null;
    }
    IResultSetController rsc = activePart.getAdapter(IResultSetController.class);
    if (rsc != null && UIUtils.hasFocus(rsc.getControl())) {
        IResultSetSelection selection = rsc.getSelection();
        if (selection != null && !selection.isEmpty()) {
            for (Object cell : selection.toArray()) {
                DBDAttributeBinding attr = selection.getElementAttribute(cell);
                ResultSetRow row = selection.getElementRow(cell);
                if (row != null && attr != null) {
                    ResultSetValueController valueController = new ResultSetValueController(rsc, attr, row, IValueController.EditType.NONE, null);
                    DBDValueHandler valueHandler = valueController.getValueHandler();
                    String uuid = generateUUID();
                    valueController.updateValue(uuid, false);
                }
            }
            rsc.redrawData(false, false);
            rsc.updateEditControls();
        }
    } else {
        ITextViewer textViewer = activePart.getAdapter(ITextViewer.class);
        if (textViewer != null) {
            ISelection selection = textViewer.getSelectionProvider().getSelection();
            if (selection instanceof TextSelection) {
                try {
                    int offset = ((TextSelection) selection).getOffset();
                    int length = ((TextSelection) selection).getLength();
                    String uuid = generateUUID();
                    textViewer.getDocument().replace(offset, length, uuid);
                    textViewer.getSelectionProvider().setSelection(new TextSelection(offset + uuid.length(), 0));
                } catch (BadLocationException e) {
                    DBWorkbench.getPlatformUI().showError("Insert UUID", "Error inserting UUID in text editor", e);
                }
            }
        }
    }
    return null;
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) IResultSetSelection(org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection) DBDValueHandler(org.jkiss.dbeaver.model.data.DBDValueHandler) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) ITextViewer(org.eclipse.jface.text.ITextViewer) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) ResultSetValueController(org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 3 with ResultSetValueController

use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController in project dbeaver by dbeaver.

the class GenerateUUIDHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart == null) {
        return null;
    }
    IResultSetController rsc = activePart.getAdapter(IResultSetController.class);
    if (rsc != null && UIUtils.hasFocus(rsc.getControl())) {
        IResultSetSelection selection = rsc.getSelection();
        if (selection != null && !selection.isEmpty()) {
            for (Object cell : selection.toArray()) {
                DBDAttributeBinding attr = selection.getElementAttribute(cell);
                ResultSetRow row = selection.getElementRow(cell);
                if (row != null && attr != null) {
                    ResultSetValueController valueController = new ResultSetValueController(rsc, attr, row, IValueController.EditType.NONE, null);
                    DBDValueHandler valueHandler = valueController.getValueHandler();
                    String uuid = generateUUID();
                    valueController.updateValue(uuid, false);
                }
            }
            rsc.redrawData(false, false);
            rsc.updateEditControls();
        }
    } else {
        ITextViewer textViewer = activePart.getAdapter(ITextViewer.class);
        if (textViewer != null) {
            ISelection selection = textViewer.getSelectionProvider().getSelection();
            if (selection instanceof TextSelection) {
                try {
                    int offset = ((TextSelection) selection).getOffset();
                    int length = ((TextSelection) selection).getLength();
                    String uuid = generateUUID();
                    textViewer.getDocument().replace(offset, length, uuid);
                    textViewer.getSelectionProvider().setSelection(new TextSelection(offset + uuid.length(), 0));
                } catch (BadLocationException e) {
                    DBWorkbench.getPlatformUI().showError("Insert UUID", "Error inserting UUID in text editor", e);
                }
            }
        }
    }
    return null;
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) IResultSetSelection(org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection) DBDValueHandler(org.jkiss.dbeaver.model.data.DBDValueHandler) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) ITextViewer(org.eclipse.jface.text.ITextViewer) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) ResultSetValueController(org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 4 with ResultSetValueController

use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController in project dbeaver by dbeaver.

the class FilterValueEditDialog method createSingleValueEditor.

private void createSingleValueEditor(Composite composite) {
    Composite editorPlaceholder = UIUtils.createPlaceholder(composite, 1);
    editorPlaceholder.setLayoutData(new GridData(GridData.FILL_BOTH));
    editorPlaceholder.setLayout(new FillLayout());
    ResultSetRow singleRow = handler.getRows()[0];
    final ResultSetValueController valueController = new ResultSetValueController(handler.getViewer(), handler.getAttribute(), singleRow, IValueController.EditType.INLINE, editorPlaceholder) {

        @Override
        public boolean isReadOnly() {
            // Filter value is never read-only
            return false;
        }
    };
    IValueEditor editor = null;
    try {
        editor = valueController.getValueManager().createEditor(valueController);
    } catch (Exception e) {
        log.error("Can't create inline value editor", e);
    }
    if (editor == null) {
        editor = new StringInlineEditor(valueController);
    }
    handler.setEditor(editor);
    editor.createControl();
    try {
        editor.primeEditorValue(valueController.getValue());
    } catch (DBException e) {
        log.error("Error populating filter value", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) ResultSetValueController(org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController) StringInlineEditor(org.jkiss.dbeaver.ui.data.editors.StringInlineEditor) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) FillLayout(org.eclipse.swt.layout.FillLayout) IValueEditor(org.jkiss.dbeaver.ui.data.IValueEditor) DBException(org.jkiss.dbeaver.DBException)

Aggregations

ResultSetRow (org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow)4 ResultSetValueController (org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController)4 BadLocationException (org.eclipse.jface.text.BadLocationException)2 ITextViewer (org.eclipse.jface.text.ITextViewer)2 TextSelection (org.eclipse.jface.text.TextSelection)2 ISelection (org.eclipse.jface.viewers.ISelection)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 GridData (org.eclipse.swt.layout.GridData)2 Composite (org.eclipse.swt.widgets.Composite)2 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 DBException (org.jkiss.dbeaver.DBException)2 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)2 DBDValueHandler (org.jkiss.dbeaver.model.data.DBDValueHandler)2 IResultSetController (org.jkiss.dbeaver.ui.controls.resultset.IResultSetController)2 IResultSetSelection (org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection)2 IValueEditor (org.jkiss.dbeaver.ui.data.IValueEditor)2 StringInlineEditor (org.jkiss.dbeaver.ui.data.editors.StringInlineEditor)2