Search in sources :

Example 1 with EventLoopProgressMonitor

use of org.eclipse.ui.internal.dialogs.EventLoopProgressMonitor in project eclipse.platform.text by eclipse.

the class LockJob method setUp.

@Before
public void setUp() throws Exception {
    IFolder folder = ResourceHelper.createFolder("FileDocumentProviderTestProject/test");
    file = (File) ResourceHelper.createFile(folder, "file.txt", "");
    assertTrue(file.exists());
    fsManager = file.getLocalManager();
    assertTrue(fsManager.fastIsSynchronized(file));
    stopLockingFlag = new AtomicBoolean(false);
    stoppedByTest = new AtomicBoolean(false);
    fileProvider = new FileDocumentProviderMock();
    lockJob = new LockJob("Locking workspace", file, stopLockingFlag, stoppedByTest);
    // We need the editor only to get the default editor status line manager
    IWorkbench workbench = PlatformUI.getWorkbench();
    page = workbench.getActiveWorkbenchWindow().getActivePage();
    editor = IDE.openEditor(page, file);
    TestUtil.runEventLoop();
    IStatusLineManager statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
    // This is default monitor which almost all editors are using
    IProgressMonitor progressMonitor = statusLineManager.getProgressMonitor();
    assertNotNull(progressMonitor);
    assertFalse(progressMonitor instanceof NullProgressMonitor);
    assertFalse(progressMonitor instanceof EventLoopProgressMonitor);
    assertTrue(progressMonitor instanceof IProgressMonitorWithBlocking);
    // Because this monitor is not EventLoopProgressMonitor, it will not
    // process UI events while waiting on workspace lock
    fileProvider.setProgressMonitor(progressMonitor);
    TestUtil.waitForJobs(500, 5000);
    Job[] jobs = Job.getJobManager().find(null);
    String jobsList = Arrays.toString(jobs);
    System.out.println("Still running jobs: " + jobsList);
    if (!Job.getJobManager().isIdle()) {
        jobs = Job.getJobManager().find(null);
        for (Job job : jobs) {
            System.out.println("Going to cancel: " + job.getName() + " / " + job);
            job.cancel();
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) EventLoopProgressMonitor(org.eclipse.ui.internal.dialogs.EventLoopProgressMonitor) IWorkbench(org.eclipse.ui.IWorkbench) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProgressMonitorWithBlocking(org.eclipse.core.runtime.IProgressMonitorWithBlocking) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IFolder(org.eclipse.core.resources.IFolder) Before(org.junit.Before)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IFolder (org.eclipse.core.resources.IFolder)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IProgressMonitorWithBlocking (org.eclipse.core.runtime.IProgressMonitorWithBlocking)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 IStatusLineManager (org.eclipse.jface.action.IStatusLineManager)1 IWorkbench (org.eclipse.ui.IWorkbench)1 EventLoopProgressMonitor (org.eclipse.ui.internal.dialogs.EventLoopProgressMonitor)1 Before (org.junit.Before)1