Lines 21-26
Link Here
|
21 |
import java.util.LinkedHashSet; |
21 |
import java.util.LinkedHashSet; |
22 |
import java.util.List; |
22 |
import java.util.List; |
23 |
import java.util.Map; |
23 |
import java.util.Map; |
|
|
24 |
import java.util.Random; |
24 |
import java.util.Set; |
25 |
import java.util.Set; |
25 |
|
26 |
|
26 |
import org.eclipse.core.runtime.CoreException; |
27 |
import org.eclipse.core.runtime.CoreException; |
Lines 48-53
Link Here
|
48 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonColors; |
49 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonColors; |
49 |
import org.eclipse.mylyn.internal.tasks.core.AbstractTask; |
50 |
import org.eclipse.mylyn.internal.tasks.core.AbstractTask; |
50 |
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer; |
51 |
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer; |
|
|
52 |
import org.eclipse.mylyn.internal.tasks.core.DateRange; |
51 |
import org.eclipse.mylyn.internal.tasks.core.TaskActivationHistory; |
53 |
import org.eclipse.mylyn.internal.tasks.core.TaskActivationHistory; |
52 |
import org.eclipse.mylyn.internal.tasks.core.TaskList; |
54 |
import org.eclipse.mylyn.internal.tasks.core.TaskList; |
53 |
import org.eclipse.mylyn.internal.tasks.ui.TaskSearchPage; |
55 |
import org.eclipse.mylyn.internal.tasks.ui.TaskSearchPage; |
Lines 59-65
Link Here
|
59 |
import org.eclipse.mylyn.internal.tasks.ui.workingsets.WorkingSetLabelComparator; |
61 |
import org.eclipse.mylyn.internal.tasks.ui.workingsets.WorkingSetLabelComparator; |
60 |
import org.eclipse.mylyn.tasks.core.ITask; |
62 |
import org.eclipse.mylyn.tasks.core.ITask; |
61 |
import org.eclipse.mylyn.tasks.core.ITaskContainer; |
63 |
import org.eclipse.mylyn.tasks.core.ITaskContainer; |
|
|
64 |
import org.eclipse.mylyn.tasks.core.ITask.PriorityLevel; |
62 |
import org.eclipse.mylyn.tasks.ui.TaskElementLabelProvider; |
65 |
import org.eclipse.mylyn.tasks.ui.TaskElementLabelProvider; |
|
|
66 |
import org.eclipse.mylyn.tasks.ui.TasksUi; |
63 |
import org.eclipse.search.internal.ui.SearchDialog; |
67 |
import org.eclipse.search.internal.ui.SearchDialog; |
64 |
import org.eclipse.swt.SWT; |
68 |
import org.eclipse.swt.SWT; |
65 |
import org.eclipse.swt.events.SelectionEvent; |
69 |
import org.eclipse.swt.events.SelectionEvent; |
Lines 362-367
Link Here
|
362 |
|
366 |
|
363 |
private static final int CREATE_ID = SEARCH_ID + 1; |
367 |
private static final int CREATE_ID = SEARCH_ID + 1; |
364 |
|
368 |
|
|
|
369 |
private static final int RANDOM_ID = CREATE_ID + 1; |
370 |
|
365 |
private static final String IS_USING_WINDOW_WORKING_SET_SETTING = "IsUsingWindowWorkingSet"; //$NON-NLS-1$ |
371 |
private static final String IS_USING_WINDOW_WORKING_SET_SETTING = "IsUsingWindowWorkingSet"; //$NON-NLS-1$ |
366 |
|
372 |
|
367 |
private static final String OPEN_IN_BROWSER_SETTING = "OpenInBrowser"; //$NON-NLS-1$ |
373 |
private static final String OPEN_IN_BROWSER_SETTING = "OpenInBrowser"; //$NON-NLS-1$ |
Lines 379-384
Link Here
|
379 |
|
385 |
|
380 |
private Button createTaskButton; |
386 |
private Button createTaskButton; |
381 |
|
387 |
|
|
|
388 |
private Button randomTaskButton; |
389 |
|
382 |
/** |
390 |
/** |
383 |
* Mylyn's task activation history |
391 |
* Mylyn's task activation history |
384 |
*/ |
392 |
*/ |
Lines 505-510
Link Here
|
505 |
}); |
513 |
}); |
506 |
} |
514 |
} |
507 |
|
515 |
|
|
|
516 |
randomTaskButton = createButton(composite, RANDOM_ID, Messages.TaskSelectionDialog_Random_Task, false); |
517 |
randomTaskButton.addSelectionListener(new SelectionListener() { |
518 |
|
519 |
public void widgetDefaultSelected(SelectionEvent e) { |
520 |
// ignore |
521 |
} |
522 |
|
523 |
public void widgetSelected(SelectionEvent e) { |
524 |
List<AbstractTask> potentialTasks = new ArrayList<AbstractTask>(); |
525 |
for (AbstractTask task : allTasks) { |
526 |
DateRange scheduledForDate = task.getScheduledForDate(); |
527 |
if (!task.getSynchronizationState().isIncoming()) { //don't consider tasks with incomings |
528 |
if (scheduledForDate == null |
529 |
|| !TasksUiPlugin.getTaskActivityManager().isScheduledForThisWeek(scheduledForDate)) { //don't consider tasks scheduled for current week |
530 |
potentialTasks.add(task); |
531 |
if (task.getPriority().equals(PriorityLevel.P4) |
532 |
|| task.getPriority().equals(PriorityLevel.P5)) { //tasks with low priority have more chances to be chosen |
533 |
potentialTasks.add(task); |
534 |
} |
535 |
} |
536 |
} |
537 |
} |
538 |
|
539 |
if (potentialTasks.size() == 0) { |
540 |
potentialTasks.addAll(allTasks); |
541 |
} |
542 |
|
543 |
int randomTaskIndex = new Random().nextInt(potentialTasks.size()); |
544 |
ITask randomTask = potentialTasks.get(randomTaskIndex); |
545 |
|
546 |
TasksUi.getTaskActivityManager().activateTask(randomTask); //activate the chosen task |
547 |
close(); //close the dialog |
548 |
} |
549 |
}); |
550 |
|
508 |
Label filler = new Label(composite, SWT.NONE); |
551 |
Label filler = new Label(composite, SWT.NONE); |
509 |
filler.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); |
552 |
filler.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); |
510 |
layout.numColumns++; |
553 |
layout.numColumns++; |
Lines 722-728
Link Here
|
722 |
if (item instanceof ITask) { |
765 |
if (item instanceof ITask) { |
723 |
return Status.OK_STATUS; |
766 |
return Status.OK_STATUS; |
724 |
} |
767 |
} |
725 |
return new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, Messages.TaskSelectionDialog_Selected_item_is_not_a_task); |
768 |
return new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, |
|
|
769 |
Messages.TaskSelectionDialog_Selected_item_is_not_a_task); |
726 |
} |
770 |
} |
727 |
|
771 |
|
728 |
} |
772 |
} |