Search in sources :

Example 1 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter 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 2 with JobChangeAdapter

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

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) {
                        UIUtils.showErrorDialog(null, "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;
                    }
                }
                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 : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob)

Example 3 with JobChangeAdapter

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

the class DataSourceHandler method connectToDataSource.

/**
     * Connects datasource
     * @param monitor progress monitor or null. If nul then new job will be started
     * @param dataSourceContainer    container to connect
     * @param onFinish               finish handler
     */
public static void connectToDataSource(@Nullable DBRProgressMonitor monitor, @NotNull DBPDataSourceContainer dataSourceContainer, @Nullable final DBRProgressListener onFinish) {
    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 ConnectJob connectJob = new ConnectJob(dataSourceDescriptor);
        final JobChangeAdapter jobChangeAdapter = new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent event) {
                IStatus result = connectJob.getConnectStatus();
                if (result.isOK()) {
                    if (!dataSourceDescriptor.isSavePassword()) {
                    // Rest password back to null
                    // TODO: to be correct we need to reset password info.
                    // but we need a password to open isolated contexts (e.g. for data export)
                    // Currently it is not possible to ask for password from isolation context opening
                    // procedure. We need to do something here...
                    //dataSourceDescriptor.getConnectionConfiguration().setUserName(oldName);
                    //dataSourceDescriptor.getConnectionConfiguration().setUserPassword(oldPassword);
                    }
                }
                if (onFinish != null) {
                    onFinish.onTaskFinished(result);
                } else if (!result.isOK()) {
                    DBUserInterface.getInstance().showError(connectJob.getName(), //NLS.bind(CoreMessages.runtime_jobs_connect_status_error, dataSourceContainer.getName()),
                    null, result);
                }
            }
        };
        if (monitor != null) {
            connectJob.runSync(monitor);
            jobChangeAdapter.done(new IJobChangeEvent() {

                @Override
                public long getDelay() {
                    return 0;
                }

                @Override
                public Job getJob() {
                    return connectJob;
                }

                @Override
                public IStatus getResult() {
                    return connectJob.getConnectStatus();
                }

                public IStatus getJobGroupResult() {
                    return null;
                }
            });
        } else {
            connectJob.addJobChangeListener(jobChangeAdapter);
            // Schedule in UI because connect may be initiated during application startup
            // and UI is still not initiated. In this case no progress dialog will appear
            // to be sure run in UI async
            DBeaverUI.asyncExec(new Runnable() {

                @Override
                public void run() {
                    connectJob.schedule();
                }
            });
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ConnectJob(org.jkiss.dbeaver.runtime.jobs.ConnectJob) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) DisconnectJob(org.jkiss.dbeaver.runtime.jobs.DisconnectJob) ConnectJob(org.jkiss.dbeaver.runtime.jobs.ConnectJob) Job(org.eclipse.core.runtime.jobs.Job) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Example 4 with JobChangeAdapter

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

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) throws InvocationTargetException, InterruptedException {
            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 5 with JobChangeAdapter

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

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)44 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)44 Job (org.eclipse.core.runtime.jobs.Job)17 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)16 IStatus (org.eclipse.core.runtime.IStatus)11 IFile (org.eclipse.core.resources.IFile)7 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)6 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 QAXmlHandler (net.heartsome.cat.ts.core.qa.QAXmlHandler)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 IOException (java.io.IOException)3 QATUDataBean (net.heartsome.cat.ts.core.qa.QATUDataBean)3 Status (org.eclipse.core.runtime.Status)3 DataSourceJob (org.jkiss.dbeaver.runtime.jobs.DataSourceJob)3 AnalyseBundleResolutionJob (bndtools.tasks.AnalyseBundleResolutionJob)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ExportDatabaseBean (net.heartsome.cat.database.bean.ExportDatabaseBean)2 ExportFilterBean (net.heartsome.cat.database.bean.ExportFilterBean)2