Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6f91cc872e67a70df1362a00182c2901511f9f1e (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
/*******************************************************************************
* Copyright (c) 2004, 2008 Tasktop Technologies 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:
 *     Eugene Kuleshov - initial API and implementation
 *     Tasktop Technologies - improvements
 *******************************************************************************/

package org.eclipse.mylyn.tasks.ui.wizards;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.mylyn.internal.tasks.ui.wizards.NewWebTaskPage;
import org.eclipse.mylyn.tasks.core.ITaskMapping;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;

/**
 * Wizard for creating new tickets through a web browser.
 * 
 * @author Eugene Kuleshov
 * @author Mik Kersten
 * @author Steffen Pingel
 * @since 2.0
 */
public class NewWebTaskWizard extends Wizard implements INewWizard {

	protected TaskRepository taskRepository;

	protected String newTaskUrl;

	private final ITaskMapping taskSelection;

	/**
	 * @since 3.0
	 */
	public NewWebTaskWizard(TaskRepository taskRepository, String newTaskUrl, ITaskMapping taskSelection) {
		this.taskRepository = taskRepository;
		this.newTaskUrl = newTaskUrl;
		this.taskSelection = taskSelection;

		setWindowTitle("New Task");
		setDefaultPageImageDescriptor(TasksUiImages.BANNER_REPOSITORY);
	}

	public void init(IWorkbench workbench, IStructuredSelection selection) {
	}

	@Override
	public void addPages() {
		addPage(new NewWebTaskPage(taskSelection));
	}

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

	@Override
	public boolean performFinish() {
		handleSelection(taskSelection);
		TasksUiUtil.openUrl(newTaskUrl);
		return true;
	}

	private void handleSelection(final ITaskMapping taskSelection) {
		if (taskSelection == null) {
			return;
		}

		String summary = taskSelection.getSummary();
		String description = taskSelection.getDescription();

		Clipboard clipboard = new Clipboard(getShell().getDisplay());
		clipboard.setContents(new Object[] { summary + "\n" + description },
				new Transfer[] { TextTransfer.getInstance() });

		MessageDialog.openInformation(
				getShell(),
				"New Task",
				"This connector does not provide a rich task editor for creating tasks.\n\n"
						+ "The error contents have been placed in the clipboard so that you can paste them into the entry form.");
	}

}

Back to the top