Search in sources :

Example 1 with ReferenceValueEditor

use of org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor in project dbeaver by serge-rider.

the class DefaultValueViewDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogGroup = (Composite) super.createDialogArea(parent);
    Label label = new Label(dialogGroup, SWT.NONE);
    label.setText(CoreMessages.dialog_data_label_value);
    Composite editorPlaceholder = UIUtils.createPlaceholder(dialogGroup, 1);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.minimumHeight = label.computeSize(SWT.DEFAULT, SWT.DEFAULT).y + 4;
    editorPlaceholder.setLayoutData(gd);
    editorPlaceholder.setLayout(new FillLayout());
    try {
        panelEditor = createPanelEditor(editorPlaceholder);
        if (panelEditor == null) {
            return dialogGroup;
        }
        panelEditor.primeEditorValue(getValueController().getValue());
    } catch (DBException e) {
        log.error(e);
        return dialogGroup;
    }
    ReferenceValueEditor referenceValueEditor = new ReferenceValueEditor(getValueController(), this);
    if (referenceValueEditor.isReferenceValue()) {
        referenceValueEditor.createEditorSelector(dialogGroup);
    }
    return dialogGroup;
}
Also used : DBException(org.jkiss.dbeaver.DBException) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) ReferenceValueEditor(org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor)

Example 2 with ReferenceValueEditor

use of org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor in project dbeaver by serge-rider.

the class TextViewDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogGroup = (Composite) super.createDialogArea(parent);
    ReferenceValueEditor referenceValueEditor = new ReferenceValueEditor(getValueController(), this);
    boolean isForeignKey = referenceValueEditor.isReferenceValue();
    Label label = new Label(dialogGroup, SWT.NONE);
    label.setText(CoreMessages.dialog_data_label_value);
    boolean readOnly = getValueController().isReadOnly();
    boolean useHex = !isForeignKey;
    final DBSTypedObject valueType = getValueController().getValueType();
    long maxSize = valueType.getMaxLength();
    if (useHex) {
        editorContainer = new CTabFolder(dialogGroup, SWT.FLAT | SWT.TOP);
        editorContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
        lengthLabel = new Label(editorContainer, SWT.RIGHT);
        lengthLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        editorContainer.setTopRight(lengthLabel, SWT.FILL);
    }
    int selectedType = 0;
    if (getDialogSettings().get(VALUE_TYPE_SELECTOR) != null) {
        selectedType = getDialogSettings().getInt(VALUE_TYPE_SELECTOR);
    }
    {
        int style = SWT.NONE;
        if (readOnly) {
            style |= SWT.READ_ONLY;
        }
        if (useHex) {
            style |= SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP;
        } else {
            // Use border only for plain text editor, otherwise tab folder's border will be used
            style |= SWT.BORDER;
        }
        textEdit = new StyledText(useHex ? editorContainer : dialogGroup, style);
        textEdit.setMargins(3, 3, 3, 3);
        if (maxSize > 0 && valueType.getDataKind() == DBPDataKind.STRING) {
            textEdit.setTextLimit((int) maxSize);
        }
        if (readOnly) {
        //textEdit.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
        }
        GridData gd = new GridData(isForeignKey ? GridData.FILL_HORIZONTAL : GridData.FILL_BOTH);
        gd.widthHint = 300;
        if (!isForeignKey) {
            gd.heightHint = 200;
            gd.grabExcessVerticalSpace = true;
        }
        textEdit.setLayoutData(gd);
        textEdit.setFocus();
        textEdit.setEditable(!readOnly);
        textEdit.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                dirty = true;
                updateValueLength();
            }
        });
        UIUtils.fillDefaultStyledTextContextMenu(textEdit);
        if (useHex) {
            CTabItem item = new CTabItem(editorContainer, SWT.NO_FOCUS);
            item.setText("Text");
            item.setImage(DBeaverIcons.getImage(DBIcon.TYPE_TEXT));
            item.setControl(textEdit);
        }
    }
    Point minSize = null;
    if (useHex) {
        hexEditControl = new HexEditControl(editorContainer, readOnly ? SWT.READ_ONLY : SWT.NONE, 6, 8);
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 200;
        gd.minimumWidth = hexEditControl.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
        hexEditControl.setLayoutData(gd);
        minSize = hexEditControl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        minSize.x += 50;
        minSize.y += 50;
        CTabItem item = new CTabItem(editorContainer, SWT.NO_FOCUS);
        item.setText("Hex");
        item.setImage(DBeaverIcons.getImage(DBIcon.TYPE_BINARY));
        item.setControl(hexEditControl);
        if (selectedType >= editorContainer.getItemCount()) {
            selectedType = 0;
        }
        editorContainer.setSelection(selectedType);
        editorContainer.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                getDialogSettings().put(VALUE_TYPE_SELECTOR, editorContainer.getSelectionIndex());
            }
        });
        hexEditControl.addListener(SWT.Modify, new Listener() {

            @Override
            public void handleEvent(Event event) {
                dirty = true;
            }
        });
        updateValueLength();
    }
    primeEditorValue(getValueController().getValue());
    if (isForeignKey) {
        referenceValueEditor.createEditorSelector(dialogGroup);
    }
    if (minSize != null) {
        // Set default size as minimum
        getShell().setMinimumSize(minSize);
    }
    return dialogGroup;
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) StyledText(org.eclipse.swt.custom.StyledText) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) ReferenceValueEditor(org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor) CTabItem(org.eclipse.swt.custom.CTabItem) Point(org.eclipse.swt.graphics.Point) HexEditControl(org.jkiss.dbeaver.ui.editors.binary.HexEditControl) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 3 with ReferenceValueEditor

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

GridData (org.eclipse.swt.layout.GridData)3 ReferenceValueEditor (org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor)3 Point (org.eclipse.swt.graphics.Point)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 DBException (org.jkiss.dbeaver.DBException)2 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 StyledText (org.eclipse.swt.custom.StyledText)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 PaintEvent (org.eclipse.swt.events.PaintEvent)1 PaintListener (org.eclipse.swt.events.PaintListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Control (org.eclipse.swt.widgets.Control)1 Label (org.eclipse.swt.widgets.Label)1 DBDValue (org.jkiss.dbeaver.model.data.DBDValue)1