blob: cd7d4b7e35960eb6b520ade3dc14deb6da3bf19b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*******************************************************************************
* Copyright (c) 2004 - 2005 University Of British Columbia and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* University Of British Columbia - initial API and implementation
*******************************************************************************/
package org.eclipse.mylar.bugzilla.ui.actions;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.mylar.bugzilla.ui.BugzillaImages;
import org.eclipse.mylar.bugzilla.ui.BugzillaUiPlugin;
import org.eclipse.mylar.bugzilla.ui.tasklist.BugzillaTask;
import org.eclipse.mylar.tasklist.ITask;
import org.eclipse.mylar.tasklist.ITaskHandler;
import org.eclipse.mylar.tasklist.MylarTasklistPlugin;
import org.eclipse.mylar.tasklist.internal.TaskCategory;
import org.eclipse.mylar.tasklist.ui.views.TaskListView;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
/**
* @author Mik Kersten and Ken Sueda
*/
public class CreateBugzillaTaskAction extends Action implements IViewActionDelegate{
private static final String LABEL = "Add Existing Bugzilla Report";
public static final String ID = "org.eclipse.mylar.tasklist.actions.create.bug";
public CreateBugzillaTaskAction() {
setText(LABEL);
setToolTipText(LABEL);
setId(ID);
setImageDescriptor(BugzillaImages.TASK_BUGZILLA);
}
@Override
public void run() {
// MylarPlugin.getDefault().actionObserved(this);
if(TaskListView.getDefault() == null)
return;
String bugIdString = TaskListView.getDefault().getBugIdFromUser();
int bugId = -1;
try {
if (bugIdString != null) {
bugId = Integer.parseInt(bugIdString);
} else {
return;
}
} catch (NumberFormatException nfe) {
TaskListView.getDefault().showMessage("Please enter a valid report number");
return;
}
// XXX we don't care about duplicates since we use a registrey
// Check the existing tasks to see if the id is used already.
// This is to prevent the creation of mutliple Bugzilla tasks
// for the same Bugzilla report.
// boolean doesIdExistAlready = false;
// doesIdExistAlready = lookForId("Bugzilla-" + bugId);
// if (doesIdExistAlready) {
// showMessage("A Bugzilla task with ID Bugzilla-" + bugId + " already exists.");
// return;
// }
ITask newTask = new BugzillaTask("Bugzilla-"+bugId, "<bugzilla info>", true);
Object selectedObject = ((IStructuredSelection)TaskListView.getDefault().getViewer().getSelection()).getFirstElement();
ITaskHandler taskHandler = MylarTasklistPlugin.getDefault().getTaskHandlerForElement(newTask);
if(taskHandler != null){
ITask addedTask = taskHandler.taskAdded(newTask);
if(addedTask instanceof BugzillaTask){
BugzillaTask newTask2 = (BugzillaTask)addedTask;
if(newTask2 == newTask){
((BugzillaTask)newTask).scheduleDownloadReport();
} else {
newTask = newTask2;
((BugzillaTask)newTask).updateTaskDetails();
}
}
} else {
((BugzillaTask)newTask).scheduleDownloadReport();
}
if (selectedObject instanceof TaskCategory){
((TaskCategory)selectedObject).addTask(newTask);
} else {
MylarTasklistPlugin.getTaskListManager().addRootTask(newTask);
}
BugzillaUiPlugin.getDefault().getBugzillaTaskListManager().addToBugzillaTaskRegistry((BugzillaTask)newTask);
//
// BugzillaTask newBugTask = new BugzillaTask("Bugzilla-"+bugId, "<bugzilla info>");
// BugzillaTask bugTask = BugzillaUiPlugin.getDefault().getBugzillaTaskListManager().getFromBugzillaTaskRegistry(newBugTask.getHandle());
// if(bugTask == null) {
// BugzillaUiPlugin.getDefault().getBugzillaTaskListManager().addToBugzillaTaskRegistry((BugzillaTask)bugTask);
// }
// Object selectedObject = ((IStructuredSelection)this.view.getViewer().getSelection()).getFirstElement();
// if (selectedObject instanceof TaskCategory){
// ((TaskCategory)selectedObject).addTask((ITask)bugTask);
// } else {
// MylarTasksPlugin.getTaskListManager().getTaskList().addRootTask((ITask)bugTask);
// }
if(TaskListView.getDefault() != null)
TaskListView.getDefault().getViewer().refresh();
}
public void init(IViewPart view) {
}
public void run(IAction action) {
run();
}
public void selectionChanged(IAction action, ISelection selection) {
}
}
|