Search in sources :

Example 1 with ProgressInfoItem

use of org.eclipse.ui.internal.progress.ProgressInfoItem in project eclipse.platform.ui by eclipse-platform.

the class ProgressContantsTest method testKeepProperty.

@Test
public void testKeepProperty() throws Exception {
    openProgressView();
    DummyJob okJob = new DummyJob("OK Job", Status.OK_STATUS);
    okJob.setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
    okJob.schedule();
    DummyJob warningJob = new DummyJob("Warning Job", new Status(IStatus.WARNING, TestPlugin.PLUGIN_ID, "Warning message"));
    warningJob.setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
    warningJob.schedule();
    processEvents();
    okJob.join();
    warningJob.join();
    processEventsUntil(() -> findProgressInfoItem(okJob) != null && findProgressInfoItem(warningJob) != null, 3000);
    boolean okJobFound = false;
    boolean warningJobFound = false;
    ProgressInfoItem[] progressInfoItems = progressView.getViewer().getProgressInfoItems();
    for (ProgressInfoItem progressInfoItem : progressInfoItems) {
        JobInfo[] jobInfos = progressInfoItem.getJobInfos();
        for (JobInfo jobInfo : jobInfos) {
            Job job = jobInfo.getJob();
            if (job.equals(okJob)) {
                okJobFound = true;
            }
            if (job.equals(warningJob)) {
                warningJobFound = true;
            }
        }
    }
    assertTrue(okJobFound);
    assertTrue(warningJobFound);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ProgressInfoItem(org.eclipse.ui.internal.progress.ProgressInfoItem) JobInfo(org.eclipse.ui.internal.progress.JobInfo) Job(org.eclipse.core.runtime.jobs.Job) Test(org.junit.Test)

Example 2 with ProgressInfoItem

use of org.eclipse.ui.internal.progress.ProgressInfoItem in project eclipse.platform.ui by eclipse-platform.

the class ProgressContantsTest method testCommandProperty.

@Test
public void testCommandProperty() throws Exception {
    openProgressView();
    DummyJob okJob = new DummyJob("OK Job", Status.OK_STATUS);
    IWorkbench workbench = PlatformUI.getWorkbench();
    ICommandService commandService = workbench.getService(ICommandService.class);
    String commandId = "org.eclipse.ui.tests.progressViewCommand";
    Command command = commandService.getCommand(commandId);
    ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, null);
    okJob.setProperty(IProgressConstants2.COMMAND_PROPERTY, parameterizedCommand);
    okJob.setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
    okJob.schedule();
    IHandlerService service = workbench.getService(IHandlerService.class);
    CommandHandler handler = new CommandHandler();
    IHandlerActivation record = service.activateHandler(commandId, handler);
    okJob.join();
    processEvents();
    ProgressInfoItem item;
    int n = 5;
    while ((item = findProgressInfoItem(okJob)) == null && n-- > 0) {
        waitForJobs(100, 1000);
    }
    assertNotNull(item);
    item.executeTrigger();
    assertTrue(handler.executed);
    service.deactivateHandler(record);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) ProgressInfoItem(org.eclipse.ui.internal.progress.ProgressInfoItem) IHandlerService(org.eclipse.ui.handlers.IHandlerService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) IHandlerActivation(org.eclipse.ui.handlers.IHandlerActivation) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ICommandService(org.eclipse.ui.commands.ICommandService) Test(org.junit.Test)

Example 3 with ProgressInfoItem

use of org.eclipse.ui.internal.progress.ProgressInfoItem in project eclipse.platform.ui by eclipse-platform.

the class ProgressContantsTest method testCommandPropertyEnablement.

