|
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004, 2007 Mylyn project committers and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
*******************************************************************************/ |
| 8 |
|
| 9 |
package org.eclipse.mylyn.internal.tasks.ui.actions; |
| 10 |
|
| 11 |
import org.eclipse.jface.action.Action; |
| 12 |
import org.eclipse.jface.action.IAction; |
| 13 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 14 |
import org.eclipse.jface.wizard.WizardDialog; |
| 15 |
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiConstants; |
| 16 |
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages; |
| 17 |
import org.eclipse.mylyn.internal.tasks.ui.wizards.NewTaskWizard; |
| 18 |
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; |
| 19 |
import org.eclipse.mylyn.tasks.core.RepositoryTaskData; |
| 20 |
import org.eclipse.mylyn.tasks.core.TaskComment; |
| 21 |
import org.eclipse.mylyn.tasks.core.TaskRepositoryManager; |
| 22 |
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin; |
| 23 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractRepositoryTaskEditor; |
| 24 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; |
| 25 |
import org.eclipse.swt.SWT; |
| 26 |
import org.eclipse.swt.dnd.Clipboard; |
| 27 |
import org.eclipse.swt.dnd.TextTransfer; |
| 28 |
import org.eclipse.swt.dnd.Transfer; |
| 29 |
import org.eclipse.swt.widgets.Shell; |
| 30 |
import org.eclipse.ui.IWorkbenchPage; |
| 31 |
import org.eclipse.ui.PlatformUI; |
| 32 |
|
| 33 |
/** |
| 34 |
* @author Frank Becker |
| 35 |
*/ |
| 36 |
public class NewBugFromCommentAction extends Action { |
| 37 |
|
| 38 |
private static final String LABEL = "New Task from Comment"; |
| 39 |
|
| 40 |
public static final String ID = "org.eclipse.mylyn.tasklist.actions.CreateNewFromComment"; |
| 41 |
|
| 42 |
private TaskComment taskComment; |
| 43 |
|
| 44 |
protected RepositoryTaskData taskData; |
| 45 |
|
| 46 |
public NewBugFromCommentAction() { |
| 47 |
super(LABEL); |
| 48 |
setId(ID); |
| 49 |
setImageDescriptor(TasksUiImages.TASK_NEW); |
| 50 |
|
| 51 |
setAccelerator(SWT.MOD1 + SWT.MOD2 + 'n'); |
| 52 |
} |
| 53 |
|
| 54 |
public void run(IAction action) { |
| 55 |
run(); |
| 56 |
} |
| 57 |
|
| 58 |
@Override |
| 59 |
public void run() { |
| 60 |
NewTaskWizard wizard = new NewTaskWizard(); |
| 61 |
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); |
| 62 |
if (shell != null && !shell.isDisposed()) { |
| 63 |
WizardDialog dialog = new WizardDialog(shell, wizard); |
| 64 |
dialog.setBlockOnOpen(true); |
| 65 |
if (dialog.open() == WizardDialog.CANCEL) { |
| 66 |
return; |
| 67 |
} |
| 68 |
|
| 69 |
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
| 70 |
AbstractRepositoryTaskEditor editor = null; |
| 71 |
String summary = ""; |
| 72 |
|
| 73 |
AbstractRepositoryConnector connector = null; |
| 74 |
TaskRepositoryManager repositoryManager = TasksUiPlugin.getRepositoryManager(); |
| 75 |
connector = repositoryManager.getRepositoryConnector(taskData.getRepositoryKind()); |
| 76 |
|
| 77 |
String description = "From task: " + connector.getTaskUrl(taskData.getRepositoryUrl(), taskData.getId()) |
| 78 |
+ " comment#" + taskComment.getNumber() + "\n\noriginal-comment:\n" + taskComment.getText(); |
| 79 |
|
| 80 |
try { |
| 81 |
TaskEditor taskEditor = (TaskEditor) page.getActiveEditor(); |
| 82 |
editor = (AbstractRepositoryTaskEditor) taskEditor.getActivePageInstance(); |
| 83 |
} catch (ClassCastException err) { |
| 84 |
Clipboard clipboard = new Clipboard(page.getWorkbenchWindow().getShell().getDisplay()); |
| 85 |
clipboard.setContents(new Object[] { summary + "\n" + description }, |
| 86 |
new Transfer[] { TextTransfer.getInstance() }); |
| 87 |
|
| 88 |
MessageDialog.openInformation( |
| 89 |
page.getWorkbenchWindow().getShell(), |
| 90 |
ITasksUiConstants.TITLE_DIALOG, |
| 91 |
"This connector does not provide a rich task editor for creating tasks.\n\n" |
| 92 |
+ "The error contents have been placed in the clipboard so that you can paste them into the entry form."); |
| 93 |
return; |
| 94 |
} |
| 95 |
|
| 96 |
editor.setSummaryText(summary); |
| 97 |
editor.setDescriptionText(description); |
| 98 |
|
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
public void setTaskComment(TaskComment taskComment) { |
| 103 |
this.taskComment = taskComment; |
| 104 |
} |
| 105 |
|
| 106 |
public void setTaskData(RepositoryTaskData taskData) { |
| 107 |
this.taskData = taskData; |
| 108 |
} |
| 109 |
|
| 110 |
} |