Search in sources :

Example 1 with BaseValueEditor

use of org.jkiss.dbeaver.ui.data.editors.BaseValueEditor 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)

Aggregations

PaintEvent (org.eclipse.swt.events.PaintEvent)1 PaintListener (org.eclipse.swt.events.PaintListener)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Control (org.eclipse.swt.widgets.Control)1 DBException (org.jkiss.dbeaver.DBException)1 DBDValue (org.jkiss.dbeaver.model.data.DBDValue)1 BaseValueEditor (org.jkiss.dbeaver.ui.data.editors.BaseValueEditor)1 ReferenceValueEditor (org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor)1