|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004 - 2007 Mylyn 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.search; |
| 10 |
|
| 11 |
import org.eclipse.jface.action.Action; |
| 12 |
import org.eclipse.jface.dialogs.InputDialog; |
| 13 |
import org.eclipse.jface.viewers.ISelection; |
| 14 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 15 |
import org.eclipse.jface.window.Window; |
| 16 |
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; |
| 17 |
import org.eclipse.mylyn.tasks.core.AbstractRepositoryQuery; |
| 18 |
import org.eclipse.mylyn.tasks.core.AbstractTask; |
| 19 |
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin; |
| 20 |
import org.eclipse.mylyn.tasks.ui.search.SearchHitCollector; |
| 21 |
import org.eclipse.search.ui.ISearchQuery; |
| 22 |
import org.eclipse.search.ui.NewSearchUI; |
| 23 |
import org.eclipse.ui.PlatformUI; |
| 24 |
|
| 25 |
/** |
| 26 |
* Used for add the last search result to the Task List. |
| 27 |
* |
| 28 |
* @author Balazs Brinkus (bug 172699) |
| 29 |
*/ |
| 30 |
public class AddTaskListAction extends Action { |
| 31 |
|
| 32 |
/** The view this action works on */ |
| 33 |
private RepositorySearchResultView resultView; |
| 34 |
|
| 35 |
/** The path of the icon */ |
| 36 |
private final String iconPath = "icons/etool16/query-new.gif"; |
| 37 |
|
| 38 |
/** |
| 39 |
* Constructor |
| 40 |
* |
| 41 |
* @param text |
| 42 |
* The text for this action |
| 43 |
* @param resultView |
| 44 |
* The <code>RepositorySearchResultView</code> this action works on |
| 45 |
*/ |
| 46 |
public AddTaskListAction(String text, RepositorySearchResultView resultView) { |
| 47 |
setText(text); |
| 48 |
setImageDescriptor(TasksUiPlugin.imageDescriptorFromPlugin(TasksUiPlugin.PLUGIN_ID, iconPath)); |
| 49 |
this.resultView = resultView; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Add the search result to the Task List. |
| 54 |
*/ |
| 55 |
public void run() { |
| 56 |
ISelection s = resultView.getViewer().getSelection(); |
| 57 |
if (s instanceof IStructuredSelection) { |
| 58 |
IStructuredSelection selection = (IStructuredSelection) s; |
| 59 |
if (selection.getFirstElement() instanceof AbstractTask) { |
| 60 |
ISearchQuery[] queries = NewSearchUI.getQueries(); |
| 61 |
AbstractTask task = (AbstractTask) selection.getFirstElement(); |
| 62 |
AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector( |
| 63 |
task.getRepositoryKind()); |
| 64 |
if (queries.length != 0 && connector != null) { |
| 65 |
SearchHitCollector searchHitCollector = (SearchHitCollector) queries[0]; |
| 66 |
AbstractRepositoryQuery query = (AbstractRepositoryQuery) searchHitCollector.getRepositoryQuery(); |
| 67 |
|
| 68 |
InputDialog dialog = new InputDialog(PlatformUI.getWorkbench() |
| 69 |
.getActiveWorkbenchWindow() |
| 70 |
.getShell(), "Enter query name", "Enter the name for the Query: ", "", null); |
| 71 |
int dialogResult = dialog.open(); |
| 72 |
if (dialogResult == Window.OK) { |
| 73 |
query.setHandleIdentifier(dialog.getValue()); |
| 74 |
TasksUiPlugin.getTaskListManager().getTaskList().addQuery(query); |
| 75 |
TasksUiPlugin.getSynchronizationManager().synchronize(connector, query, null, true); |
| 76 |
} |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
} |