Search in sources :

Example 1 with DBDContentCached

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

the class TextViewDialog method primeEditorValue.

@Override
public void primeEditorValue(@Nullable Object value) {
    if (value instanceof DBDContentCached) {
        value = ((DBDContentCached) value).getCachedValue();
    }
    if (value instanceof byte[]) {
        // Binary
        byte[] bytes = (byte[]) value;
        textEdit.setText(GeneralUtils.convertToString(bytes, 0, bytes.length));
        if (hexEditControl != null) {
            hexEditControl.setContent(bytes, getDefaultCharset());
        }
    } else {
        // Should be string
        final IValueController valueController = getValueController();
        final String strValue = valueController.getValueHandler().getValueDisplayString(valueController.getValueType(), value, DBDDisplayFormat.EDIT);
        textEdit.setText(strValue);
        if (hexEditControl != null) {
            setBinaryContent(strValue);
        }
    }
}
Also used : DBDContentCached(org.jkiss.dbeaver.model.data.DBDContentCached) IValueController(org.jkiss.dbeaver.ui.data.IValueController)

Example 2 with DBDContentCached

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

the class ContentEditorInput method updateContentFromFile.

public void updateContentFromFile(IProgressMonitor monitor) throws DBException {
    if (valueController.isReadOnly()) {
        throw new DBCException("Can't update read-only value");
    }
    DBRProgressMonitor localMonitor = RuntimeUtils.makeMonitor(monitor);
    Object value = getValue();
    if (value instanceof DBDContent) {
        DBDContent content = (DBDContent) value;
        DBDContentStorage storage = content.getContents(localMonitor);
        if (storage instanceof DBDContentStorageLocal) {
            // Nothing to update - we user content's storage
            contentDetached = true;
        } else if (storage instanceof DBDContentCached) {
            // Create new storage and pass it to content
            try (FileInputStream is = new FileInputStream(contentFile)) {
                if (storage instanceof StringContentStorage) {
                    try (Reader reader = new InputStreamReader(is, fileCharset)) {
                        storage = StringContentStorage.createFromReader(reader);
                    }
                } else {
                    storage = BytesContentStorage.createFromStream(is, contentFile.length(), fileCharset);
                }
                // StringContentStorage.
                contentDetached = content.updateContents(localMonitor, storage);
            } catch (IOException e) {
                throw new DBException("Error reading content from file", e);
            }
        } else {
            // Create new storage and pass it to content
            storage = new TemporaryContentStorage(DBeaverCore.getInstance(), contentFile, fileCharset);
            contentDetached = content.updateContents(localMonitor, storage);
        }
    } else {
        // Just read as string
        updateStringValueFromFile(contentFile);
        contentDetached = true;
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) TemporaryContentStorage(org.jkiss.dbeaver.model.impl.TemporaryContentStorage) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage) DBDContentCached(org.jkiss.dbeaver.model.data.DBDContentCached) DBDContent(org.jkiss.dbeaver.model.data.DBDContent) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBDContentStorageLocal(org.jkiss.dbeaver.model.data.DBDContentStorageLocal) StringContentStorage(org.jkiss.dbeaver.model.impl.StringContentStorage)

Example 3 with DBDContentCached

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

the class TextViewDialog method primeEditorValue.

@Override
public void primeEditorValue(@Nullable Object value) {
    if (value instanceof DBDContentCached) {
        value = ((DBDContentCached) value).getCachedValue();
    }
    if (value instanceof byte[]) {
        // Binary
        byte[] bytes = (byte[]) value;
        textEdit.setText(GeneralUtils.convertToString(bytes, 0, bytes.length));
        if (hexEditControl != null) {
            hexEditControl.setContent(bytes, getDefaultCharset());
        }
    } else {
        // Should be string
        final IValueController valueController = getValueController();
        final String strValue = valueController.getValueHandler().getValueDisplayString(valueController.getValueType(), value, DBDDisplayFormat.EDIT);
        textEdit.setText(strValue);
        if (hexEditControl != null) {
            setBinaryContent(strValue);
        }
    }
}
Also used : DBDContentCached(org.jkiss.dbeaver.model.data.DBDContentCached) IValueController(org.jkiss.dbeaver.ui.data.IValueController)

Example 4 with DBDContentCached

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

the class ContentEditorInput method updateContentFromFile.

