Search in sources :

Example 1 with DBSTypedObject

use of org.jkiss.dbeaver.model.struct.DBSTypedObject 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 2 with DBSTypedObject

use of org.jkiss.dbeaver.model.struct.DBSTypedObject in project dbeaver by serge-rider.

the class ContentPanelEditor method makeValueId.

private String makeValueId() {
    String valueId;
    DBSTypedObject valueType = valueController.getValueType();
    if (valueType instanceof DBDAttributeBinding) {
        valueType = ((DBDAttributeBinding) valueType).getAttribute();
    }
    if (valueType instanceof DBSObject) {
        DBSObject object = (DBSObject) valueType;
        valueId = DBUtils.getObjectFullName(object, DBPEvaluationContext.DDL);
        if (object.getParentObject() != null) {
            valueId = DBUtils.getObjectFullName(object.getParentObject(), DBPEvaluationContext.DDL) + ":" + valueId;
        }
    } else {
        valueId = valueController.getValueName();
    }
    String dsId = "unknown";
    if (valueController.getExecutionContext() != null) {
        dsId = valueController.getExecutionContext().getDataSource().getContainer().getId();
    }
    return dsId + ":" + valueId;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 3 with DBSTypedObject

use of org.jkiss.dbeaver.model.struct.DBSTypedObject in project dbeaver by serge-rider.

the class PostgreArrayValueHandler method getValueDisplayString.

@NotNull
@Override
public String getValueDisplayString(@NotNull DBSTypedObject column, Object value, @NotNull DBDDisplayFormat format) {
    DBDCollection collection = (DBDCollection) value;
    if (!DBUtils.isNullValue(value)) {
        DBDValueHandler valueHandler = collection.getComponentValueHandler();
        StringBuilder str = new StringBuilder();
        str.append("{");
        for (int i = 0; i < collection.getItemCount(); i++) {
            if (i > 0) {
                //$NON-NLS-1$
                str.append(',');
            }
            final Object item = collection.getItem(i);
            String itemString;
            if (item instanceof JDBCCollection) {
                // Multi-dimensional arrays case
                itemString = getValueDisplayString(column, item, format);
            } else {
                itemString = valueHandler.getValueDisplayString(collection.getComponentType(), item, DBDDisplayFormat.NATIVE);
            }
            str.append(itemString);
        }
        str.append("}");
        return str.toString();
    }
    return super.getValueDisplayString(column, value, format);
}
Also used : JDBCCollection(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection) DBDCollection(org.jkiss.dbeaver.model.data.DBDCollection) DBDValueHandler(org.jkiss.dbeaver.model.data.DBDValueHandler) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) NotNull(org.jkiss.code.NotNull)

Example 4 with DBSTypedObject

use of org.jkiss.dbeaver.model.struct.DBSTypedObject in project dbeaver by serge-rider.

the class OracleContentXML method bindParameter.

@Override
public void bindParameter(JDBCSession session, JDBCPreparedStatement preparedStatement, DBSTypedObject columnType, int paramIndex) throws DBCException {
    try {
        if (storage != null) {
            try (InputStream streamReader = storage.getContentStream()) {
                final Object xmlObject = createXmlObject(session, streamReader);
                preparedStatement.setObject(paramIndex, xmlObject);
            }
        } else {
            preparedStatement.setNull(paramIndex, java.sql.Types.SQLXML);
        }
    } catch (SQLException e) {
        throw new DBCException(e, session.getDataSource());
    } catch (IOException e) {
        throw new DBCException("IO error while reading XML", e);
    }
}
Also used : SQLException(java.sql.SQLException) InputStream(java.io.InputStream) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) DBCException(org.jkiss.dbeaver.model.exec.DBCException) IOException(java.io.IOException)

Example 5 with DBSTypedObject

use of org.jkiss.dbeaver.model.struct.DBSTypedObject in project dbeaver by serge-rider.

the class PostgreArrayValueHandler method getValueFromObject.

@Override
public DBDCollection getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy) throws DBCException {
    if (object != null) {
        String className = object.getClass().getName();
        if (object instanceof String || className.equals(PostgreConstants.PG_OBJECT_CLASS)) {
            PostgreDataType itemType = null;
            final PostgreDataType arrayType = PostgreUtils.findDataType((PostgreDataSource) session.getDataSource(), type);
            if (arrayType != null) {
                itemType = arrayType.getElementType();
            }
            if (itemType != null) {
                if (className.equals(PostgreConstants.PG_OBJECT_CLASS)) {
                    final Object value = PostgreUtils.extractPGObjectValue(object);
                    if (value == null) {
                        return null;
                    } else if (value instanceof String) {
                        return convertStringToArray(session, itemType, (String) value);
                    } else {
                        // Can't parse
                        return new JDBCCollection(itemType, DBUtils.findValueHandler(session, itemType), new Object[] { value });
                    }
                } else if (object instanceof String) {
                    return convertStringToArray(session, itemType, (String) object);
                }
            }
        }
    }
    return super.getValueFromObject(session, type, object, copy);
}
Also used : JDBCCollection(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection) PostgreDataType(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataType) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject)

Aggregations

DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)7 SQLException (java.sql.SQLException)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 JDBCCollection (org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 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 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Point (org.eclipse.swt.graphics.Point)1 GridData (org.eclipse.swt.layout.GridData)1 NotNull (org.jkiss.code.NotNull)1 Nullable (org.jkiss.code.Nullable)1 PostgreDataType (org.jkiss.dbeaver.ext.postgresql.model.PostgreDataType)1 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)1 DBDCollection (org.jkiss.dbeaver.model.data.DBDCollection)1