Search in sources :

Example 11 with DBDContent

use of org.jkiss.dbeaver.model.data.DBDContent 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)

Example 12 with DBDContent

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

the class ContentEditorInput method prepareContent.

private void prepareContent(DBRProgressMonitor monitor) throws DBException {
    DBDContent content = getContent();
    DBDContentStorage storage = content.getContents(monitor);
    if (contentDetached) {
        release(monitor);
        contentDetached = false;
    }
    if (storage instanceof DBDContentStorageLocal) {
        // User content's storage directly
        contentFile = ((DBDContentStorageLocal) storage).getDataFile();
        contentDetached = true;
    } else {
        // Copy content to local file
        try {
            // Create file
            if (contentFile == null) {
                String valueId;
                if (valueController instanceof IAttributeController) {
                    valueId = ((IAttributeController) valueController).getColumnId();
                } else {
                    valueId = valueController.getValueName();
                }
                contentFile = ContentUtils.createTempContentFile(monitor, DBeaverCore.getInstance(), valueId);
            }
            // Write value to file
            copyContentToFile(content, monitor);
        } catch (IOException e) {
            // Delete temp file
            if (contentFile != null && contentFile.exists()) {
                if (!contentFile.delete()) {
                    log.warn("Can't delete temporary content file '" + contentFile.getAbsolutePath() + "'");
                }
            }
            throw new DBException("Can't delete content file", e);
        }
    }
    // Mark file as readonly
    if (valueController.isReadOnly()) {
        markReadOnly(true);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBDContent(org.jkiss.dbeaver.model.data.DBDContent) DBDContentStorageLocal(org.jkiss.dbeaver.model.data.DBDContentStorageLocal) IAttributeController(org.jkiss.dbeaver.ui.data.IAttributeController) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage)

Example 13 with DBDContent

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

the class ContentEditor method getContent.

@Nullable
DBDContent getContent() {
    IValueController valueController = getValueController();
    Object value = valueController == null ? null : valueController.getValue();
    if (value instanceof DBDContent) {
        return (DBDContent) value;
    } else {
        return null;
    }
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) IValueController(org.jkiss.dbeaver.ui.data.IValueController) Nullable(org.jkiss.code.Nullable)

Example 14 with DBDContent

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

the class ContentEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    setPartName(input.getName());
    DBDContent content = getContent();
    if (content == null) {
        return;
    }
    // Fill nested editorParts info
    IEditorPart[] editorParts = getEditorInput().getEditors();
    for (IEditorPart editorPart : editorParts) {
        contentParts.add(new ContentPartInfo(editorPart, editorPart == getEditorInput().getDefaultEditor()));
    //editorPart.init(site, input);
    }
    ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent)

Example 15 with DBDContent

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

the class ContentEditor method createPages.

@Override
protected void createPages() {
    super.createPages();
    DBDContent content = getContent();
    if (content == null) {
        return;
    }
    ContentPartInfo defaultPage = null;
    for (ContentPartInfo contentPart : contentParts) {
        if (contentPart.isDefault) {
            defaultPage = contentPart;
        }
        IEditorPart editorPart = contentPart.editorPart;
        try {
            int index = addPage(editorPart, getEditorInput());
            setPageText(index, editorPart.getTitle());
            setPageImage(index, editorPart.getTitleImage());
            contentPart.activated = true;
            contentPart.index = index;
        } catch (PartInitException e) {
            log.error(e);
        }
    }
    if (defaultPage != null) {
        setActiveEditor(defaultPage.editorPart);
    }
    this.partsLoaded = true;
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent)

Aggregations

DBDContent (org.jkiss.dbeaver.model.data.DBDContent)17 DBDContentStorage (org.jkiss.dbeaver.model.data.DBDContentStorage)7 DBException (org.jkiss.dbeaver.DBException)5 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)4 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)4 File (java.io.File)3 Reader (java.io.Reader)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)3 DBDContentStorageLocal (org.jkiss.dbeaver.model.data.DBDContentStorageLocal)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 StringContentStorage (org.jkiss.dbeaver.model.impl.StringContentStorage)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 Action (org.eclipse.jface.action.Action)1 Separator (org.eclipse.jface.action.Separator)1 Nullable (org.jkiss.code.Nullable)1 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)1