Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 117517 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylar/internal/team/ContextChangeSet.java (-9 / +10 lines)
Lines 11-22 Link Here
11
11
12
package org.eclipse.mylar.internal.team;
12
package org.eclipse.mylar.internal.team;
13
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.HashSet;
17
import java.util.List;
18
import java.util.Set;
19
20
import org.eclipse.core.resources.IResource;
14
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.ResourcesPlugin;
15
import org.eclipse.core.resources.ResourcesPlugin;
22
import org.eclipse.core.resources.mapping.ResourceMapping;
16
import org.eclipse.core.resources.mapping.ResourceMapping;
Lines 35-40 Link Here
35
import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager;
29
import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager;
36
import org.osgi.service.prefs.Preferences;
30
import org.osgi.service.prefs.Preferences;
37
31
32
import java.util.ArrayList;
33
import java.util.Arrays;
34
import java.util.HashSet;
35
import java.util.List;
36
import java.util.Set;
37
38
/**
38
/**
39
 * @author Mik Kersten
39
 * @author Mik Kersten
40
 */
40
 */
Lines 101-109 Link Here
101
				MylarTeamPlugin.COMMIT_PREFIX_COMPLETED);
101
				MylarTeamPlugin.COMMIT_PREFIX_COMPLETED);
102
		String progressPrefix = MylarTeamPlugin.getDefault().getPreferenceStore().getString(
102
		String progressPrefix = MylarTeamPlugin.getDefault().getPreferenceStore().getString(
103
				MylarTeamPlugin.COMMIT_PREFIX_PROGRESS);
103
				MylarTeamPlugin.COMMIT_PREFIX_PROGRESS);
104
		String comment = "";
104
//		String comment = "";
105
		comment = generateComment(task, completedPrefix, progressPrefix);
105
//		comment = generateComment(task, completedPrefix, progressPrefix);
106
		return comment;
106
//		return comment;
107
        return TemplateHandlersManager.INSTANCE.generateComment(task, completedPrefix,progressPrefix);
107
	}
108
	}
108
109
109
	@Override
110
	@Override
(-)plugin.xml (+41 lines)
Lines 3-8 Link Here
3
<?eclipse version="3.0"?>
3
<?eclipse version="3.0"?>
4
<plugin>
4
<plugin>
5
   <extension-point id="providers" name="Mylar Team Providers" schema="schema/providers.exsd"/>
5
   <extension-point id="providers" name="Mylar Team Providers" schema="schema/providers.exsd"/>
6
   <extension-point id="templateHandlers" name="Mylar Template Handlers" schema="schema/templateHandlers.exsd"/>
6
    
7
    
7
   <extension
8
   <extension
8
         point="org.eclipse.mylar.team.providers">
9
         point="org.eclipse.mylar.team.providers">
Lines 152-155 Link Here
152
	   </viewerActionBinding>
153
	   </viewerActionBinding>
153
	</extension>
154
	</extension>
154
	
155
	
156
    <extension
157
          point="org.eclipse.mylar.team.templateHandlers">
158
       <templateHandler
159
             class="org.eclipse.mylar.internal.team.template.TaskCompletionDateTemplateHandler"
160
             description="Provides the completion date of a Mylar task."
161
             recognizedKeyword="task.completion.date"/>
162
       <templateHandler
163
             class="org.eclipse.mylar.internal.team.template.TaskCreationDateTemplateHandler"
164
             description="Provides the creation date of a Mylar task."
165
             recognizedKeyword="task.creation.date"/>
166
       <templateHandler
167
             class="org.eclipse.mylar.internal.team.template.TaskDescriptionTemplateHandler"
168
             description="Provides the description of a Mylar task."
169
             recognizedKeyword="task.description"/>
170
       <templateHandler
171
             class="org.eclipse.mylar.internal.team.template.TaskHandleIdentifierTemplateHandler"
172
             description="Provides the handle or identifier of a Mylar task."
