Search in sources :

Example 26 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by dbeaver.

the class NavigatorHandlerRefresh method refreshNavigator.

public static void refreshNavigator(final Collection<? extends DBNNode> refreshObjects) {
    Job refreshJob = new AbstractJob("Refresh navigator object(s)") {

        public Throwable error;

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void done(IJobChangeEvent event) {
                    if (error != null) {
                        DBUserInterface.getInstance().showError("Refresh", "Error refreshing node", error);
                    }
                }
            });
            Set<DBNNode> refreshedSet = new HashSet<>();
            for (DBNNode node : refreshObjects) {
                if (node.isDisposed() || node.isLocked()) {
                    // Skip locked nodes
                    continue;
                }
                // Check this node was already refreshed
                if (!refreshedSet.isEmpty()) {
                    boolean skip = false;
                    for (DBNNode refreshed : refreshedSet) {
                        if (node == refreshed || node.isChildOf(refreshed)) {
                            skip = true;
                            break;
                        }
                    }
                    if (skip) {
                        continue;
                    }
                }
                // Check for dirty editor (some local changes) and ask for confirmation
                if (node instanceof DBNDatabaseFolder && !(node.getParentNode() instanceof DBNDatabaseFolder) && node.getParentNode() instanceof DBNDatabaseNode) {
                    // USe parent if this node is a folder
                    node = node.getParentNode();
                }
                IEditorPart nodeEditor = NavigatorHandlerObjectOpen.findEntityEditor(DBeaverUI.getActiveWorkbenchWindow(), node);
                if (nodeEditor != null && nodeEditor.isDirty()) {
                    if (!new UIConfirmation() {

                        @Override
                        protected Boolean runTask() {
                            return ConfirmationDialog.showConfirmDialog(null, DBeaverPreferences.CONFIRM_ENTITY_REVERT, ConfirmationDialog.QUESTION, nodeEditor.getTitle()) == IDialogConstants.YES_ID;
                        }
                    }.execute()) {
                        continue;
                    }
                }
                setName("Refresh '" + node.getNodeName() + "'...");
                try {
                    DBNNode refreshed = node.refreshNode(monitor, DBNEvent.FORCE_REFRESH);
                    if (refreshed != null) {
                        refreshedSet.add(refreshed);
                    }
                } catch (Throwable ex) {
                    error = ex;
                }
            }
            return Status.OK_STATUS;
        }
    };
    refreshJob.setUser(true);
    refreshJob.schedule();
}
Also used : UIConfirmation(org.jkiss.dbeaver.ui.UIConfirmation) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IEditorPart(org.eclipse.ui.IEditorPart) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) Job(org.eclipse.core.runtime.jobs.Job) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 27 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by dbeaver.

the class GenerateSQLDialog method executeSQL.

protected void executeSQL() {
    final String jobName = getShell().getText();
    final String[] scriptLines = generateSQLScript();
    DataSourceJob job = new DataSourceJob(jobName, executionContext) {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            try (DBCSession session = getExecutionContext().openSession(monitor, DBCExecutionPurpose.UTIL, jobName)) {
                for (String line : scriptLines) {
                    DBCStatement statement = DBUtils.makeStatement(session, line, false);
                    try {
                        statement.executeStatement();
                    } finally {
                        statement.close();
                    }
                }
            } catch (DBCException e) {
                return GeneralUtils.makeExceptionStatus(e);
            }
            return Status.OK_STATUS;
        }
    };
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            if (event.getResult().isOK()) {
                if (onSuccess != null) {
                    onSuccess.run();
                }
            }
        }
    });
    job.schedule();
}
Also used : DataSourceJob(org.jkiss.dbeaver.runtime.jobs.DataSourceJob) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 28 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by dbeaver.

the class ObjectListControl method loadData.

