Search in sources :

Example 1 with DBDValue

use of org.jkiss.dbeaver.model.data.DBDValue in project dbeaver by dbeaver.

the class JDBCComposite method getStructValue.

public Struct getStructValue() throws DBCException {
    Object[] attrs = new Object[values.length];
    for (int i = 0; i < values.length; i++) {
        Object attr = values[i];
        if (attr instanceof DBDValue) {
            attr = ((DBDValue) attr).getRawValue();
        }
        attrs[i] = attr;
    }
    final DBSDataType dataType = getDataType();
    try (DBCSession session = DBUtils.openUtilSession(new VoidProgressMonitor(), dataType.getDataSource(), "Create JDBC struct")) {
        if (session instanceof Connection) {
            return ((Connection) session).createStruct(dataType.getTypeName(), attrs);
        } else {
            return new JDBCStructImpl(dataType.getTypeName(), attrs);
        }
    } catch (Throwable e) {
        throw new DBCException("Error creating struct", e);
    }
}
Also used : DBDValue(org.jkiss.dbeaver.model.data.DBDValue) JDBCStructImpl(org.jkiss.dbeaver.model.impl.jdbc.JDBCStructImpl) DBCException(org.jkiss.dbeaver.model.exec.DBCException) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBCSession(org.jkiss.dbeaver.model.exec.DBCSession)

Example 2 with DBDValue

use of org.jkiss.dbeaver.model.data.DBDValue in project dbeaver by serge-rider.

the class ViewValuePanel method viewValue.

