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/team/MylarTeamPlugin.java (-62 / +91 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 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
 *     Eike Stepper - template based commit templates
11
 *******************************************************************************/
1
package org.eclipse.mylar.team;
12
package org.eclipse.mylar.team;
2
13
14
3
import org.eclipse.mylar.context.core.MylarStatusHandler;
15
import org.eclipse.mylar.context.core.MylarStatusHandler;
4
import org.eclipse.mylar.internal.team.ContextChangeSetManager;
16
import org.eclipse.mylar.internal.team.ContextChangeSetManager;
5
import org.eclipse.ui.IStartup;
17
import org.eclipse.ui.IStartup;
Lines 7-79 Link Here
7
import org.eclipse.ui.plugin.AbstractUIPlugin;
19
import org.eclipse.ui.plugin.AbstractUIPlugin;
8
import org.osgi.framework.BundleContext;
20
import org.osgi.framework.BundleContext;
9
21
22
10
/**
23
/**
11
 * The activator class controls the plug-in life cycle
24
 * The activator class controls the plug-in life cycle
12
 */
25
 */
13
public class MylarTeamPlugin extends AbstractUIPlugin implements IStartup {
26
public class MylarTeamPlugin extends AbstractUIPlugin implements IStartup
27
{
14
28
15
	public static final String PLUGIN_ID = "org.eclipse.mylar.team";
29
  public static final String PLUGIN_ID = "org.eclipse.mylar.team";
16
30
17
	private static MylarTeamPlugin INSTANCE;
31
  private static MylarTeamPlugin INSTANCE;
18
32
19
	private ContextChangeSetManager changeSetManager;
33
  private ContextChangeSetManager changeSetManager;
20
34
21
	public static final String CHANGE_SET_MANAGE = "org.eclipse.mylar.team.changesets.manage";
35
  public static final String CHANGE_SET_MANAGE = "org.eclipse.mylar.team.changesets.manage";
22
36
23
	public static final String COMMIT_PREFIX_COMPLETED = "org.eclipse.mylar.team.commit.template.completed";
37
  public static final String COMMIT_TEMPLATE_COMPLETED = "org.eclipse.mylar.team.commit.template.completed";
24
38
25
	public static final String COMMIT_PREFIX_PROGRESS = "org.eclipse.mylar.team.commit.template.progress";
39
  public static final String COMMIT_TEMPLATE_PROGRESS = "org.eclipse.mylar.team.commit.template.progress";
26
40
27
	public static final String DEFAULT_PREFIX_PROGRESS = "Progress on:";
41
  public static final String COMMIT_REGEX_TASK_ID = "org.eclipse.mylar.team.commit.regex";
28
42
  
29
	public static final String DEFAULT_PREFIX_COMPLETED = "Completed:";
43
  public static final String DEFAULT_TEMPLATE_PROGRESS = "[${task.id}] ${task.summary} ${task.url}";
30
44
31
	public MylarTeamPlugin() {
45
  public static final String DEFAULT_TEMPLATE_COMPLETED = "[${task.id}] ${task.summary} (COMPLETED) ${task.url}";
32
		INSTANCE = this;
46
33
	}
47
  public static final String DEFAULT_REGEX_TASK_ID = "\\[(\\d+)\\].*";
34
48
35
	public void start(BundleContext context) throws Exception {
49
  public MylarTeamPlugin()
36
		super.start(context);
50
  {
37
		initPreferenceDefaults();
51
    INSTANCE = this;
38
52
  }
39
		PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
53
40
			public void run() {
54
  public void start(BundleContext context) throws Exception
41
				try { 
55
  {
42
					changeSetManager = new ContextChangeSetManager();
56
    super.start(context);
43
					if (getPreferenceStore().getBoolean(CHANGE_SET_MANAGE)) {
57
    initPreferenceDefaults();
44
						changeSetManager.enable();
58
45
					}
59
    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable()
46
				} catch (Exception e) {
60
    {
47
					MylarStatusHandler.fail(e, "Mylar Team start failed",
61
      public void run()
48
							false);
62
      {
49
				}
63
        try
50
			}
64
        {
51
		});
65
          changeSetManager = new ContextChangeSetManager();
52
	}
66
          if (getPreferenceStore().getBoolean(CHANGE_SET_MANAGE))
53
67
          {
54
	public void earlyStartup() {
68
            changeSetManager.enable();
55
		// all done in start	
69
          }
56
	}
70
        }
57
	
71
        catch (Exception e)
58
	public void stop(BundleContext context) throws Exception {
72
        {
59
		INSTANCE = null;
73
          MylarStatusHandler.fail(e, "Mylar Team start failed", false);
60
		super.stop(context);
74
        }
61
		changeSetManager.disable();
75
      }
62
	}
76
    });
63
77
  }
64
	private void initPreferenceDefaults() {
78
65
		getPreferenceStore().setDefault(CHANGE_SET_MANAGE, true);
79
  public void earlyStartup()
66
		getPreferenceStore().setDefault(COMMIT_PREFIX_COMPLETED,
80
  {
67
				DEFAULT_PREFIX_COMPLETED);
81
    // all done in start	
68
		getPreferenceStore().setDefault(COMMIT_PREFIX_PROGRESS,
82
  }
69
				DEFAULT_PREFIX_PROGRESS);
83
70
	}
84
  public void stop(BundleContext context) throws Exception
71
85
  {
72
	public static MylarTeamPlugin getDefault() {
86
    INSTANCE = null;
73
		return INSTANCE;
87
    super.stop(context);
74
	}
88
    changeSetManager.disable();
75
89
  }
76
	public ContextChangeSetManager getChangeSetManager() {
90
77
		return changeSetManager;
91
  private void initPreferenceDefaults()
78
	}
92
  {
93
    getPreferenceStore().setDefault(CHANGE_SET_MANAGE, true);
94
    getPreferenceStore().setDefault(COMMIT_TEMPLATE_COMPLETED, DEFAULT_TEMPLATE_COMPLETED);
95
    getPreferenceStore().setDefault(COMMIT_TEMPLATE_PROGRESS, DEFAULT_TEMPLATE_PROGRESS);
96
    getPreferenceStore().setDefault(COMMIT_REGEX_TASK_ID, DEFAULT_REGEX_TASK_ID);
97
  }
98
99
  public static MylarTeamPlugin getDefault()
100
  {
101
    return INSTANCE;
102
  }
103
104
  public ContextChangeSetManager getChangeSetManager()
105
  {
106
    return changeSetManager;
107
  }
79
}
108
}
(-)src/org/eclipse/mylar/internal/team/ContextChangeSet.java (-240 / +320 lines)
Lines 7-21 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
9
 *     University Of British Columbia - initial API and implementation
10
 *     Eike Stepper - template based commit templates
10
 *******************************************************************************/
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
14
20
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.ResourcesPlugin;
16
import org.eclipse.core.resources.ResourcesPlugin;
Lines 23-30 Link Here
23
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.core.runtime.IAdaptable;
25
import org.eclipse.mylar.context.core.InteractionEvent;
20
import org.eclipse.mylar.context.core.InteractionEvent;
21
import org.eclipse.mylar.context.core.MylarStatusHandler;
26
import org.eclipse.mylar.resources.MylarResourcesPlugin;
22
import org.eclipse.mylar.resources.MylarResourcesPlugin;
27
import org.eclipse.mylar.tasks.core.ITask;
23
import org.eclipse.mylar.tasks.core.ITask;
24
import org.eclipse.mylar.team.ITemplateHandlersManager;
28
import org.eclipse.mylar.team.MylarTeamPlugin;
25
import org.eclipse.mylar.team.MylarTeamPlugin;
29
import org.eclipse.team.core.TeamException;
26
import org.eclipse.team.core.TeamException;
30
import org.eclipse.team.core.diff.IDiff;
27
import org.eclipse.team.core.diff.IDiff;
Lines 35-279 Link Here
35
import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager;
32
import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager;
36
import org.osgi.service.prefs.Preferences;
33
import org.osgi.service.prefs.Preferences;
37
34
35
import java.util.ArrayList;
36
import java.util.Arrays;
37
import java.util.HashSet;
38
import java.util.List;
39
import java.util.Set;
40
import java.util.regex.Matcher;
41
import java.util.regex.Pattern;
42
43
38
/**
44
/**
39
 * @author Mik Kersten
45
 * @author Mik Kersten
40
 */
46
 */
