Search in sources :

Example 51 with DBDContent

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

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 52 with DBDContent

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

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)

Aggregations

DBDContent (org.jkiss.dbeaver.model.data.DBDContent)52 DBDContentStorage (org.jkiss.dbeaver.model.data.DBDContentStorage)33 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)23 Reader (java.io.Reader)15 DBException (org.jkiss.dbeaver.DBException)13 PrintWriter (java.io.PrintWriter)10 File (java.io.File)9 Date (java.util.Date)8 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)8 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 DBDContentStorageLocal (org.jkiss.dbeaver.model.data.DBDContentStorageLocal)6 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)6 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 DBDContentCached (org.jkiss.dbeaver.model.data.DBDContentCached)4 StringContentStorage (org.jkiss.dbeaver.model.data.storage.StringContentStorage)4 DBCException (org.jkiss.dbeaver.model.exec.DBCException)4