Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6404ee15563be738e289a2a40cae29be8c6fe706 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*******************************************************************************
 * Copyright (c) 2003 - 2006 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.mylyn.internal.bugzilla.ui.wizard;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttributeFactory;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylyn.internal.bugzilla.ui.BugzillaUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.TaskListPreferenceConstants;
import org.eclipse.mylyn.tasks.core.RepositoryTaskData;
import org.eclipse.mylyn.tasks.core.Task;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
import org.eclipse.mylyn.tasks.ui.editors.NewTaskEditorInput;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;

/**
 * @author Mik Kersten
 * @author Rob Elves
 */
public class NewBugzillaTaskWizard extends Wizard implements INewWizard {

	private static final String TITLE = "New Bugzilla Task";

	private IWorkbench workbenchInstance;

	private final TaskRepository repository;

	private final BugzillaProductPage productPage;

	/**
	 * Flag to indicate if the wizard can be completed (finish button enabled)
	 */
	protected boolean completed = false;

	/** The taskData used to store all of the data for the wizard */
	protected RepositoryTaskData taskData;

	// TODO: Change taskData to a RepositoryTaskData
	// protected RepositoryTaskData taskData;

	public NewBugzillaTaskWizard(TaskRepository repository) {
		this(false, repository);
		taskData = new RepositoryTaskData(new BugzillaAttributeFactory(), BugzillaCorePlugin.REPOSITORY_KIND,
				repository.getUrl(), TasksUiPlugin.getDefault().getNextNewRepositoryTaskId(), Task.DEFAULT_TASK_KIND);
		taskData.setNew(true);
		super.setDefaultPageImageDescriptor(BugzillaUiPlugin.imageDescriptorFromPlugin(
				"org.eclipse.mylyn.internal.bugzilla.ui", "icons/wizban/bug-wizard.gif"));
		super.setWindowTitle(TITLE);
		setNeedsProgressMonitor(true);
	}

	public NewBugzillaTaskWizard(boolean fromDialog, TaskRepository repository) {
		super();
		this.repository = repository;
		this.productPage = new BugzillaProductPage(workbenchInstance, this, repository);
	}

	public void init(IWorkbench workbench, IStructuredSelection selection) {
		this.workbenchInstance = workbench;
	}

	@Override
	public void addPages() {
		super.addPages();
		addPage(productPage);
	}

	@Override
	public boolean canFinish() {
		return completed;
	}

	@Override
	public boolean performFinish() {

		try {
			productPage.saveDataToModel();
			NewTaskEditorInput editorInput = new NewTaskEditorInput(repository, taskData);
			IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
			TasksUiUtil.openEditor(editorInput, TaskListPreferenceConstants.TASK_EDITOR_ID, page);
			return true;
		} catch (Exception e) {
			productPage.applyToStatusLine(new Status(IStatus.ERROR, "not_used", 0,
					"Problem occurred retrieving repository configuration from " + repository.getUrl(), null));
		}
		return false;
	}

}

// @Override
// protected void saveBugOffline() {
// // AbstractRepositoryConnector client = (AbstractRepositoryConnector)
// // MylarTaskListPlugin.getRepositoryManager()
// // .getRepositoryConnector(BugzillaPlugin.REPOSITORY_KIND);
// // client.saveOffline(taskData);
// }
//
// @Override
// protected AbstractBugzillaWizardPage getWizardDataPage() {
// return null;
// }

// Open new bug editor

// if (super.performFinish()) {
//
// String bugIdString = this.getId();
// int bugId = -1;
// // boolean validId = false;
// try {
// if (bugIdString != null) {
// bugId = Integer.parseInt(bugIdString);
// // validId = true;
// }
// } catch (NumberFormatException nfe) {
// MessageDialog.openError(null, IBugzillaConstants.TITLE_MESSAGE_DIALOG,
// "Could not create bug taskId, no valid taskId");
// return false;
// }
// // if (!validId) {
// // MessageDialog.openError(null,
// // IBugzillaConstants.TITLE_MESSAGE_DIALOG,
// // "Could not create bug taskId, no valid taskId");
// // return false;
// // }
//
// BugzillaTask newTask = new
// BugzillaTask(AbstractRepositoryTask.getHandle(repository.getUrl(), bugId),
// "<bugzilla info>", true);
// Object selectedObject = null;
// if (TaskListView.getFromActivePerspective() != null)
// selectedObject = ((IStructuredSelection)
// TaskListView.getFromActivePerspective().getViewer()
// .getSelection()).getFirstElement();
//
// // MylarTaskListPlugin.getTaskListManager().getTaskList().addTask(newTask);
//
// if (selectedObject instanceof TaskCategory) {
// MylarTaskListPlugin.getTaskListManager().getTaskList()
// .addTask(newTask, ((TaskCategory) selectedObject));
// } else {
// MylarTaskListPlugin.getTaskListManager().getTaskList().addTask(newTask,
// MylarTaskListPlugin.getTaskListManager().getTaskList().getRootCategory());
// }
//
// TasksUiUtil.refreshAndOpenTaskListElement(newTask);
// MylarTaskListPlugin.getSynchronizationManager().synchNow(0);
//
// return true;
// }

Back to the top