41
public class ContextChangeSet extends CVSActiveChangeSet implements IAdaptable {
47
public class ContextChangeSet extends CVSActiveChangeSet implements IAdaptable
48
{
42
49
43
	private static final String PREFIX_HTTP = "http://";
50
  private static final String PREFIX_HTTP = "http://";
44
51
45
	private static final String PREFIX_HTTPS = "https://";
52
  private static final String PREFIX_HTTPS = "https://";
46
53
47
	private static final String PREFIX_DELIM = ": ";
54
  private static final String PREFIX_DELIM = ": ";
48
55
49
	// HACK: copied from super
56
  // HACK: copied from super
50
	private static final String CTX_TITLE = "title";
57
  private static final String CTX_TITLE = "title";
51
58
52
	public static final String SOURCE_ID = "org.eclipse.mylar.java.context.changeset.add";
59
  public static final String SOURCE_ID = "org.eclipse.mylar.java.context.changeset.add";
53
60
54
	private boolean suppressInterestContribution = false;
61
  private boolean suppressInterestContribution = false;
55
62
56
	private ITask task;
63
  private ITask task;
57
64
58
	public ContextChangeSet(ITask task, ActiveChangeSetManager manager) {
65
  public ContextChangeSet(ITask task, ActiveChangeSetManager manager)
59
		super(manager, task.getDescription());
66
  {
60
		this.task = task;
67
    super(manager, task.getDescription());
61
		initTitle();
68
    this.task = task;
62
	}
69
    initTitle();
63
70
  }
64
	@Override
71
65
	public boolean isUserCreated() {
72
  @Override
66
		return true;
73
  public boolean isUserCreated()
67
	}
74
  {
68
	
75
    return true;
69
	public void initTitle() {
76
  }
70
		super.setName(task.getDescription());
77
71
		super.setTitle(task.getDescription());
78
  public void initTitle()
72
	}
79
  {
73
80
    super.setName(task.getDescription());
74
	/**
81
    super.setTitle(task.getDescription());
75
	 * Encodes the handle in the title, since init won't get called on this
82
  }
76
	 * class.
83
77
	 */
84
  /**
78
	@Override
85
   * Encodes the handle in the title, since init won't get called on this
79
	public void save(Preferences prefs) {
86
   * class.
80
		super.save(prefs);
87
   */
81
		prefs.put(CTX_TITLE, getTitleForPersistance());
88
  @Override
82
	}
89
  public void save(Preferences prefs)
83
90
  {
84
	private String getTitleForPersistance() {
91
    super.save(prefs);
85
		return getTitle() + " (" + task.getHandleIdentifier() + ")";
92
    prefs.put(CTX_TITLE, getTitleForPersistance());
86
	}
93
  }
87
94
88
	public static String getHandleFromPersistedTitle(String title) {
95
  private String getTitleForPersistance()
89
		int delimStart = title.lastIndexOf('(');
96
  {
90
		int delimEnd = title.lastIndexOf(')');
97
    return getTitle() + " (" + task.getHandleIdentifier() + ")";
91
		if (delimStart != -1 && delimEnd != -1) {
98
  }
92
			return title.substring(delimStart + 1, delimEnd);
99
93
		} else {
100
  public static String getHandleFromPersistedTitle(String title)
94
			return null;
101
  {
95
		}
102
    int delimStart = title.lastIndexOf('(');
96
	}
103
    int delimEnd = title.lastIndexOf(')');
97
104
    if (delimStart != -1 && delimEnd != -1)
98
	@Override
105
    {
99
	public String getComment() {
106
      return title.substring(delimStart + 1, delimEnd);
100
		String completedPrefix = MylarTeamPlugin.getDefault().getPreferenceStore().getString(
107
    }
101
				MylarTeamPlugin.COMMIT_PREFIX_COMPLETED);
108
    else
102
		String progressPrefix = MylarTeamPlugin.getDefault().getPreferenceStore().getString(
109
    {
103
				MylarTeamPlugin.COMMIT_PREFIX_PROGRESS);
110
      return null;
104
		String comment = "";
111
    }
105
		comment = generateComment(task, completedPrefix, progressPrefix);
112
  }
106
		return comment;
113
107
	}
114
  @Override
108
115
  public String getComment()
109
	@Override
116
  {
110
	public void remove(IResource resource) {
117
    String completedTemplate = MylarTeamPlugin.getDefault().getPreferenceStore().getString(
111
		super.remove(resource);
118
            MylarTeamPlugin.COMMIT_TEMPLATE_COMPLETED);
112
	}
119
    String progressTemplate = MylarTeamPlugin.getDefault().getPreferenceStore().getString(
113
120
            MylarTeamPlugin.COMMIT_TEMPLATE_PROGRESS);
114
	@Override
121
    return ITemplateHandlersManager.INSTANCE.generateComment(task, completedTemplate,
115
	public void remove(IResource[] newResources) {
122
            progressTemplate);
116
		super.remove(newResources);
123
  }
117
	}
124
118
125
  @Override
119
	@Override
126
  public void remove(IResource resource)
120
	public void add(IDiff diff) {
127
  {
121
		super.add(diff);
128
    super.remove(resource);
122
		IResource resource = getResourceFromDiff(diff);
129
  }
123
		if (!suppressInterestContribution && resource != null) {
130
124
			Set<IResource> resources = new HashSet<IResource>();
131
  @Override
125
			resources.add(resource); 
132
  public void remove(IResource[] newResources)
126
			if (MylarResourcesPlugin.getDefault() != null) {
133
  {
127
				MylarResourcesPlugin.getDefault().getInterestUpdater().addResourceToContext(resources, InteractionEvent.Kind.SELECTION);
134
    super.remove(newResources);
128
			}
135
  }
129
		}
136
130
	}
137
  @Override
131
138
  public void add(IDiff diff)
132
	private IResource getResourceFromDiff(IDiff diff) {
139
  {
133
		if (diff instanceof ResourceDiff) {
140
    super.add(diff);
134
			return ((ResourceDiff)diff).getResource();
141
    IResource resource = getResourceFromDiff(diff);
135
		} else if (diff instanceof ThreeWayDiff) {
142
    if (!suppressInterestContribution && resource != null)
136
			ThreeWayDiff threeWayDiff = (ThreeWayDiff)diff;
143
    {
137
			return ResourcesPlugin.getWorkspace().getRoot().findMember(threeWayDiff.getPath());
144
      Set<IResource> resources = new HashSet<IResource>();
138
		} else {
145
      resources.add(resource);
139
			return null;
146
      if (MylarResourcesPlugin.getDefault() != null)
140
		}
147
      {
141
	} 
148
        MylarResourcesPlugin.getDefault().getInterestUpdater().addResourceToContext(resources,
142
149
                InteractionEvent.Kind.SELECTION);
143
	@Override
150
      }
144
	public void add(IDiff[] diffs) {
151
    }
145
		super.add(diffs);
152
  }
146
	}
153
147
154
  private IResource getResourceFromDiff(IDiff diff)
148
	@Override
155
  {
149
	public void add(IResource[] newResources) throws CoreException {
156
    if (diff instanceof ResourceDiff)
150
		super.add(newResources);
157
    {
151
	}
158
      return ((ResourceDiff)diff).getResource();
152
159
    }
153
	public void restoreResources(IResource[] newResources) throws CoreException {
160
    else if (diff instanceof ThreeWayDiff)
154
		suppressInterestContribution = true;
161
    {
155
		try {
162
      ThreeWayDiff threeWayDiff = (ThreeWayDiff)diff;
156
			super.add(newResources);
163
      return ResourcesPlugin.getWorkspace().getRoot().findMember(threeWayDiff.getPath());
157
			setComment(getComment());
164
    }
158
		} catch (TeamException e) {
165
    else
159
			throw e;
166
    {
160
		} finally {
167
      return null;
161
			suppressInterestContribution = false;
168
    }
162
		}
169
  }
163
	}
170
164
171
  @Override
165
	@Override
172
  public void add(IDiff[] diffs)
166
	public IResource[] getResources() {
173
  {
167
		List<IResource> allResources = getAllResourcesInChangeContext();
174
    super.add(diffs);
168
		return allResources.toArray(new IResource[allResources.size()]);
175
  }
169
	}
176
170
177
  @Override
171
	public List<IResource> getAllResourcesInChangeContext() {
178
  public void add(IResource[] newResources) throws CoreException
172
		Set<IResource> allResources = new HashSet<IResource>();
179
  {
173
		allResources.addAll(Arrays.asList(super.getResources()));
180
    super.add(newResources);
174
		if (MylarResourcesPlugin.getDefault() != null && task.isActive()) {
181
  }
175
			// TODO: if super is always managed correctly should remove following line
182
176
			allResources.addAll(MylarResourcesPlugin.getDefault().getInterestingResources());
183
  public void restoreResources(IResource[] newResources) throws CoreException
177
		}
184
  {
178
		return new ArrayList<IResource>(allResources);
185
    suppressInterestContribution = true;
179
	}
186
    try
180
187
    {
181
	/**
188
      super.add(newResources);
182
	 * TODO: unnessary check context?
189
      setComment(getComment());
183
	 */
190
    }
184
	public boolean contains(IResource local) {
191
    catch (TeamException e)
185
		return getAllResourcesInChangeContext().contains(local);
192
    {
186
	}
193
      throw e;
187
194
    }
188
	public static String generateComment(ITask task, String completedPrefix, String progressPrefix) {
195
    finally
189
		String comment;
196
    {
190
		completedPrefix = fixUpDelimIfPresent(completedPrefix);
197
      suppressInterestContribution = false;
191
		progressPrefix = fixUpDelimIfPresent(progressPrefix);
198
    }
192
		if (task.isCompleted()) {
199
  }
193
			comment = completedPrefix + PREFIX_DELIM;
200
194
		} else {
201
  @Override
195
			comment = progressPrefix + PREFIX_DELIM;
202
  public IResource[] getResources()
196
		}
203
  {
197
		comment += task.getDescription();
204
    List<IResource> allResources = getAllResourcesInChangeContext();
198
		String url = task.getUrl();
205
    return allResources.toArray(new IResource[allResources.size()]);
199
		if (url != null && !url.equals("") && !url.endsWith("//")) {
206
  }
200
			comment += " \n" + url;
207
201
		}
208
  public List<IResource> getAllResourcesInChangeContext()
202
		return comment;
209
  {
203
	}
210
    Set<IResource> allResources = new HashSet<IResource>();
204
211
    allResources.addAll(Arrays.asList(super.getResources()));
205
	private static String fixUpDelimIfPresent(String prefix) {
212
    if (MylarResourcesPlugin.getDefault() != null && task.isActive())
206
		if (prefix.endsWith(":") || prefix.endsWith(PREFIX_DELIM)) {
213
    {
207
			prefix = prefix.substring(0, prefix.lastIndexOf(':'));
214
      // TODO: if super is always managed correctly should remove following line
208
		}
215
      allResources.addAll(MylarResourcesPlugin.getDefault().getInterestingResources());
209
		return prefix;
216
    }
210
	}
217
    return new ArrayList<IResource>(allResources);
211
218
  }
212
	public static String getTaskIdFromCommentOrLabel(String comment) {
219
213
		int firstDelimIndex = comment.indexOf(PREFIX_DELIM);
220
  /**
214
		if (firstDelimIndex != -1) {
221
   * TODO: unnessary check context?
215
			int idStart = firstDelimIndex + PREFIX_DELIM.length();
222
   */
216
			int idEnd = comment.indexOf(PREFIX_DELIM, firstDelimIndex + PREFIX_DELIM.length());// comment.indexOf(PREFIX_DELIM);
223
  public boolean contains(IResource local)
217
			if (idEnd != -1 && idStart < idEnd) {
224
  {
218
				String id = comment.substring(idStart, idEnd);
225
    return getAllResourcesInChangeContext().contains(local);
219
				if (id != null)
226
  }
220
					return id.trim();
227
221
			} else {
228
  public static String generateComment(ITask task, String completedTemplate, String progressTemplate)
222
				// change set label
229
  {
223
				return comment.substring(0, firstDelimIndex);
230
    return ITemplateHandlersManager.INSTANCE.generateComment(task, completedTemplate,
224
			}
231
            progressTemplate);
225
		}
232
  }
226
		return null;
233
227
	}
234
  public static String getTaskIdFromCommentOrLabel(String commentOrLabel)
228
235
  {
229
	public static String getUrlFromComment(String comment) {
236
    String id = getTaskIdFromComment(commentOrLabel);
230
		int httpIndex = comment.indexOf(PREFIX_HTTP);
237
    if (id == null)
231
		int httpsIndex = comment.indexOf(PREFIX_HTTPS);
238
    {
232
		int idStart = -1;
239
      id = getTaskIdFromLabel(commentOrLabel);
233
		if (httpIndex != -1) {
240
    }
234
			idStart = httpIndex;
241
235
		} else if (httpsIndex != -1) {
242
    return id;
236
			idStart = httpsIndex;
243
  }
237
		}
244
238
		if (idStart != -1) {
245
  public static String getTaskIdFromComment(String comment)
239
			int idEnd = comment.indexOf(' ', idStart);
246
  {
240
			if (idEnd == -1) {
247
    try
241
				return comment.substring(idStart);
248
    {
242
			} else if (idEnd != -1 && idStart < idEnd) {
249
      String regex = MylarTeamPlugin.getDefault().getPreferenceStore().getString(
243
				return comment.substring(idStart, idEnd);
250
              MylarTeamPlugin.COMMIT_REGEX_TASK_ID);
244
			}
251
245
		}
252
      Pattern pattern = Pattern.compile(regex);
246
		return null;
253
      Matcher matcher = pattern.matcher(comment);
247
	}
254
      if (matcher.find())
248
255
      {
249
	@Override
256
        return matcher.group(1);
250
	public boolean equals(Object object) {
257
      }
251
		if (object instanceof ContextChangeSet && task != null) {
258
    }
252
			ContextChangeSet changeSet = (ContextChangeSet) object;
259
    catch (Exception ex)
253
			return task.equals(changeSet.getTask());
260
    {
254
		} else {
261
      MylarStatusHandler.log(ex, "Problem while parsing task id from comment");
255
			return super.equals(object);
262
    }
256
		}
263
257
	}
264
    return null;
258
265
  }
259
	@Override
266
260
	public int hashCode() {
267
  public static String getTaskIdFromLabel(String label)
261
		if (task != null) {
268
  {
262
			return task.hashCode();
269
    int firstDelimIndex = label.indexOf(PREFIX_DELIM);
263
		} else {
270
    if (firstDelimIndex != -1)
264
			return super.hashCode();
271
    {
265
		}
272
      int idStart = firstDelimIndex + PREFIX_DELIM.length();
266
	}
273
      int idEnd = label.indexOf(PREFIX_DELIM, firstDelimIndex + PREFIX_DELIM.length());// comment.indexOf(PREFIX_DELIM);
267
274
      if (idEnd != -1 && idStart < idEnd)
268
	public ITask getTask() {
275
      {
269
		return task;
276
        String id = label.substring(idStart, idEnd);
270
	}
277
        if (id != null) return id.trim();
271
278
      }
272
	public Object getAdapter(Class adapter) {
279
      else
273
		if (adapter == ResourceMapping.class) {
280
      {
274
			return new ChangeSetResourceMapping(this);
281
        // change set label
275
		} else {
282
        return label.substring(0, firstDelimIndex);
276
			return null;
283
      }
277
		}
284
    }
278
	}
285
    return null;
286
  }
287
288
  public static String getUrlFromComment(String comment)
289
  {
290
    int httpIndex = comment.indexOf(PREFIX_HTTP);
291
    int httpsIndex = comment.indexOf(PREFIX_HTTPS);
292
    int idStart = -1;
293
    if (httpIndex != -1)
294
    {
295
      idStart = httpIndex;
296
    }
297
    else if (httpsIndex != -1)
298
    {
299
      idStart = httpsIndex;
300
    }
301
    if (idStart != -1)
302
    {
303
      int idEnd = comment.indexOf(' ', idStart);
304
      if (idEnd == -1)
305
      {
306
        return comment.substring(idStart);
307
      }
308
      else if (idEnd != -1 && idStart < idEnd)
309
      {
310
        return comment.substring(idStart, idEnd);
311
      }
312
    }
313
    return null;
314
  }
315
316
  @Override
317
  public boolean equals(Object object)
318
  {
319
    if (object instanceof ContextChangeSet && task != null)
320
    {
321
      ContextChangeSet changeSet = (ContextChangeSet)object;
322
      return task.equals(changeSet.getTask());
323
    }
324
    else
325
    {
326
      return super.equals(object);
327
    }
328
  }
329
330
  @Override
331
  public int hashCode()
332
  {
333
    if (task != null)
334
    {
335
      return task.hashCode();
336
    }
337
    else
338
    {
339
      return super.hashCode();
340
    }
341
  }
342
343
  public ITask getTask()
344
  {
345
    return task;
346
  }
347
348
  public Object getAdapter(Class adapter)
349
  {
350
    if (adapter == ResourceMapping.class)
351
    {
352
      return new ChangeSetResourceMapping(this);
353
    }
354
    else
355
    {
356
      return null;
357
    }
358
  }
279
}
359
}
(-)plugin.xml (+89 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.TemplateHandler$RepositoryKind"
160
             description="Provides the repository kind of a Mylar task."
161
             recognizedKeyword="repository.kind"/>
162
       <templateHandler
163
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$RepositoryURL"
164
             description="Provides the repository URL of a Mylar task."
165
             recognizedKeyword="repository.url"/>
166
       <templateHandler
167
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskAssignee"
168
             description="Provides the user a Mylar task is assigned to, if available."
169
             recognizedKeyword="task.assignee"/>
170
       <templateHandler
171
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskCC"
172
             description="Provides the comma separated CC list of a Mylar task, if available."
173
             recognizedKeyword="task.cc"/>
174
       <templateHandler
175
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskDescription"
176
             description="Provides the description of a Mylar task."
177
             recognizedKeyword="task.description"/>
178
       <templateHandler
179
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskHandle"
180
             description="Provides the handle of a Mylar task."
181
             recognizedKeyword="task.handle"/>
182
       <templateHandler
183
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskID"
184
             description="Provides the ID of a Mylar task."
185
             recognizedKeyword="task.id"/>
186
       <templateHandler
187
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskKeywords"
188
             description="Provides the comma separated keyword list of a Mylar task, if available."
189
             recognizedKeyword="task.keywords"/>
190
       <templateHandler
191
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskLastModified"
192
             description="Provides the date of last modification of a Mylar task, if available."
193
             recognizedKeyword="task.lastmodified"/>
194
       <templateHandler
195
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskNotes"
196
             description="Provides the notes of a Mylar task."
197
             recognizedKeyword="task.notes"/>
198
       <templateHandler
199
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskPriority"
200
             description="Provides the priority of a Mylar task."
201
             recognizedKeyword="task.priority"/>
202
       <templateHandler
203
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskProduct"
204
             description="Provides the prroduct a Mylar task belongs to, if available."
205
             recognizedKeyword="task.product"/>
206
       <templateHandler
207
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskReporter"
208
             description="Provides the user who reported a Mylar task, if available."
209
             recognizedKeyword="task.reporter"/>
210
       <templateHandler
211
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskResolution"
212
             description="Provides the resolution of a Mylar task, if available."
213
             recognizedKeyword="task.resolution"/>
214
       <templateHandler
215
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskStatus"
216
             description="Provides the status of a Mylar task, if available."
217
             recognizedKeyword="task.status"/>
218
       <templateHandler
219
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskSummary"
220
             description="Provides the summary or description of a Mylar task, whichever is available."
221
             recognizedKeyword="task.summary"/>
222
       <templateHandler
223
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskType"
224
             description="Provides the type of a Mylar task."
225
             recognizedKeyword="task.type"/>
226
       <templateHandler
227
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$TaskURL"
228
             description="Provides the URL of a Mylar task."
229
             recognizedKeyword="task.url"/>
230
       <templateHandler
231
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$Date$TaskCompletion"
232
             description="Provides the completion date of a Mylar task."
233
             recognizedKeyword="task.completiondate"/>
234
       <templateHandler
235
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$Date$TaskCreation"
236
             description="Provides the creation date of a Mylar task."
237
             recognizedKeyword="task.creationdate"/>
238
       <templateHandler
239
             class="org.eclipse.mylar.internal.team.template.TemplateHandler$Date$TaskReminder"
240
             description="Provides the reminder date of a Mylar task."
241
             recognizedKeyword="task.reminderdate"/>
242
    </extension>
243
	
155
</plugin>
244
</plugin>
(-)src/org/eclipse/mylar/internal/team/ui/preferences/MylarTeamPreferencePage.java (-96 / +161 lines)
Lines 7-17 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
9
 *     University Of British Columbia - initial API and implementation
10
 *     Eike tepper - commit comment template preferences
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
12
package org.eclipse.mylar.internal.team.ui.preferences;
13
package org.eclipse.mylar.internal.team.ui.preferences;
13
14
15
16
import org.eclipse.jface.fieldassist.IContentProposalProvider;
17
import org.eclipse.jface.fieldassist.IControlContentAdapter;
18
import org.eclipse.jface.fieldassist.IControlCreator;
19
import org.eclipse.jface.fieldassist.TextContentAdapter;
14
import org.eclipse.jface.preference.PreferencePage;
20
import org.eclipse.jface.preference.PreferencePage;
21
import org.eclipse.mylar.internal.team.template.TemplateHandlerContentProposalProvider;
22
import org.eclipse.mylar.internal.team.ui.preferences.workaround.RegExContentProposalProvider;
15
import org.eclipse.mylar.team.MylarTeamPlugin;
23
import org.eclipse.mylar.team.MylarTeamPlugin;
16
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.layout.GridData;
Lines 24-128 Link Here
24
import org.eclipse.swt.widgets.Text;
32
import org.eclipse.swt.widgets.Text;
25
import org.eclipse.ui.IWorkbench;
33
import org.eclipse.ui.IWorkbench;
26
import org.eclipse.ui.IWorkbenchPreferencePage;
34
import org.eclipse.ui.IWorkbenchPreferencePage;
35
import org.eclipse.ui.fieldassist.ContentAssistField;
36
27
37
28
/**
38
/**
29
 * @author Mik Kersten
39
 * @author Mik Kersten
30
 */
40
 */
31
public class MylarTeamPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
41
public class MylarTeamPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
32
42
{
33
	private Button changeSetsManage;
43
  private Button changeSetsManage;
34
44
35
	private Text commitPrefixCompleted = null;
45
  private Text commitTemplateCompleted = null;
36
46
37
	private Text commitPrefixProgress = null;
47
  private Text commitTemplateProgress = null;
48
49
  private Text regexText;
50
51
  public MylarTeamPreferencePage()
52
  {
53
    super();
54
    setPreferenceStore(MylarTeamPlugin.getDefault().getPreferenceStore());
55
  }
56
57
  @Override
58
  protected Control createContents(Composite parent)
59
  {
60
    Composite container = new Composite(parent, SWT.NULL);
61
    GridLayout layout = new GridLayout(1, false);
62
    container.setLayout(layout);
63
64
    createChangeSetGroup(container);
65
    createCommitGroup(container);
66
    return container;
67
  }
68
69
  public void init(IWorkbench workbench)
70
  {
71
    // TODO Auto-generated method stub
72
  }
73
74
  @Override
75
  public boolean performOk()
76
  {
77
    getPreferenceStore().setValue(MylarTeamPlugin.COMMIT_TEMPLATE_COMPLETED,
78
            commitTemplateCompleted.getText());
79
    getPreferenceStore().setValue(MylarTeamPlugin.COMMIT_TEMPLATE_PROGRESS,
80
            commitTemplateProgress.getText());
81
    getPreferenceStore().setValue(MylarTeamPlugin.COMMIT_REGEX_TASK_ID, regexText.getText());
82
    getPreferenceStore().setValue(MylarTeamPlugin.CHANGE_SET_MANAGE,
83
            changeSetsManage.getSelection());
84
85
    if (changeSetsManage.getSelection())
86
    {
87
      MylarTeamPlugin.getDefault().getChangeSetManager().enable();
88
    }
89
    else
90
    {
91
      MylarTeamPlugin.getDefault().getChangeSetManager().disable();
92
    }
93
    return true;
94
  }
95
96
  @Override
97
  public boolean performCancel()
98
  {
99
    return true;
100
  }
101
102
  public void performDefaults()
103
  {
104
    super.performDefaults();
105
    commitTemplateCompleted.setText(getPreferenceStore().getDefaultString(
106
            MylarTeamPlugin.COMMIT_TEMPLATE_COMPLETED));
107
    commitTemplateProgress.setText(getPreferenceStore().getDefaultString(
108
            MylarTeamPlugin.COMMIT_TEMPLATE_PROGRESS));
109
    changeSetsManage.setSelection(getPreferenceStore().getDefaultBoolean(
110
            MylarTeamPlugin.CHANGE_SET_MANAGE));
111
  }
112
113
  private Label createLabel(Composite parent, String text)
114
  {
115
    Label label = new Label(parent, SWT.LEFT);
116
    label.setText(text);
117
    GridData data = new GridData();
118
    data.horizontalSpan = 2;
119
    data.horizontalAlignment = GridData.BEGINNING;
120
    label.setLayoutData(data);
121
    return label;
122
  }
123
124
  private void createChangeSetGroup(Composite parent)
125
  {
126
    Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
127
    group.setText("Change Sets");
128
    group.setLayout(new GridLayout(1, false));
129
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
130
131
    changeSetsManage = new Button(group, SWT.CHECK);
132
    changeSetsManage.setText("Automatically create and manage with task context");
133
    changeSetsManage.setSelection(getPreferenceStore()
134
            .getBoolean(MylarTeamPlugin.CHANGE_SET_MANAGE));
135
  }
136
137
  private void createCommitGroup(Composite parent)
138
  {
139
    Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
140
    group.setText("Automatic Commit Messages");
141
    group.setLayout(new GridLayout(2, false));
142
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
143
144
    Label completedLabel = createLabel(group, "Completed task template: ");
145
    completedLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
146
147
    String completedTemplate = getPreferenceStore().getString(
148
            MylarTeamPlugin.COMMIT_TEMPLATE_COMPLETED);
149
    commitTemplateCompleted = addTemplateField(group, completedTemplate,
150
            new TemplateHandlerContentProposalProvider());
151
152
    Label progressLabel = createLabel(group, "In progress task template: ");
153
    progressLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
154
155
    String progressTemplate = getPreferenceStore().getString(
156
            MylarTeamPlugin.COMMIT_TEMPLATE_PROGRESS);
157
    commitTemplateProgress = addTemplateField(group, progressTemplate,
158
            new TemplateHandlerContentProposalProvider());
159
160
    Label regexLabel = createLabel(group, "Regex to parse task id: ");
161
    regexLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
162
163
    String regex = getPreferenceStore().getString(MylarTeamPlugin.COMMIT_REGEX_TASK_ID);
164
    regexText = addTemplateField(group, regex, new RegExContentProposalProvider(true));
165
  }
166
167
  private Text addTemplateField(final Composite parent, final String text,
168
          IContentProposalProvider provider)
169
  {
170
    IControlContentAdapter adapter = new TextContentAdapter();
171
    IControlCreator controlCreator = new IControlCreator()
172
    {
173
      public Control createControl(Composite parent, int style)
174
      {
175
        Text control = new Text(parent, style);
176
        control.setText(text);
177
        return control;
178
      }
179
    };
180
181
    ContentAssistField field = new ContentAssistField(parent, SWT.BORDER, controlCreator, adapter,
182
            provider, null, new char[] {'$'});
183
184
    GridData gd = new GridData();
185
    gd.horizontalAlignment = GridData.FILL;
186
    gd.grabExcessHorizontalSpace = true;
187
    gd.verticalAlignment = GridData.CENTER;
188
    gd.grabExcessVerticalSpace = false;
189
    field.getLayoutControl().setLayoutData(gd);
38
190
39
	public MylarTeamPreferencePage() {
191
    return (Text)field.getControl();
40
		super();
192
  }
41
		setPreferenceStore(MylarTeamPlugin.getDefault().getPreferenceStore());
42
	}
43
44
	@Override
45
	protected Control createContents(Composite parent) {
46
		Composite container = new Composite(parent, SWT.NULL);
47
		GridLayout layout = new GridLayout(1, false);
48
		container.setLayout(layout);
49
50
		createChangeSetGroup(container);
51
		createCommitGroup(container);
52
		return container;
53
	}
54
55
	public void init(IWorkbench workbench) {
56
		// TODO Auto-generated method stub
57
	}
58
59
	@Override
60
	public boolean performOk() {
61
		getPreferenceStore().setValue(MylarTeamPlugin.COMMIT_PREFIX_COMPLETED, commitPrefixCompleted.getText());
62
		getPreferenceStore().setValue(MylarTeamPlugin.COMMIT_PREFIX_PROGRESS, commitPrefixProgress.getText());
63
		getPreferenceStore().setValue(MylarTeamPlugin.CHANGE_SET_MANAGE, changeSetsManage.getSelection());
64
65
		if (changeSetsManage.getSelection()) {
66
			MylarTeamPlugin.getDefault().getChangeSetManager().enable();
67
		} else {
68
			MylarTeamPlugin.getDefault().getChangeSetManager().disable();
69
		}
70
		return true;
71
	}
72
73
	@Override
74
	public boolean performCancel() {
75
		return true;
76
	}
77
78
	public void performDefaults() {
79
		super.performDefaults();
80
		commitPrefixCompleted.setText(getPreferenceStore().getDefaultString(MylarTeamPlugin.COMMIT_PREFIX_COMPLETED));
81
		commitPrefixProgress.setText(getPreferenceStore().getDefaultString(MylarTeamPlugin.COMMIT_PREFIX_PROGRESS));
82
		changeSetsManage.setSelection(getPreferenceStore().getDefaultBoolean(MylarTeamPlugin.CHANGE_SET_MANAGE));
83
	}
84
85
	private Label createLabel(Composite parent, String text) {
86
		Label label = new Label(parent, SWT.LEFT);
87
		label.setText(text);
88
		GridData data = new GridData();
89
		data.horizontalSpan = 2;
90
		data.horizontalAlignment = GridData.BEGINNING;
91
		label.setLayoutData(data);
92
		return label;
93
	}
94
95
	private void createChangeSetGroup(Composite parent) {
96
		Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
97
		group.setText("Change Sets");
98
		group.setLayout(new GridLayout(1, false));
99
		group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
100
101
		changeSetsManage = new Button(group, SWT.CHECK);
102
		changeSetsManage.setText("Automatically create and manage with task context");
103
		changeSetsManage.setSelection(getPreferenceStore().getBoolean(MylarTeamPlugin.CHANGE_SET_MANAGE));
104
	}
105
106
	private void createCommitGroup(Composite parent) {
107
		Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
108
		group.setText("Automatic Commit Messages");
109
		group.setLayout(new GridLayout(2, false));
110
		group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
111
112
		Label completedLabel = createLabel(group, "Completed task prefix: ");
113
		completedLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
114
115
		String completedPrefix = getPreferenceStore().getString(MylarTeamPlugin.COMMIT_PREFIX_COMPLETED);
116
		commitPrefixCompleted = new Text(group, SWT.BORDER);
117
		commitPrefixCompleted.setText(completedPrefix);
118
		commitPrefixCompleted.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
119
120
		Label progressLabel = createLabel(group, "In progress task prefix: ");
121
		progressLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
122
123
		String progressPrefix = getPreferenceStore().getString(MylarTeamPlugin.COMMIT_PREFIX_PROGRESS);
124
		commitPrefixProgress = new Text(group, SWT.BORDER);
125
		commitPrefixProgress.setText(progressPrefix);
126
		commitPrefixProgress.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
127
	}
128
}
193
}
(-)src/org/eclipse/mylar/internal/team/ui/preferences/workaround/RegExMessages.properties (+495 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2000, 2005 IBM Corporation 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
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
## Content Assist for regular expressions ##
13
## Copied from org.eclipse.ui.texteditor.RegExMessages.properties.
14
## Needed by org.eclipse.mylar.internal.team.ui.preferences.workaround.RegExMessages.
15
## TODO Ask platform guys to open this API
16
# use \\\u0075 for a backslash-u
17
displayString_bs_bs= \\\\ - Backslash
18
additionalInfo_bs_bs= Backslash
19
displayString_bs_0= \\0nnn - Octal character code
20
additionalInfo_bs_0= Octal character code\n\nExamples:\n\\011 (tabulator)\n\\0112 (character J)
21
displayString_bs_x= \\xhh - Hex character code
22
additionalInfo_bs_x= Hexadecimal character code\n\nExamples:\n\\x09 (tabulator)\n\\x4A or \\x4a (character J)
23
displayString_bs_u= \\\u0075hhhh - Hex code for Unicode character
24
additionalInfo_bs_u= Hexadecimal code for Unicode character\n\nExamples:\n\\\u0075004A (character J)\n\\\u007503B2 (lowercase Greek letter beta: \u03B2)
25
displayString_bs_t= \\t - Tab
26
additionalInfo_bs_t= Tabulator (\\x09, decimal: 9)
27
displayString_bs_n= \\n - Newline
28
additionalInfo_bs_n= Newline (\\x0A, decimal: 10)
29
displayString_bs_r= \\r - CR
30
additionalInfo_bs_r= Carriage Return (\\x0D, decimal: 13)
31
displayString_bs_f= \\f - FF
32
additionalInfo_bs_f= Form Feed (\\x0C, decimal: 12)
33
displayString_bs_a= \\a - Beep
34
additionalInfo_bs_a= Beep, Bell, Alert (\\x07, decimal: 7)
35
displayString_bs_e= \\e - Esc
36
additionalInfo_bs_e= Escape (\\x1B, decimal: 27)
37
displayString_bs_c= \\c - Control character
38
additionalInfo_bs_c= Control character\n\nExample:\n\\cC (Ctrl+C)
39
40
displayString_dot= . - Any character
41
additionalInfo_dot= The dot matches any character except line terminators.\n\n\
42
To make the dot match line terminators as well, \n\
43
start the expression with the embedded flag expression \n\
44
"(?s)" (without quotes).
45
displayString_bs_d= \\d - A digit
46
additionalInfo_bs_d= A digit: [0-9]
47
displayString_bs_D= \\D - Not a digit
48
additionalInfo_bs_D= Not a digit: [^0-9]
49
displayString_bs_s= \\s - A whitespace
50
additionalInfo_bs_s= A whitespace: [ \\t\\n\\x0B\\f\\r]
51
displayString_bs_S= \\S - Not a whitespace
52
additionalInfo_bs_S= Not a whitespace: [^\\s]
53
displayString_bs_w= \\w - An alphanumeric (word character)
54
additionalInfo_bs_w= An alphanumeric (a word character): [a-zA-Z_0-9]
55
displayString_bs_W= \\W - Not an alphanumeric
56
additionalInfo_bs_W= Not an alphanumeric (not a word character): [^\\w]
57
58
displayString_start= ^ - Line start
59
additionalInfo_start= Line start (positional match)\n\nExample:\n\
60
The expression "^Eclipse" matches the term "Eclipse"\n\
61
only on the second line of text\n\
62
"The Eclipse Project\n\
63
Eclipse Platform".
64
displayString_end= $ - Line end
65
additionalInfo_end= Line end (positional match)\n\nExample:\n\
66
The expression "Eclipse$" matches the term "Eclipse"\n\
67
only on the second line of text\n\
68
"- Install the Eclipse Platform\n\
69
- Run Eclipse".
70
displayString_bs_b= \\b- Word beginning or end
71
additionalInfo_bs_b= Word beginning or end (positional match)\n\nExample:\n\
72
The expression "s\\b" matches only the last "s" of "glasses" in text\n\
73
"I lost my glasses."
74
displayString_bs_B= \\B - Not a word beginning or end
75
additionalInfo_bs_B= Not a word beginning or end (positional match)\n\nExample:\n\
76
The expression "\\BS" matches only "S" of "printString" in text\n\
77
"void print(String printString)".
78
displayString_bs_A= \\A - Start of input
79
additionalInfo_bs_A= Start of input (positional match)\n\nExample:\n\
80
The expression "\\ABC" matches only "BC" of "BCD" in text\n\
81
"BCD ABC\n\
82
BCDEF".
83
displayString_bs_G= \\G - Previous match's end
84
additionalInfo_bs_G= Previous match's end (positional match)\n\nExample:\n\
85
The expression "\\Ga" matches the first and then the second "a" in text\n\
86
"aardvark" (when starting from the beginning).
87
displayString_bs_Z= \\Z - End of input, does not consider last line terminator
88
additionalInfo_bs_Z= End of input, does not consider last line terminator (positional match)\n\n\
89
The expression matches at the end of the file, except for when the\n\
90
file ends in a line terminator, in which case it matches before that\n\
91
line terminator.\n\nExample:\n\
92
The expression "ing\\Z" matches "ing" in text\n\
93
"testing", as well as in text\n\
94
"testing\n\
95
", but doesn't match in text\n\
96
"testing\n\
97
\n\
98
"
99
displayString_bs_z= \\z - End of input
100
additionalInfo_bs_z= End of input (positional match)\n\nExample:\n\
101
The expression "ing\\z" matches "ing" in text\n\
102
"testing", but doesn't match in text\n\
103
"testing\n\
104
"
105
106
### repetition quantifiers ###
107
displayString_quest= ? - Greedy match 0 or 1 times
108
additionalInfo_quest= Greedy match 0 or 1 times.\n\n\
109
First tries to match the preceding token.\n\
110
Falls back to not matching if this choice made a full match impossible.\n\nExample:\n\
111
The expression "fo?" matches "f", "fo", and "fo" in text\n\
112
"f fo foo".
113
displayString_star= * - Greedy match 0 or more times
114
additionalInfo_star= Greedy match 0 or more times.\n\n\
115
First tries to match the preceding token as many times as possible.\n\
116
Falls back to matching it less often if this choice made a full match impossible.\n\nExamples:\n\
117
- The expression "fo*" matches "f", "fo", and "foo" in text\n\
118
"f fo foo".\n\
119
- The expression "fo*o\\d" matches all three words in text\n\
120
"fo1 foo2 fooo3".\n\
121
- The expression "<.*>" matches the whole text\n\
122
"<p><b>bold</b>".
123
displayString_plus= + - Greedy match 1 or more times
124
additionalInfo_plus= Greedy match 1 or more times\n\n\
125
First tries to match the preceding token as many times as possible.\n\
126
Falls back to matching it less often if this choice made a full match impossible.\n\nExamples:\n\
127
- The expression "fo+" matches "fo" and "foo" in text\n\
128
"f fo foo".\n\
129
- The expression "fo+o\\d" matches "foo2" and "fooo3" in text\n\
130
"fo1 foo2 fooo3".\n\
131
- The expression "<.+>" matches the whole text\n\
132
"<p><b>bold</b>", but does not match anywhere in "<>".
133
displayString_exact= {n} - Greedy match exactly n times
134
additionalInfo_exact= Greedy match exactly n times.\n\nExamples:\n\
135
- The expression "\\\\0[0-3][0-7]{2}" matches all three-digit octal character tokens.\n\
136
- The expression "\\b\\w{4}\\b" matches all four-letter-words\n\
137
such as "Java", "cool", or "food" (but not "dog").
138
displayString_least= {n,} - Greedy match >= n times
139
additionalInfo_least= Greedy match >= n times.\n\n\
140
First tries to match the preceding token as many times as possible.\n\
141
Falls back to matching it less often (but at least n times),\n\
142
if this choice made a full match impossible.\n\nExamples:\n\
143
- The expression "fo{2,}" matches "foo" and "fooo" in text\n\
144
"f fo foo fooo".\n\
145
- The expression "fo{2,}o\\d" matches "fooo3" and "foooo4" in text\n\
146
"fo1 foo2 fooo3 foooo4".\n\
147
- The expression "10{3,}[^0]" matches all powers of ten that are larger than one thousand.\n\n\
148
Note: The expressions "{0,}" and "*" are equivalent;\n\
149
likewise, "{1,}" is equivalent to "+".
150
displayString_count= {n,m} - Greedy match >= n times but <= m times
151
additionalInfo_count= Greedy match >= n times but <= m times.\n\n\
152
First tries to match the preceding token m times.\n\
153
Falls back to matching it less often (but at least n times),\n\
154
if this choice made a full match impossible.\n\nExamples:\n\
155
- The expression "fo{1,2}" matches "fo", "foo", and "foo" in text\n\
156
"f fo foo fooo".\n\
157
- The expression "fo{1,2}o\\d" matches "foo2" and "fooo3" in text\n\
158
"fo1 foo2 fooo3 foooo4".\n\
159
- The expression "^.{70,80}$" matches all the lines that contain\n\
160
between 70 and 80 characters (inclusive).
161
162
displayString_questLazy= ?? - Lazy match 0 or 1 times
163
additionalInfo_questLazy= Lazy match 0 or 1 times.\n\n\
164
First tries to not match the preceding token.\n\
165
Falls back to matching it if this choice made a full match impossible.\n\nExample:\n\
166
The expression "fo??" matches "f", "f", and "f" in text\n\
167
"f fo foo".
168
displayString_starLazy= *? - Lazy match 0 or more times
169
additionalInfo_starLazy= Lazy match 0 or more times.\n\n\
170
First tries to not match the preceding token.\n\
171
Falls back to matching it more often if this choice made a full match impossible.\n\nExamples:\n\
172
- The expression "fo*?" matches "f", "f", and "f" in text\n\
173
"f fo foo".\n\
174
- The expression "fo*?o\\d" matches all three words in text\n\
175
"fo1 foo2 fooo3".\n\
176
- The expression "<.*?>" matches "<p>", "<b>", and "</b>" in text\n\
177
"<p><b>bold</b>". Note: a more performant expression for finding\n\
178
xml tags is "<[^>]*>", which avoids backtracking.
179
displayString_plusLazy= +? - Lazy match 1 or more times
180
additionalInfo_plusLazy= Lazy match 1 or more times\n\n\
181
First tries to match the preceding token once.\n\
182
Falls back to matching it more often if this choice made a full match impossible.\n\nExamples:\n\
183
- The expression "fo+?" matches "fo" and "fo" in text\n\
184
"f fo foo".\n\
185
- The expression "fo+?o\\d" matches "foo2" and "fooo3" in text\n\
186
"fo1 foo2 fooo3".\n\
187
- The expression "<.+?>" matches "<p>", "<b>", and "</b>" in text\n\
188
"<p><b>bold</b>". Note: a more performant expression for finding\n\
189
xml tags is "<[^>]*>", which avoids backtracking.
190
displayString_exactLazy= {n}? - Lazy match exactly n times
191
additionalInfo_exactLazy= Lazy match exactly n times.\n\n\
192
This expression is equivalent to the expression\n\
193
{n} - Greedy match exactly n times.
194
displayString_leastLazy= {n,}? - Lazy match >= n times
195
additionalInfo_leastLazy= Lazy match >= n times.\n\n\
196
First tries to match the preceding token n times. Falls back to\n\
197
matching it more often, if this choice made a full match impossible.\n\nExamples:\n\
198
- The expression "fo{2,}?" matches "foo" and "foo" in text\n\
199
"f fo foo fooo".\n\
200
- The expression "fo{2,}?o\\d" matches "fooo3" and "foooo4" in text\n\
201
"fo1 foo2 fooo3 foooo4".\n\
202
- The expression "10{3,}?[^0]" matches all powers of ten that are larger than one thousand.\n\n\
203
Note: The expressions "{0,}?" and "*?" are equivalent;\n\
204
likewise, "{1,}?" is equivalent to "+?".
205
displayString_countLazy= {n,m}? - Lazy match >= n times but <= m times
206
additionalInfo_countLazy= Lazy match >= n times but <= m times.\n\n\
207
First tries to match the preceding token n times.\n\
208
Falls back to matching it more often (but at most m times),\n\
209
if this choice made a full match impossible.\n\nExamples:\n\
210
- The expression "fo{1,2}?" matches "fo", "fo", and "fo" in text\n\
211
"f fo foo fooo".\n\
212
- The expression "fo{1,2}?o\\d" matches "foo2" and "fooo3" in text\n\
213
"fo1 foo2 fooo3 foooo4".\n\
214
215
displayString_questPoss= ?+ - Possessive match 0 or 1 times (no backtracking)
216
additionalInfo_questPoss= Possessive match 0 or 1 times.\n\n\
217
Matches the preceding token if possible. Never backtracks,\n\
218
even if this choice renders a full match impossible.\n\nExample:\n\
219
The expression "fo?+o\\d" matches the first, but not the second line in text\n\
220
"fo1\n\
221
foo1".
222
displayString_starPoss= *+ Possessive match 0 or more times (no backtracking)
223
additionalInfo_starPoss= Possessive match 0 or more times.\n\n\
224
Tries to match the preceding token as many times as possible. Never backtracks,\n\
225
even if this choice renders a full match impossible.\n\nExamples:\n\
226
- The expression "fo*+" matches "f", "fo" and "foo" in text\n\
227
"f fo foo".\n\
228
- The expression "fo*+o\\d" matches nowhere in text\n\
229
"fo1 foo2 fooo3".\n\
230
- The expression "<.*+>" matches nowhere in text\n\
231
"<p><b>bold</b>".
232
displayString_plusPoss= ++ - Possessive match 1 or more times (no backtracking)
233
additionalInfo_plusPoss= Possessive match 1 or more times.\n\n\
234
Tries to match the preceding token as many times as possible. Never backtracks,\n\
235
even if this choice renders a full match impossible.\n\nExamples:\n\
236
- The expression "fo++" matches "fo" and "foo" in text\n\
237
"f fo foo".\n\
238
- The expression "fo++o\\d" matches nowhere in text\n\
239
"fo1 foo2 fooo3".\n\
240
- The expression "<.++>" matches nowhere in text\n\
241
"<p><b>bold</b>".
242
243
displayString_exactPoss= {n}+ - Possessive match exactly n times (no backtracking)
244
additionalInfo_exactPoss= Possessive match exactly n times.\n\n\
245
This expression is equivalent to the expression\n\
246
{n} - Greedy match exactly n times.
247
displayString_leastPoss= {n,}+ - Possessive match >= n times (no backtracking)
248
additionalInfo_leastPoss= Possessive match >= n times.\n\n\
249
Tries to match the preceding token as many times as possible, but at least n times.\n\
250
Never backtracks, even if this choice renders a full match impossible.\n\nExamples:\n\
251
- The expression "fo{2,}+" matches "foo" and "fooo" in text\n\
252
"f fo foo fooo".\n\
253
- The expression "fo{2,}?o\\d" matches nowhere in text\n\
254
"fo1 foo2 fooo3 foooo4".\n\
255
Note: The expressions "{0,}?" and "*?" are equivalent;\n\
256
likewise, "{1,}?" is equivalent to "+?".
257
258
displayString_countPoss= {n,m}+ - Possessive match >= n times but <= m times (no backtracking)
259
additionalInfo_countPoss= Possessive match >= n times but <= m times.\n\n\
260
Tries to match the preceding token as many times as possible, \n\
261
at least n times and at most m times.\n\
262
Never backtracks, even if this choice renders a full match impossible.\n\nExamples:\n\
263
- The expression "fo{1,2}+" matches "fo", "foo", and "foo" in text\n\
264
"f fo foo fooo".\n\
265
- The expression "fo{1,2}+o\\d" matches only "fooo3" in text\n\
266
"fo1 foo2 fooo3 foooo4".\n\
267
- The expression "^.{70,80}+$" matches all the lines that contain\n\
268
between 70 and 80 characters (inclusive).
269
270
displayString_alt= U|V - Alternation: U or V
271
additionalInfo_alt= Alternation.\n\n\
272
First tries to match subexpression U. Falls back and tries to match V if U didn't match.\n\nExamples:\n\
273
- The expression "A|B" applied to text "BA" first matches "B", then "A".\n\
274
- The expression "AB|BC|CD" applied to text "ABC BC DAB" matches, in sequence:\n\
275
"AB" in the first word, the second word "BC", "AB" at the very end.
276
displayString_group= (Expr) - Mark Expr as capturing group
277
additionalInfo_group= Mark Expr as capturing group.\n\n\
278
Capturing groups are numbered by counting their opening parentheses from left to right.\n\
279
In the expression "((A)(B(C)))", for example, there are four such groups:\n\
280
1   ((A)(B(C)))\n\
281
2   (A)\n\
282
3   (B(C))\n\
283
4   (C)\n\
284
\n\
285
Group zero always stands for the entire expression. During a match,\n\
286
each subsequence of the input sequence that matches such a group is saved.\n\
287
The captured subsequence i may be used later in the expression, via a back reference "\\i",\n\
288
and may also be used in the replace string via "$i".\n\
289
\n\
290
Note: Groups beginning with (? are pure, non-capturing groups that\n\
291
do not capture text and do not count towards the group total.
292
293
displayString_bs_i= \\i - Match of the capturing group i
294
additionalInfo_bs_i= Match of the capturing group i.\n\n\
295
\\i matches the subsequence that has already been saved as capturing group i.\n\
296
\\0 is not a valid group number in the regular expression.\n\nExample:\n\
297
The expression "(\\d+)\\+\\1" matches "10+10" in text "9+10+10+11".\n\
298
\n\
299
Note: in the replace string, $i stands for the capturing group i. 
300
301
displayString_bs= \\ - Quote next character
302
additionalInfo_bs= Quote next character\n\nExample:\n\
303
The expression "\\{\\n\\}" matches the text "{n}".
304
305
displayString_bs_Q= \\Q - Start quoting
306
additionalInfo_bs_Q= Start quoting\n\n\
307
All characters between \\Q and the next \\E are taken literally and are not interpreted.\n\nExample:\n\
308
The expression "\\Qnew int[] {42}\\E;" matches text "new int[] {42}".
309
displayString_bs_E= \\E - End quoting
310
additionalInfo_bs_E= End quoting\n\n\
311
All characters between \\Q and the next \\E are taken literally and are not interpreted.\n\nExample:\n\
312
The expression "\\Qnew int[] {42}\\E;" matches text "new int[] {42}".
313
314
displayString_set= [ecl] - Character set
315
additionalInfo_set= Character set\n\n\
316
Matches a single character out of the set.\n\nExample:\n\
317
The expression "[ecl]" matches "c" and "l" in text "cold".
318
displayString_setExcl= [^ecl] - Excluded character set
319
additionalInfo_setExcl= Excluded character set\n\n\
320
Matches a single character that is not one of the excluded characters.\n\nExamples:\n\
321
The expression "[^ecl]" matches "o" and "d" in text "cold".\n\
322
The expression "[a-z&&[^ecl]]" matches any character from a to z, excluding e, c, and l.
323
displayString_setRange= [c-l] - Character range
324
additionalInfo_setRange= Character range\n\n\
325
Matches a single character out of the range from 'c' to 'l'.\n\nExamples:\n\
326
The expression "[c-l]" matches "c", "l", and "d" in text "cold".\n\
327
The expression "[a-z&&[^ecl]]" matches any character from a to z, excluding e, c, and l.
328
displayString_setInter= && - Intersection of character sets
329
additionalInfo_setInter= Intersection of character sets\n\n\
330
Matches a character that is in both of the given sets.\n\nExample:\n\
331
The expression "[a-z&&[^ecl]]" matches any character from a to z, excluding e, c, and l.
332
333
displayString_posix= \\p{Class} - POSIX or Unicode character class
334
additionalInfo_posix= POSIX or Unicode character class\n\n\
335
Matches a character from the given character class 'Class'.\n\
336
Valid classes are:\n\
337
\n\
338
- POSIX character classes (US-ASCII only):\n\
339
\    Lower, Upper, ASCII, Alpha, Digit, Alnum, Punct,\n\
340
\    Graph, Print, Blank, Cntrl, XDigit, and Space.\n\
341
\n\
342
- Unicode blocks and categories, e.g.:\n\
343
\    BasicLatin\n\
344
\    Latin-1Supplement\n\
345
\    Greek\n\
346
\    Lu: Uppercase Letter\n\
347
\    Ll: Lowercase Letter\n\
348
\    L:  Letter\n\
349
\    N:  Number\n\
350
\    Z:  Separator\n\
351
\    LD: Letter or Digit\n\
352
\    L1: Latin-1
353
354
displayString_posixNot= \\P{Class} - Excluded POSIX or Unicode character class
355
additionalInfo_posixNot= Excluded POSIX or Unicode character class\n\n\
356
Negation of character set \\p{Class}. Example:\n\
357
\\P{ASCII} is equivalent to [^\\p{ASCII}] and matches all non-ASCII characters.\n\n\
358
Valid classes are:\n\
359
\n\
360
- POSIX character classes (US-ASCII only):\n\
361
\    Lower, Upper, ASCII, Alpha, Digit, Alnum, Punct,\n\
362
\    Graph, Print, Blank, Cntrl, XDigit, and Space.\n\
363
\n\
364
- Unicode blocks and categories, e.g.:\n\
365
\    BasicLatin\n\
366
\    Latin-1Supplement\n\
367
\    Greek\n\
368
\    Lu: Uppercase Letter\n\
369
\    Ll: Lowercase Letter\n\
370
\    L:  Letter\n\
371
\    N:  Number\n\
372
\    Z:  Separator\n\
373
\    LD: Letter or Digit\n\
374
\    L1: Latin-1
375
376
377
#Flags:
378
displayString_flag= (?ismd-ismd) - Turn flags on or off
379
additionalInfo_flag= Turn flags on and off for the rest of the matching process.\n\n\
380
Flags before the dash are turned on; those after the dash are turned off.\n\
381
The following flags are supported:\n\
382
- i: case-insensitive matching\n\
383
\n\
384
- s: single-line, or dotall matching mode:\n\
385
\        The expression . matches any character, including a line terminator.\n\
386
\n\
387
- m: multiline matching mode:\n\
388
\        The expressions ^ and $ match just after or just before,\n\
389
\        respectively, a line terminator or the end of the input sequence.\n\
390
\        By default these expressions only match at the beginning and the\n\
391
\        end of the entire input sequence.\n\
392
\n\
393
- d: Unix lines matching mode:\n\
394
\        Only the '\\n' line terminator\n\
395
\        is recognized in the behavior of ., ^, and $
396
# - u: unicode-aware case folding:\n\
397
#        Case-insensitive matching, when enabled, is done in a manner consistent\n\
398
#        with the Unicode Standard. By default, case-insensitive matching\n\
399
#        assumes that only characters in the US-ASCII charset are being matched.
400
# - c: canonical equivalence\n\
401
#        Two characters will be considered to match if, and only if, their full\n\
402
#        canonical decompositions match. The expression "a\\\u0075030A", for example,\n\
403
#        will match the string "a\u030A" when this flag is specified.\n\
404
#        By default, matching does not take canonical equivalence into account.
405
# - x: comments mode\n\
406
#        Whitespace is ignored, and embedded comments starting with\n\
407
#        # are ignored until the end of a line.\n\
408
409
displayString_flagExpr= (?ismd-ismd:Expr) - Turn flags on or off in Expr
410
additionalInfo_flagExpr= Turn flags on and off in Expr.\n\n\
411
Flags before the dash are turned on; those after the dash are turned off.\n\
412
The following flags are supported:\n\
413
- i: case-insensitive matching\n\
414
\n\
415
- s: single-line, or dotall matching mode:\n\
416
\        The expression . matches any character, including a line terminator.\n\
417
\n\
418
- m: multiline matching mode:\n\
419
\        The expressions ^ and $ match just after or just before,\n\
420
\        respectively, a line terminator or the end of the input sequence.\n\
421
\        By default these expressions only match at the beginning and the\n\
422
\        end of the entire input sequence.\n\
423
\n\
424
- d: Unix lines matching mode:\n\
425
\        Only the '\\n' line terminator\n\
426
\        is recognized in the behavior of ., ^, and $
427
428
429
#Noncapturing groups:
430
displayString_nonCap= (?:Expr) - Non-capturing group
431
additionalInfo_nonCap= Non-capturing group of regular expression Expr.\n\n\
432
The group is not saved in a back reference.\n\nExample:\n\
433
The expression "(?:\\w+) (\\d+)" matches "bug 42" in text "It's bug 42.".\n\
434
A back reference "$1" in the replace string will be replaced by "42".
435
436
displayString_atomicCap= (?>Expr) - Non-capturing atomic group
437
additionalInfo_atomicCap= Non-capturing atomic group of regular expression Expr.\n\n\
438
Matches the regular expression Expr once, but does not backtrack into the expression\n\
439
again if the first match did not prove to be successful later on.\n\
440
The group is not saved in a back reference.
441
442
#Lookaround:
443
displayString_posLookahead= (?=Expr) - Zero-width positive lookahead
444
additionalInfo_posLookahead= Expr, via zero-width positive lookahead.\n\n\
445
Matches a position (zero-width: does not consume the matched characters),\n\
446
where the next characters (-> lookahead)\n\
447
do match (-> positive) the embedded expression Expr.\n\nExamples:\n\
448
- The expression "var(?==)" matches only the first "var" in text "var=17; other=var;".\n\
449
- The expression "\\b(?=\\w{7}\\b)\\w*clip\\w*\\b" matches any\n\
450
seven-letter-word that contains "clip". It matches "Eclipse", but not "paperclip".
451
452
displayString_negLookahead= (?!Expr) - Zero-width negative lookahead
453
additionalInfo_negLookahead= Expr, via zero-width negative lookahead.\n\n\
454
Matches a position (zero-width: does not consume the matched characters),\n\
455
where the next characters (-> lookahead)\n\
456
do not match (-> negative) the embedded expression Expr.\n\nExamples:\n\
457
- The expression "var(?!=)" matches only the second "var" in text "var=17; other=var;".\n\
458
- The expression "\\b(?!\\w{5,7}\\b)\\w*clip\\w*\\b" matches any\n\
459
word that contains "clip" and consists of less than 5 or more than 7 characters.\n\
460
It matches "clip" and "paperclip", but not "Eclipse".
461
462
displayString_posLookbehind= (?<=Expr) - Zero-width positive lookbehind
463
additionalInfo_posLookbehind= Expr, via zero-width positive lookbehind.\n\n\
464
Matches a position (zero-width: does not consume the matched characters),\n\
465
where the previous characters (-> lookbehind)\n\
466
do match (-> positive) the embedded expression Expr.\n\nExample:\n\
467
- The expression "\\w{5,}+(?<=as)\\b" matches "alias" and "bananas",\n\
468
but does not match "peas", "apples", or "Alaska".
469
470
displayString_negLookbehind= (?<!Expr) - Zero-width negative lookbehind
471
additionalInfo_negLookbehind= Expr, via zero-width negative lookbehind.\n\n\
472
Matches a position (zero-width: does not consume the matched characters),\n\
473
where the previous characters (-> lookbehind)\n\
474
do not match (-> negative) the embedded expression Expr.\n\nExample:\n\
475
- The expression "\\w{5,}+(?<!as)\\b" matches "Eclipse" and "apples",\n\
476
but does not match "peas" or "bananas".
477
478
#Replace string:
479
displayString_dollar= $i - Match of the capturing group i
480
additionalInfo_dollar= Match of the capturing group i.\n\n\
481
$i is the string that has been saved as capturing group i.\n\
482
$0 is the subsequence matched by the entire expression.\n\
483
\n\
484
Note: in the find expression, \\i stands for the capturing group i. 
485
displayString_replace_bs= \\ - Quote next character
486
additionalInfo_replace_bs= Quote next character\n\nExamples:\n\
487
"\\$" will be replaced by "$".\n\
488
"\\a" will be replaced by "a".\n\
489
"\\\\" will be replaced by "\\".
490
displayString_tab= Tab - The tabulator character
491
additionalInfo_tab= The tabulator character (\\t in the find expression).
492
displayString_cr= CR - The carriage return character
493
additionalInfo_cr= The carriage return character (\\r or \\x0D in the find expression).
494
displayString_nl= Newline - The newline character
495
additionalInfo_nl= The newline character (\\n or \\x0A in the find expression).
(-)src/org/eclipse/mylar/internal/team/template/TemplateHandlersManager.java (+219 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
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
 *    Eike Stepper - initial API and implementation
10
 **************************************************************************/
11
package org.eclipse.mylar.internal.team.template;
12
13
14
import org.eclipse.core.runtime.IConfigurationElement;
15
import org.eclipse.core.runtime.IExtension;
16
import org.eclipse.core.runtime.IExtensionPoint;
17
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.mylar.context.core.MylarStatusHandler;
19
import org.eclipse.mylar.tasks.core.ITask;
20
import org.eclipse.mylar.team.ITemplateHandler;
21
import org.eclipse.mylar.team.ITemplateHandlersManager;
22
import org.eclipse.mylar.team.MylarTeamPlugin;
23
24
import java.text.MessageFormat;
25
import java.util.ArrayList;
26
27
28
/**
29
 * @author Eike Stepper
30
 */
31
public class TemplateHandlersManager implements ITemplateHandlersManager
32
{
33
  private static final String ATTR_CLASS = "class";
34
35
  private static final String ATTR_DESCRIPTION = "description";
36
37
  private static final String ATTR_RECOGNIZED_KEYWORD = "recognizedKeyword";
38
39
  private static final String ELEM_TEMPLATE_HANDLER = "templateHandler";
40
41
  private static final String EXT_POINT_TEMPLATE_HANDLERS = "templateHandlers";
42
43
  public TemplateHandlersManager()
44
  {
45
  }
46
47
  public String[] getRecognizedKeywords()
48
  {
49
    final ArrayList<String> result = new ArrayList<String>();
50
    new ExtensionProcessor()
51
    {
52
      @Override
53
      protected Object processContribution(IConfigurationElement element, String keyword,
54
              String description, String className) throws Exception
55
      {
56
        result.add(keyword);
57
        return null;
58
      }
59
    }.run();
60
61
    return result.toArray(new String[result.size()]);
62
  }
63
64
  public String getHandlerDescription(final String keyword)
65
  {
66
    return (String)new ExtensionProcessor()
67
    {
68
      @Override
69
      protected Object processContribution(IConfigurationElement element, String foundKeyword,
70
              String description, String className) throws Exception
71
      {
72
        return keyword.equals(foundKeyword) ? description : null;
73
      }
74
    }.run();
75
  }
76
77
  public ITemplateHandler createHandler(final String keyword)
78
  {
79
    return (ITemplateHandler)new ExtensionProcessor()
80
    {
81
      @Override
82
      protected Object processContribution(IConfigurationElement element, String foundKeyword,
83
              String description, String className) throws Exception
84
      {
85
        if (keyword.equals(foundKeyword))
86
        {
87
          ITemplateHandler handler = (ITemplateHandler)element
88
                  .createExecutableExtension(ATTR_CLASS);
89
          if (handler instanceof TemplateHandler)
90
          {
91
            ((TemplateHandler)handler).setDescription(description);
92
            ((TemplateHandler)handler).setRecognizedKeyword(foundKeyword);
93
          }
94
          else
95
          {
96
            String recognizedKeyword = handler.getRecognizedKeyword();
97
            if (recognizedKeyword == null || !recognizedKeyword.equals(foundKeyword))
98
            {
99
              throw new IllegalArgumentException(
100
                      "Keyword markup does not match handler implementation");
101
            }
102
          }
103
104
          return handler;
105
        }
106
107
        return null;
108
      }
109
    }.run();
110
  }
111
112
  public String generateComment(ITask task, String completedTemplate, String progressTemplate)
113
  {
114
    String template = task.isCompleted() ? completedTemplate : progressTemplate;
115
    return processKeywords(task, template);
116
  }
117
118
  private String processKeywords(ITask task, String template)
119
  {
120
    String[] segments = template.split("\\$\\{");
121
    StringBuffer buffer = new StringBuffer(segments[0]);
122
123
    for (int i = 1; i < segments.length; i++)
124
    {
125
      String segment = segments[i];
126
      String value = null;
127
      int brace = segment.indexOf('}');
128
      if (brace > 0)
129
      {
130
        String keyword = segment.substring(0, brace);
131
        value = processKeyword(task, keyword);
132
      }
133
134
      if (value != null)
135
      {
136
        buffer.append(value);
137
        buffer.append(segment.substring(brace + 1));
138
      }
139
      else
140
      {
141
        buffer.append("${");
142
        buffer.append(segment);
143
      }
144
    }
145
146
    return buffer.toString();
147
  }
148
149
  private String processKeyword(ITask task, String keyword)
150
  {
151
    try
152
    {
153
      ITemplateHandler handler = createHandler(keyword);
154
      if (handler != null)
155
      {
156
        return handler.getValue(task);
157
      }
158
    }
159
    catch (Exception ex)
160
    {
161
      MylarStatusHandler.log(ex, "Problem while delegating to template handler");
162
    }
163
164
    return null;
165
  }
166
167
  /**
168
   * @author Eike Stepper
169
   */
170
  private static class ExtensionProcessor
171
  {
172
    public Object run()
173
    {
174
      IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(
175
              MylarTeamPlugin.PLUGIN_ID, EXT_POINT_TEMPLATE_HANDLERS);
176
      IExtension[] extensions = extPoint.getExtensions();
177
      for (int i = 0; i < extensions.length; i++)
178
      {
179
        IExtension extension = extensions[i];
180
        IConfigurationElement[] elements = extension.getConfigurationElements();
181
        for (int j = 0; j < elements.length; j++)
182
        {
183
          IConfigurationElement element = elements[j];
184
          if (ELEM_TEMPLATE_HANDLER.equals(element.getName()))
185
          {
186
            try
187
            {
188
              Object result = processContribution(element);
189
              if (result != null) return result;
190
            }
191
            catch (Exception ex)
192
            {
193
              final String msg = MessageFormat.format(
194
                      "Error while processing template handler contribution {0} from plugin {1}.",
195
                      element.getAttribute(ATTR_CLASS), element.getContributor().getName());
196
              MylarStatusHandler.log(ex, msg);
197
            }
198
          }
199
        }
200
      }
201
202
      return null;
203
    }
204
205
    protected Object processContribution(IConfigurationElement element) throws Exception
206
    {
207
      String keyword = element.getAttribute(ATTR_RECOGNIZED_KEYWORD);
208
      String description = element.getAttribute(ATTR_DESCRIPTION);
209
      String className = element.getAttribute(ATTR_CLASS);
210
      return processContribution(element, keyword, description, className);
211
    }
212
213
    protected Object processContribution(IConfigurationElement element, String keyword,
214
            String description, String className) throws Exception
215
    {
216
      return null;
217
    }
218
  }
219
}
(-)src/org/eclipse/mylar/team/ITemplateHandlersManager.java (+31 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
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
 *    Eike Stepper - initial API and implementation
10
 **************************************************************************/
11
package org.eclipse.mylar.team;
12
13
14
import org.eclipse.mylar.tasks.core.ITask;
15
16
17
/**
18
 * @author Eike Stepper
19
 */
20
public interface ITemplateHandlersManager
21
{
22
  public static final ITemplateHandlersManager INSTANCE = new org.eclipse.mylar.internal.team.template.TemplateHandlersManager();
23
24
  public String[] getRecognizedKeywords();
25
26
  public String getHandlerDescription(String keyword);
27
28
  public ITemplateHandler createHandler(String keyword);
29
30
  public String generateComment(ITask task, String completedTemplate, String progressTemplate);
31
}
(-)src/org/eclipse/mylar/internal/team/ui/preferences/workaround/RegExMessages.java (+207 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.team.ui.preferences.workaround;
13
14
import org.eclipse.osgi.util.NLS;
15
16
/**
17
 * RegEx messages. Helper class to get NLSed messages.
18
 * <p>
19
 * Copied from org.eclipse.ui.texteditor.RegExMessages.
20
 * <p>
21
 * Needed by org.eclipse.mylar.internal.team.ui.preferences.workaround.RegExContentProposalProvider.
22
 * <p>
23
 * TODO Ask platform guys to open this API
24
 * 
25
 * @since 3.1
26
 */
27
final class RegExMessages extends NLS {
28
29
    private static final String BUNDLE_NAME= RegExMessages.class.getName();
30
31
    private RegExMessages() {
32
        // Do not instantiate
33
    }
34
35
    static {
36
        reloadMessages();
37
    }
38
    
39
    static void reloadMessages() {
40
        NLS.initializeMessages(BUNDLE_NAME, RegExMessages.class);
41
    }
42
    
43
    //characters
44
    public static String displayString_bs_bs;
45
    public static String additionalInfo_bs_bs;
46
    public static String displayString_bs_0;
47
    public static String additionalInfo_bs_0;
48
    public static String displayString_bs_x;
49
    public static String additionalInfo_bs_x;
50
    public static String displayString_bs_u;
51
    public static String additionalInfo_bs_u;
52
    public static String displayString_bs_t;
53
    public static String additionalInfo_bs_t;
54
    public static String displayString_bs_n;
55
    public static String additionalInfo_bs_n;
56
    public static String displayString_bs_r;
57
    public static String additionalInfo_bs_r;
58
    public static String displayString_bs_f;
59
    public static String additionalInfo_bs_f;
60
    public static String displayString_bs_a;
61
    public static String additionalInfo_bs_a;
62
    public static String displayString_bs_e;
63
    public static String additionalInfo_bs_e;
64
    public static String displayString_bs_c;
65
    public static String additionalInfo_bs_c;
66
    
67
    //character classes
68
    public static String displayString_dot;
69
    public static String additionalInfo_dot;
70
    public static String displayString_bs_d;
71
    public static String additionalInfo_bs_d;
72
    public static String displayString_bs_D;
73
    public static String additionalInfo_bs_D;
74
    public static String displayString_bs_s;
75
    public static String additionalInfo_bs_s;
76
    public static String displayString_bs_S;
77
    public static String additionalInfo_bs_S;
78
    public static String displayString_bs_w;
79
    public static String additionalInfo_bs_w;
80
    public static String displayString_bs_W;
81
    public static String additionalInfo_bs_W;
82
    
83
    //boundary matchers
84
    public static String displayString_start;
85
    public static String additionalInfo_start;
86
    public static String displayString_end;
87
    public static String additionalInfo_end;
88
    public static String displayString_bs_b;
89
    public static String additionalInfo_bs_b;
90
    public static String displayString_bs_B;
91
    public static String additionalInfo_bs_B;
92
    public static String displayString_bs_A;
93
    public static String additionalInfo_bs_A;
94
    public static String displayString_bs_G;
95
    public static String additionalInfo_bs_G;
96
    public static String displayString_bs_Z;
97
    public static String additionalInfo_bs_Z;
98
    public static String displayString_bs_z;
99
    public static String additionalInfo_bs_z;
100
    
101
    //greedy quantifiers
102
    public static String displayString_quest;
103
    public static String additionalInfo_quest;
104
    public static String displayString_star;
105
    public static String additionalInfo_star;
106
    public static String displayString_plus;
107
    public static String additionalInfo_plus;
108
    public static String displayString_exact;
109
    public static String additionalInfo_exact;
110
    public static String displayString_least;
111
    public static String additionalInfo_least;
112
    public static String displayString_count;
113
    public static String additionalInfo_count;
114
    
115
    //lazy quantifiers
116
    public static String displayString_questLazy;
117
    public static String additionalInfo_questLazy;
118
    public static String displayString_starLazy;
119
    public static String additionalInfo_starLazy;
120
    public static String displayString_plusLazy;
121
    public static String additionalInfo_plusLazy;
122
    public static String displayString_exactLazy;
123
    public static String additionalInfo_exactLazy;
124
    public static String displayString_leastLazy;
125
    public static String additionalInfo_leastLazy;
126
    public static String displayString_countLazy;
127
    public static String additionalInfo_countLazy;
128
    
129
    //possessive quantifiers
130
    public static String displayString_questPoss;
131
    public static String additionalInfo_questPoss;
132
    public static String displayString_starPoss;
133
    public static String additionalInfo_starPoss;
134
    public static String displayString_plusPoss;
135
    public static String additionalInfo_plusPoss;
136
    public static String displayString_exactPoss;
137
    public static String additionalInfo_exactPoss;
138
    public static String displayString_leastPoss;
139
    public static String additionalInfo_leastPoss;
140
    public static String displayString_countPoss;
141
    public static String additionalInfo_countPoss;
142
    
143
    //alternative
144
    public static String displayString_alt;
145
    public static String additionalInfo_alt;
146
    
147
    //capturing groups
148
    public static String displayString_group;
149
    public static String additionalInfo_group;
150
    public static String displayString_bs_i;
151
    public static String additionalInfo_bs_i;
152
    
153
    //quoting
154
    public static String displayString_bs;
155
    public static String additionalInfo_bs;
156
    public static String displayString_bs_Q;
157
    public static String additionalInfo_bs_Q;
158
    public static String displayString_bs_E;
159
    public static String additionalInfo_bs_E;
160
    
161
    //character sets
162
    public static String displayString_set;
163
    public static String additionalInfo_set;
164
    public static String displayString_setExcl;
165
    public static String additionalInfo_setExcl;
166
    public static String displayString_setRange;
167
    public static String additionalInfo_setRange;
168
    public static String displayString_setInter;
169
    public static String additionalInfo_setInter;
170
    public static String displayString_posix;
171
    public static String additionalInfo_posix;
172
    public static String displayString_posixNot;
173
    public static String additionalInfo_posixNot;
174
    
175
    public static String displayString_flag;
176
    public static String additionalInfo_flag;
177
    public static String displayString_flagExpr;
178
    public static String additionalInfo_flagExpr;
179
    
180
    //non-capturing group
181
    public static String displayString_nonCap;
182
    public static String additionalInfo_nonCap;
183
    public static String displayString_atomicCap;
184
    public static String additionalInfo_atomicCap;
185
    
186
    //look-ahead
187
    public static String displayString_posLookahead;
188
    public static String additionalInfo_posLookahead;
189
    public static String displayString_negLookahead;
190
    public static String additionalInfo_negLookahead;
191
    public static String displayString_posLookbehind;
192
    public static String additionalInfo_posLookbehind;
193
    public static String displayString_negLookbehind;
194
    public static String additionalInfo_negLookbehind;
195
    
196
    //replace
197
    public static String displayString_dollar;
198
    public static String additionalInfo_dollar;
199
    public static String additionalInfo_replace_bs;
200
    public static String displayString_replace_bs;
201
    public static String displayString_tab;
202
    public static String additionalInfo_tab;
203
    public static String displayString_nl;
204
    public static String additionalInfo_nl;
205
    public static String displayString_cr;
206
    public static String additionalInfo_cr;
207
}
(-)src/org/eclipse/mylar/internal/team/ui/preferences/workaround/README.java (+22 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
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
 *    Eike Stepper - initial API and implementation
10
 **************************************************************************/
11
package org.eclipse.mylar.internal.team.ui.preferences.workaround;
12
13
/**
14
 * The classes in this package are copied from org.eclipse.ui.texteditor because
15
 * the class org.eclipse.ui.texteditor.RegExContentProposalProvider is not public.
16
 * TODO We should ask platform guys to open this API.
17
 * 
18
 * @author Eike Stepper
19
 */
20
public class README
21
{
22
}
(-)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/team/ITemplateHandler.java (+27 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
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
 *    Eike Stepper - initial API and implementation
10
 **************************************************************************/
11
package org.eclipse.mylar.team;
12
13
14
import org.eclipse.mylar.tasks.core.ITask;
15
16
17
/**
18
 * @author Eike Stepper
19
 */
20
public interface ITemplateHandler
21
{
22
  public String getDescription();
23
24
  public String getRecognizedKeyword();
25
26
  public String getValue(ITask task);
27
}
(-)src/org/eclipse/mylar/internal/team/template/TemplateHandler.java (+384 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
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
 *    Eike Stepper - initial API and implementation
10
 **************************************************************************/
11
package org.eclipse.mylar.internal.team.template;
12
13
14
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
15
import org.eclipse.mylar.tasks.core.ITask;
16
import org.eclipse.mylar.team.ITemplateHandler;
17
18
import java.util.List;
19
20
21
/**
22
 * @author Eike Stepper
23
 */
24
public abstract class TemplateHandler implements ITemplateHandler
25
{
26
  protected String description;
27
28
  protected String recognizedKeyword;
29
30
  protected TemplateHandler()
31
  {
32
  }
33
34
  public String getDescription()
35
  {
36
    return description != null ? description : "Handler for '" + recognizedKeyword + "'";
37
  }
38
39
  public void setDescription(String description)
40
  {
41
    this.description = description;
42
  }
43
44
  public String getRecognizedKeyword()
45
  {
46
    return recognizedKeyword;
47
  }
48
49
  public void setRecognizedKeyword(String recognizedKeyword)
50
  {
51
    if (recognizedKeyword == null)
52
    {
53
      throw new IllegalArgumentException("Keyword to recognize must not be null"); //$NON-NLS-1$
54
    }
55
56
    this.recognizedKeyword = recognizedKeyword;
57
  }
58
59
  public static String implode(List<String> list, String separator)
60
  {
61
    StringBuilder builder = new StringBuilder();
62
    for (String cc : list)
63
    {
64
      if (builder.length() != 0)
65
      {
66
        builder.append(separator);
67
      }
68
69
      builder.append(cc);
70
    }
71
72
    return builder.toString();
73
  }
74
75
  /**
76
   * @author Eike Stepper
77
   */
78
  public static class RepositoryKind extends TemplateHandler
79
  {
80
    public String getValue(ITask task)
81
    {
82
      if (task instanceof AbstractRepositoryTask)
83
      {
84
        return ((AbstractRepositoryTask)task).getRepositoryKind();
85
      }
86
87
      return null;
88
    }
89
  }
90
91
  /**
92
   * @author Eike Stepper
93
   */
94
  public static class RepositoryURL extends TemplateHandler
95
  {
96
    public String getValue(ITask task)
97
    {
98
      if (task instanceof AbstractRepositoryTask)
99
      {
100
        return ((AbstractRepositoryTask)task).getRepositoryUrl();
101
      }
102
103
      return null;
104
    }
105
  }
106
107
  /**
108
   * @author Eike Stepper
109
   */
110
  public static class TaskProduct extends TemplateHandler
111
  {
112
    public String getValue(ITask task)
113
    {
114
      if (task instanceof AbstractRepositoryTask)
115
      {
116
        return ((AbstractRepositoryTask)task).getTaskData().getProduct();
117
      }
118
119
      return null;
120
    }
121
  }
122
123
  /**
124
   * @author Eike Stepper
125
   */
126
  public static class TaskAssignee extends TemplateHandler
127
  {
128
    public String getValue(ITask task)
129
    {
130
      if (task instanceof AbstractRepositoryTask)
131
      {
132
        return ((AbstractRepositoryTask)task).getTaskData().getAssignedTo();
133
      }
134
135
      return null;
136
    }
137
  }
138
139
  /**
140
   * @author Eike Stepper
141
   */
142
  public static class TaskReporter extends TemplateHandler
143
  {
144
    public String getValue(ITask task)
145
    {
146
      if (task instanceof AbstractRepositoryTask)
147
      {
148
        return ((AbstractRepositoryTask)task).getTaskData().getReporter();
149
      }
150
151
      return null;
152
    }
153
  }
154
155
  /**
156
   * @author Eike Stepper
157
   */
158
  public static class TaskResolution extends TemplateHandler
159
  {
160
    public String getValue(ITask task)
161
    {
162
      if (task instanceof AbstractRepositoryTask)
163
      {
164
        return ((AbstractRepositoryTask)task).getTaskData().getResolution();
165
      }
166
167
      return null;
168
    }
169
  }
170
171
  /**
172
   * @author Eike Stepper
173
   */
174
  public static class TaskStatus extends TemplateHandler
175
  {
176
    public String getValue(ITask task)
177
    {
178
      if (task instanceof AbstractRepositoryTask)
179
      {
180
        return ((AbstractRepositoryTask)task).getTaskData().getStatus();
181
      }
182
183
      return null;
184
    }
185
  }
186
187
  /**
188
   * @author Eike Stepper
189
   */
190
  public static class TaskCC extends TemplateHandler
191
  {
192
    public String getValue(ITask task)
193
    {
194
      if (task instanceof AbstractRepositoryTask)
195
      {
196
        List<String> list = ((AbstractRepositoryTask)task).getTaskData().getCC();
197
        return implode(list, ", ");
198
      }
199
200
      return null;
201
    }
202
  }
203
204
  /**
205
   * @author Eike Stepper
206
   */
207
  public static class TaskKeywords extends TemplateHandler
208
  {
209
    public String getValue(ITask task)
210
    {
211
      if (task instanceof AbstractRepositoryTask)
212
      {
213
        List<String> list = ((AbstractRepositoryTask)task).getTaskData().getKeywords();
214
        return implode(list, ", ");
215
      }
216
217
      return null;
218
    }
219
  }
220
221
  /**
222
   * @author Eike Stepper
223
   */
224
  public static class TaskLastModified extends TemplateHandler
225
  {
226
    public String getValue(ITask task)
227
    {
228
      if (task instanceof AbstractRepositoryTask)
229
      {
230
        return ((AbstractRepositoryTask)task).getTaskData().getLastModified();
231
      }
232
233
      return null;
234
    }
235
  }
236
237
  /**
238
   * @author Eike Stepper
239
   */
240
  public static class TaskSummary extends TemplateHandler
241
  {
242
    public String getValue(ITask task)
243
    {
244
      if (task instanceof AbstractRepositoryTask)
245
      {
246
        return ((AbstractRepositoryTask)task).getTaskData().getSummary();
247
      }
248
249
      return task.getDescription();
250
    }
251
  }
252
253
  /**
254
   * @author Eike Stepper
255
   */
256
  public static class TaskDescription extends TemplateHandler
257
  {
258
    public String getValue(ITask task)
259
    {
260
      return task.getDescription();
261
    }
262
  }
263
264
  /**
265
   * @author Eike Stepper
266
   */
267
  public static class TaskHandle extends TemplateHandler
268
  {
269
    public String getValue(ITask task)
270
    {
271
      return task.getHandleIdentifier();
272
    }
273
  }
274
275
  /**
276
   * @author Eike Stepper
277
   */
278
  public static class TaskID extends TemplateHandler
279
  {
280
    public String getValue(ITask task)
281
    {
282
      return AbstractRepositoryTask.getTaskId(task.getHandleIdentifier());
283
    }
284
  }
285
286
  /**
287
   * @author Eike Stepper
288
   */
289
  public static class TaskNotes extends TemplateHandler
290
  {
291
    public String getValue(ITask task)
292
    {
293
      return task.getNotes();
294
    }
295
  }
296
297
  /**
298
   * @author Eike Stepper
299
   */
300
  public static class TaskPriority extends TemplateHandler
301
  {
302
    public String getValue(ITask task)
303
    {
304
      return task.getPriority();
305
    }
306
  }
307
308
  /**
309
   * @author Eike Stepper
310
   */
311
  public static class TaskType extends TemplateHandler
312
  {
313
    public String getValue(ITask task)
314
    {
315
      return task.getTaskType();
316
    }
317
  }
318
319
  /**
320
   * @author Eike Stepper
321
   */
322
  public static class TaskURL extends TemplateHandler
323
  {
324
    public String getValue(ITask task)
325
    {
326
      return task.getUrl();
327
    }
328
  }
329
330
  /**
331
   * @author Eike Stepper
332
   */
333
  protected static abstract class Date extends TemplateHandler
334
  {
335
    public String getValue(ITask task)
336
    {
337
      java.util.Date date = getDate(task);
338
      return formatDate(date);
339
    }
340
341
    protected String formatDate(java.util.Date date)
342
    {
343
      return date.toString();
344
    }
345
346
    protected abstract java.util.Date getDate(ITask task);
347
348
    /**
349
     * @author Eike Stepper
350
     */
351
    public static class TaskCompletion extends Date
352
    {
353
      @Override
354
      protected java.util.Date getDate(ITask task)
355
      {
356
        return task.getCompletionDate();
357
      }
358
    }
359
360
    /**
361
     * @author Eike Stepper
362
     */
363
    public static class TaskCreation extends Date
364
    {
365
      @Override
366
      protected java.util.Date getDate(ITask task)
367
      {
368
        return task.getCreationDate();
369
      }
370
    }
371
372
    /**
373
     * @author Eike Stepper
374
     */
375
    public static class TaskReminder extends Date
376
    {
377
      @Override
378
      protected java.util.Date getDate(ITask task)
379
      {
380
        return task.getReminderDate();
381
      }
382
    }
383
  }
384
}
(-)src/org/eclipse/mylar/internal/team/template/TemplateHandlerContentProposalProvider.java (+158 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
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
 *    Eike Stepper - initial API and implementation
10
 **************************************************************************/
11
package org.eclipse.mylar.internal.team.template;
12
13
14
import org.eclipse.jface.fieldassist.IContentProposal;
15
import org.eclipse.jface.fieldassist.IContentProposalProvider;
16
import org.eclipse.mylar.team.ITemplateHandlersManager;
17
18
import java.util.ArrayList;
19
import java.util.List;
20
21
22
/**
23
 * @author Eike Stepper
24
 */
25
public class TemplateHandlerContentProposalProvider implements IContentProposalProvider
26
{
27
  public IContentProposal[] getProposals(String contents, int position)
28
  {
29
    ProposalComputer proposalComputer = new ProposalComputer(contents, position);
30
    return proposalComputer.computeProposals();
31
  }
32
33
  /**
34
   * @author Eike Stepper
35
   */
36
  protected static class ProposalComputer
37
  {
38
    private String contents;
39
40
    private int position;
41
42
    private List<IContentProposal> result = new ArrayList<IContentProposal>();
43
44
    private String[] keywords;
45
46
    private String prefix;
47
48
    public ProposalComputer(String contents, int position)
49
    {
50
      this.contents = contents;
51
      this.position = position;
52
      initKeywords();
53
      initPrefix();
54
    }
55
56
    public IContentProposal[] computeProposals()
57
    {
58
      for (String keyword : keywords)
59
      {
60
        String proposal = getMatch(keyword);
61
        if (proposal != null)
62
        {
63
          addProposal(proposal, keyword);
64
        }
65
      }
66
67
      return result.toArray(new IContentProposal[result.size()]);
68
    }
69
70
    protected ITemplateHandlersManager getTemplateHandlersManager()
71
    {
72
      return ITemplateHandlersManager.INSTANCE;
73
    }
74
75
    private void initKeywords()
76
    {
77
      keywords = getTemplateHandlersManager().getRecognizedKeywords();
78
    }
79
80
    private void initPrefix()
81
    {
82
      prefix = "";
83
      String beforePosition = contents.substring(0, position);
84
      if (beforePosition.endsWith("$"))
85
      {
86
        prefix = "$";
87
      }
88
      else
89
      {
90
        int start = beforePosition.lastIndexOf("${");
91
        if (start >= 0)
92
        {
93
          int end = contents.indexOf('}', start);
94
          if (end >= position)
95
          {
96
            prefix = contents.substring(start, position);
97
          }
98
        }
99
      }
100
    }
101
102
    private String getMatch(String keyword)
103
    {
104
      String wholeProposal = "${" + keyword + "}";
105
      if (wholeProposal.startsWith(prefix))
106
      {
107
        return wholeProposal.substring(prefix.length());
108
      }
109
110
      return null;
111
    }
112
113
    private void addProposal(String proposal, String keyword)
114
    {
115
      String description = getTemplateHandlersManager().getHandlerDescription(keyword);
116
      result.add(new Proposal(proposal, keyword, description));
117
    }
118
119
    /**
120
     * @author Eike Stepper
121
     */
122
    private static final class Proposal implements IContentProposal
123
    {
124
      private final String proposal;
125
126
      private final String keyword;
127
128
      private final String description;
129
130
      private Proposal(String proposal, String keyword, String description)
131
      {
132
        this.proposal = proposal;
133
        this.keyword = keyword;
134
        this.description = description;
135
      }
136
137
      public String getContent()
138
      {
139
        return proposal;
140
      }
141
142
      public int getCursorPosition()
143
      {
144
        return proposal.length();
145
      }
146
147
      public String getDescription()
148
      {
149
        return description;
150
      }
151
152
      public String getLabel()
153
      {
154
        return "${" + keyword + "}";
155
      }
156
    }
157
  }
158
}
(-)src/org/eclipse/mylar/internal/team/ui/preferences/workaround/RegExContentProposalProvider.java (+380 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.team.ui.preferences.workaround;
13
14
import java.util.ArrayList;
15
16
import org.eclipse.jface.fieldassist.IContentProposal;
17
import org.eclipse.jface.fieldassist.IContentProposalProvider;
18
19
/**
20
 * Content assist proposal provider for regular expressions.
21
 * <p>
22
 * Note: Replaces <code>RegExContentAssistProcessor</code> which was introduced in 3.0.
23
 * </p>
24
 * Copied from org.eclipse.ui.texteditor.RegExContentProposalProvider.
25
 * <p>
26
 * Needed by org.eclipse.mylar.internal.team.ui.preferences.workaround.MylarTeamPreferencePage.
27
 * <p>
28
 * TODO Ask platform guys to open this API
29
 *
30
 * @since 3.2
31
 */
32
public final class RegExContentProposalProvider implements IContentProposalProvider {
33
34
    
35
    /**
36
     * Proposal computer.
37
     */
38
    private static class ProposalComputer {
39
40
        private static class Proposal implements IContentProposal {
41
            
42
            private String fContent;
43
            private String fLabel;
44
            private String fDescription;
45
            private int fCursorPosition;
46
            
47
            Proposal(String content, String label, String description, int cursorPosition) {
48
                fContent= content;
49
                fLabel= label;
50
                fDescription= description;
51
                fCursorPosition= cursorPosition;
52
            }
53
            
54
            public String getContent() {
55
                return fContent;
56
            }
57
            
58
            public String getLabel() {
59
                return fLabel;
60
            }
61
            
62
            public String getDescription() {
63
                return fDescription;
64
            }
65
            
66
            public int getCursorPosition() {
67
                return fCursorPosition;
68
            }
69
        }
70
        
71
72
        /**
73
         * The whole regular expression.
74
         */
75
        private final String fExpression;
76
        /**
77
         * The document offset.
78
         */
79
        private final int fDocumentOffset;
80
        /**
81
         * The high-priority proposals.
82
         */
83
        private final ArrayList fPriorityProposals;
84
        /**
85
         * The low-priority proposals.
86
         */
87
        private final ArrayList fProposals;
88
        /**
89
         * <code>true</code> iff <code>fExpression</code> ends with an open escape.
90
         */
91
        private final boolean fIsEscape;
92
93
        /**
94
         * Creates a new Proposal Computer.
95
         * @param contents the contents of the subject control
96
         * @param position the cursor position
97
         */
98
        public ProposalComputer(String contents, int position) {
99
            fExpression= contents;
100
            fDocumentOffset= position;
101
            fPriorityProposals= new ArrayList();
102
            fProposals= new ArrayList();
103
            
104
            boolean isEscape= false;
105
            esc: for (int i= position - 1; i >= 0; i--) {
106
                if (fExpression.charAt(i) == '\\')
107
                    isEscape= !isEscape;
108
                else
109
                    break esc;
110
            }
111
            fIsEscape= isEscape;
112
        }
113
114
        /**
115
         * Computes applicable proposals for the find field.
116
         * @return the proposals
117
         */
118
        public IContentProposal[] computeFindProposals() {
119
            //characters
120
            addBsProposal("\\\\", RegExMessages.displayString_bs_bs, RegExMessages.additionalInfo_bs_bs); //$NON-NLS-1$
121
            addBracketProposal("\\0", 2, RegExMessages.displayString_bs_0, RegExMessages.additionalInfo_bs_0); //$NON-NLS-1$
122
            addBracketProposal("\\x", 2, RegExMessages.displayString_bs_x, RegExMessages.additionalInfo_bs_x); //$NON-NLS-1$
123
            addBracketProposal("\\u", 2, RegExMessages.displayString_bs_u, RegExMessages.additionalInfo_bs_u); //$NON-NLS-1$
124
            addBsProposal("\\t", RegExMessages.displayString_bs_t, RegExMessages.additionalInfo_bs_t); //$NON-NLS-1$
125
            addBsProposal("\\n", RegExMessages.displayString_bs_n, RegExMessages.additionalInfo_bs_n); //$NON-NLS-1$
126
            addBsProposal("\\r", RegExMessages.displayString_bs_r, RegExMessages.additionalInfo_bs_r); //$NON-NLS-1$
127
            addBsProposal("\\f", RegExMessages.displayString_bs_f, RegExMessages.additionalInfo_bs_f); //$NON-NLS-1$
128
            addBsProposal("\\a", RegExMessages.displayString_bs_a, RegExMessages.additionalInfo_bs_a); //$NON-NLS-1$
129
            addBsProposal("\\e", RegExMessages.displayString_bs_e, RegExMessages.additionalInfo_bs_e); //$NON-NLS-1$
130
            addBsProposal("\\c", RegExMessages.displayString_bs_c, RegExMessages.additionalInfo_bs_c); //$NON-NLS-1$
131
            
132
            if (! fIsEscape)
133
                addBracketProposal(".", 1, RegExMessages.displayString_dot, RegExMessages.additionalInfo_dot); //$NON-NLS-1$
134
            addBsProposal("\\d", RegExMessages.displayString_bs_d, RegExMessages.additionalInfo_bs_d); //$NON-NLS-1$
135
            addBsProposal("\\D", RegExMessages.displayString_bs_D, RegExMessages.additionalInfo_bs_D); //$NON-NLS-1$
136
            addBsProposal("\\s", RegExMessages.displayString_bs_s, RegExMessages.additionalInfo_bs_s); //$NON-NLS-1$
137
            addBsProposal("\\S", RegExMessages.displayString_bs_S, RegExMessages.additionalInfo_bs_S); //$NON-NLS-1$
138
            addBsProposal("\\w", RegExMessages.displayString_bs_w, RegExMessages.additionalInfo_bs_w); //$NON-NLS-1$
139
            addBsProposal("\\W", RegExMessages.displayString_bs_W, RegExMessages.additionalInfo_bs_W); //$NON-NLS-1$
140
            
141
            // back reference
142
            addBsProposal("\\", RegExMessages.displayString_bs_i, RegExMessages.additionalInfo_bs_i); //$NON-NLS-1$
143
            
144
            //quoting
145
            addBsProposal("\\", RegExMessages.displayString_bs, RegExMessages.additionalInfo_bs); //$NON-NLS-1$
146
            addBsProposal("\\Q", RegExMessages.displayString_bs_Q, RegExMessages.additionalInfo_bs_Q); //$NON-NLS-1$
147
            addBsProposal("\\E", RegExMessages.displayString_bs_E, RegExMessages.additionalInfo_bs_E); //$NON-NLS-1$
148
            
149
            //character sets
150
            if (! fIsEscape) {
151
                addBracketProposal("[]", 1, RegExMessages.displayString_set, RegExMessages.additionalInfo_set); //$NON-NLS-1$
152
                addBracketProposal("[^]", 2, RegExMessages.displayString_setExcl, RegExMessages.additionalInfo_setExcl); //$NON-NLS-1$
153
                addBracketProposal("[-]", 1, RegExMessages.displayString_setRange, RegExMessages.additionalInfo_setRange); //$NON-NLS-1$
154
                addProposal("&&", RegExMessages.displayString_setInter, RegExMessages.additionalInfo_setInter); //$NON-NLS-1$
155
            }
156
            if (! fIsEscape && fDocumentOffset > 0 && fExpression.charAt(fDocumentOffset - 1) == '\\') {
157
                addProposal("\\p{}", 3, RegExMessages.displayString_posix, RegExMessages.additionalInfo_posix); //$NON-NLS-1$
158
                addProposal("\\P{}", 3, RegExMessages.displayString_posixNot, RegExMessages.additionalInfo_posixNot); //$NON-NLS-1$
159
            } else {
160
                addBracketProposal("\\p{}", 3, RegExMessages.displayString_posix, RegExMessages.additionalInfo_posix); //$NON-NLS-1$
161
                addBracketProposal("\\P{}", 3, RegExMessages.displayString_posixNot, RegExMessages.additionalInfo_posixNot); //$NON-NLS-1$
162
            }
163
            
164
//          addBsProposal("\\p{Lower}", RegExMessages.displayString_bs_p{Lower}, RegExMessages.additionalInfo_bs_p{Lower}); //$NON-NLS-1$
165
//          addBsProposal("\\p{Upper}", RegExMessages.displayString_bs_p{Upper}, RegExMessages.additionalInfo_bs_p{Upper}); //$NON-NLS-1$
166
//          addBsProposal("\\p{ASCII}", RegExMessages.displayString_bs_p{ASCII}, RegExMessages.additionalInfo_bs_p{ASCII}); //$NON-NLS-1$
167
//          addBsProposal("\\p{Alpha}", RegExMessages.displayString_bs_p{Alpha}, RegExMessages.additionalInfo_bs_p{Alpha}); //$NON-NLS-1$
168
//          addBsProposal("\\p{Digit}", RegExMessages.displayString_bs_p{Digit}, RegExMessages.additionalInfo_bs_p{Digit}); //$NON-NLS-1$
169
//          addBsProposal("\\p{Alnum}", RegExMessages.displayString_bs_p{Alnum}, RegExMessages.additionalInfo_bs_p{Alnum}); //$NON-NLS-1$
170
//          addBsProposal("\\p{Punct}", RegExMessages.displayString_bs_p{Punct}, RegExMessages.additionalInfo_bs_p{Punct}); //$NON-NLS-1$
171
//          addBsProposal("\\p{Graph}", RegExMessages.displayString_bs_p{Graph}, RegExMessages.additionalInfo_bs_p{Graph}); //$NON-NLS-1$
172
//          addBsProposal("\\p{Print}", RegExMessages.displayString_bs_p{Print}, RegExMessages.additionalInfo_bs_p{Print}); //$NON-NLS-1$
173
//          addBsProposal("\\p{Blank}", RegExMessages.displayString_bs_p{Blank}, RegExMessages.additionalInfo_bs_p{Blank}); //$NON-NLS-1$
174
//          addBsProposal("\\p{Cntrl}", RegExMessages.displayString_bs_p{Cntrl}, RegExMessages.additionalInfo_bs_p{Cntrl}); //$NON-NLS-1$
175
//          addBsProposal("\\p{XDigit}", RegExMessages.displayString_bs_p{XDigit}, RegExMessages.additionalInfo_bs_p{XDigit}); //$NON-NLS-1$
176
//          addBsProposal("\\p{Space}", RegExMessages.displayString_bs_p{Space}, RegExMessages.additionalInfo_bs_p{Space}); //$NON-NLS-1$
177
//
178
//          addBsProposal("\\p{InGreek}", RegExMessages.displayString_bs_p{InGreek}, RegExMessages.additionalInfo_bs_p{InGreek}); //$NON-NLS-1$
179
//          addBsProposal("\\p{Lu}", RegExMessages.displayString_bs_p{Lu}, RegExMessages.additionalInfo_bs_p{Lu}); //$NON-NLS-1$
180
//          addBsProposal("\\p{Sc}", RegExMessages.displayString_bs_p{Sc}, RegExMessages.additionalInfo_bs_p{Sc}); //$NON-NLS-1$
181
//          addBsProposal("\\P{InGreek}", RegExMessages.displayString_bs_P{InGreek}, RegExMessages.additionalInfo_bs_P{InGreek}); //$NON-NLS-1$
182
            
183
            //boundary matchers
184
            if (fDocumentOffset == 0) {
185
                addPriorityProposal("^", RegExMessages.displayString_start, RegExMessages.additionalInfo_start); //$NON-NLS-1$
186
            } else if (fDocumentOffset == 1 && fExpression.charAt(0) == '^') {
187
                addBracketProposal("^", 1, RegExMessages.displayString_start, RegExMessages.additionalInfo_start); //$NON-NLS-1$
188
            }
189
            if (fDocumentOffset == fExpression.length()) {
190
                addProposal("$", RegExMessages.displayString_end, RegExMessages.additionalInfo_end); //$NON-NLS-1$
191
            }
192
            addBsProposal("\\b", RegExMessages.displayString_bs_b, RegExMessages.additionalInfo_bs_b); //$NON-NLS-1$
193
            addBsProposal("\\B", RegExMessages.displayString_bs_B, RegExMessages.additionalInfo_bs_B); //$NON-NLS-1$
194
            addBsProposal("\\A", RegExMessages.displayString_bs_A, RegExMessages.additionalInfo_bs_A); //$NON-NLS-1$
195
            addBsProposal("\\G", RegExMessages.displayString_bs_G, RegExMessages.additionalInfo_bs_G); //$NON-NLS-1$
196
            addBsProposal("\\Z", RegExMessages.displayString_bs_Z, RegExMessages.additionalInfo_bs_Z); //$NON-NLS-1$
197
            addBsProposal("\\z", RegExMessages.displayString_bs_z, RegExMessages.additionalInfo_bs_z); //$NON-NLS-1$
198
            
199
            if (! fIsEscape) {
200
                //capturing groups
201
                addBracketProposal("()", 1, RegExMessages.displayString_group, RegExMessages.additionalInfo_group); //$NON-NLS-1$
202
                
203
                //flags
204
                addBracketProposal("(?)", 2, RegExMessages.displayString_flag, RegExMessages.additionalInfo_flag); //$NON-NLS-1$
205
                addBracketProposal("(?:)", 3, RegExMessages.displayString_flagExpr, RegExMessages.additionalInfo_flagExpr); //$NON-NLS-1$
206
            
207
                //non-capturing group
208
                addBracketProposal("(?:)", 3, RegExMessages.displayString_nonCap, RegExMessages.additionalInfo_nonCap); //$NON-NLS-1$
209
                addBracketProposal("(?>)", 3, RegExMessages.displayString_atomicCap, RegExMessages.additionalInfo_atomicCap); //$NON-NLS-1$
210
                
211
                //lookaraound
212
                addBracketProposal("(?=)", 3, RegExMessages.displayString_posLookahead, RegExMessages.additionalInfo_posLookahead); //$NON-NLS-1$
213
                addBracketProposal("(?!)", 3, RegExMessages.displayString_negLookahead, RegExMessages.additionalInfo_negLookahead); //$NON-NLS-1$
214
                addBracketProposal("(?<=)", 4, RegExMessages.displayString_posLookbehind, RegExMessages.additionalInfo_posLookbehind); //$NON-NLS-1$
215
                addBracketProposal("(?<!)", 4, RegExMessages.displayString_negLookbehind, RegExMessages.additionalInfo_negLookbehind); //$NON-NLS-1$
216
                
217
                //greedy quantifiers
218
                addBracketProposal("?", 1, RegExMessages.displayString_quest, RegExMessages.additionalInfo_quest); //$NON-NLS-1$
219
                addBracketProposal("*", 1, RegExMessages.displayString_star, RegExMessages.additionalInfo_star); //$NON-NLS-1$
220
                addBracketProposal("+", 1, RegExMessages.displayString_plus, RegExMessages.additionalInfo_plus); //$NON-NLS-1$
221
                addBracketProposal("{}", 1, RegExMessages.displayString_exact, RegExMessages.additionalInfo_exact); //$NON-NLS-1$
222
                addBracketProposal("{,}", 1, RegExMessages.displayString_least, RegExMessages.additionalInfo_least); //$NON-NLS-1$
223
                addBracketProposal("{,}", 1, RegExMessages.displayString_count, RegExMessages.additionalInfo_count); //$NON-NLS-1$
224
                
225
                //lazy quantifiers
226
                addBracketProposal("??", 1, RegExMessages.displayString_questLazy, RegExMessages.additionalInfo_questLazy); //$NON-NLS-1$
227
                addBracketProposal("*?", 1, RegExMessages.displayString_starLazy, RegExMessages.additionalInfo_starLazy); //$NON-NLS-1$
228
                addBracketProposal("+?", 1, RegExMessages.displayString_plusLazy, RegExMessages.additionalInfo_plusLazy); //$NON-NLS-1$
229
                addBracketProposal("{}?", 1, RegExMessages.displayString_exactLazy, RegExMessages.additionalInfo_exactLazy); //$NON-NLS-1$
230
                addBracketProposal("{,}?", 1, RegExMessages.displayString_leastLazy, RegExMessages.additionalInfo_leastLazy); //$NON-NLS-1$
231
                addBracketProposal("{,}?", 1, RegExMessages.displayString_countLazy, RegExMessages.additionalInfo_countLazy); //$NON-NLS-1$
232
                
233
                //possessive quantifiers
234
                addBracketProposal("?+", 1, RegExMessages.displayString_questPoss, RegExMessages.additionalInfo_questPoss); //$NON-NLS-1$
235
                addBracketProposal("*+", 1, RegExMessages.displayString_starPoss, RegExMessages.additionalInfo_starPoss); //$NON-NLS-1$
236
                addBracketProposal("++", 1, RegExMessages.displayString_plusPoss, RegExMessages.additionalInfo_plusPoss); //$NON-NLS-1$
237
                addBracketProposal("{}+", 1, RegExMessages.displayString_exactPoss, RegExMessages.additionalInfo_exactPoss); //$NON-NLS-1$
238
                addBracketProposal("{,}+", 1, RegExMessages.displayString_leastPoss, RegExMessages.additionalInfo_leastPoss); //$NON-NLS-1$
239
                addBracketProposal("{,}+", 1, RegExMessages.displayString_countPoss, RegExMessages.additionalInfo_countPoss); //$NON-NLS-1$
240
                
241
                //alternative
242
                addBracketProposal("|", 1, RegExMessages.displayString_alt, RegExMessages.additionalInfo_alt); //$NON-NLS-1$
243
            }
244
            
245
            fPriorityProposals.addAll(fProposals);
246
            return (IContentProposal[]) fPriorityProposals.toArray(new IContentProposal[fProposals.size()]);
247
        }
248
249
        /**
250
         * Computes applicable proposals for the replace field.
251
         * @return the proposals
252
         */
253
        public IContentProposal[] computeReplaceProposals() {
254
            if (fDocumentOffset > 0 && '$' == fExpression.charAt(fDocumentOffset - 1)) {
255
                addProposal("", RegExMessages.displayString_dollar, RegExMessages.additionalInfo_dollar); //$NON-NLS-1$
256
            } else {
257
                addProposal("$", RegExMessages.displayString_dollar, RegExMessages.additionalInfo_dollar); //$NON-NLS-1$
258
                addBsProposal("\\", RegExMessages.displayString_replace_bs, RegExMessages.additionalInfo_replace_bs); //$NON-NLS-1$
259
                addProposal("\t", RegExMessages.displayString_tab, RegExMessages.additionalInfo_tab); //$NON-NLS-1$
260
            }
261
            return (IContentProposal[]) fProposals.toArray(new IContentProposal[fProposals.size()]);
262
        }
263
        
264
        /**
265
         * Adds a proposal.
266
         * 
267
         * @param proposal the string to be inserted
268
         * @param displayString the proposal's label
269
         * @param additionalInfo the additional information
270
         */
271
        private void addProposal(String proposal, String displayString, String additionalInfo) {
272
            fProposals.add(new Proposal(proposal, displayString, additionalInfo, proposal.length()));
273
        }
274
275
        /**
276
         * Adds a proposal.
277
         * 
278
         * @param proposal the string to be inserted
279
         * @param cursorPosition the cursor position after insertion,
280
         *      relative to the start of the proposal
281
         * @param displayString the proposal's label
282
         * @param additionalInfo the additional information
283
         */
284
        private void addProposal(String proposal, int cursorPosition, String displayString, String additionalInfo) {
285
            fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition));
286
        }
287
288
        /**
289
         * Adds a proposal to the priority proposals list.
290
         * 
291
         * @param proposal the string to be inserted
292
         * @param displayString the proposal's label
293
         * @param additionalInfo the additional information
294
         */
295
        private void addPriorityProposal(String proposal, String displayString, String additionalInfo) {
296
            fPriorityProposals.add(new Proposal(proposal, displayString, additionalInfo, proposal.length()));
297
        }
298
        
299
        /**
300
         * Adds a proposal. Ensures that existing pre- and postfixes are not duplicated.
301
         * 
302
         * @param proposal the string to be inserted
303
         * @param cursorPosition the cursor position after insertion,
304
         *      relative to the start of the proposal
305
         * @param displayString the proposal's label
306
         * @param additionalInfo the additional information
307
         */
308
        private void addBracketProposal(String proposal, int cursorPosition, String displayString, String additionalInfo) {
309
            String prolog= fExpression.substring(0, fDocumentOffset);
310
            if (! fIsEscape && prolog.endsWith("\\") && proposal.startsWith("\\")) { //$NON-NLS-1$//$NON-NLS-2$
311
                fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition));
312
                return;
313
            }
314
            for (int i= 1; i <= cursorPosition; i++) {
315
                String prefix= proposal.substring(0, i);
316
                if (prolog.endsWith(prefix)) {
317
                    String postfix= proposal.substring(cursorPosition);
318
                    String epilog= fExpression.substring(fDocumentOffset);
319
                    if (epilog.startsWith(postfix)) {
320
                        fPriorityProposals.add(new Proposal(proposal.substring(i, cursorPosition), displayString, additionalInfo, cursorPosition-i));
321
                    } else {
322
                        fPriorityProposals.add(new Proposal(proposal.substring(i), displayString, additionalInfo, cursorPosition-i));
323
                    }
324
                    return;
325
                }
326
            }
327
            fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition));
328
        }
329
330
        /**
331
         * Adds a proposal that starts with a backslash.
332
         * Ensures that the backslash is not repeated if already typed.
333
         * 
334
         * @param proposal the string to be inserted
335
         * @param displayString the proposal's label
336
         * @param additionalInfo the additional information
337
         */
338
        private void addBsProposal(String proposal, String displayString, String additionalInfo) {
339
            String prolog= fExpression.substring(0, fDocumentOffset);
340
            int position= proposal.length();
341
            // If the string already contains the backslash, do not include in the proposal
342
            if (prolog.endsWith("\\")) { //$NON-NLS-1$
343
                position--;
344
                proposal= proposal.substring(1);
345
            }
346
347
            if (fIsEscape) {
348
                fPriorityProposals.add(new Proposal(proposal, displayString, additionalInfo, position));
349
            } else {
350
                addProposal(proposal, position, displayString, additionalInfo);
351
            }
352
        }
353
    }
354
    
355
    /**
356
     * <code>true</code> iff the processor is for the find field.
357
     * <code>false</code> iff the processor is for the replace field.
358
     */
359
    private final boolean fIsFind;
360
    
361
362
    /**
363
     * Creates a new completion proposal provider.
364
     * 
365
     * @param isFind <code>true</code> if the provider is used for the 'find' field
366
     *                  <code>false</code> if the provider is used for the 'reaplce' field
367
     */
368
    public RegExContentProposalProvider(boolean isFind) {
369
        fIsFind= isFind;
370
    }
371
    
372
    /*
373
     * @see org.eclipse.jface.fieldassist.IContentProposalProvider#getProposals(java.lang.String, int)
374
     */
375
    public IContentProposal [] getProposals(String contents, int position) {
376
        if (fIsFind)
377
            return new ProposalComputer(contents, position).computeFindProposals();
378
        return new ProposalComputer(contents, position).computeReplaceProposals();
379
    }
380
}
(-)src/org/eclipse/mylar/ide/tests/CommitMessageTest.java (-7 / +7 lines)
Lines 25-37 Link Here
25
25
26
	@SuppressWarnings("serial")
26
	@SuppressWarnings("serial")
27
	public void testBugzillaCommentParsing() {
27
	public void testBugzillaCommentParsing() {
28
		ITask task = new Task("handle", "111: foo", false) {
28
		ITask task = new Task("handle-111", "foo", false) {
29
			public boolean isLocal() {
29
			public boolean isLocal() {
30
				return false;
30
				return false;
31
			}
31
			}
32
		};
32
		};
33
		String comment = ContextChangeSet.generateComment(task, MylarTeamPlugin.DEFAULT_PREFIX_COMPLETED,
33
		String comment = ContextChangeSet.generateComment(task, MylarTeamPlugin.DEFAULT_TEMPLATE_COMPLETED,
34
				MylarTeamPlugin.DEFAULT_PREFIX_PROGRESS);
34
				MylarTeamPlugin.DEFAULT_TEMPLATE_PROGRESS);
35
		String bugId = ContextChangeSet.getTaskIdFromCommentOrLabel(comment);
35
		String bugId = ContextChangeSet.getTaskIdFromCommentOrLabel(comment);
36
		assertEquals("111", bugId);
36
		assertEquals("111", bugId);
37
	}
37
	}
Lines 40-55 Link Here
40
	public void testLocalTaskCommentParsing() {
40
	public void testLocalTaskCommentParsing() {
41
		ITask task = new Task("handle", "foo", false);
41
		ITask task = new Task("handle", "foo", false);
42
		task.setUrl("http://eclipse.org/mylar");
42
		task.setUrl("http://eclipse.org/mylar");
43
		String comment = ContextChangeSet.generateComment(task, MylarTeamPlugin.DEFAULT_PREFIX_COMPLETED,
43
		String comment = ContextChangeSet.generateComment(task, MylarTeamPlugin.DEFAULT_TEMPLATE_COMPLETED,
44
				MylarTeamPlugin.DEFAULT_PREFIX_PROGRESS);
44
				MylarTeamPlugin.DEFAULT_TEMPLATE_PROGRESS);
45
//		String bugId = MylarContextChangeSet.getTaskIdFromCommentOrLabel(comment);
45
//		String bugId = MylarContextChangeSet.getTaskIdFromCommentOrLabel(comment);
46
//		assertEquals(null, bugId);
46
//		assertEquals(null, bugId);
47
		String url = ContextChangeSet.getUrlFromComment(comment);
47
		String url = ContextChangeSet.getUrlFromComment(comment);
48
		assertEquals("http://eclipse.org/mylar", url);
48
		assertEquals("http://eclipse.org/mylar", url);
49
49
50
		task.setUrl("http://eclipse.org/mylar bla \n bla");
50
		task.setUrl("http://eclipse.org/mylar bla \n bla");
51
		String comment2 = ContextChangeSet.generateComment(task, MylarTeamPlugin.DEFAULT_PREFIX_COMPLETED,
51
		String comment2 = ContextChangeSet.generateComment(task, MylarTeamPlugin.DEFAULT_TEMPLATE_COMPLETED,
52
				MylarTeamPlugin.DEFAULT_PREFIX_PROGRESS);
52
				MylarTeamPlugin.DEFAULT_TEMPLATE_PROGRESS);
53
		String url2 = ContextChangeSet.getUrlFromComment(comment2);
53
		String url2 = ContextChangeSet.getUrlFromComment(comment2);
54
		assertEquals("http://eclipse.org/mylar", url2);
54
		assertEquals("http://eclipse.org/mylar", url2);
55
	}
55
	}

Return to bug 117517