Search in sources :

Example 1 with ExternalContentStorage

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

the class DialogUtils method loadFromFile.

public static boolean loadFromFile(final IValueController controller) {
    if (!(controller.getValue() instanceof DBDContent)) {
        log.error(CoreMessages.model_jdbc_bad_content_value_ + controller.getValue());
        return false;
    }
    Shell shell = UIUtils.getShell(controller.getValueSite());
    final File openFile = openFile(shell);
    if (openFile == null) {
        return false;
    }
    final DBDContent value = (DBDContent) controller.getValue();
    DBeaverUI.runInUI(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), new DBRRunnableWithProgress() {

        @Override
        public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                DBDContentStorage storage;
                if (ContentUtils.isTextContent(value)) {
                    storage = new ExternalContentStorage(DBeaverCore.getInstance(), openFile, GeneralUtils.UTF8_ENCODING);
                } else {
                    storage = new ExternalContentStorage(DBeaverCore.getInstance(), openFile);
                }
                value.updateContents(monitor, storage);
                controller.updateValue(value, true);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
        }
    });
    return true;
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) ExternalContentStorage(org.jkiss.dbeaver.model.impl.ExternalContentStorage) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with ExternalContentStorage

use of org.jkiss.dbeaver.model.impl.ExternalContentStorage in project dbeaver by dbeaver.

the class DialogUtils method loadFromFile.

public static boolean loadFromFile(final IValueController controller) {
    if (!(controller.getValue() instanceof DBDContent)) {
        log.error(CoreMessages.model_jdbc_bad_content_value_ + controller.getValue());
        return false;
    }
    Shell shell = UIUtils.getShell(controller.getValueSite());
    final File openFile = openFile(shell);
    if (openFile == null) {
        return false;
    }
    final DBDContent value = (DBDContent) controller.getValue();
    DBeaverUI.runInUI(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), new DBRRunnableWithProgress() {

        @Override
        public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                DBDContentStorage storage;
                if (ContentUtils.isTextContent(value)) {
                    storage = new ExternalContentStorage(DBeaverCore.getInstance(), openFile, GeneralUtils.UTF8_ENCODING);
                } else {
                    storage = new ExternalContentStorage(DBeaverCore.getInstance(), openFile);
                }
                value.updateContents(monitor, storage);
                controller.updateValue(value, true);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
        }
    });
    return true;
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) ExternalContentStorage(org.jkiss.dbeaver.model.impl.ExternalContentStorage) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 DBDContent (org.jkiss.dbeaver.model.data.DBDContent)2 DBDContentStorage (org.jkiss.dbeaver.model.data.DBDContentStorage)2 ExternalContentStorage (org.jkiss.dbeaver.model.impl.ExternalContentStorage)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)2