public void updateContentFromFile(DBRProgressMonitor monitor, Object value) throws DBException {
    if (valueController.isReadOnly()) {
        throw new DBCException("Can't update read-only value");
    }
    if (value instanceof DBDContent) {
        DBDContent content = (DBDContent) value;
        DBDContentStorage storage = content.getContents(monitor);
        if (storage instanceof DBDContentStorageLocal) {
            // Nothing to update - we use content's storage
            content.updateContents(monitor, storage);
            contentDetached = true;
        } else if (storage instanceof DBDContentCached) {
            // Create new storage and pass it to content
            try (FileInputStream is = new FileInputStream(contentFile)) {
                if (ContentUtils.isTextContent(content)) {
                    try (Reader reader = new InputStreamReader(is, fileCharset)) {
                        storage = StringContentStorage.createFromReader(reader);
                    }
                } else {
                    storage = BytesContentStorage.createFromStream(is, contentFile.length(), fileCharset);
                }
                // StringContentStorage.
                contentDetached = content.updateContents(monitor, storage);
            } catch (IOException e) {
                throw new DBException("Error reading content from file", e);
            }
        } else {
            // Create new storage and pass it to content
            storage = new TemporaryContentStorage(DBWorkbench.getPlatform(), contentFile, fileCharset);
            contentDetached = content.updateContents(monitor, storage);
        }
    } else if (stringStorage != null) {
        // Just read as string
        valueController.updateValue(stringStorage.getString(), false);
        contentDetached = true;
    }
}
Also used : DBDContentCached(org.jkiss.dbeaver.model.data.DBDContentCached) DBException(org.jkiss.dbeaver.DBException) DBDContent(org.jkiss.dbeaver.model.data.DBDContent) DBCException(org.jkiss.dbeaver.model.exec.DBCException) TemporaryContentStorage(org.jkiss.dbeaver.model.data.storage.TemporaryContentStorage) DBDContentStorageLocal(org.jkiss.dbeaver.model.data.DBDContentStorageLocal) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage)

Example 5 with DBDContentCached

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

the class ContentInlineEditor method primeEditorValue.

@Override
public void primeEditorValue(@Nullable Object value) throws DBException {
    if (value instanceof DBDContentCached) {
        DBDContentCached newValue = (DBDContentCached) value;
        Object cachedValue = newValue.getCachedValue();
        String stringValue;
        if (cachedValue == null) {
            // $NON-NLS-1$
            stringValue = "";
        } else if (cachedValue instanceof byte[]) {
            byte[] bytes = (byte[]) cachedValue;
            stringValue = DBValueFormatting.getBinaryPresentation(valueController.getExecutionContext().getDataSource()).toString(bytes, 0, bytes.length);
        } else if (cachedValue instanceof ByteBuffer) {
            byte[] bytes = ((ByteBuffer) cachedValue).array();
            stringValue = DBValueFormatting.getBinaryPresentation(valueController.getExecutionContext().getDataSource()).toString(bytes, 0, bytes.length);
        } else {
            stringValue = cachedValue.toString();
        }
        control.setText(stringValue);
        control.selectAll();
    }
}
Also used : DBDContentCached(org.jkiss.dbeaver.model.data.DBDContentCached) ByteBuffer(java.nio.ByteBuffer)

Aggregations

DBDContentCached (org.jkiss.dbeaver.model.data.DBDContentCached)14 DBDContentStorage (org.jkiss.dbeaver.model.data.DBDContentStorage)8 DBException (org.jkiss.dbeaver.DBException)4 DBDContent (org.jkiss.dbeaver.model.data.DBDContent)4 DBDContentStorageLocal (org.jkiss.dbeaver.model.data.DBDContentStorageLocal)4 DBCException (org.jkiss.dbeaver.model.exec.DBCException)4 IValueController (org.jkiss.dbeaver.ui.data.IValueController)4 ByteBuffer (java.nio.ByteBuffer)2 NotNull (org.jkiss.code.NotNull)2 Nullable (org.jkiss.code.Nullable)2 TemporaryContentStorage (org.jkiss.dbeaver.model.data.storage.TemporaryContentStorage)2 StringContentStorage (org.jkiss.dbeaver.model.impl.StringContentStorage)2 TemporaryContentStorage (org.jkiss.dbeaver.model.impl.TemporaryContentStorage)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2