Search in sources :

Example 31 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class NavigatorHandlerObjectCreateCopy method pasteResource.

private void pasteResource(DBNResource resourceNode, DBNResource toFolder) {
    final IResource resource = resourceNode.getResource();
    final IResource targetResource = toFolder.getResource();
    assert resource != null;
    assert targetResource != null;
    final IContainer targetFolder = targetResource instanceof IContainer ? (IContainer) targetResource : targetResource.getParent();
    try {
        DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    copyResource(monitor, resource, targetFolder);
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        UIUtils.showErrorDialog(null, "Copy error", "Error copying resource", e.getTargetException());
    } catch (InterruptedException e) {
    // ignore
    }
}
Also used : DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 32 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class NavigatorActionSetActiveObject method run.

@Override
public void run(IAction action) {
    if (selection instanceof IStructuredSelection) {
        DBNNode selectedNode = NavigatorUtils.getSelectedNode(selection);
        if (selectedNode instanceof DBNDatabaseNode) {
            final DBNDatabaseNode databaseNode = (DBNDatabaseNode) selectedNode;
            final DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, databaseNode.getObject());
            if (activeContainer != null) {
                TasksJob.runTask("Select active object", new DBRRunnableWithProgress() {

                    @Override
                    public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            activeContainer.setDefaultObject(monitor, databaseNode.getObject());
                        } catch (DBException e) {
                            throw new InvocationTargetException(e);
                        }
                    }
                });
            }
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBSObjectSelector(org.jkiss.dbeaver.model.struct.DBSObjectSelector) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 33 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class SelectObjectDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText(title);
    Composite group = (Composite) super.createDialogArea(parent);
    GridData gd = new GridData(GridData.FILL_BOTH);
    group.setLayoutData(gd);
    ObjectListControl<T> objectList = new ObjectListControl<T>(group, SWT.BORDER | (singleSelection ? SWT.SINGLE : SWT.MULTI), new ListContentProvider()) {

        @NotNull
        @Override
        protected String getListConfigId(List<Class<?>> classList) {
            return "ObjectsSelector";
        }

        @Override
        protected LoadingJob<Collection<T>> createLoadService() {
            return LoadingJob.createService(new AbstractLoadService<Collection<T>>() {

                @Override
                public Collection<T> evaluate(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    return objects;
                }

                @Override
                public Object getFamily() {
                    return SelectObjectDialog.this;
                }
            }, new ObjectsLoadVisualizer());
        }
    };
    objectList.createProgressPanel();
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 300;
    gd.minimumWidth = 300;
    objectList.setLayoutData(gd);
    objectList.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            selectedObjects.clear();
            selectedObjects.addAll(selection.toList());
            getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
        }
    });
    objectList.setDoubleClickHandler(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (getButton(IDialogConstants.OK_ID).isEnabled()) {
                okPressed();
            }
        }
    });
    objectList.loadData();
    return group;
}
Also used : ObjectListControl(org.jkiss.dbeaver.ui.controls.itemlist.ObjectListControl) Composite(org.eclipse.swt.widgets.Composite) InvocationTargetException(java.lang.reflect.InvocationTargetException) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SWT(org.eclipse.swt.SWT) GridData(org.eclipse.swt.layout.GridData) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 34 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor 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 35 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class GotoObjectDialog method fillContentProvider.

@Override
protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) throws CoreException {
    DBSStructureAssistant structureAssistant = DBUtils.getAdapter(DBSStructureAssistant.class, context.getDataSource());
    if (structureAssistant == null) {
        return;
    }
    String nameMask = ((ObjectFilter) itemsFilter).getNameMask();
    DBRProgressMonitor monitor = RuntimeUtils.makeMonitor(progressMonitor);
    try {
        monitor.beginTask("Search for '" + nameMask + "'", 100);
        List<DBSObjectType> typesToSearch = new ArrayList<>();
        for (DBSObjectType type : structureAssistant.getSupportedObjectTypes()) {
            Class<? extends DBSObject> typeClass = type.getTypeClass();
            if (DBSEntityElement.class.isAssignableFrom(typeClass)) {
                // Skipp attributes (columns), methods, etc
                continue;
            }
            typesToSearch.add(type);
        }
        Collection<DBSObjectReference> result = structureAssistant.findObjectsByMask(monitor, container, typesToSearch.toArray(new DBSObjectType[typesToSearch.size()]), nameMask, false, true, 1000);
        DBPDataSourceContainer dsContainer = context.getDataSource().getContainer();
        for (DBSObjectReference ref : result) {
            DBSObjectFilter filter = dsContainer.getObjectFilter(ref.getObjectClass(), ref.getContainer(), true);
            if (filter == null || !filter.isEnabled() || filter.matches(ref.getName())) {
                contentProvider.add(ref, itemsFilter);
            }
        }
    } catch (DBException e) {
        throw new CoreException(GeneralUtils.makeExceptionStatus(e));
    } finally {
        monitor.done();
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) ArrayList(java.util.ArrayList) StyledString(org.eclipse.jface.viewers.StyledString) CoreException(org.eclipse.core.runtime.CoreException) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Aggregations

DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)79 DBException (org.jkiss.dbeaver.DBException)45 InvocationTargetException (java.lang.reflect.InvocationTargetException)36 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)30 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)14 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)12 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)12 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)10 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)10 ArrayList (java.util.ArrayList)8 IStatus (org.eclipse.core.runtime.IStatus)8 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)6 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)6 GridData (org.eclipse.swt.layout.GridData)6 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)6 List (java.util.List)5 NotNull (org.jkiss.code.NotNull)5 File (java.io.File)4 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)4