Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2010 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 |
package org.eclipse.mylyn.internal.java.tasks; |
9 |
|
10 |
import org.eclipse.jface.text.templates.TemplateContext; |
11 |
import org.eclipse.jface.text.templates.TemplateVariableResolver; |
12 |
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; |
13 |
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; |
14 |
import org.eclipse.mylyn.tasks.core.ITask; |
15 |
import org.eclipse.mylyn.tasks.ui.TasksUi; |
16 |
|
17 |
/** |
18 |
* Resolver to resolve variables from the mylyn context. |
19 |
* |
20 |
* @author Andreas Höhmann (bug #296441) |
21 |
* @since 3.3.1 |
22 |
*/ |
23 |
public class TasksTemplateVariableResolver extends TemplateVariableResolver { |
24 |
|
25 |
/** |
26 |
* Would be used as resolver <code>type</code> to provide the ID of the active task. |
27 |
*/ |
28 |
private static final String TYPE_ACTIVE_TASK_ID = "activeTaskKey"; //$NON-NLS-1$ |
29 |
|
30 |
/** |
31 |
* Would be used as resolver <code>type</code> to provide the prefix (i.e. "bug") of the active task. |
32 |
*/ |
33 |
private static final String TYPE_ACTIVE_TASK_PREFIX = "activeTaskPrefix"; //$NON-NLS-1$ |
34 |
|
35 |
/** |
36 |
* {@inheritDoc} |
37 |
*/ |
38 |
@Override |
39 |
protected String resolve(final TemplateContext context) { |
40 |
final String type = getType(); |
41 |
if (TYPE_ACTIVE_TASK_ID.equalsIgnoreCase(type)) { |
42 |
final ITask activeTask = TasksUiPlugin.getTaskActivityManager().getActiveTask(); |
43 |
if (activeTask != null) { |
44 |
return activeTask.getTaskId(); |
45 |
} |
46 |
} |
47 |
if (TYPE_ACTIVE_TASK_PREFIX.equalsIgnoreCase(type)) { |
48 |
final ITask activeTask = TasksUiPlugin.getTaskActivityManager().getActiveTask(); |
49 |
if (activeTask != null) { |
50 |
final AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector( |
51 |
activeTask.getConnectorKind()); |
52 |
if (connector != null) { |
53 |
return connector.getTaskIdPrefix(); |
54 |
} |
55 |
} |
56 |
} |
57 |
return ""; //$NON-NLS-1$ |
58 |
} |
59 |
} |