Search in sources :

Example 51 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project linuxtools by eclipse.

the class LibHoverPreferencePage method regenerate.

private synchronized void regenerate() {
    generateButton.setEnabled(false);
    Job k = new Job(LibHoverMessages.getString(REGENERATE_MSG)) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IPreferenceStore ps = DevHelpPlugin.getDefault().getPreferenceStore();
            ParseDevHelp.DevHelpParser p = new ParseDevHelp.DevHelpParser(ps.getString(PreferenceConstants.DEVHELP_DIRECTORY));
            LibHoverInfo hover = p.parse(monitor);
            // Update the devhelp library info if it is on library list
            Collection<LibHoverLibrary> libs = LibHover.getLibraries();
            for (LibHoverLibrary l : libs) {
                if (l.getName().equals("devhelp")) {
                    // $NON-NLS-1$
                    l.setHoverinfo(hover);
                    break;
                }
            }
            try {
                // Now, output the LibHoverInfo for caching later
                // $NON-NLS-1$
                IPath location = LibhoverPlugin.getDefault().getStateLocation().append("C");
                File ldir = new File(location.toOSString());
                ldir.mkdir();
                // $NON-NLS-1$
                location = location.append("devhelp.libhover");
                try (FileOutputStream f = new FileOutputStream(location.toOSString());
                    ObjectOutputStream out = new ObjectOutputStream(f)) {
                    out.writeObject(hover);
                }
                monitor.done();
            } catch (IOException e) {
                monitor.done();
                return new Status(IStatus.ERROR, DevHelpPlugin.PLUGIN_ID, e.getLocalizedMessage(), e);
            }
            return Status.OK_STATUS;
        }
    };
    k.setUser(true);
    k.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            Display.getDefault().syncExec(() -> {
                if (generateButton != null)
                    generateButton.setEnabled(true);
            });
        }
    });
    k.schedule();
}
Also used : LibHoverLibrary(org.eclipse.linuxtools.internal.cdt.libhover.LibHoverLibrary) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IOException(java.io.IOException) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) ObjectOutputStream(java.io.ObjectOutputStream) LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ParseDevHelp(org.eclipse.linuxtools.internal.cdt.libhover.devhelp.ParseDevHelp) FileOutputStream(java.io.FileOutputStream) Job(org.eclipse.core.runtime.jobs.Job) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) File(java.io.File)

Example 52 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project knime-core by knime.

the class AbstractP2Action method startLoadJob.

/**
 * Starts the repository load job. After the repositories have been loaded,
 * {@link #openWizard(LoadMetadataRepositoryJob, ProvisioningUI)} is called.
 */
protected final void startLoadJob() {
    final ProvisioningUI provUI = ProvisioningUI.getDefaultUI();
    Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
    final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(provUI);
    loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));
    loadJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(final IJobChangeEvent event) {
            if (PlatformUI.isWorkbenchRunning() && event.getResult().isOK()) {
                openWizard(loadJob, provUI);
            }
        }
    });
    loadJob.setUser(true);
    loadJob.schedule();
}
Also used : ProvisioningUI(org.eclipse.equinox.p2.ui.ProvisioningUI) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) LoadMetadataRepositoryJob(org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob)

Aggregations

IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)52 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)52 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)20 Job (org.eclipse.core.runtime.jobs.Job)20 IStatus (org.eclipse.core.runtime.IStatus)12 IFile (org.eclipse.core.resources.IFile)7 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)6 File (java.io.File)5 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 LoadMetadataRepositoryJob (org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 QAXmlHandler (net.heartsome.cat.ts.core.qa.QAXmlHandler)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 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 FileOutputStream (java.io.FileOutputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2