173
             recognizedKeyword="task.id"/>
174
       <templateHandler
175
             class="org.eclipse.mylar.internal.team.template.TaskNotesTemplateHandler"
176
             description="Provides the notes of a Mylar task."
177
             recognizedKeyword="task.notes"/>
178
       <templateHandler
179
             class="org.eclipse.mylar.internal.team.template.TaskPriorityTemplateHandler"
180
             description="Provides the priority of a Mylar task."
181
             recognizedKeyword="task.priority"/>
182
       <templateHandler
183
             class="org.eclipse.mylar.internal.team.template.TaskReminderDateTemplateHandler"
184
             description="Provides the reminder date of a Mylar task."
185
             recognizedKeyword="task.reminder.date"/>
186
       <templateHandler
187
             class="org.eclipse.mylar.internal.team.template.TaskTypeTemplateHandler"
188
             description="Provides the type of a Mylar task."
189
             recognizedKeyword="task.type"/>
190
       <templateHandler
191
             class="org.eclipse.mylar.internal.team.template.TaskURLTemplateHandler"
192
             description="Provides the URL of a Mylar task."
193
             recognizedKeyword="task.url"/>
194
    </extension>
195
	
155
</plugin>
196
</plugin>
(-)src/org/eclipse/mylar/internal/team/template/AbstractDateTemplateHandler.java (+26 lines)
Added Link Here
1
package org.eclipse.mylar.internal.team.template;
2
3
4
import org.eclipse.mylar.internal.team.AbstractTemplateHandler;
5
import org.eclipse.mylar.tasks.core.ITask;
6
7
import java.util.Date;
8
9
10
public abstract class AbstractDateTemplateHandler extends AbstractTemplateHandler
11
{
12
  public AbstractDateTemplateHandler()
13
  {
14
  }
15
16
  /* (non-Javadoc)
17
   * @see org.eclipse.mylar.team.ITemplateHandler#getValue(org.eclipse.mylar.tasks.core.ITask)
18
   */
19
  public String getValue(ITask task)
20
  {
21
    Date date = getDate(task);
22
    return date.toString();
23
  }
24
  
25
  protected abstract Date getDate(ITask task);
26
}
(-)src/org/eclipse/mylar/internal/team/template/TaskCreationDateTemplateHandler.java (+21 lines)
Added Link Here
1
package org.eclipse.mylar.internal.team.template;
2
3
import org.eclipse.mylar.tasks.core.ITask;
4
5
import java.util.Date;
6
7
public class TaskCreationDateTemplateHandler extends AbstractDateTemplateHandler
8
{
9
  public TaskCreationDateTemplateHandler()
10
  {
11
  }
12
13
  /* (non-Javadoc)
14
   * @see org.eclipse.mylar.internal.team.template.AbstractDateTemplateHandler#getDate(org.eclipse.mylar.tasks.core.ITask)
15
   */
16
  @Override
17
  protected Date getDate(ITask task)
18
  {
19
    return task.getCreationDate();
20
  }
21
}
(-)src/org/eclipse/mylar/internal/team/template/TaskNotesTemplateHandler.java (+21 lines)
Added Link Here
1
package org.eclipse.mylar.internal.team.template;
2
3
4
import org.eclipse.mylar.internal.team.AbstractTemplateHandler;
5
import org.eclipse.mylar.tasks.core.ITask;
6
7
8
public class TaskNotesTemplateHandler extends AbstractTemplateHandler
9
{
10
  public TaskNotesTemplateHandler()
11
  {
12
  }
13
14
  /* (non-Javadoc)
15
   * @see org.eclipse.mylar.team.ITemplateHandler#getValue(org.eclipse.mylar.tasks.core.ITask)
16
   */
17
  public String getValue(ITask task)
18
  {
19
    return task.getNotes();
20
  }
21
}
(-)src/org/eclipse/mylar/internal/team/template/TaskHandleIdentifierTemplateHandler.java (+21 lines)
Added Link Here
1
package org.eclipse.mylar.internal.team.template;
2
3
4
import org.eclipse.mylar.internal.team.AbstractTemplateHandler;
5
import org.eclipse.mylar.tasks.core.ITask;
6
7
8
public class TaskHandleIdentifierTemplateHandler extends AbstractTemplateHandler
9
{
10
  public TaskHandleIdentifierTemplateHandler()
11
  {
12
  }
13
14
  /* (non-Javadoc)
15
   * @see org.eclipse.mylar.team.ITemplateHandler#getValue(org.eclipse.mylar.tasks.core.ITask)
16
   */
17
  public String getValue(ITask task)
18
  {
19
    return task.getHandleIdentifier();
20
  }
21
}
(-)src/org/eclipse/mylar/internal/team/template/TaskReminderDateTemplateHandler.java (+21 lines)
Added Link Here
1
package org.eclipse.mylar.internal.team.template;
2
3
import org.eclipse.mylar.tasks.core.ITask;
4
5
import java.util.Date;
6
7
public class TaskReminderDateTemplateHandler extends AbstractDateTemplateHandler
8
{
9
  public TaskReminderDateTemplateHandler()
10
  {
11
  }
12
13
  /* (non-Javadoc)
14
   * @see org.eclipse.mylar.internal.team.template.AbstractDateTemplateHandler#getDate(org.eclipse.mylar.tasks.core.ITask)
15
   */
16
  @Override
17
  protected Date getDate(ITask task)
18
  {
19
    return task.getReminderDate();
20
  }
21
}
(-)src/org/eclipse/mylar/internal/team/AbstractTemplateHandler.java (+41 lines)
Added Link Here
1
package org.eclipse.mylar.internal.team;
2
3
4
import org.eclipse.mylar.team.ITemplateHandler;
5
6
7
public abstract class AbstractTemplateHandler implements ITemplateHandler
8
{
9
  protected String description;
10
11
  protected String recognizedKeyword;
12
13
  public AbstractTemplateHandler()
14
  {
15
  }
16
17
  public String getDescription()
18
  {
19
    return description != null ? description : "Handler for '" + recognizedKeyword + "'";
20
  }
21
22
  public void setDescription(String description)
23
  {
24
    this.description = description;
25
  }
26
27
  public String getRecognizedKeyword()
28
  {
29
    return recognizedKeyword;
30
  }
31
32
  public void setRecognizedKeyword(String recognizedKeyword)
33
  {
34
    if (recognizedKeyword == null)
35
    {
36
      throw new IllegalArgumentException("Keyword to recognize must not be null");
37
    }
38
39
    this.recognizedKeyword = recognizedKeyword;
40
  }
41
}
(-)src/org/eclipse/mylar/internal/team/template/TaskPriorityTemplateHandler.java (+21 lines)
Added Link Here
1
package org.eclipse.mylar.internal.team.template;
2
3
4
import org.eclipse.mylar.internal.team.AbstractTemplateHandler;
5
import org.eclipse.mylar.tasks.core.ITask;
6
7
8
public class TaskPriorityTemplateHandler extends AbstractTemplateHandler
9
{
10
  public TaskPriorityTemplateHandler()
11
  {
12
  }
13
14
  /* (non-Javadoc)
15
   * @see org.eclipse.mylar.team.ITemplateHandler#getValue(org.eclipse.mylar.tasks.core.ITask)
16
   */
17
  public String getValue(ITask task)
18
  {
19
    return task.getPriority();
20
  }
21
}
(-)src/org/eclipse/mylar/internal/team/template/TaskCompletionDateTemplateHandler.java (+21 lines)
Added Link Here
1
package org.eclipse.mylar.internal.team.template;
2
3
import org.eclipse.mylar.tasks.core.ITask;
4
5
import java.util.Date;
6
7
public class TaskCompletionDateTemplateHandler extends AbstractDateTemplateHandler
8
{
9
  public TaskCompletionDateTemplateHandler()
10
  {
11
  }
12
13
  /* (non-Javadoc)
14
   * @see org.eclipse.mylar.internal.team.template.AbstractDateTemplateHandler#getDate(org.eclipse.mylar.tasks.core.ITask)
15
   */
16
  @Override
17
  protected Date getDate(ITask task)
18
  {
19
    return task.getCompletionDate();
20
  }
21
}
(-)src/org/eclipse/mylar/internal/team/template/TaskURLTemplateHandler.java (+21 lines)
Added Link Here
1
package org.eclipse.mylar.internal.team.template;
2
3
4
import org.eclipse.mylar.internal.team.AbstractTemplateHandler;
5
import org.eclipse.mylar.tasks.core.ITask;
6
7
8
public class TaskURLTemplateHandler extends AbstractTemplateHandler
9
{
10
  public TaskURLTemplateHandler()
11
  {
12
  }
13
14
  /* (non-Javadoc)
15
   * @see org.eclipse.mylar.team.ITemplateHandler#getValue(org.eclipse.mylar.tasks.core.ITask)
16
   */
17
  public String getValue(ITask task)
18
  {
19
    return task.getUrl();
20
  }
21
}
(-)schema/templateHandlers.exsd (+122 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.mylar.team">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.mylar.team" id="templateHandlers" name="Mylar Template Handlers"/>
7
      </appInfo>
8
      <documentation>
9
         [Enter description of this extension point.]
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <complexType>
15
         <sequence>
16
            <element ref="templateHandler" minOccurs="1" maxOccurs="unbounded"/>
17
         </sequence>
18
         <attribute name="point" type="string" use="required">
19
            <annotation>
20
               <documentation>
21
                  
22
               </documentation>
23
            </annotation>
24
         </attribute>
25
         <attribute name="id" type="string">
26
            <annotation>
27
               <documentation>
28
                  
29
               </documentation>
30
            </annotation>
31
         </attribute>
32
         <attribute name="name" type="string">
33
            <annotation>
34
               <documentation>
35
                  
36
               </documentation>
37
               <appInfo>
38
                  <meta.attribute translatable="true"/>
39
               </appInfo>
40
            </annotation>
41
         </attribute>
42
      </complexType>
43
   </element>
44
45
   <element name="templateHandler">
46
      <complexType>
47
         <attribute name="class" type="string" use="required">
48
            <annotation>
49
               <documentation>
50
                  
51
               </documentation>
52
               <appInfo>
53
                  <meta.attribute kind="java" basedOn="org.eclipse.mylar.team.ITemplateHandler"/>
54
               </appInfo>
55
            </annotation>
56
         </attribute>
57
         <attribute name="description" type="string">
58
            <annotation>
59
               <documentation>
60
                  
61
               </documentation>
62
               <appInfo>
63
                  <meta.attribute translatable="true"/>
64
               </appInfo>
65
            </annotation>
66
         </attribute>
67
         <attribute name="recognizedKeyword" type="string" use="required">
68
            <annotation>
69
               <documentation>
70
                  
71
               </documentation>
72
            </annotation>
73
         </attribute>
74
      </complexType>
75
   </element>
76
77
   <annotation>
78
      <appInfo>
79
         <meta.section type="since"/>
80
      </appInfo>
81
      <documentation>
82
         [Enter the first release in which this extension point appears.]
83
      </documentation>
84
   </annotation>
85
86
   <annotation>
87
      <appInfo>
88
         <meta.section type="examples"/>
89
      </appInfo>
90
      <documentation>
91
         [Enter extension point usage example here.]
92
      </documentation>
93
   </annotation>
94
95
   <annotation>
96
      <appInfo>
97
         <meta.section type="apiInfo"/>
98
      </appInfo>
99
      <documentation>
100
         [Enter API information here.]
101
      </documentation>
102
   </annotation>
103
104
   <annotation>
105
      <appInfo>
106
         <meta.section type="implementation"/>
107
      </appInfo>
108
      <documentation>
109
         [Enter information about supplied implementation of this extension point.]
110
      </documentation>
111
   </annotation>
112
113
   <annotation>
114
      <appInfo>
115
         <meta.section type="copyright"/>
116
      </appInfo>
117
      <documentation>
118
         
119
      </documentation>
120
   </annotation>
121
122
</schema>
(-)src/org/eclipse/mylar/internal/team/TemplateHandlersManager.java (+155 lines)
Added Link Here
1
package org.eclipse.mylar.internal.team;
2
3
4
import org.eclipse.core.runtime.IConfigurationElement;
5
import org.eclipse.core.runtime.IExtension;
6
import org.eclipse.core.runtime.IExtensionPoint;
7
import org.eclipse.core.runtime.Platform;
8
import org.eclipse.mylar.context.core.MylarStatusHandler;
9
import org.eclipse.mylar.tasks.core.ITask;
10
import org.eclipse.mylar.team.ITemplateHandler;
11
import org.eclipse.mylar.team.MylarTeamPlugin;
12
13
import java.text.MessageFormat;
14
import java.util.ArrayList;
15
import java.util.Collections;
16
import java.util.List;
17
18
19
/**
20
 * @author Eike Stepper
21
 */
22
public class TemplateHandlersManager
23
{
24
  public static final TemplateHandlersManager INSTANCE = new TemplateHandlersManager();
25
26
  private static final String ATTR_CLASS = "class";
27
28
  private static final String ATTR_DESCRIPTION = "description";
29
30
  private static final String ATTR_RECOGNIZED_KEYWORD = "recognizedKeyword";
31
32
  private static final String ELEM_TEMPLATE_HANDLER = "templateHandler";
33
34
  private static final String EXT_POINT_TEMPLATE_HANDLERS = "templateHandlers";
35
36
  private List<ITemplateHandler> handlers;
37
38
  private TemplateHandlersManager()
39
  {
40
    readExtensions();
41
  }
42
43
  private void readExtensions()
44
  {
45
    ArrayList<ITemplateHandler> handlerList = new ArrayList<ITemplateHandler>();
46
    IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(
47
            MylarTeamPlugin.PLUGIN_ID, EXT_POINT_TEMPLATE_HANDLERS);
48
    IExtension[] extensions = extPoint.getExtensions();
49
    for (int i = 0; i < extensions.length; i++)
50
    {
51
      IExtension extension = extensions[i];
52
      IConfigurationElement[] elements = extension.getConfigurationElements();
53
      for (int j = 0; j < elements.length; j++)
54
      {
55
        IConfigurationElement element = elements[j];
56
        if (ELEM_TEMPLATE_HANDLER.equals(element.getName()))
57
        {
58
          try
59
          {
60
            String description = element.getAttribute(ATTR_DESCRIPTION);
61
            String keyword = element.getAttribute(ATTR_RECOGNIZED_KEYWORD);
62
            ITemplateHandler handler = (ITemplateHandler)element
63
                    .createExecutableExtension(ATTR_CLASS);
64
            if (handler instanceof AbstractTemplateHandler)
65
            {
66
              ((AbstractTemplateHandler)handler).setDescription(description);
67
              ((AbstractTemplateHandler)handler).setRecognizedKeyword(keyword);
68
            }
69
            else
70
            {
71
              String recognizedKeyword = handler.getRecognizedKeyword();
72
              if (recognizedKeyword == null || !recognizedKeyword.equals(keyword))
73
              {
74
                throw new IllegalArgumentException(
75
                        "Keyword markup does not match handler implementation");
76
              }
77
            }
78
79
            handlerList.add(handler);
80
          }
81
          catch (Exception e)
82
          {
83
            MylarStatusHandler.log(e, MessageFormat.format(
84
                    "Error while initializing template handler contribution {0} from plugin {1}.",
85
                    element.getAttribute(ATTR_CLASS), element.getContributor().getName()));
86
          }
87
        }
88
      }
89
    }
90
91
    handlerList.trimToSize();
92
    this.handlers = Collections.unmodifiableList(handlerList);
93
  }
94
95
  /**
96
   * Returns the list of contributed {@link ITemplateHandler}.
97
   * 
98
   * @return a list of {@link ITemplateHandler}
99
   */
100
  public List<ITemplateHandler> getHandlers()
101
  {
102
    return handlers;
103
  }
104
105
  public String generateComment(ITask task, String completedTemplate,
106
          String progressTemplate)
107
  {
108
    String template = task.isCompleted() ? completedTemplate : progressTemplate;
109
    return processKeywords(task, template);
110
  }
111
112
  public String processKeywords(ITask task, String template)
113
  {
114
    String[] segments = template.split("\\$\\{");
115
    StringBuffer buffer = new StringBuffer(segments[0]);
116
117
    for (int i = 1; i < segments.length; i++)
118
    {
119
      String segment = segments[i];
120
      String value = null;
121
      int brace = segment.indexOf('}');
122
      if (brace > 0)
123
      {
124
        String keyword = segment.substring(0, brace);
125
        value = handleKeyword(task, keyword);
126
      }
127
128
      if (value != null)
129
      {
130
        buffer.append(value);
131
        buffer.append(segment.substring(brace + 1));
132
      }
133
      else
134
      {
135
        buffer.append("${");
136
        buffer.append(segment);
137
      }
138
    }
139
140
    return buffer.toString();
141
  }
142
143
  private String handleKeyword(ITask task, String keyword)
144
  {
145
    for (ITemplateHandler handler : getHandlers())
146
    {
147
      if (handler.getRecognizedKeyword().equals(keyword))
148
      {
149
        return handler.getValue(task);
150
      }
151
    }
152
153
    return null;
154
  }
155
}
(-)src/org/eclipse/mylar/internal/team/template/TaskTypeTemplateHandler.java (+21 lines)
Added Link Here
1
package org.eclipse.mylar.internal.team.template;
2
3
4
import org.eclipse.mylar.internal.team.AbstractTemplateHandler;
5
import org.eclipse.mylar.tasks.core.ITask;
6
7
8
public class TaskTypeTemplateHandler extends AbstractTemplateHandler
9
{
10
  public TaskTypeTemplateHandler()
11
  {
12
  }
13
14
  /* (non-Javadoc)
15
   * @see org.eclipse.mylar.team.ITemplateHandler#getValue(org.eclipse.mylar.tasks.core.ITask)
16
   */
17
  public String getValue(ITask task)
18
  {
19
    return task.getTaskType();
20
  }
21
}
(-)src/org/eclipse/mylar/team/ITemplateHandler.java (+14 lines)
Added Link Here
1
package org.eclipse.mylar.team;
2
3
4
import org.eclipse.mylar.tasks.core.ITask;
5
6
7
public interface ITemplateHandler
8
{
9
  public String getDescription();
10
11
  public String getRecognizedKeyword();
12
13
  public String getValue(ITask task);
14
}
(-)src/org/eclipse/mylar/internal/team/template/TaskDescriptionTemplateHandler.java (+21 lines)
Added Link Here
1
package org.eclipse.mylar.internal.team.template;
2
3
4
import org.eclipse.mylar.internal.team.AbstractTemplateHandler;
5
import org.eclipse.mylar.tasks.core.ITask;
6
7
8
public class TaskDescriptionTemplateHandler extends AbstractTemplateHandler
9
{
10
  public TaskDescriptionTemplateHandler()
11
  {
12
  }
13
14
  /* (non-Javadoc)
15
   * @see org.eclipse.mylar.team.ITemplateHandler#getValue(org.eclipse.mylar.tasks.core.ITask)
16
   */
17
  public String getValue(ITask task)
18
  {
19
    return task.getDescription();
20
  }
21
}

Return to bug 117517