Java 类org.eclipse.core.runtime.jobs.IJobChangeListener 实例源码

项目:termsuite-ui    文件:ProgressMonitorFocusJobDialog.java   
@Override
public int open() {
    int result = super.open();

    // add a listener that will close the dialog when the job completes.
    IJobChangeListener listener = createCloseListener();
    job.addJobChangeListener(listener);
    if (job.getState() == Job.NONE) {
        // if the job completed before we had a chance to add
        // the listener, just remove the listener and return
        job.removeJobChangeListener(listener);
        finishedRun();
        cleanUpFinishedJob();
    }

    return result;
}
项目:eclipse.jdt.ls    文件:MavenBuildSupportTest.java   
@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);
    }
}
项目:termsuite-ui    文件:ProgressMonitorFocusJobDialog.java   
/**
 * Returns a listener that will close the dialog when the job completes.
 *
 * @return IJobChangeListener
 */
private IJobChangeListener createCloseListener() {
    return new JobChangeAdapter() {
        @Override
        public void done(IJobChangeEvent event) {
            // first of all, make sure this listener is removed
            event.getJob().removeJobChangeListener(this);
            if (!PlatformUI.isWorkbenchRunning()) {
                return;
            }
            // nothing to do if the dialog is already closed
            if (getShell() == null) {
                return;
            }
            Job closeJob = new UIJob(
                    ProgressMessages.ProgressMonitorFocusJobDialog_CLoseDialogJob) {
                @Override
                public IStatus runInUIThread(IProgressMonitor monitor) {
                    Shell currentShell = getShell();
                    if (currentShell == null || currentShell.isDisposed()) {
                        return Status.CANCEL_STATUS;
                    }
                    finishedRun();
                    return Status.OK_STATUS;
                }
            };
            closeJob.setSystem(true);
            closeJob.schedule();
        }
    };
}
项目:xiliary    文件:CompletionObserverListTest.java   
@Test
public void iteratorEnsuresSaveCopy() {
  observers.add( mock( IJobChangeListener.class ) );

  Iterator<IJobChangeListener> iterator = observers.iterator();
  iterator.next();
  iterator.remove();
  Iterator<IJobChangeListener> actual = observers.iterator();

  assertThat( actual ).hasSize( 1 );
}
项目:xiliary    文件:CompletionObserverListTest.java   
@Test
public void add() {
  IJobChangeListener expected = mock( IJobChangeListener.class );

  observers.add( expected );

  assertThat( observers.iterator() )
    .hasSize( 1 )
    .containsExactly( expected );
}
项目:xiliary    文件:CompletionObserverListTest.java   
@Test
public void addMulti() {
  observers.add( mock( IJobChangeListener.class ) );
  observers.add( mock( IJobChangeListener.class ) );

  assertThat( observers.iterator() ).hasSize( 2 );
}
项目:xiliary    文件:CompletionObserverListTest.java   
@Test
public void remove() {
  IJobChangeListener listener = mock( IJobChangeListener.class );
  observers.add( listener );

  observers.remove( listener );

  assertThat( observers.iterator() ).isEmpty();
}
项目:xiliary    文件:CompletionObserverListTest.java   
@Test
public void removeWithMultiListeners() {
  IJobChangeListener expected = mock( IJobChangeListener.class );
  IJobChangeListener toRemove = mock( IJobChangeListener.class );
  observers.add( expected );
  observers.add( toRemove );

  observers.remove( toRemove );

  assertThat( observers.iterator() )
    .hasSize( 1 )
    .containsExactly( expected );
}
项目:xiliary    文件:ClearJobPDETest.java   
@Before
public void setUp() {
  listener = mock( IJobChangeListener.class );
  observers = createCompletionObserverList( listener );
  viewerAdapter = mock( ViewerAdapter.class );
  placeholder = new PendingUpdatePlaceHolder();
  clearJob = new ClearJob( observers, viewerAdapter, placeholder );
  jobHelper = new JobHelper( clearJob );
}
项目:xiliary    文件:CompletionObserverList.java   
Iterator<IJobChangeListener> iterator() {
  ArrayList<IJobChangeListener> result = new ArrayList<IJobChangeListener>();
  if( listeners != null ) {
    Object[] observers = listeners.getListeners();
    for( Object object : observers ) {
      result.add( ( IJobChangeListener )object );
    }
  }
  return result.iterator();
}
项目:GrayTin    文件:TargetPlatformReloader.java   
public void setTargetPlatform(final IProgressMonitor monitor) throws CoreException {
    IFile targetFile = SDKActivator.getTargetPlatformFile();
    monitor.subTask("Setting up target platform (" + targetFile + ")");
    // acquire target platform service
    TargetPlatformService service = (TargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
    ITargetHandle targetHandle = service.getTarget(targetFile.getLocationURI());
    final ITargetDefinition targetDefinition = targetHandle.getTargetDefinition();

    IJobChangeListener jca = new JobChangeListenerImpl(targetDefinition);

    // When loading Target is done, rebuild java search scope index. 
    LoadTargetDefinitionJob.load(targetDefinition, jca);
    monitor.worked(1);
}
项目:GrayTin    文件:TargetPlatformReloader.java   
public void setTargetPlatform(final IProgressMonitor monitor) throws CoreException {
    IFile targetFile = SDKActivator.getTargetPlatformFile();
    monitor.subTask("Setting up target platform (" + targetFile + ")");
    // acquire target platform service
    TargetPlatformService service = (TargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
    ITargetHandle targetHandle = service.getTarget(targetFile.getLocationURI());
    final ITargetDefinition targetDefinition = targetHandle.getTargetDefinition();

    IJobChangeListener jca = new JobChangeListenerImpl(targetDefinition);

    // When loading Target is done, rebuild java search scope index. 
    LoadTargetDefinitionJob.load(targetDefinition, jca);
    monitor.worked(1);
}
项目:tlaplus    文件:ModelCheckerTest.java   
@Test
public void testNewModel() {
    // Open specA
    SWTBotMenu fileMenu = bot.menu("File");
    SWTBotMenu openSpecMenu = fileMenu.menu("Open Spec");
    SWTBotMenu addNewSpecMenu = openSpecMenu.menu("Add New Spec...");
    addNewSpecMenu.click();

    bot.textWithLabel("Root-module file:").setText(specA);
    bot.button("Finish").click();

    final String specName = getSpecName(new File(specA));

    // specs are created in non-UI thread asynchronously which causes a
    // delay before the menu entry becomes available
    bot.waitUntil(Conditions.waitForMenu(bot.activeShell(), WithText.<MenuItem> withText(specName)));

    // create a new model
    final SWTBotMenu modelMenu = bot.menu("TLC Model Checker");
    final SWTBotMenu newModelMenu = modelMenu.menu("New Model...");
    newModelMenu.click();
    bot.button("OK").click();

    // wait for model editor to show up and parse
    bot.waitUntil(new ModelEditorOpenCondition("Model_"));

    // register job listener who listens for the model checker job
    final String modelName = UIHelper.getActiveEditor().getTitle();
    final Model model = ToolboxHandle.getCurrentSpec().getAdapter(TLCSpec.class).getModel(modelName);
    final IJobChangeListener listener = new DummyJobChangeListener(model);
    Job.getJobManager().addJobChangeListener(listener);

    // start model checking by clicking the menu. This is more robust
    // compared to the f11 keystroke which can get lost when fired during
    // initialization of the model editor.
    bot.menu("TLC Model Checker").menu("Run model").click();

    // make unit test wait for model checker job to finish
    bot.waitUntil((ICondition) listener, SWTBotPreferences.TIMEOUT * 3);

    // Do some unregistration prior to model deletion:
    Job.getJobManager().removeJobChangeListener(listener);

    // close corresponding editor if open
    final IEditorPart editorWithModelOpened = model.getAdapter(ModelEditor.class);
    if (editorWithModelOpened != null) {
        UIHelper.runUISync(new Runnable() {
            public void run() {
                UIHelper.getActivePage().closeEditor(editorWithModelOpened,
                        false);
            }
        });
    }

    // Delete the newly created model again. It does not use the UI because
    // SWTBot cannot handle the modal confirmation dialog do delete the
    // model.
    // Deleting the model is necessary because repeated test execution would
    // leave huge numbers of model leftovers contributing to slowed down test
    // execution (see SizeControlContribution for reason why).
    try {
        model.delete(new NullProgressMonitor());
    } catch (CoreException e) {
        e.printStackTrace();
    }
}
项目:tlaplus    文件:RenameSpecHandlerTest.java   
/**
 * @see Bug #58 in general/bugzilla/index.html
 */
@Test
public void renameSpec() throws InterruptedException {
    openSpecExplorer();

    SWTBotTreeItem treeItem = bot.tree().getTreeItem(TEST_SPEC + " [ " + TEST_SPEC + TLA_SUFFIX + " ]");
    checkForModelExistenceUI(treeItem);

    SWTBotMenu contextMenu = treeItem.contextMenu("Rename");
    contextMenu.click();

    // rename to ..._Copy
    bot.button("OK").click();

    // wait for rename to be done
    bot.waitUntil(new SpecEditorOpenCondition(TEST_SPEC));

    // verify (via API)
    checkSpecAndModelExistenceAPI(TEST_SPEC + "_Copy");

    // try to find the renamed file (via UI)
    openSpecExplorer();
    treeItem = bot.tree().getTreeItem(TEST_SPEC + "_Copy [ " + TEST_SPEC + TLA_SUFFIX + " ]");

    /*
     * try to launch the model
     */
    SWTBotTreeItem modelTreeItem = checkForModelExistenceUI(treeItem);
    modelTreeItem.contextMenu("Open").click();
    Assert.assertNotNull("UI tree item (model) could not be found", modelTreeItem);

    // register job listener who listens for the model checker job
    final String modelName = UIHelper.getActiveEditor().getTitle();
    final Model model = ToolboxHandle.getCurrentSpec().getAdapter(TLCSpec.class).getModel(modelName);
    final IJobChangeListener listener = new DummyJobChangeListener(model);
    Job.getJobManager().addJobChangeListener(listener);

    // start model checking by clicking the menu. This is more robust
    // compared to the f11 keystroke which can get lost when fired during
    // initialization of the model editor.
    bot.menu("TLC Model Checker").menu("Run model").click();

    // make unit test wait for model checker job to finish
    bot.waitUntil((ICondition) listener, SWTBotPreferences.TIMEOUT * 3);

    // Do some unregistration prior to model deletion:
    Job.getJobManager().removeJobChangeListener(listener);

    // close corresponding editor if open
    final IEditorPart editorWithModelOpened = model.getAdapter(ModelEditor.class);
    if (editorWithModelOpened != null) {
        UIHelper.runUISync(new Runnable() {
            public void run() {
                UIHelper.getActivePage().closeEditor(editorWithModelOpened,
                        false);
            }
        });
    }
}
项目:xiliary    文件:CompletionObserverListTest.java   
@Test
public void iterator() {
  Iterator<IJobChangeListener> actual = observers.iterator();

  assertThat( actual ).isEmpty();
}
项目:xiliary    文件:ClearJobPDETest.java   
private static CompletionObserverList createCompletionObserverList( IJobChangeListener listener ) {
  CompletionObserverList result = new CompletionObserverList();
  result.add( listener );
  return result;
}
项目:xiliary    文件:CompletionObserverList.java   
void add( IJobChangeListener listener ) {
  ensureList();
  listeners.add( listener );
}
项目:xiliary    文件:CompletionObserverList.java   
void remove( IJobChangeListener listener ) {
  listeners.remove( listener );
  deleteEmptyList();
}
项目:xiliary    文件:DeferredContentManager.java   
public void addUpdateCompleteListener( IJobChangeListener listener ) {
  completionObservers.add( listener );
}
项目:xiliary    文件:DeferredContentManager.java   
public void removeUpdateCompleteListener( IJobChangeListener listener ) {
  completionObservers.remove( listener );
}
项目:xiliary    文件:ClearJob.java   
private void register( CompletionObserverList observerList ) {
  Iterator<IJobChangeListener> iterator = observerList.iterator();
  while( iterator.hasNext() ) {
    addJobChangeListener( iterator.next() );
  }
}
项目:elexis-3-base    文件:AbstractChartComposite.java   
/**
 * @param listener
 */
public void addJobChangeListener(IJobChangeListener listener) {
    this.creator.addJobChangeListener(listener);
}
项目:elexis-3-base    文件:AbstractChartComposite.java   
/**
 * @param listener
 */
public void removeJobChangeListener(IJobChangeListener listener) {
    this.creator.removeJobChangeListener(listener);

}