Search in sources :

Example 1 with IJobChangeListener

use of org.eclipse.core.runtime.jobs.IJobChangeListener in project tmdm-studio-se by Talend.

the class MDMValidationRunner method validate.

public static IModelValidateResult validate(List<IRepositoryViewObject> viewObjs, IValidationPreference validationPref, boolean forbidShowResultDialog) {
    MDMValidationRunner runner = new MDMValidationRunner(viewObjs, validationPref, forbidShowResultDialog);
    IJobChangeListener listener = new JobChangeAdapter() {

        @Override
        public void aboutToRun(IJobChangeEvent event) {
            running = true;
        }

        @Override
        public void done(IJobChangeEvent event) {
            running = false;
        }
    };
    runner.addJobChangeListener(listener);
    runner.schedule();
    try {
        runner.join();
    } catch (InterruptedException e) {
        log.error(e.getMessage(), e);
    }
    return runner.validateResult;
}
Also used : IJobChangeListener(org.eclipse.core.runtime.jobs.IJobChangeListener) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 2 with IJobChangeListener

use of org.eclipse.core.runtime.jobs.IJobChangeListener in project eclipse.jdt.ls by eclipse.

the class MavenBuildSupportTest method testIgnoreInnerPomChanges.

@Test
public void testIgnoreInnerPomChanges() throws Exception {
    IProject project = importMavenProject("archetyped");
    assertEquals("The inner pom should not have been imported", 2, WorkspaceHelper.getAllProjects().size());
    IFile innerPom = project.getFile("src/main/resources/archetype-resources/pom.xml");
    preferences.setUpdateBuildConfigurationStatus(FeatureStatus.automatic);
    boolean[] updateTriggered = new boolean[1];
    IJobChangeListener listener = new JobChangeAdapter() {

        @Override
        public void scheduled(IJobChangeEvent event) {
            if (event.getJob().getName().contains("Update project")) {
                updateTriggered[0] = true;
            }
        }
    };
    try {
        Job.getJobManager().addJobChangeListener(listener);
        projectsManager.fileChanged(innerPom.getRawLocationURI().toString(), CHANGE_TYPE.CHANGED);
        waitForBackgroundJobs();
        assertFalse("Update project should not have been triggered", updateTriggered[0]);
    } finally {
        Job.getJobManager().removeJobChangeListener(listener);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IJobChangeListener(org.eclipse.core.runtime.jobs.IJobChangeListener) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 3 with IJobChangeListener

use of org.eclipse.core.runtime.jobs.IJobChangeListener in project jbosstools-openshift by jbosstools.

the class ImportApplicationWizard method createImportJob.

private void createImportJob(boolean reuseGitRepository) {
    if (reuseGitRepository) {
        this.importJob = new ImportJob(model.getGitUrl(), model.getGitRef(), model.getRepoPath(), model.isCheckoutBranchReusedRepo());
    } else {
        this.importJob = new ImportJob(model.getGitUrl(), model.getGitRef(), model.getRepoPath());
    }
    String gitContextDir = model.getGitContextDir();
    if (StringUtils.isNotEmpty(gitContextDir)) {
        importJob.setFilters(Collections.singleton(gitContextDir));
    }
    importJob.setUser(true);
    importJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            boolean success = JobUtils.isOk(importJob.getResult());
            if (success) {
                saveRepoPath();
            }
            UsageStats.getInstance().importV3Application(model.getConnection().getHost(), success);
        }
    });
    for (IJobChangeListener importJobChangeListener : importJobChangeListenersList) {
        importJob.addJobChangeListener(importJobChangeListener);
    }
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeListener(org.eclipse.core.runtime.jobs.IJobChangeListener) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 4 with IJobChangeListener

use of org.eclipse.core.runtime.jobs.IJobChangeListener in project polymap4-core by Polymap4.

the class OperationSupport method execute2.

/**
 *@see #execute(IUndoableOperation, boolean, boolean, IJobChangeListener...)
 */
public void execute2(final IUndoableOperation op, boolean async, boolean progress, Consumer<IJobChangeEvent>... doneHandlers) {
    IJobChangeListener[] listeners = new IJobChangeListener[doneHandlers.length];
    for (int i = 0; i < doneHandlers.length; i++) {
        Consumer<IJobChangeEvent> handler = doneHandlers[i];
        listeners[i] = new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent ev) {
                handler.accept(ev);
            }
        };
    }
    execute(op, async, progress, listeners);
}
Also used : IJobChangeListener(org.eclipse.core.runtime.jobs.IJobChangeListener) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 5 with IJobChangeListener

use of org.eclipse.core.runtime.jobs.IJobChangeListener in project polymap4-core by Polymap4.

the class OperationSupport method execute.

/**
 * Executes the given operation inside an {@link UIJob job}.
 *
 * @param op
 * @param async Indicates that the calling thread should not block execution and
 *        return imediatelly.
 * @param progress Indicates the the operation is executed inside a progress
 *        dialog. Make sure that the operation does not open dialogs as they might get covered up
 *        by the progress dialog.
 * @throws ExecutionException
 */
public void execute(final IUndoableOperation op, boolean async, boolean progress, IJobChangeListener... listeners) {
    OperationJob job = new OperationJob(op) {

        protected void run() throws Exception {
            // try to preset task name without beginTask()
            monitor.setTaskName(op.getLabel());
            OperationExecutor executor = OperationExecutor.newInstance(op);
            IUndoableOperation executorOp = executor.operation();
            executorOp.addContext(context);
            history.execute(executorOp, monitor, executor.newOperationInfo(-1));
        }
    };
    for (IJobChangeListener l : listeners) {
        job.addJobChangeListenerWithContext(l);
    }
    // check nested
    UIJob parent = UIJob.ofThread();
    if (parent != null && parent instanceof OperationJob) {
        log.info("Nested operation: " + op);
        run(job, async, progress);
    // IUndoableOperation parentOp = ((OperationJob)parent).op;
    // 
    // SubProgressMonitor subMonitor = new SubProgressMonitor(
    // UIJob.monitorForThread(), IProgressMonitor.UNKNOWN, parentOp.getLabel() );
    // 
    // OperationExecutor executor = OperationExecutor.newInstance( op );
    // IUndoableOperation executorOp = executor.getOperation();
    // executorOp.addContext( context );
    // 
    // history.execute( executorOp, subMonitor, executor.getInfo() );
    } else // start job
    {
        run(job, async, progress);
    }
}
Also used : IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) IJobChangeListener(org.eclipse.core.runtime.jobs.IJobChangeListener) UIJob(org.polymap.core.runtime.UIJob)

Aggregations

IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)9 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)8 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)6 Observable (java.util.Observable)2 Observer (java.util.Observer)2 Job (org.eclipse.core.runtime.jobs.Job)2 KeyStoreAlias (org.jcryptool.crypto.keystore.backend.KeyStoreAlias)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IUndoableOperation (org.eclipse.core.commands.operations.IUndoableOperation)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 Display (org.eclipse.swt.widgets.Display)1 Test (org.junit.Test)1 UIJob (org.polymap.core.runtime.UIJob)1