Search in sources :

Example 1 with ExternalContentStorage

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

the class ContentEditorInput method loadFromExternalFile.

void loadFromExternalFile(File extFile, IProgressMonitor monitor) throws CoreException {
    try {
        release();
        contentFile = extFile;
        contentDetached = true;
        Object value = getValue();
        if (value instanceof DBDContent) {
            ((DBDContent) value).updateContents(new DefaultProgressMonitor(monitor), new ExternalContentStorage(DBWorkbench.getPlatform(), extFile));
        } else {
            updateStringValueFromFile(extFile);
        }
        refreshContentParts(extFile);
    } catch (Throwable e) {
        throw new CoreException(GeneralUtils.makeExceptionStatus(e));
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) DBDContent(org.jkiss.dbeaver.model.data.DBDContent) ExternalContentStorage(org.jkiss.dbeaver.model.data.storage.ExternalContentStorage) DefaultProgressMonitor(org.jkiss.dbeaver.model.runtime.DefaultProgressMonitor)

Example 2 with ExternalContentStorage

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

the class ContentValueManager method loadFromFile.

public static boolean loadFromFile(final IValueController controller) {
    if (!(controller.getValue() instanceof DBDContent)) {
        log.error(ResultSetMessages.model_jdbc_bad_content_value_ + controller.getValue());
        return false;
    }
    Shell shell = UIUtils.getShell(controller.getValueSite());
    final File openFile = DialogUtils.openFile(shell);
    if (openFile == null) {
        return false;
    }
    final DBDContent value = (DBDContent) controller.getValue();
    UIUtils.runInUI(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), monitor -> {
        try {
            DBDContentStorage storage;
            if (ContentUtils.isTextContent(value)) {
                storage = new ExternalContentStorage(DBWorkbench.getPlatform(), openFile, GeneralUtils.UTF8_ENCODING);
            } else {
                storage = new ExternalContentStorage(DBWorkbench.getPlatform(), openFile);
            }
            value.updateContents(monitor, storage);
            controller.updateValue(value, true);
        } catch (Exception e) {
            throw new InvocationTargetException(e);
        }
    });
    return true;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ExternalContentStorage(org.jkiss.dbeaver.model.data.storage.ExternalContentStorage) DBCException(org.jkiss.dbeaver.model.exec.DBCException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with ExternalContentStorage

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

the class ContentEditorInput method loadFromExternalFile.

void loadFromExternalFile(File extFile, IProgressMonitor monitor) throws CoreException {
    try {
        release();
        contentFile = extFile;
        contentDetached = true;
        Object value = getValue();
        if (value instanceof DBDContent) {
            ((DBDContent) value).updateContents(new DefaultProgressMonitor(monitor), new ExternalContentStorage(DBWorkbench.getPlatform(), extFile));
        } else {
            updateStringValueFromFile(extFile);
        }
        refreshContentParts(extFile);
    } catch (Throwable e) {
        throw new CoreException(GeneralUtils.makeExceptionStatus(e));
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) DBDContent(org.jkiss.dbeaver.model.data.DBDContent) ExternalContentStorage(org.jkiss.dbeaver.model.data.storage.ExternalContentStorage) DefaultProgressMonitor(org.jkiss.dbeaver.model.runtime.DefaultProgressMonitor)

Example 4 with ExternalContentStorage

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

the class ContentValueManager method loadFromFile.

public static boolean loadFromFile(final IValueController controller) {
    if (!(controller.getValue() instanceof DBDContent)) {
        log.error(ResultSetMessages.model_jdbc_bad_content_value_ + controller.getValue());
        return false;
    }
    Shell shell = UIUtils.getShell(controller.getValueSite());
    final File openFile = DialogUtils.openFile(shell);
    if (openFile == null) {
        return false;
    }
    final DBDContent value = (DBDContent) controller.getValue();
    UIUtils.runInUI(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), monitor -> {
        try {
            DBDContentStorage storage;
            if (ContentUtils.isTextContent(value)) {
                storage = new ExternalContentStorage(DBWorkbench.getPlatform(), openFile, GeneralUtils.UTF8_ENCODING);
            } else {
                storage = new ExternalContentStorage(DBWorkbench.getPlatform(), openFile);
            }
            value.updateContents(monitor, storage);
            controller.updateValue(value, true);
        } catch (Exception e) {
            throw new InvocationTargetException(e);
        }
    });
    return true;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ExternalContentStorage(org.jkiss.dbeaver.model.data.storage.ExternalContentStorage) DBCException(org.jkiss.dbeaver.model.exec.DBCException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ExternalContentStorage (org.jkiss.dbeaver.model.data.storage.ExternalContentStorage)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 CoreException (org.eclipse.core.runtime.CoreException)2 Shell (org.eclipse.swt.widgets.Shell)2 DBException (org.jkiss.dbeaver.DBException)2 DBDContent (org.jkiss.dbeaver.model.data.DBDContent)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 DefaultProgressMonitor (org.jkiss.dbeaver.model.runtime.DefaultProgressMonitor)2