Search in sources :

Example 1 with StringContentStorage

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

the class AbstractTextPanelEditor method extractEditorValue.

@Override
public void extractEditorValue(@NotNull DBRProgressMonitor monitor, @NotNull StyledText control, @NotNull DBDContent value) throws DBException {
    if (valueController.getValue() instanceof DBDContent) {
        monitor.beginTask("Extract text", 1);
        try {
            monitor.subTask("Extracting text from editor");
            editor.doSave(RuntimeUtils.getNestedMonitor(monitor));
            final IEditorInput editorInput = editor.getEditorInput();
            if (editorInput instanceof ContentEditorInput) {
                final ContentEditorInput contentEditorInput = (ContentEditorInput) editorInput;
                contentEditorInput.updateContentFromFile(monitor, value);
            }
        } catch (Exception e) {
            throw new DBException("Error extracting text from editor", e);
        } finally {
            monitor.done();
        }
    } else {
        value.updateContents(monitor, new StringContentStorage(control.getText()));
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBDContent(org.jkiss.dbeaver.model.data.DBDContent) ContentEditorInput(org.jkiss.dbeaver.ui.editors.content.ContentEditorInput) StringContentStorage(org.jkiss.dbeaver.model.data.storage.StringContentStorage) IEditorInput(org.eclipse.ui.IEditorInput) PartInitException(org.eclipse.ui.PartInitException) DBException(org.jkiss.dbeaver.DBException)

Example 2 with StringContentStorage

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

the class StringContent method updateContents.

@Override
public boolean updateContents(DBRProgressMonitor monitor, DBDContentStorage storage) throws DBException {
    try {
        try (Reader reader = storage.getContentReader()) {
            StringWriter sw = new StringWriter((int) storage.getContentLength());
            ContentUtils.copyStreams(reader, storage.getContentLength(), sw, monitor);
            this.storage = new StringContentStorage(sw.toString());
        }
    } catch (IOException e) {
        throw new DBCException("IO error while reading content", e);
    }
    return true;
}
Also used : StringWriter(java.io.StringWriter) Reader(java.io.Reader) DBCException(org.jkiss.dbeaver.model.exec.DBCException) StringContentStorage(org.jkiss.dbeaver.model.data.storage.StringContentStorage) IOException(java.io.IOException)

Example 3 with StringContentStorage

use of org.jkiss.dbeaver.model.data.storage.StringContentStorage in project dbeaver by dbeaver.

the class StringContent method updateContents.

@Override
public boolean updateContents(DBRProgressMonitor monitor, DBDContentStorage storage) throws DBException {
    try {
        try (Reader reader = storage.getContentReader()) {
            StringWriter sw = new StringWriter((int) storage.getContentLength());
            ContentUtils.copyStreams(reader, storage.getContentLength(), sw, monitor);
            this.storage = new StringContentStorage(sw.toString());
        }
    } catch (IOException e) {
        throw new DBCException("IO error while reading content", e);
    }
    return true;
}
Also used : StringWriter(java.io.StringWriter) Reader(java.io.Reader) DBCException(org.jkiss.dbeaver.model.exec.DBCException) StringContentStorage(org.jkiss.dbeaver.model.data.storage.StringContentStorage) IOException(java.io.IOException)

Example 4 with StringContentStorage

use of org.jkiss.dbeaver.model.data.storage.StringContentStorage in project dbeaver by dbeaver.

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(new VoidProgressMonitor(), new StringContentStorage(newValue));
        } else {
            content.updateContents(new VoidProgressMonitor(), 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.data.storage.BytesContentStorage) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) StringContentStorage(org.jkiss.dbeaver.model.data.storage.StringContentStorage) DBException(org.jkiss.dbeaver.DBException)

Example 5 with StringContentStorage

use of org.jkiss.dbeaver.model.data.storage.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(new VoidProgressMonitor(), new StringContentStorage(newValue));
        } else {
            content.updateContents(new VoidProgressMonitor(), 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.data.storage.BytesContentStorage) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) StringContentStorage(org.jkiss.dbeaver.model.data.storage.StringContentStorage) DBException(org.jkiss.dbeaver.DBException)

Aggregations

StringContentStorage (org.jkiss.dbeaver.model.data.storage.StringContentStorage)6 DBException (org.jkiss.dbeaver.DBException)4 DBDContent (org.jkiss.dbeaver.model.data.DBDContent)4 IOException (java.io.IOException)2 Reader (java.io.Reader)2 StringWriter (java.io.StringWriter)2 IEditorInput (org.eclipse.ui.IEditorInput)2 PartInitException (org.eclipse.ui.PartInitException)2 BytesContentStorage (org.jkiss.dbeaver.model.data.storage.BytesContentStorage)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)2 ContentEditorInput (org.jkiss.dbeaver.ui.editors.content.ContentEditorInput)2