Search in sources :

Example 71 with IJobChangeEvent

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

the class ObjectEditorPageControl method runService.

public synchronized <OBJECT_TYPE> void runService(LoadingJob<OBJECT_TYPE> service) {
    curService = service;
    service.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            synchronized (ObjectEditorPageControl.this) {
                curService = null;
            }
        }
    });
    service.schedule();
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 72 with IJobChangeEvent

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

the class SchedulerDefault method scheduleTransformation.

@Override
public void scheduleTransformation(final File mdFile, final File htFile, final Callback<File> onDone) {
    final String jobName = "Transforming: " + mdFile.getName();
    Job job = new Job(jobName) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IStatus status = Status.OK_STATUS;
            try {
                transformer.transformMarkdownFile(mdFile, htFile);
            } catch (IOException e) {
                status = new Status(Status.ERROR, pluginId, jobName, e);
            }
            return status;
        }
    };
    job.setUser(false);
    job.setSystem(false);
    job.setPriority(Job.SHORT);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            // refreshFile(htFile);
            if (event.getResult().isOK()) {
                if (onDone != null) {
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            onDone.onComplete(htFile);
                        }
                    });
                }
            } else {
                // normal reporting has occurred
                if (onDone != null) {
                    final Throwable exception = event.getResult().getException();
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            onDone.onError(htFile, exception);
                        }
                    });
                }
            }
        }
    });
    job.schedule();
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IOException(java.io.IOException) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job)

Example 73 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project snow-owl by b2ihealthcare.

the class ValidationThreadPool method submit.

public Promise<Object> submit(CheckType checkType, Runnable runnable) {
    final Job job = new ValidationJob(checkType.getName(), runnable);
    final String uniqueRuleId = UUID.randomUUID().toString();
    final ISchedulingRule schedulingRule = new ValidationRuleSchedulingRule(checkType, maxValidationThreadCount, maxConcurrentExpensiveJobs, maxConcurrentNormalJobs, uniqueRuleId);
    final Promise<Object> promise = new Promise<>();
    job.setSystem(true);
    job.setRule(schedulingRule);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            if (event.getResult().isOK()) {
                promise.resolve(Boolean.TRUE);
            } else {
                promise.reject(new ValidationException(String.format("Validation job failed with status %s.", event.getResult())));
            }
        }
    });
    job.schedule();
    return promise;
}
Also used : Promise(com.b2international.snowowl.core.events.util.Promise) ValidationException(javax.validation.ValidationException) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 74 with IJobChangeEvent

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

the class ERDEditorStandalone method loadDiagram.

/*
    protected void createActions()
    {
        super.createActions();

        //addEditorAction(new SaveAction(this));
    }
*/
@Override
protected synchronized void loadDiagram(boolean refreshMetadata) {
    if (diagramLoadingJob != null) {
        // Do not start new one while old is running
        return;
    }
    diagramLoadingJob = LoadingJob.createService(new AbstractLoadService<EntityDiagram>("Load diagram '" + getEditorInput().getName() + "'") {

        @Override
        public EntityDiagram evaluate(DBRProgressMonitor monitor) {
            try {
                return loadContentFromFile(monitor);
            } catch (DBException e) {
                log.error(e);
            }
            return null;
        }

        @Override
        public Object getFamily() {
            return ERDEditorStandalone.this;
        }
    }, progressControl.createLoadVisualizer());
    diagramLoadingJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            diagramLoadingJob = null;
        }
    });
    diagramLoadingJob.schedule();
    setPartName(getEditorInput().getName());
}
Also used : DBException(org.jkiss.dbeaver.DBException) AbstractLoadService(org.jkiss.dbeaver.model.runtime.load.AbstractLoadService) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 75 with IJobChangeEvent

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

the class DataSourceHandler method disconnectDataSource.

public static void disconnectDataSource(DBPDataSourceContainer dataSourceContainer, @Nullable final Runnable onFinish) {
    // Save users
    for (DBPDataSourceTask user : dataSourceContainer.getTasks()) {
        if (user instanceof ISaveablePart) {
            if (!SaveChangesHandler.validateAndSave(new VoidProgressMonitor(), (ISaveablePart) user)) {
                return;
            }
        }
    }
    if (!checkAndCloseActiveTransaction(dataSourceContainer)) {
        return;
    }
    if (dataSourceContainer instanceof DataSourceDescriptor && dataSourceContainer.isConnected()) {
        final DataSourceDescriptor dataSourceDescriptor = (DataSourceDescriptor) dataSourceContainer;
        if (!ArrayUtils.isEmpty(Job.getJobManager().find(dataSourceDescriptor))) {
            // Already connecting/disconnecting - just return
            return;
        }
        final DisconnectJob disconnectJob = new DisconnectJob(dataSourceDescriptor);
        disconnectJob.addJobChangeListener(new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent event) {
                IStatus result = disconnectJob.getConnectStatus();
                if (onFinish != null) {
                    onFinish.run();
                } else if (!result.isOK()) {
                    DBWorkbench.getPlatformUI().showError(disconnectJob.getName(), null, result);
                }
                DataSourcePropertyTester.firePropertyChange(DataSourcePropertyTester.PROP_CONNECTED);
            }
        });
        disconnectJob.schedule();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DisconnectJob(org.jkiss.dbeaver.runtime.jobs.DisconnectJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) DBPDataSourceTask(org.jkiss.dbeaver.model.DBPDataSourceTask) ISaveablePart(org.eclipse.ui.ISaveablePart) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Aggregations

IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)172 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)163 Job (org.eclipse.core.runtime.jobs.Job)46 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)45 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 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 CoreException (org.eclipse.core.runtime.CoreException)12 DataSourceJob (org.jkiss.dbeaver.runtime.jobs.DataSourceJob)12 Status (org.eclipse.core.runtime.Status)11 IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)11 IOException (java.io.IOException)10 DBException (org.jkiss.dbeaver.DBException)10 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)10 IProject (org.eclipse.core.resources.IProject)9 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 Composite (org.eclipse.swt.widgets.Composite)7