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);
}
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);
}
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();
}
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;
}
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;
}
}
}
Aggregations