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"; |
371 |
private static final String IS_USING_WINDOW_WORKING_SET_SETTING = "IsUsingWindowWorkingSet"; |
366 |
|
372 |
|
367 |
private static final String OPEN_IN_BROWSER_SETTING = "OpenInBrowser"; |
373 |
private static final String OPEN_IN_BROWSER_SETTING = "OpenInBrowser"; |
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, "&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 || !scheduledForDate.isThisWeek()) { //don't consider tasks scheduled for current week |
529 |
potentialTasks.add(task); |
530 |
if (task.getPriority().equals(PriorityLevel.P4) |
531 |
|| task.getPriority().equals(PriorityLevel.P5)) { //tasks with low priority have more chances to be chosen |
532 |
potentialTasks.add(task); |
533 |
} |
534 |
} |
535 |
} |
536 |
} |
537 |
|
538 |
if (potentialTasks.size() == 0) { |
539 |
potentialTasks.addAll(allTasks); |
540 |
} |
541 |
|
542 |
int randomTaskIndex = new Random().nextInt(potentialTasks.size()); |
543 |
ITask randomTask = potentialTasks.get(randomTaskIndex); |
544 |
|
545 |
TasksUi.getTaskActivityManager().activateTask(randomTask); //activate the chosen task |
546 |
close(); //close the dialog |
547 |
} |
548 |
}); |
549 |
|
508 |
Label filler = new Label(composite, SWT.NONE); |
550 |
Label filler = new Label(composite, SWT.NONE); |
509 |
filler.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); |
551 |
filler.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); |
510 |
layout.numColumns++; |
552 |
layout.numColumns++; |