public void loadData(boolean lazy) {
    if (this.loadingJob != null) {
        int dataLoadUpdatePeriod = 200;
        int dataLoadTimes = getDataLoadTimeout() / dataLoadUpdatePeriod;
        try {
            for (int i = 0; i < dataLoadTimes; i++) {
                Thread.sleep(dataLoadUpdatePeriod);
                if (this.loadingJob == null) {
                    break;
                }
            }
        } catch (InterruptedException e) {
        // interrupted
        }
        if (loadingJob != null) {
            UIUtils.showMessageBox(getShell(), "Load", "Service is busy", SWT.ICON_WARNING);
            return;
        }
        return;
    }
    getListPropertySource();
    clearLazyCache();
    this.lazyLoadCanceled = false;
    if (lazy) {
        // start loading service
        synchronized (this) {
            this.loadingJob = createLoadService();
            if (this.loadingJob != null) {
                this.loadingJob.addJobChangeListener(new JobChangeAdapter() {

                    @Override
                    public void done(IJobChangeEvent event) {
                        loadingJob = null;
                    }
                });
                this.loadingJob.schedule(LAZY_LOAD_DELAY);
            }
        }
    } else {
        // Load data synchronously
        final LoadingJob<Collection<OBJECT_TYPE>> loadService = createLoadService();
        if (loadService != null) {
            loadService.syncRun();
        }
    }
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 29 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project yamcs-studio by yamcs.

the class PreloadingRepositoryHandler method doExecuteAndLoad.

void doExecuteAndLoad() {
    if (preloadRepositories()) {
        // cancel any load that is already running
        Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
        final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI());
        setLoadJobProperties(loadJob);
        if (waitForPreload()) {
            loadJob.addJobChangeListener(new JobChangeAdapter() {

                public void done(IJobChangeEvent event) {
                    if (PlatformUI.isWorkbenchRunning())
                        if (event.getResult().isOK()) {
                            PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                                public void run() {
                                    doExecute(loadJob);
                                }
                            });
                        }
                }
            });
            loadJob.setUser(true);
            loadJob.schedule();
        } else {
            loadJob.setSystem(true);
            loadJob.setUser(false);
            loadJob.schedule();
            doExecute(null);
        }
    } else {
        doExecute(null);
    }
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) LoadMetadataRepositoryJob(org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob)

Example 30 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by dbeaver.

the class PropertySourceAbstract method getPropertyValue.

@Override
public Object getPropertyValue(@Nullable DBRProgressMonitor monitor, final Object object, final ObjectPropertyDescriptor prop) {
    try {
        if (monitor == null && prop.isLazy(object, true) && !prop.supportsPreview()) {
            final Object value = lazyValues.get(prop.getId());
            if (value != null) {
                return value;
            }
            if (lazyValues.containsKey(prop.getId())) {
                // Some lazy props has null value
                return null;
            }
            if (!loadLazyProps) {
                return null;
            } else {
                synchronized (lazyProps) {
                    lazyProps.add(prop);
                    if (lazyLoadJob == null) {
                        // We assume that it can be called ONLY by properties viewer
                        // So, start lazy loading job to update it after value will be loaded
                        lazyLoadJob = LoadingJob.createService(new PropertySheetLoadService(), new PropertySheetLoadVisualizer());
                        lazyLoadJob.addJobChangeListener(new JobChangeAdapter() {

                            @Override
                            public void done(IJobChangeEvent event) {
                                synchronized (lazyProps) {
                                    if (!lazyProps.isEmpty()) {
                                        lazyLoadJob.schedule(100);
                                    } else {
                                        lazyLoadJob = null;
                                    }
                                }
                            }
                        });
                        lazyLoadJob.schedule(100);
                    }
                }
                // Return dummy string for now
                lazyValues.put(prop.getId(), null);
                return null;
            }
        } else {
            return prop.readValue(object, monitor);
        }
    } catch (Throwable e) {
        if (e instanceof InvocationTargetException) {
            e = ((InvocationTargetException) e).getTargetException();
        }
        log.error("Error reading property '" + prop.getId() + "' from " + object, e);
        return e.getMessage();
    }
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)166 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)157 Job (org.eclipse.core.runtime.jobs.Job)44 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)43 IStatus (org.eclipse.core.runtime.IStatus)36 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)30 ArrayList (java.util.ArrayList)13 IFile (org.eclipse.core.resources.IFile)13 CoreException (org.eclipse.core.runtime.CoreException)12 DataSourceJob (org.jkiss.dbeaver.runtime.jobs.DataSourceJob)12 Status (org.eclipse.core.runtime.Status)11 IOException (java.io.IOException)10 DBException (org.jkiss.dbeaver.DBException)10 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)10 File (java.io.File)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)8 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 Composite (org.eclipse.swt.widgets.Composite)7 IProject (org.eclipse.core.resources.IProject)6