private void viewValue(boolean forceRefresh) {
    if (valueSaving) {
        return;
    }
    if (valueManager == null || valueEditor == null) {
        forceRefresh = true;
    }
    if (forceRefresh) {
        cleanupPanel();
        // Create a new one
        valueManager = previewController.getValueManager();
        try {
            valueEditor = valueManager.createEditor(previewController);
        } catch (Throwable e) {
            UIUtils.showErrorDialog(viewPlaceholder.getShell(), "Value preview", "Can't create value viewer", e);
            return;
        }
        if (valueEditor != null) {
            try {
                valueEditor.createControl();
            } catch (Exception e) {
                log.error(e);
            }
            Control control = valueEditor.getControl();
            if (control != null) {
                UIUtils.addFocusTracker(presentation.getController().getSite(), VALUE_VIEW_CONTROL_ID, control);
                presentation.getController().lockActionsByFocus(control);
            }
            referenceValueEditor = new ReferenceValueEditor(previewController, valueEditor);
            if (referenceValueEditor.isReferenceValue()) {
                GridLayout gl = new GridLayout(1, false);
                viewPlaceholder.setLayout(gl);
                valueEditor.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                referenceValueEditor.createEditorSelector(viewPlaceholder);
            } else {
                viewPlaceholder.setLayout(new FillLayout());
            }
        } else {
            final Composite placeholder = UIUtils.createPlaceholder(viewPlaceholder, 1);
            placeholder.setBackground(placeholder.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            placeholder.addPaintListener(new PaintListener() {

                @Override
                public void paintControl(PaintEvent e) {
                    Rectangle bounds = placeholder.getBounds();
                    String message = "No editor for [" + previewController.getValueType().getTypeName() + "]";
                    Point ext = e.gc.textExtent(message);
                    e.gc.drawText(message, (bounds.width - ext.x) / 2, bounds.height / 3 + 20);
                }
            });
            referenceValueEditor = null;
        }
        viewPlaceholder.layout();
    }
    if (valueEditor instanceof BaseValueEditor) {
        ((BaseValueEditor) valueEditor).setAutoSaveEnabled(false);
    }
    if (valueEditor != null) {
        try {
            Object newValue = previewController.getValue();
            if (newValue instanceof DBDValue) {
                // Do not check for difference
                valueEditor.primeEditorValue(newValue);
            } else {
                Object oldValue = null;
                try {
                    if (previewController.getExecutionContext() != null) {
                        oldValue = valueEditor.extractEditorValue();
                    }
                } catch (Throwable e) {
                // Some error extracting current value
                // This may happen if we were disconnected
                }
                if (!CommonUtils.equalObjects(oldValue, newValue)) {
                    valueEditor.primeEditorValue(newValue);
                }
            }
        } catch (DBException e) {
            log.error(e);
        }
        valueEditor.setDirty(false);
    }
    if (valueEditor instanceof BaseValueEditor) {
        ((BaseValueEditor) valueEditor).setAutoSaveEnabled(true);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Rectangle(org.eclipse.swt.graphics.Rectangle) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) ReferenceValueEditor(org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor) DBException(org.jkiss.dbeaver.DBException) BaseValueEditor(org.jkiss.dbeaver.ui.data.editors.BaseValueEditor) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) DBDValue(org.jkiss.dbeaver.model.data.DBDValue) GridData(org.eclipse.swt.layout.GridData)

Example 3 with DBDValue

use of org.jkiss.dbeaver.model.data.DBDValue in project dbeaver by dbeaver.

the class ViewValuePanel method viewValue.

private void viewValue(boolean forceRefresh) {
    if (valueSaving) {
        return;
    }
    if (valueManager == null || valueEditor == null) {
        forceRefresh = true;
    }
    if (forceRefresh) {
        cleanupPanel();
        // Create a new one
        valueManager = previewController.getValueManager();
        try {
            valueEditor = valueManager.createEditor(previewController);
        } catch (Throwable e) {
            DBUserInterface.getInstance().showError("Value preview", "Can't create value viewer", e);
            return;
        }
        if (valueEditor != null) {
            try {
                valueEditor.createControl();
            } catch (Exception e) {
                log.error(e);
            }
            Control control = valueEditor.getControl();
            if (control != null) {
                UIUtils.addFocusTracker(presentation.getController().getSite(), VALUE_VIEW_CONTROL_ID, control);
                presentation.getController().lockActionsByFocus(control);
            }
            referenceValueEditor = new ReferenceValueEditor(previewController, valueEditor);
            if (referenceValueEditor.isReferenceValue()) {
                GridLayout gl = new GridLayout(1, false);
                viewPlaceholder.setLayout(gl);
                valueEditor.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                referenceValueEditor.createEditorSelector(viewPlaceholder);
            } else {
                viewPlaceholder.setLayout(new FillLayout());
            }
        } else {
            final Composite placeholder = UIUtils.createPlaceholder(viewPlaceholder, 1);
            placeholder.setBackground(placeholder.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            placeholder.addPaintListener(new PaintListener() {

                @Override
                public void paintControl(PaintEvent e) {
                    Rectangle bounds = placeholder.getBounds();
                    String message = "No editor for [" + previewController.getValueType().getTypeName() + "]";
                    Point ext = e.gc.textExtent(message);
                    e.gc.drawText(message, (bounds.width - ext.x) / 2, bounds.height / 3 + 20);
                }
            });
            referenceValueEditor = null;
        }
        viewPlaceholder.layout();
    }
    if (valueEditor instanceof BaseValueEditor) {
        ((BaseValueEditor) valueEditor).setAutoSaveEnabled(false);
    }
    if (valueEditor != null) {
        try {
            Object newValue = previewController.getValue();
            if (newValue instanceof DBDValue) {
                // Do not check for difference
                valueEditor.primeEditorValue(newValue);
            } else {
                Object oldValue = null;
                try {
                    if (previewController.getExecutionContext() != null) {
                        oldValue = valueEditor.extractEditorValue();
                    }
                } catch (Throwable e) {
                // Some error extracting current value
                // This may happen if we were disconnected
                }
                if (!CommonUtils.equalObjects(oldValue, newValue)) {
                    valueEditor.primeEditorValue(newValue);
                }
            }
        } catch (DBException e) {
            log.error(e);
        }
        valueEditor.setDirty(false);
    }
    if (valueEditor instanceof BaseValueEditor) {
        ((BaseValueEditor) valueEditor).setAutoSaveEnabled(true);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Rectangle(org.eclipse.swt.graphics.Rectangle) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) ReferenceValueEditor(org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor) DBException(org.jkiss.dbeaver.DBException) BaseValueEditor(org.jkiss.dbeaver.ui.data.editors.BaseValueEditor) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) DBDValue(org.jkiss.dbeaver.model.data.DBDValue) GridData(org.eclipse.swt.layout.GridData)

Example 4 with DBDValue

use of org.jkiss.dbeaver.model.data.DBDValue in project dbeaver by serge-rider.

the class JDBCComposite method getStructValue.

public Struct getStructValue() throws DBCException {
    if (rawStruct != null) {
        return rawStruct;
    }
    Object[] attrs = new Object[values.length];
    for (int i = 0; i < values.length; i++) {
        Object attr = values[i];
        if (attr instanceof DBDValue) {
            attr = ((DBDValue) attr).getRawValue();
        }
        attrs[i] = attr;
    }
    final DBSDataType dataType = getDataType();
    try (DBCSession session = DBUtils.openUtilSession(new VoidProgressMonitor(), dataType, "Create JDBC struct")) {
        if (session instanceof Connection) {
            return ((Connection) session).createStruct(dataType.getTypeName(), attrs);
        } else {
            return new JDBCStructImpl(dataType.getTypeName(), attrs, getStringRepresentation());
        }
    } catch (Throwable e) {
        throw new DBCException("Error creating struct", e);
    }
}
Also used : DBDValue(org.jkiss.dbeaver.model.data.DBDValue) JDBCStructImpl(org.jkiss.dbeaver.model.impl.jdbc.JDBCStructImpl) DBCException(org.jkiss.dbeaver.model.exec.DBCException) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBCSession(org.jkiss.dbeaver.model.exec.DBCSession)

Example 5 with DBDValue

use of org.jkiss.dbeaver.model.data.DBDValue in project dbeaver by serge-rider.

the class ValueViewerPanel method viewValue.

private void viewValue(boolean forceRefresh) {
    if (valueSaving) {
        return;
    }
    if (valueManager == null || valueEditor == null) {
        forceRefresh = true;
    }
    if (forceRefresh) {
        cleanupPanel();
        referenceValueEditor = new ReferenceValueEditor(previewController, valueEditor);
        final boolean referenceValue = referenceValueEditor.isReferenceValue();
        if (referenceValue) {
            previewController.setEditType(IValueController.EditType.INLINE);
        } else {
            previewController.setEditType(IValueController.EditType.PANEL);
        }
        // Create a new one
        valueManager = previewController.getValueManager();
        try {
            valueEditor = valueManager.createEditor(previewController);
        } catch (Throwable e) {
            DBWorkbench.getPlatformUI().showError("Value preview", "Can't create value viewer", e);
            return;
        }
        if (valueEditor != null) {
            try {
                valueEditor.createControl();
            } catch (Exception e) {
                log.error(e);
            }
            boolean singleLineEditor = false;
            Control control = valueEditor.getControl();
            if (control != null) {
                singleLineEditor = control instanceof Combo || control instanceof CCombo || control instanceof Button || (control instanceof Text && (control.getStyle() & SWT.MULTI) == 0);
                UIUtils.addFocusTracker(presentation.getController().getSite(), VALUE_VIEW_CONTROL_ID, control);
                presentation.getController().lockActionsByFocus(control);
            }
            if (referenceValue || singleLineEditor) {
                GridLayout gl = new GridLayout(1, false);
                viewPlaceholder.setLayout(gl);
                valueEditor.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                referenceValueEditor.setValueEditor(valueEditor);
                referenceValueEditor.createEditorSelector(viewPlaceholder);
            } else {
                viewPlaceholder.setLayout(new FillLayout());
            }
        } else {
            final Composite placeholder = UIUtils.createPlaceholder(viewPlaceholder, 1);
            placeholder.setBackground(placeholder.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            placeholder.addPaintListener(e -> {
                Rectangle bounds = placeholder.getBounds();
                String message = "No editor for [" + previewController.getValueType().getTypeName() + "]";
                Point ext = e.gc.textExtent(message);
                e.gc.drawText(message, (bounds.width - ext.x) / 2, bounds.height / 3 + 20);
            });
            referenceValueEditor = null;
        }
        viewPlaceholder.layout();
    }
    if (valueEditor instanceof BaseValueEditor) {
        ((BaseValueEditor) valueEditor).setAutoSaveEnabled(false);
    }
    if (valueEditor != null) {
        try {
            Object newValue = previewController.getValue();
            if (newValue instanceof DBDValueError) {
            // Error value. Do not populate it in value viewer
            } else if (newValue instanceof DBDValue) {
                // Do not check for difference
                valueEditor.primeEditorValue(newValue);
            } else {
                Object oldValue = null;
                try {
                    if (previewController.getExecutionContext() != null) {
                        oldValue = valueEditor.extractEditorValue();
                    }
                } catch (Throwable e) {
                // Some error extracting current value
                // This may happen if we were disconnected
                }
                if (forceRefresh || !CommonUtils.equalObjects(oldValue, newValue)) {
                    valueEditor.primeEditorValue(newValue);
                }
            }
        } catch (DBException e) {
            log.error(e);
        }
        valueEditor.setDirty(false);
    }
    if (valueEditor instanceof BaseValueEditor) {
        ((BaseValueEditor) valueEditor).setAutoSaveEnabled(true);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) Rectangle(org.eclipse.swt.graphics.Rectangle) CCombo(org.eclipse.swt.custom.CCombo) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) ReferenceValueEditor(org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor) DBException(org.jkiss.dbeaver.DBException) BaseValueEditor(org.jkiss.dbeaver.ui.data.editors.BaseValueEditor) GridLayout(org.eclipse.swt.layout.GridLayout) CCombo(org.eclipse.swt.custom.CCombo) DBDValue(org.jkiss.dbeaver.model.data.DBDValue) GridData(org.eclipse.swt.layout.GridData) DBDValueError(org.jkiss.dbeaver.model.impl.data.DBDValueError)

Aggregations

DBDValue (org.jkiss.dbeaver.model.data.DBDValue)5 Point (org.eclipse.swt.graphics.Point)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 FillLayout (org.eclipse.swt.layout.FillLayout)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 DBException (org.jkiss.dbeaver.DBException)3 BaseValueEditor (org.jkiss.dbeaver.ui.data.editors.BaseValueEditor)3 ReferenceValueEditor (org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor)3 PaintEvent (org.eclipse.swt.events.PaintEvent)2 PaintListener (org.eclipse.swt.events.PaintListener)2 Composite (org.eclipse.swt.widgets.Composite)2 Control (org.eclipse.swt.widgets.Control)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 DBCSession (org.jkiss.dbeaver.model.exec.DBCSession)2 JDBCStructImpl (org.jkiss.dbeaver.model.impl.jdbc.JDBCStructImpl)2 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)2 CCombo (org.eclipse.swt.custom.CCombo)1 DBDValueError (org.jkiss.dbeaver.model.impl.data.DBDValueError)1