@Test
public void testCommandPropertyEnablement() throws Exception {
    openProgressView();
    DummyJob okJob = new DummyJob("OK Job", Status.OK_STATUS);
    okJob.shouldFinish = false;
    IWorkbench workbench = PlatformUI.getWorkbench();
    ECommandService commandService = workbench.getService(ECommandService.class);
    String commandId = "org.eclipse.ui.tests.progressEnableViewCommand";
    // Must use ECommandService#defineCommand to have the proper legacy
    // handler hookup beforehand, such as for handler changes
    Category category = commandService.defineCategory("org.eclipse.ui.tests.progress.category", "test", "test");
    Command command = commandService.defineCommand(commandId, "test", "test", category, new IParameter[0]);
    ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, null);
    okJob.setProperty(IProgressConstants2.COMMAND_PROPERTY, parameterizedCommand);
    okJob.setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
    okJob.schedule();
    processEventsUntil(() -> findProgressInfoItem(okJob) != null, 3000);
    ProgressInfoItem item = findProgressInfoItem(okJob);
    assertNotNull(item);
    assertFalse(item.isTriggerEnabled());
    IHandlerService service = workbench.getService(IHandlerService.class);
    CommandHandler handler = new CommandHandler();
    IHandlerActivation activation = service.activateHandler(commandId, handler);
    assertTrue(item.isTriggerEnabled());
    service.deactivateHandler(activation);
    assertFalse(item.isTriggerEnabled());
    okJob.cancel();
    okJob.join();
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) ProgressInfoItem(org.eclipse.ui.internal.progress.ProgressInfoItem) Category(org.eclipse.core.commands.Category) IHandlerService(org.eclipse.ui.handlers.IHandlerService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) IHandlerActivation(org.eclipse.ui.handlers.IHandlerActivation) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ECommandService(org.eclipse.e4.core.commands.ECommandService) Test(org.junit.Test)

Example 4 with ProgressInfoItem

use of org.eclipse.ui.internal.progress.ProgressInfoItem in project eclipse.platform.ui by eclipse-platform.

the class ProgressContantsTest method countBelongingProgressItems.

/**
 * Count the number of items in progress view whose represented job
 * {@link Job#belongsTo(Object) belongs} to the given family.
 */
private int countBelongingProgressItems(Object family) {
    int count = 0;
    ProgressInfoItem[] progressInfoItems = progressView.getViewer().getProgressInfoItems();
    for (ProgressInfoItem progressInfoItem : progressInfoItems) {
        JobInfo[] jobInfos = progressInfoItem.getJobInfos();
        for (JobInfo jobInfo : jobInfos) {
            if (jobInfo.getJob().belongsTo(family)) {
                count++;
            }
        }
    }
    return count;
}
Also used : ProgressInfoItem(org.eclipse.ui.internal.progress.ProgressInfoItem) JobInfo(org.eclipse.ui.internal.progress.JobInfo)

Example 5 with ProgressInfoItem

use of org.eclipse.ui.internal.progress.ProgressInfoItem in project eclipse.platform.ui by eclipse-platform.

the class ProgressViewTests method testItemOrder.

