Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 159074 Details for
Bug 296441
[key-binding] provide template for inserting id of activate task
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
third version
296441.patch (text/plain), 16.78 KB, created by
Andreas Höhmann
on 2010-02-14 12:54:16 EST
(
hide
)
Description:
third version
Filename:
MIME Type:
Creator:
Andreas Höhmann
Created:
2010-02-14 12:54:16 EST
Size:
16.78 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mylyn.ide.tests >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.ide.tests/META-INF/MANIFEST.MF,v >retrieving revision 1.25 >diff -u -r1.25 MANIFEST.MF >--- META-INF/MANIFEST.MF 3 Feb 2010 17:17:04 -0000 1.25 >+++ META-INF/MANIFEST.MF 14 Feb 2010 17:51:42 -0000 >@@ -6,11 +6,18 @@ > Bundle-Vendor: Eclipse Mylyn > Require-Bundle: org.eclipse.core.runtime, > org.eclipse.jface, >+ org.eclipse.jface.text, > org.eclipse.ui.workbench, >+ org.eclipse.jdt.ui, >+ org.apache.commons.lang;bundle-version="2.3.0", > org.junit, > org.eclipse.mylyn.context.core, > org.eclipse.mylyn.context.tests, > org.eclipse.mylyn.team.ui, >- org.eclipse.mylyn.resources.ui >+ org.eclipse.mylyn.resources.ui, >+ org.eclipse.mylyn.ide.ui, >+ org.eclipse.mylyn.tasks.ui;bundle-version="3.4.0", >+ org.eclipse.mylyn.tasks.core;bundle-version="3.4.0", >+ org.eclipse.mylyn.tasks.tests;bundle-version="3.4.0" > Export-Package: org.eclipse.mylyn.ide.tests;x-internal:=true > Bundle-RequiredExecutionEnvironment: J2SE-1.5 >Index: src/org/eclipse/mylyn/ide/tests/TaskTemplateResolverTest.java >=================================================================== >RCS file: src/org/eclipse/mylyn/ide/tests/TaskTemplateResolverTest.java >diff -N src/org/eclipse/mylyn/ide/tests/TaskTemplateResolverTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/ide/tests/TaskTemplateResolverTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,143 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Andreas Höhmann. >+ * 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: >+ * Andreas Höhmann - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.mylyn.ide.tests; >+ >+import java.util.Iterator; >+ >+import junit.framework.TestCase; >+ >+import org.apache.commons.lang.builder.ToStringBuilder; >+import org.apache.commons.lang.exception.ExceptionUtils; >+import org.eclipse.jdt.internal.corext.template.java.JavaContextType; >+import org.eclipse.jdt.internal.corext.template.java.JavaDocContextType; >+import org.eclipse.jdt.internal.ui.JavaPlugin; >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.Document; >+import org.eclipse.jface.text.Position; >+import org.eclipse.jface.text.templates.ContextTypeRegistry; >+import org.eclipse.jface.text.templates.DocumentTemplateContext; >+import org.eclipse.jface.text.templates.Template; >+import org.eclipse.jface.text.templates.TemplateBuffer; >+import org.eclipse.jface.text.templates.TemplateContextType; >+import org.eclipse.jface.text.templates.TemplateException; >+import org.eclipse.jface.text.templates.TemplateTranslator; >+import org.eclipse.jface.text.templates.TemplateVariable; >+import org.eclipse.jface.text.templates.TemplateVariableResolver; >+import org.eclipse.mylyn.internal.tasks.core.LocalTask; >+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; >+import org.eclipse.mylyn.tasks.core.ITask; >+import org.eclipse.mylyn.tasks.tests.connector.MockTask; >+ >+/** >+ * @author andreas hoehmann >+ * @since 3.4 >+ */ >+public class TaskTemplateResolverTest extends TestCase { >+ >+ /** >+ * Test with no active task. The resolver should not be able to resolve the mylyn template-variable. >+ */ >+ public void testNoTaskActive() { >+ canHandleTemplateResolver("${activeTaskKey}", "activeTaskKey"); >+ canHandleTemplateResolver("${activeTaskPrefix}", "activeTaskPrefix"); >+ } >+ >+ /** >+ * Test with active task. The resolver must resolve the mylyn template-variable to the expected values. >+ */ >+ public void testActiveLocalTask() { >+ ITask task = new LocalTask("12345", "Test Task"); >+ TasksUiPlugin.getTaskActivityManager().activateTask(task); >+ canHandleTemplateResolver("${activeTaskKey}", "12345"); >+ canHandleTemplateResolver("${activeTaskPrefix}", "task"); >+ canHandleTemplateResolver("${activeTaskPrefix} ${activeTaskKey}", "task 12345"); >+ canHandleTemplateResolver("${activeTaskPrefix} #${activeTaskKey}", "task #12345"); >+ } >+ >+ /** >+ * Test with active task. Special check if task-key contains a "-". >+ */ >+ public void testActiveTaskJira() { >+ ITask task = new MockTask("http://foo.bar", "12345"); >+ task.setTaskKey("DEMO-2"); >+ TasksUiPlugin.getTaskActivityManager().activateTask(task); >+ canHandleTemplateResolver("${activeTaskKey}", "DEMO-2"); >+ canHandleTemplateResolver("${activeTaskPrefix} ${activeTaskKey}", "task DEMO-2"); >+ } >+ >+ /** >+ * Test with active task. Check if fallback from task-key to task-id is working. >+ */ >+ public void testActiveTaskIdOrKey() { >+ ITask task = new MockTask("http://foo.bar", "12345"); >+ TasksUiPlugin.getTaskActivityManager().activateTask(task); >+ canHandleTemplateResolver("${activeTaskKey}", "12345"); >+ canHandleTemplateResolver("${activeTaskPrefix}", "task"); >+ // from now the task have a key ... the resolve will prefer this key >+ task.setTaskKey("foobar"); >+ canHandleTemplateResolver("${activeTaskKey}", "foobar"); >+ } >+ >+ private void canHandleTemplateResolver(String templateContent, String expectedResolvedTemplate) { >+ // check java template context >+ canHandleTemplateResolver(JavaContextType.ID_ALL, templateContent, expectedResolvedTemplate); >+ // check javadoc template context >+ canHandleTemplateResolver(JavaDocContextType.ID, templateContent, expectedResolvedTemplate); >+ } >+ >+ private void canHandleTemplateResolver(final String contextType, final String templateContent, >+ final String expectedResolvedTemplate) { >+ final ContextTypeRegistry registry = JavaPlugin.getDefault().getTemplateContextRegistry(); >+ final TemplateContextType context = registry.getContextType(contextType); >+ final Template template = new Template("name", "description", contextType, templateContent, false); >+ final TemplateTranslator translator = new TemplateTranslator(); >+ TemplateBuffer buffer = null; >+ try { >+ buffer = translator.translate(template); >+ } catch (TemplateException e) { >+ fail(String.format("Can't translate template '%s' : %s", ToStringBuilder.reflectionToString(template), >+ ExceptionUtils.getMessage(e))); >+ } >+ final TemplateVariable[] variables = buffer.getVariables(); >+ for (final TemplateVariable variable : variables) { >+ assertTrue(String.format("No resolver found for variable '%s' in template '%s'", >+ ToStringBuilder.reflectionToString(variable), ToStringBuilder.reflectionToString(template)), >+ canHandleVariable(context, variable)); >+ } >+ assertEquals(expectedResolvedTemplate, getResolveTemplate(context, template)); >+ } >+ >+ private boolean canHandleVariable(final TemplateContextType context, final TemplateVariable variable) { >+ for (final Iterator iterator = context.resolvers(); iterator.hasNext();) { >+ final TemplateVariableResolver resolver = (TemplateVariableResolver) iterator.next(); >+ if (variable.getType().equals(resolver.getType())) { >+ return true; >+ } >+ } >+ return false; >+ } >+ >+ private String getResolveTemplate(final TemplateContextType context, final Template template) { >+ final DocumentTemplateContext templateContext = new DocumentTemplateContext(context, new Document(), >+ new Position(0)); >+ TemplateBuffer templateBuffer = null; >+ try { >+ templateBuffer = templateContext.evaluate(template); >+ } catch (BadLocationException e) { >+ fail(String.format("Can't evaluate template '%s' : %s", ToStringBuilder.reflectionToString(template), >+ ExceptionUtils.getMessage(e))); >+ } catch (TemplateException e) { >+ fail(String.format("Can't evaluate template '%s' : %s", ToStringBuilder.reflectionToString(template), >+ ExceptionUtils.getMessage(e))); >+ } >+ return templateBuffer.getString(); >+ } >+} >\ No newline at end of file >#P org.eclipse.mylyn.ide.ui >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.ide.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.378 >diff -u -r1.378 MANIFEST.MF >--- META-INF/MANIFEST.MF 3 Feb 2010 17:14:18 -0000 1.378 >+++ META-INF/MANIFEST.MF 14 Feb 2010 17:51:44 -0000 >@@ -15,7 +15,9 @@ > org.eclipse.mylyn.context.ui;bundle-version="[3.0.0,4.0.0)", > org.eclipse.mylyn.commons.core;bundle-version="[3.0.0,4.0.0)", > org.eclipse.mylyn.resources.ui;bundle-version="[3.0.0,4.0.0)", >- org.eclipse.mylyn.commons.ui;bundle-version="[3.0.0,4.0.0)" >+ org.eclipse.mylyn.commons.ui;bundle-version="[3.0.0,4.0.0)", >+ org.eclipse.mylyn.tasks.core;bundle-version="[3.0.0,4.0.0)", >+ org.eclipse.mylyn.tasks.ui;bundle-version="[3.0.0,4.0.0)" > Bundle-ActivationPolicy: lazy > Export-Package: org.eclipse.mylyn.ide.ui, > org.eclipse.mylyn.internal.ide.ui;x-internal:=true, >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.ide.ui/plugin.xml,v >retrieving revision 1.68 >diff -u -r1.68 plugin.xml >--- plugin.xml 12 Aug 2009 00:19:17 -0000 1.68 >+++ plugin.xml 14 Feb 2010 17:51:44 -0000 >@@ -222,5 +222,37 @@ > </newWizardShortcut> > </perspectiveExtension> > </extension> >+ <extension >+ id="org.eclipse.mylyn.internal.ide.ui.editors.templates" >+ point="org.eclipse.ui.editors.templates"> >+ <resolver >+ class="org.eclipse.mylyn.internal.ide.ui.TasksTemplateVariableResolver" >+ contextTypeId="java" >+ description="%MylynTemplateVariableResolver.activeTaskId.description" >+ name="Active Task ID" >+ type="activeTaskKey"> >+ </resolver> >+ <resolver >+ class="org.eclipse.mylyn.internal.ide.ui.TasksTemplateVariableResolver" >+ contextTypeId="javadoc" >+ description="%MylynTemplateVariableResolver.activeTaskId.description" >+ name="Active Task ID" >+ type="activeTaskKey"> >+ </resolver> >+ <resolver >+ class="org.eclipse.mylyn.internal.ide.ui.TasksTemplateVariableResolver" >+ contextTypeId="java" >+ description="%MylynTemplateVariableResolver.activeTaskPrefix.description" >+ name="Active Task Prefix" >+ type="activeTaskPrefix"> >+ </resolver> >+ <resolver >+ class="org.eclipse.mylyn.internal.ide.ui.TasksTemplateVariableResolver" >+ contextTypeId="javadoc" >+ description="%MylynTemplateVariableResolver.activeTaskPrefix.description" >+ name="Active Task Prefix" >+ type="activeTaskPrefix"> >+ </resolver> >+ </extension> > > </plugin> >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.ide.ui/plugin.properties,v >retrieving revision 1.3 >diff -u -r1.3 plugin.properties >--- plugin.properties 24 Jul 2009 12:06:30 -0000 1.3 >+++ plugin.properties 14 Feb 2010 17:51:43 -0000 >@@ -25,3 +25,6 @@ > FocusTaskMarkersViewAction.tooltip = Focus on Active Task > FocusBookmarkMarkersViewAction.label = Focus on Active Task > FocusBookmarkMarkersViewAction.tooltip = Focus on Active Task >+ >+MylynTemplateVariableResolver.activeTaskId.description = Return the ID of the active task >+MylynTemplateVariableResolver.activeTaskPrefix.description = Return the Prefix of the active task >Index: src/org/eclipse/mylyn/internal/ide/ui/TasksTemplateVariableResolver.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/ide/ui/TasksTemplateVariableResolver.java >diff -N src/org/eclipse/mylyn/internal/ide/ui/TasksTemplateVariableResolver.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/ide/ui/TasksTemplateVariableResolver.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,114 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Andreas Höhmann. >+ * 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: >+ * Andreas Höhmann - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.mylyn.internal.ide.ui; >+ >+import org.eclipse.jface.text.templates.TemplateContext; >+import org.eclipse.jface.text.templates.TemplateVariableResolver; >+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; >+import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; >+import org.eclipse.mylyn.tasks.core.ITask; >+ >+/** >+ * Resolver to resolve variables from the <b>mylyn</b> context. >+ * <p> >+ * This resolver can handle the following mylyn variable: >+ * <ul> >+ * <li>activeTaskPrefix - the prefix for the active task (if any) or null</li> >+ * <li>activeTaskKey - the key (or id) for the active task (if any) or null</li> >+ * </ul> >+ * </p> >+ * <h4>You want more variable? That's easy :D.</h4> >+ * <p> >+ * First add another template-resolver (for detail information see <a href="http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_editors_templates.html" >+ * >here</a>) for the <code>org.eclipse.mylyn.internal.ide.ui.editors.templates</code>. >+ * >+ * <pre> >+ * <extension point="org.eclipse.ui.editors.templates" >+ * id="org.eclipse.mylyn.internal.ide.ui.editors.templates"> >+ * <resolver >+ * class="org.eclipse.mylyn.internal.ide.ui.TasksTemplateVariableResolver" >+ * contextTypeId="<b>java</b>" >+ * description="%MylynTemplateVariableResolver.<b>activeTaskId.description</b>" >+ * name="<b>Active Task ID</b>" >+ * type="<b>activeTaskKey</b>"> >+ * </resolver> >+ * </extension> >+ * </pre> >+ * >+ * You have to define/change the: >+ * <ul> >+ * <li><b>contextTypeId</b> - you should define an resolver for the "java" and the "javadoc" context and maybe more >+ * contexts.</li> >+ * <li><b>type</b> - this is the property which can be used by users in there templates</li> >+ * <li><b>description</b> - this is the localized description for the resolver, have a look into >+ * <code>plugin.properties</code></li> >+ * <li><b>name</b> - the display name of the resolver (for internal usage only)</li> >+ * </ul> >+ * </p> >+ * <p> >+ * The you must put your resolver code here. >+ * <ol> >+ * <li>add a new constant for the resolver-<b>type</b> ("activeTaskKey")</li> >+ * <li>check your type in {@link #resolve(TemplateContext)} and resolve the type, return <code>null</code> if nothing >+ * can resolved, always <b>trim</b> your result</li> >+ * </ol> >+ * </p> >+ * <p> >+ * <i>Each returned variable should be trimmed to avoid avoid unnecessary spaces between the resolved variables, i.e. >+ * ("${activeTaskPrefix}${activeTaskKey}" should become "task2" and not "task 2").</i> >+ * </p> >+ * >+ * @author Andreas Höhmann (bug #296441) >+ * @since 3.3.2 >+ */ >+public class TasksTemplateVariableResolver extends TemplateVariableResolver { >+ >+ /** >+ * Would be used as resolver <code>type</code> to provide the ID of the active task. >+ */ >+ private static final String TYPE_ACTIVE_TASK_ID = "activeTaskKey"; //$NON-NLS-1$ >+ >+ /** >+ * Would be used as resolver <code>type</code> to provide the prefix (i.e. "bug") of the active task. >+ */ >+ private static final String TYPE_ACTIVE_TASK_PREFIX = "activeTaskPrefix"; //$NON-NLS-1$ >+ >+ /** >+ * {@inheritDoc} >+ */ >+ @Override >+ protected String resolve(final TemplateContext context) { >+ final String type = getType(); >+ if (TYPE_ACTIVE_TASK_ID.equalsIgnoreCase(type)) { >+ final ITask activeTask = TasksUiPlugin.getTaskActivityManager().getActiveTask(); >+ if (activeTask != null) { >+ String taskKey = activeTask.getTaskKey(); >+ if (taskKey == null) { >+ // use the task-id, i.e. for a local task, such a task doesn't have a task-key >+ taskKey = activeTask.getTaskId(); >+ } >+ if (taskKey != null) { >+ return taskKey.trim(); >+ } >+ } >+ } else if (TYPE_ACTIVE_TASK_PREFIX.equalsIgnoreCase(type)) { >+ final ITask activeTask = TasksUiPlugin.getTaskActivityManager().getActiveTask(); >+ if (activeTask != null) { >+ String taskPrefix = TasksUiInternal.getTaskPrefix(activeTask.getConnectorKind()); >+ if (taskPrefix != null) { >+ return taskPrefix.trim(); >+ } >+ } >+ } >+ // ... here later maybe more supported types ... >+ return null; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 296441
:
154464
|
155050
|
155051
|
155177
|
155305
|
155306
| 159074 |
159075
|
169601