Search in sources :

Example 1 with StringContentStorage

use of org.jkiss.dbeaver.model.impl.StringContentStorage in project dbeaver by serge-rider.

the class TextPanelEditor method extractEditorValue.

@Override
public void extractEditorValue(@NotNull DBRProgressMonitor monitor, @NotNull StyledText control, @NotNull DBDContent value) throws DBException {
    monitor.subTask("Read text value");
    value.updateContents(monitor, new StringContentStorage(control.getText()));
}
Also used : StringContentStorage(org.jkiss.dbeaver.model.impl.StringContentStorage)

Example 2 with StringContentStorage

use of org.jkiss.dbeaver.model.impl.StringContentStorage in project dbeaver by serge-rider.

the class ContentInlineEditor method extractEditorValue.

@Override
public Object extractEditorValue() {
    String newValue = control.getText();
    final DBDContent content = (DBDContent) valueController.getValue();
    assert content != null;
    try {
        if (isText) {
            content.updateContents(VoidProgressMonitor.INSTANCE, new StringContentStorage(newValue));
        } else {
            content.updateContents(VoidProgressMonitor.INSTANCE, new BytesContentStorage(newValue.getBytes(GeneralUtils.getDefaultFileEncoding()), GeneralUtils.getDefaultFileEncoding()));
        }
    } catch (Exception e) {
        log.error(e);
    }
    return content;
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) BytesContentStorage(org.jkiss.dbeaver.model.impl.BytesContentStorage) StringContentStorage(org.jkiss.dbeaver.model.impl.StringContentStorage) DBException(org.jkiss.dbeaver.DBException)

Example 3 with StringContentStorage

use of org.jkiss.dbeaver.model.impl.StringContentStorage in project dbeaver by serge-rider.

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);
    DBDContent content = getContent();
    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);
    }
}
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)

Aggregations

StringContentStorage (org.jkiss.dbeaver.model.impl.StringContentStorage)3 DBException (org.jkiss.dbeaver.DBException)2 DBDContent (org.jkiss.dbeaver.model.data.DBDContent)2 DBDContentCached (org.jkiss.dbeaver.model.data.DBDContentCached)1 DBDContentStorage (org.jkiss.dbeaver.model.data.DBDContentStorage)1 DBDContentStorageLocal (org.jkiss.dbeaver.model.data.DBDContentStorageLocal)1 DBCException (org.jkiss.dbeaver.model.exec.DBCException)1 BytesContentStorage (org.jkiss.dbeaver.model.impl.BytesContentStorage)1 TemporaryContentStorage (org.jkiss.dbeaver.model.impl.TemporaryContentStorage)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1