@Test
public void testItemOrder() throws Exception {
    openProgressView();
    ArrayList<DummyJob> jobsToSchedule = new ArrayList<>();
    ArrayList<DummyJob> allJobs = new ArrayList<>();
    DummyJob userJob = new DummyJob("1. User Job", Status.OK_STATUS);
    userJob.setUser(true);
    jobsToSchedule.add(userJob);
    DummyJob highPrioJob = new DummyJob("2. High Priority Job", Status.OK_STATUS);
    highPrioJob.setPriority(Job.INTERACTIVE);
    jobsToSchedule.add(highPrioJob);
    DummyJob job1 = new DummyJob("3. Usual job 1", Status.OK_STATUS);
    jobsToSchedule.add(job1);
    DummyJob job2 = new DummyJob("4. Usual job 2", Status.OK_STATUS);
    jobsToSchedule.add(job2);
    DummyJob job3 = new DummyJob("5. Usual job 3", Status.OK_STATUS);
    jobsToSchedule.add(job3);
    DummyJob lowPrioJob = new DummyJob("6. Low Priority Job", Status.OK_STATUS);
    lowPrioJob.setPriority(Job.DECORATE);
    jobsToSchedule.add(lowPrioJob);
    allJobs.addAll(jobsToSchedule);
    try {
        ArrayList<DummyJob> shuffledJobs = new ArrayList<>(jobsToSchedule);
        Collections.shuffle(shuffledJobs);
        StringBuilder scheduleOrder = new StringBuilder("Jobs schedule order: ");
        // order will only hold on the first time.
        progressView.getViewer().refresh();
        // wait till throttled update ran.
        Thread.sleep(200);
        Job dummyJob = new Job("dummy throttled caller") {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                return Status.OK_STATUS;
            }
        };
        // trigger throttled update to clear ProgressViewerComparator.lastIndexes
        dummyJob.schedule();
        // is busy otherwise):
        for (DummyJob job : shuffledJobs) {
            job.shouldFinish = false;
            // if the schedule updates the progress View (throttled) the sort order is
            job.schedule();
            // affected
            scheduleOrder.append(job.getName()).append(", ");
        }
        TestPlugin.getDefault().getLog().log(new Status(IStatus.OK, TestPlugin.PLUGIN_ID, scheduleOrder.toString()));
        for (DummyJob job : allJobs) {
            processEventsUntil(() -> job.inProgress, TimeUnit.SECONDS.toMillis(3));
        }
        progressView.getViewer().refresh();
        processEventsUntil(() -> progressView.getViewer().getProgressInfoItems().length == allJobs.size(), TimeUnit.SECONDS.toMillis(5));
        ProgressInfoItem[] progressInfoItems = progressView.getViewer().getProgressInfoItems();
        assertEquals("Not all jobs visible in progress view", allJobs.size(), progressInfoItems.length);
        Object[] expected = allJobs.toArray();
        Object[] actual = Arrays.stream(progressInfoItems).map(pi -> pi.getJobInfos()[0].getJob()).toArray();
        assertArrayEquals("Wrong job order", expected, actual);
    } finally {
        for (DummyJob job : jobsToSchedule) {
            job.shouldFinish = true;
        }
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Arrays(java.util.Arrays) JobTreeElement(org.eclipse.ui.internal.progress.JobTreeElement) Job(org.eclipse.core.runtime.jobs.Job) FinishedJobs(org.eclipse.ui.internal.progress.FinishedJobs) RunWith(org.junit.runner.RunWith) Status(org.eclipse.core.runtime.Status) ProgressInfoItem(org.eclipse.ui.internal.progress.ProgressInfoItem) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ArrayList(java.util.ArrayList) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TimeUnit(java.util.concurrent.TimeUnit) IStatus(org.eclipse.core.runtime.IStatus) JobInfo(org.eclipse.ui.internal.progress.JobInfo) TestPlugin(org.eclipse.ui.tests.TestPlugin) TaskInfo(org.eclipse.ui.internal.progress.TaskInfo) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Collections(java.util.Collections) IProgressConstants(org.eclipse.ui.progress.IProgressConstants) ProgressInfoItem(org.eclipse.ui.internal.progress.ProgressInfoItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) Job(org.eclipse.core.runtime.jobs.Job) Test(org.junit.Test)

Aggregations

ProgressInfoItem (org.eclipse.ui.internal.progress.ProgressInfoItem)6 JobInfo (org.eclipse.ui.internal.progress.JobInfo)4 Test (org.junit.Test)4 Command (org.eclipse.core.commands.Command)2 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Job (org.eclipse.core.runtime.jobs.Job)2 IWorkbench (org.eclipse.ui.IWorkbench)2 IHandlerActivation (org.eclipse.ui.handlers.IHandlerActivation)2 IHandlerService (org.eclipse.ui.handlers.IHandlerService)2 JobTreeElement (org.eclipse.ui.internal.progress.JobTreeElement)2 TaskInfo (org.eclipse.ui.internal.progress.TaskInfo)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 TimeUnit (java.util.concurrent.TimeUnit)1 Category (org.eclipse.core.commands.Category)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ECommandService (org.eclipse.e4.core.commands.ECommandService)1