|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004 - 2007 University Of British Columbia 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 |
* Contributors: |
| 9 |
* University Of British Columbia - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
|
| 12 |
package org.eclipse.mylar.internal.context.ui.actions; |
| 13 |
|
| 14 |
import org.eclipse.jface.action.IAction; |
| 15 |
import org.eclipse.jface.dialogs.InputDialog; |
| 16 |
import org.eclipse.jface.viewers.ISelection; |
| 17 |
import org.eclipse.jface.window.Window; |
| 18 |
import org.eclipse.mylar.internal.tasks.ui.views.TaskListView; |
| 19 |
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector; |
| 20 |
import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; |
| 21 |
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; |
| 22 |
import org.eclipse.mylar.tasks.core.ITask; |
| 23 |
import org.eclipse.mylar.tasks.ui.TasksUiPlugin; |
| 24 |
import org.eclipse.mylar.tasks.ui.search.SearchHitCollector; |
| 25 |
import org.eclipse.search.ui.ISearchQuery; |
| 26 |
import org.eclipse.search.ui.NewSearchUI; |
| 27 |
import org.eclipse.ui.IViewActionDelegate; |
| 28 |
import org.eclipse.ui.IViewPart; |
| 29 |
import org.eclipse.ui.PlatformUI; |
| 30 |
|
| 31 |
/** |
| 32 |
* Used for creating a query from the last task search result. |
| 33 |
* |
| 34 |
* @author Balazs Brinkus (bug 172699) |
| 35 |
*/ |
| 36 |
public class CreateTaskListQueryAction implements IViewActionDelegate { |
| 37 |
|
| 38 |
private AbstractRepositoryConnector connector; |
| 39 |
|
| 40 |
private AbstractRepositoryQuery query; |
| 41 |
|
| 42 |
public void init(IViewPart view) { |
| 43 |
// ignore |
| 44 |
} |
| 45 |
|
| 46 |
public void run(IAction action) { |
| 47 |
ISearchQuery[] queries = NewSearchUI.getQueries(); |
| 48 |
|
| 49 |
if (queries.length != 0 && connector != null) { |
| 50 |
SearchHitCollector searchHitCollector = (SearchHitCollector) queries[0]; |
| 51 |
query = (AbstractRepositoryQuery) searchHitCollector.getRepositoryQuery(); |
| 52 |
|
| 53 |
InputDialog dialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
| 54 |
"Enter query name", "Enter the name for the Query: ", "", null); |
| 55 |
int dialogResult = dialog.open(); |
| 56 |
if (dialogResult == Window.OK) { |
| 57 |
query.setHandleIdentifier(dialog.getValue()); |
| 58 |
TasksUiPlugin.getTaskListManager().getTaskList().addQuery(query); |
| 59 |
TasksUiPlugin.getSynchronizationManager().synchronize(connector, query, null, true); |
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
public void selectionChanged(IAction action, ISelection selection) { |
| 66 |
ITask selectedTask = TaskListView.getSelectedTask(selection); |
| 67 |
if (selectedTask instanceof AbstractRepositoryTask) { |
| 68 |
AbstractRepositoryTask task = (AbstractRepositoryTask) selectedTask; |
| 69 |
connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(task.getRepositoryKind()); |
| 70 |
action.setEnabled(true); |
| 71 |
} else { |
| 72 |
connector = null; |
| 73 |
action.setEnabled(false); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
} |