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 102461 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.properties (+3 lines)
Lines 7-12 Link Here
7
# 
7
# 
8
# Contributors:
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
#     Maik Schreiber - bug 102461
10
###############################################################################
11
###############################################################################
11
providerName=Eclipse.org
12
providerName=Eclipse.org
12
pluginName=CVS Team Provider UI
13
pluginName=CVS Team Provider UI
Lines 239-241 Link Here
239
240
240
RepoPreference.Name=CVS Repositories
241
RepoPreference.Name=CVS Repositories
241
RepoPreference.Description=Preferences that contain the CVS repository connection information
242
RepoPreference.Description=Preferences that contain the CVS repository connection information
243
244
CommentTemplatesPreferencePage.name=Comment Templates
(-)plugin.xml (+10 lines)
Lines 681-686 Link Here
681
   <extension
681
   <extension
682
         point="org.eclipse.ui.preferencePages">
682
         point="org.eclipse.ui.preferencePages">
683
      <page
683
      <page
684
            name="%CommentTemplatesPreferencePage.name"
685
            category="org.eclipse.team.cvs.ui.CVSPreferences"
686
            class="org.eclipse.team.internal.ccvs.ui.CommentTemplatesPreferencePage"
687
            id="org.eclipse.team.cvs.ui.CommentTemplatesPreferences">
688
            <keywordReference id="org.eclipse.team.cvs.ui.cvs"/>
689
      </page>
690
   </extension>
691
   <extension
692
         point="org.eclipse.ui.preferencePages">
693
      <page
684
            name="%ConsolePreferencePage.name"
694
            name="%ConsolePreferencePage.name"
685
            category="org.eclipse.team.cvs.ui.CVSPreferences"
695
            category="org.eclipse.team.cvs.ui.CVSPreferences"
686
            class="org.eclipse.team.internal.ccvs.ui.console.ConsolePreferencesPage"
696
            class="org.eclipse.team.internal.ccvs.ui.console.ConsolePreferencesPage"
(-)src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java (-2 / +13 lines)
Lines 5-11 Link Here
5
 * available at http://www.eclipse.org/legal/epl-v10.html
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
6
 * 
7
 * Contributors: 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
8
 *     IBM - Initial API and implementation
9
 *     Maik Schreiber - bug 102461
9
 **********************************************************************/
10
 **********************************************************************/
10
package org.eclipse.team.internal.ccvs.ui;
11
package org.eclipse.team.internal.ccvs.ui;
11
12
Lines 815-820 Link Here
815
	public static String CommitCommentArea_2;
816
	public static String CommitCommentArea_2;
816
	public static String CommitCommentArea_3;
817
	public static String CommitCommentArea_3;
817
	public static String CommitCommentArea_4;
818
	public static String CommitCommentArea_4;
819
    public static String CommitCommentArea_5;
820
    public static String CommitCommentArea_6;
818
821
819
	public static String CheckoutProjectOperation_8;
822
	public static String CheckoutProjectOperation_8;
820
	public static String CheckoutProjectOperation_9;
823
	public static String CheckoutProjectOperation_9;
Lines 985-988 Link Here
985
988
986
    public static String OpenChangeSetAction_0;
989
    public static String OpenChangeSetAction_0;
987
    public static String OpenChangeSetAction_1;
990
    public static String OpenChangeSetAction_1;
988
}
991
    
992
    public static String CommentTemplatesPreferencePage_Description;
993
    public static String CommentTemplatesPreferencePage_New;
994
    public static String CommentTemplatesPreferencePage_Edit;
995
    public static String CommentTemplatesPreferencePage_Remove;
996
    public static String CommentTemplatesPreferencePage_Preview;
997
    public static String CommentTemplatesPreferencePage_EditCommentTemplateTitle;
998
    public static String CommentTemplatesPreferencePage_EditCommentTemplateMessage;
999
}
(-)src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java (-11 / +65 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Sebastian Davids - bug 57208
10
 *     Sebastian Davids - bug 57208
11
 *     Maik Schreiber - bug 102461
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.team.internal.ccvs.ui;
13
package org.eclipse.team.internal.ccvs.ui;
13
14
Lines 26-31 Link Here
26
import org.eclipse.team.internal.ccvs.core.*;
27
import org.eclipse.team.internal.ccvs.core.*;
27
import org.eclipse.team.internal.ui.SWTUtils;
28
import org.eclipse.team.internal.ui.SWTUtils;
28
import org.eclipse.team.internal.ui.dialogs.DialogArea;
29
import org.eclipse.team.internal.ui.dialogs.DialogArea;
30
import org.eclipse.ui.dialogs.PreferencesUtil;
29
31
30
/**
32
/**
31
 * This area provides the widgets for providing the CVS commit comment
33
 * This area provides the widgets for providing the CVS commit comment
Lines 125-159 Link Here
125
        
127
        
126
        private final String fMessage;
128
        private final String fMessage;
127
        private final String [] fComments;
129
        private final String [] fComments;
130
        private String[] fCommentTemplates;
128
        private final Combo fCombo;
131
        private final Combo fCombo;
129
        
132
        
130
        
133
        
131
        public ComboBox(Composite composite, String message, String [] options) {
134
        public ComboBox(Composite composite, String message, String [] options,
135
                String[] commentTemplates) {
132
            
136
            
133
            fMessage= message;
137
            fMessage= message;
134
            fComments= options;
138
            fComments= options;
139
            fCommentTemplates = commentTemplates;
135
            
140
            
136
            fCombo = new Combo(composite, SWT.READ_ONLY);
141
            fCombo = new Combo(composite, SWT.READ_ONLY);
137
            fCombo.setLayoutData(SWTUtils.createHFillGridData());
142
            fCombo.setLayoutData(SWTUtils.createHFillGridData());
138
            
143
            
139
            // populate the previous comment list
144
            // populate the previous comment list
140
            fCombo.add(fMessage);
145
            populateList();
141
            for (int i = 0; i < fComments.length; i++) {
142
                fCombo.add(HistoryView.flattenText(fComments[i]));
143
            }
144
            fCombo.setText(fMessage);
145
            
146
            
146
            // We don't want to have an initial selection
147
            // We don't want to have an initial selection
147
            // (see bug 32078: http://bugs.eclipse.org/bugs/show_bug.cgi?id=32078)
148
            // (see bug 32078: http://bugs.eclipse.org/bugs/show_bug.cgi?id=32078)
148
            fCombo.addFocusListener(this);
149
            fCombo.addFocusListener(this);
149
            fCombo.addSelectionListener(this);
150
            fCombo.addSelectionListener(this);
150
        }
151
        }
152
153
		private void populateList() {
154
			fCombo.removeAll();
155
			
156
			fCombo.add(fMessage);
157
            for (int i = 0; i < fCommentTemplates.length; i++) {
158
                fCombo.add(CVSUIMessages.CommitCommentArea_6 + ": " + //$NON-NLS-1$
159
                		HistoryView.flattenText(fCommentTemplates[i]));
160
            }
161
            for (int i = 0; i < fComments.length; i++) {
162
                fCombo.add(HistoryView.flattenText(fComments[i]));
163
            }
164
            fCombo.setText(fMessage);
165
		}
151
        
166
        
152
        public void widgetSelected(SelectionEvent e) {
167
        public void widgetSelected(SelectionEvent e) {
153
            final int index = fCombo.getSelectionIndex();
168
            int index = fCombo.getSelectionIndex();
154
            if (index > 0) {
169
            if (index > 0) {
170
                index--;
155
                setChanged();
171
                setChanged();
156
                notifyObservers(fComments[index - 1]);
172
                
173
                // map from combo box index to array index
174
                String message;
175
                if (index < fCommentTemplates.length) {
176
                	message = fCommentTemplates[index];
177
                } else {
178
                	message = fComments[index - fCommentTemplates.length];
179
                }
180
                notifyObservers(message);
157
            }
181
            }
158
        }
182
        }
159
        
183
        
Lines 178-187 Link Here
178
        public void setEnabled(boolean enabled) {
202
        public void setEnabled(boolean enabled) {
179
            fCombo.setEnabled(enabled);
203
            fCombo.setEnabled(enabled);
180
        }
204
        }
205
206
		void setCommentTemplates(String[] templates) {
207
			fCommentTemplates = templates;
208
			populateList();
209
		}
181
    }
210
    }
182
    
211
    
183
    private static final String EMPTY_MESSAGE= CVSUIMessages.CommitCommentArea_0; //$NON-NLS-1$
212
    private static final String EMPTY_MESSAGE= CVSUIMessages.CommitCommentArea_0; //$NON-NLS-1$
184
    private static final String COMBO_MESSAGE= CVSUIMessages.CommitCommentArea_1; //$NON-NLS-1$
213
    private static final String COMBO_MESSAGE= CVSUIMessages.CommitCommentArea_1; //$NON-NLS-1$
214
    private static final String CONFIGURE_TEMPLATES_MESSAGE= CVSUIMessages.CommitCommentArea_5; //$NON-NLS-1$
185
    
215
    
186
    public static final String OK_REQUESTED = "OkRequested";//$NON-NLS-1$
216
    public static final String OK_REQUESTED = "OkRequested";//$NON-NLS-1$
187
    public static final String COMMENT_MODIFIED = "CommentModified";//$NON-NLS-1$
217
    public static final String COMMENT_MODIFIED = "CommentModified";//$NON-NLS-1$
Lines 206-224 Link Here
206
        fTextBox= new TextBox(fComposite, EMPTY_MESSAGE, getInitialComment());
236
        fTextBox= new TextBox(fComposite, EMPTY_MESSAGE, getInitialComment());
207
        
237
        
208
        final String [] comments = CVSUIPlugin.getPlugin().getRepositoryManager().getPreviousComments();
238
        final String [] comments = CVSUIPlugin.getPlugin().getRepositoryManager().getPreviousComments();
209
        fComboBox= new ComboBox(fComposite, COMBO_MESSAGE, comments);
239
        final String[] commentTemplates = CVSUIPlugin.getPlugin().getRepositoryManager().getCommentTemplates();
240
        fComboBox= new ComboBox(fComposite, COMBO_MESSAGE, comments, commentTemplates);
241
        
242
        Link templatesPrefsLink = new Link(fComposite, 0);
243
        templatesPrefsLink.setText("<a href=\"configureTemplates\">" + //$NON-NLS-1$
244
        		CONFIGURE_TEMPLATES_MESSAGE + "</a>"); //$NON-NLS-1$
245
        templatesPrefsLink.addSelectionListener(new SelectionListener() {
246
			public void widgetDefaultSelected(SelectionEvent e) {
247
				openCommentTemplatesPreferencePage();
248
			}
249
		
250
			public void widgetSelected(SelectionEvent e) {
251
				openCommentTemplatesPreferencePage();
252
			}
253
		});
210
        
254
        
211
        fComboBox.addObserver(fTextBox);
255
        fComboBox.addObserver(fTextBox);
212
    }
256
    }
213
    
257
    
214
    public String getComment(boolean save) {
258
    void openCommentTemplatesPreferencePage() {
259
		PreferencesUtil.createPreferenceDialogOn(
260
				null,
261
				"org.eclipse.team.cvs.ui.CommentTemplatesPreferences", //$NON-NLS-1$
262
				new String[] { "org.eclipse.team.cvs.ui.CommentTemplatesPreferences" }, //$NON-NLS-1$
263
				null).open();
264
		fComboBox.setCommentTemplates(
265
				CVSUIPlugin.getPlugin().getRepositoryManager().getCommentTemplates());
266
	}
267
268
	public String getComment(boolean save) {
215
        final String comment= fTextBox.getText();
269
        final String comment= fTextBox.getText();
216
        if (comment == null)
270
        if (comment == null)
217
            return ""; //$NON-NLS-1$
271
            return ""; //$NON-NLS-1$
218
        
272
        
219
        final String stripped= strip(comment);
273
        final String stripped= strip(comment);
220
        if (save && comment.length() > 0)
274
        if (save && comment.length() > 0)
221
            CVSUIPlugin.getPlugin().getRepositoryManager().addComment(comment);
275
            CVSUIPlugin.getPlugin().getRepositoryManager().addComment(comment, false);
222
276
223
        return stripped;
277
        return stripped;
224
    }
278
    }
(-)src/org/eclipse/team/internal/ccvs/ui/messages.properties (+11 lines)
Lines 7-12 Link Here
7
#
7
#
8
# Contributors:
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
#     Maik Schreiber - bug 102461
10
###############################################################################
11
###############################################################################
11
PasswordManagementPreferencePage_2=When you create a CVS repository location you have the option of saving the password to disk. This page allows you to manage the stored passwords. The following CVS repository locations have saved passwords:
12
PasswordManagementPreferencePage_2=When you create a CVS repository location you have the option of saving the password to disk. This page allows you to manage the stored passwords. The following CVS repository locations have saved passwords:
12
PasswordManagementPreferencePage_3=Location
13
PasswordManagementPreferencePage_3=Location
Lines 853-858 Link Here
853
CommitCommentArea_2=Empty commit comment
854
CommitCommentArea_2=Empty commit comment
854
CommitCommentArea_3=The commit comment is empty. Are you sure you would like to continue with an empty comment?
855
CommitCommentArea_3=The commit comment is empty. Are you sure you would like to continue with an empty comment?
855
CommitCommentArea_4=Re&member decision?
856
CommitCommentArea_4=Re&member decision?
857
CommitCommentArea_5=Configure Comment Templates...
858
CommitCommentArea_6=Template
856
859
857
860
858
861
Lines 1039-1041 Link Here
1039
UncommittedChangesDialog_3=&The dirty resources contained in ''{0}''
1042
UncommittedChangesDialog_3=&The dirty resources contained in ''{0}''
1040
UncommittedChangesDialog_4=&The full path of ''{0}''
1043
UncommittedChangesDialog_4=&The full path of ''{0}''
1041
AddWizard_0=Add to Version Control
1044
AddWizard_0=Add to Version Control
1045
1046
CommentTemplatesPreferencePage_Description=&Create, edit or remove comment templates:
1047
CommentTemplatesPreferencePage_New=&New...
1048
CommentTemplatesPreferencePage_Edit=&Edit...
1049
CommentTemplatesPreferencePage_Remove=&Remove
1050
CommentTemplatesPreferencePage_Preview=Previe&w:
1051
CommentTemplatesPreferencePage_EditCommentTemplateTitle=Enter Comment Template
1052
CommentTemplatesPreferencePage_EditCommentTemplateMessage=Please enter a comment template:
(-)src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java (-11 / +137 lines)
Lines 7-12 Link Here
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Maik Schreiber - bug 102461
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.team.internal.ccvs.ui.repo;
12
package org.eclipse.team.internal.ccvs.ui.repo;
12
13
Lines 47-54 Link Here
47
	// new state file
48
	// new state file
48
	private static final String REPOSITORIES_VIEW_FILE = "repositoriesView.xml"; //$NON-NLS-1$
49
	private static final String REPOSITORIES_VIEW_FILE = "repositoriesView.xml"; //$NON-NLS-1$
49
	private static final String COMMENT_HIST_FILE = "commitCommentHistory.xml"; //$NON-NLS-1$
50
	private static final String COMMENT_HIST_FILE = "commitCommentHistory.xml"; //$NON-NLS-1$
51
    private static final String COMMENT_TEMPLATES_FILE = "commentTemplates.xml"; //$NON-NLS-1$
50
	static final String ELEMENT_COMMIT_COMMENT = "CommitComment"; //$NON-NLS-1$
52
	static final String ELEMENT_COMMIT_COMMENT = "CommitComment"; //$NON-NLS-1$
51
	static final String ELEMENT_COMMIT_HISTORY = "CommitComments"; //$NON-NLS-1$
53
	static final String ELEMENT_COMMIT_HISTORY = "CommitComments"; //$NON-NLS-1$
54
    static final String ELEMENT_COMMENT_TEMPLATES = "CommitCommentTemplates"; //$NON-NLS-1$
52
55
53
	private Map repositoryRoots = new HashMap();
56
	private Map repositoryRoots = new HashMap();
54
	
57
	
Lines 56-61 Link Here
56
59
57
	// The previously remembered comment
60
	// The previously remembered comment
58
	static String[] previousComments = new String[0];
61
	static String[] previousComments = new String[0];
62
    static String[] commentTemplates = new String[0];
59
	
63
	
60
	public static boolean notifyRepoView = true;
64
	public static boolean notifyRepoView = true;
61
	
65
	
Lines 303-308 Link Here
303
	public void startup() {
307
	public void startup() {
304
		loadState();
308
		loadState();
305
		loadCommentHistory();
309
		loadCommentHistory();
310
        loadCommentTemplates();
306
		CVSProviderPlugin.getPlugin().addRepositoryListener(new ICVSListener() {
311
		CVSProviderPlugin.getPlugin().addRepositoryListener(new ICVSListener() {
307
			public void repositoryAdded(ICVSRepositoryLocation root) {
312
			public void repositoryAdded(ICVSRepositoryLocation root) {
308
				rootAdded(root);
313
				rootAdded(root);
Lines 316-321 Link Here
316
	public void shutdown() throws TeamException {
321
	public void shutdown() throws TeamException {
317
		saveState();
322
		saveState();
318
		saveCommentHistory();
323
		saveCommentHistory();
324
        saveCommentTemplates();
319
	}
325
	}
320
	
326
	
321
	private void loadState() {
327
	private void loadState() {
Lines 372-377 Link Here
372
			CVSUIPlugin.log(e);
378
			CVSUIPlugin.log(e);
373
		}
379
		}
374
	}
380
	}
381
    private void loadCommentTemplates() {
382
        IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(COMMENT_TEMPLATES_FILE);
383
        File file = pluginStateLocation.toFile();
384
        if (!file.exists()) return;
385
        try {
386
            BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
387
            try {
388
                readCommentTemplates(is);
389
            } finally {
390
                is.close();
391
            }
392
        } catch (IOException e) {
393
            CVSUIPlugin.log(Status.ERROR, CVSUIMessages.RepositoryManager_ioException, e); //$NON-NLS-1$
394
        } catch (TeamException e) {
395
            CVSUIPlugin.log(e);
396
        }
397
    }
375
	
398
	
376
	protected void saveState() throws TeamException {
399
	protected void saveState() throws TeamException {
377
		IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation();
400
		IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation();
Lines 430-435 Link Here
430
			throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_HIST_FILE }), ex); //$NON-NLS-1$
453
			throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_HIST_FILE }), ex); //$NON-NLS-1$
431
		}
454
		}
432
	}
455
	}
456
    private void readCommentTemplates(InputStream stream) throws IOException, TeamException {
457
        try {
458
            SAXParserFactory factory = SAXParserFactory.newInstance();
459
            SAXParser parser = factory.newSAXParser();
460
            parser.parse(new InputSource(stream), new CommentTemplatesContentHandler());
461
        } catch (SAXException ex) {
462
            throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_TEMPLATES_FILE }), ex); //$NON-NLS-1$
463
        } catch (ParserConfigurationException ex) {
464
            throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_TEMPLATES_FILE }), ex); //$NON-NLS-1$
465
        }
466
    }
433
	
467
	
434
	private void readOldState(DataInputStream dis) throws IOException, TeamException {
468
	private void readOldState(DataInputStream dis) throws IOException, TeamException {
435
		int repoSize = dis.readInt();
469
		int repoSize = dis.readInt();
Lines 512-523 Link Here
512
		 		 throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_save, new String[] { histFile.getAbsolutePath() }), e)); //$NON-NLS-1$
546
		 		 throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_save, new String[] { histFile.getAbsolutePath() }), e)); //$NON-NLS-1$
513
		 }
547
		 }
514
	}
548
	}
549
    protected void saveCommentTemplates() throws TeamException {
550
        IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation();
551
        File tempFile = pluginStateLocation.append(COMMENT_TEMPLATES_FILE + ".tmp").toFile(); //$NON-NLS-1$
552
        File histFile = pluginStateLocation.append(COMMENT_TEMPLATES_FILE).toFile();
553
        try {
554
                 XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(tempFile)));
555
                 try {
556
                         writeCommentTemplates(writer);
557
                 } finally {
558
                         writer.close();
559
                 }
560
                 if (histFile.exists()) {
561
                         histFile.delete();
562
                 }
563
                 boolean renamed = tempFile.renameTo(histFile);
564
                 if (!renamed) {
565
                         throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_rename, new String[] { tempFile.getAbsolutePath() }), null)); //$NON-NLS-1$
566
                 }
567
         } catch (IOException e) {
568
                 throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_save, new String[] { histFile.getAbsolutePath() }), e)); //$NON-NLS-1$
569
         }
570
    }
515
	private void writeCommentHistory(XMLWriter writer) {
571
	private void writeCommentHistory(XMLWriter writer) {
516
		writer.startTag(ELEMENT_COMMIT_HISTORY, null, false);
572
		writer.startTag(ELEMENT_COMMIT_HISTORY, null, false);
517
		for (int i=0; i<previousComments.length && i<MAX_COMMENTS; i++)
573
		for (int i=0; i<previousComments.length && i<MAX_COMMENTS; i++)
518
			writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, previousComments[i]);
574
			writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, previousComments[i]);
519
		writer.endTag(ELEMENT_COMMIT_HISTORY);
575
		writer.endTag(ELEMENT_COMMIT_HISTORY);
520
	}
576
	}
577
    private void writeCommentTemplates(XMLWriter writer) {
578
        writer.startTag(ELEMENT_COMMENT_TEMPLATES, null, false);
579
        for (int i=0; i<commentTemplates.length; i++)
580
            writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, commentTemplates[i]);
581
        writer.endTag(ELEMENT_COMMENT_TEMPLATES);
582
    }
521
		 
583
		 
522
	public void addRepositoryListener(IRepositoryListener listener) {
584
	public void addRepositoryListener(IRepositoryListener listener) {
523
		listeners.add(listener);
585
		listeners.add(listener);
Lines 778-798 Link Here
778
		return previousComments;
840
		return previousComments;
779
	}
841
	}
780
842
843
    /**
844
     * Get list of comment templates.
845
     */
846
    public String[] getCommentTemplates() {
847
        return commentTemplates;
848
    }
849
    
781
	/**
850
	/**
782
	 * Method addComment.
851
	 * Method addComment.
783
	 * @param string
852
	 * @param string
784
	 */
853
	 */
785
	public void addComment(String comment) {
854
	public void addComment(String comment, boolean template) {
786
		// Only add the comment if its not there already
855
        if (template) {
787
		if (containsComment(comment)) return;
856
            addCommentTemplate(comment);
788
		// Insert the comment as the first element
857
        } else {
789
		String[] newComments = new String[Math.min(previousComments.length + 1, MAX_COMMENTS)];
858
            addComment(comment);
790
		newComments[0] = comment;
859
        }
791
		for (int i = 1; i < newComments.length; i++) {
860
	}
792
			newComments[i] = previousComments[i-1];
861
    
793
		}
862
    private void addCommentTemplate(String comment) {
794
		previousComments = newComments;
863
        // Only add the comment if its not there already
795
	}
864
        if (containsCommentTemplate(comment))
865
            return;
866
867
        // remove from list of regular comments if there
868
        if (containsComment(comment)) {
869
            List newComments = new ArrayList();
870
            for (int i = 0; i < previousComments.length; i++) {
871
                if (!previousComments[i].equals(comment))
872
                    newComments.add(previousComments[i]);
873
            }
874
            previousComments = (String[]) newComments.toArray(new String[0]);
875
        }
876
877
        // Insert the comment as first element
878
        String[] newComments = new String[commentTemplates.length + 1];
879
        System.arraycopy(commentTemplates, 0, newComments, 1, commentTemplates.length);
880
        newComments[0] = comment;
881
        commentTemplates = newComments;
882
    }
883
    
884
    private void addComment(String comment) {
885
        // Only add the comment if its not there already
886
        if (containsComment(comment))
887
            return;
888
889
        // remove from list of comment templates if there
890
        if (containsCommentTemplate(comment)) {
891
            List newComments = new ArrayList();
892
            for (int i = 0; i < commentTemplates.length; i++) {
893
                if (!commentTemplates[i].equals(comment))
894
                    newComments.add(commentTemplates[i]);
895
            }
896
            commentTemplates = (String[]) newComments.toArray(new String[0]);
897
        }
898
        
899
        // Insert the comment as the first element
900
        String[] newComments = new String[Math.min(
901
                previousComments.length + 1, MAX_COMMENTS)];
902
        newComments[0] = comment;
903
        for (int i = 1; i < newComments.length; i++) {
904
            newComments[i] = previousComments[i - 1];
905
        }
906
        previousComments = newComments;
907
    }
796
908
797
	private boolean containsComment(String comment) {
909
	private boolean containsComment(String comment) {
798
		for (int i = 0; i < previousComments.length; i++) {
910
		for (int i = 0; i < previousComments.length; i++) {
Lines 802-805 Link Here
802
		}
914
		}
803
		return false;
915
		return false;
804
	}
916
	}
917
    
918
    private boolean containsCommentTemplate(String comment) {
919
        for (int i = 0; i < commentTemplates.length; i++) {
920
            if (commentTemplates[i].equals(comment)) {
921
                return true;
922
            }
923
        }
924
        return false;
925
    }
926
    
927
    public void replaceAndSaveCommentTemplates(String[] templates) throws TeamException {
928
    	commentTemplates = templates;
929
    	saveCommentTemplates();
930
    }
805
}
931
}
(-)src/org/eclipse/team/internal/ccvs/ui/CommentTemplateEditDialog.java (+260 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
package org.eclipse.team.internal.ccvs.ui;
12
13
import org.eclipse.jface.dialogs.Dialog;
14
import org.eclipse.jface.dialogs.IDialogConstants;
15
import org.eclipse.jface.dialogs.IInputValidator;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.ModifyEvent;
18
import org.eclipse.swt.events.ModifyListener;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.Label;
24
import org.eclipse.swt.widgets.Shell;
25
import org.eclipse.swt.widgets.Text;
26
27
/**
28
 * A simple input dialog for soliciting an input string from the user.
29
 * <p>
30
 * This concrete dialog class can be instantiated as is, or further subclassed as
31
 * required.
32
 * </p>
33
 */
34
public class CommentTemplateEditDialog extends Dialog {
35
    /**
36
     * The title of the dialog.
37
     */
38
    private String title;
39
40
    /**
41
     * The message to display, or <code>null</code> if none.
42
     */
43
    private String message;
44
45
    /**
46
     * The input value; the empty string by default.
47
     */
48
    private String value = "";//$NON-NLS-1$
49
50
    /**
51
     * The input validator, or <code>null</code> if none.
52
     */
53
    private IInputValidator validator;
54
55
    /**
56
     * Ok button widget.
57
     */
58
    private Button okButton;
59
60
    /**
61
     * Input text widget.
62
     */
63
    private Text text;
64
65
    /**
66
     * Error message label widget.
67
     */
68
    private Text errorMessageText;
69
70
    /**
71
     * Creates an input dialog with OK and Cancel buttons. Note that the dialog
72
     * will have no visual representation (no widgets) until it is told to open.
73
     * <p>
74
     * Note that the <code>open</code> method blocks for input dialogs.
75
     * </p>
76
     * 
77
     * @param parentShell
78
     *            the parent shell, or <code>null</code> to create a top-level
79
     *            shell
80
     * @param dialogTitle
81
     *            the dialog title, or <code>null</code> if none
82
     * @param dialogMessage
83
     *            the dialog message, or <code>null</code> if none
84
     * @param initialValue
85
     *            the initial input value, or <code>null</code> if none
86
     *            (equivalent to the empty string)
87
     * @param validator
88
     *            an input validator, or <code>null</code> if none
89
     */
90
    public CommentTemplateEditDialog(Shell parentShell, String dialogTitle,
91
            String dialogMessage, String initialValue, IInputValidator validator) {
92
        super(parentShell);
93
        this.title = dialogTitle;
94
        message = dialogMessage;
95
        if (initialValue == null)
96
            value = "";//$NON-NLS-1$
97
        else
98
            value = initialValue;
99
        this.validator = validator;
100
    }
101
102
    /*
103
     * (non-Javadoc) Method declared on Dialog.
104
     */
105
    protected void buttonPressed(int buttonId) {
106
        if (buttonId == IDialogConstants.OK_ID) {
107
            value = text.getText();
108
        } else {
109
            value = null;
110
        }
111
        super.buttonPressed(buttonId);
112
    }
113
114
    /*
115
     * (non-Javadoc)
116
     * 
117
     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
118
     */
119
    protected void configureShell(Shell shell) {
120
        super.configureShell(shell);
121
        if (title != null)
122
            shell.setText(title);
123
    }
124
125
    /*
126
     * (non-Javadoc)
127
     * 
128
     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
129
     */
130
    protected void createButtonsForButtonBar(Composite parent) {
131
        // create OK and Cancel buttons by default
132
        okButton = createButton(parent, IDialogConstants.OK_ID,
133
                IDialogConstants.OK_LABEL, true);
134
        createButton(parent, IDialogConstants.CANCEL_ID,
135
                IDialogConstants.CANCEL_LABEL, false);
136
        //do this here because setting the text will set enablement on the ok
137
        // button
138
        text.setFocus();
139
        if (value != null) {
140
            text.setText(value);
141
            text.selectAll();
142
        }
143
    }
144
145
    /*
146
     * (non-Javadoc) Method declared on Dialog.
147
     */
148
    protected Control createDialogArea(Composite parent) {
149
        // create composite
150
        Composite composite = (Composite) super.createDialogArea(parent);
151
        // create message
152
        if (message != null) {
153
            Label label = new Label(composite, SWT.WRAP);
154
            label.setText(message);
155
            GridData data = new GridData(GridData.GRAB_HORIZONTAL
156
                    | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL
157
                    | GridData.VERTICAL_ALIGN_CENTER);
158
            data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
159
            label.setLayoutData(data);
160
            label.setFont(parent.getFont());
161
        }
162
        text = new Text(composite, SWT.MULTI | SWT.BORDER);
163
        GridData gd = new GridData(GridData.GRAB_HORIZONTAL
164
                | GridData.HORIZONTAL_ALIGN_FILL);
165
		gd.heightHint = convertHeightInCharsToPixels(5);
166
		text.setLayoutData(gd);
167
        text.addModifyListener(new ModifyListener() {
168
            public void modifyText(ModifyEvent e) {
169
                validateInput();
170
            }
171
        });
172
        errorMessageText = new Text(composite, SWT.READ_ONLY);
173
        errorMessageText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
174
                | GridData.HORIZONTAL_ALIGN_FILL));
175
        errorMessageText.setBackground(errorMessageText.getDisplay()
176
                .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
177
178
        applyDialogFont(composite);
179
        return composite;
180
    }
181
182
    /**
183
     * Returns the error message label.
184
     * 
185
     * @return the error message label
186
     * @deprecated use setErrorMessage(String) instead
187
     */
188
    protected Label getErrorMessageLabel() {
189
        return null;
190
    }
191
192
    /**
193
     * Returns the ok button.
194
     * 
195
     * @return the ok button
196
     */
197
    protected Button getOkButton() {
198
        return okButton;
199
    }
200
201
    /**
202
     * Returns the text area.
203
     * 
204
     * @return the text area
205
     */
206
    protected Text getText() {
207
        return text;
208
    }
209
210
    /**
211
     * Returns the validator.
212
     * 
213
     * @return the validator
214
     */
215
    protected IInputValidator getValidator() {
216
        return validator;
217
    }
218
219
    /**
220
     * Returns the string typed into this input dialog.
221
     * 
222
     * @return the input string
223
     */
224
    public String getValue() {
225
        return value;
226
    }
227
228
    /**
229
     * Validates the input.
230
     * <p>
231
     * The default implementation of this framework method delegates the request
232
     * to the supplied input validator object; if it finds the input invalid,
233
     * the error message is displayed in the dialog's message line. This hook
234
     * method is called whenever the text changes in the input field.
235
     * </p>
236
     */
237
    protected void validateInput() {
238
        String errorMessage = null;
239
        if (validator != null) {
240
            errorMessage = validator.isValid(text.getText());
241
        }
242
        // Bug 16256: important not to treat "" (blank error) the same as null
243
        // (no error)
244
        setErrorMessage(errorMessage);
245
    }
246
247
    /**
248
     * Sets or clears the error message.
249
     * If not <code>null</code>, the OK button is disabled.
250
     * 
251
     * @param errorMessage
252
     *            the error message, or <code>null</code> to clear
253
     * @since 3.0
254
     */
255
    public void setErrorMessage(String errorMessage) {
256
        errorMessageText.setText(errorMessage == null ? "" : errorMessage); //$NON-NLS-1$
257
        okButton.setEnabled(errorMessage == null);
258
        errorMessageText.getParent().update();
259
    }
260
}
(-)src/org/eclipse/team/internal/ccvs/ui/CommentTemplatesPreferencePage.java (+245 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 Maik Schreiber.
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
 *    Maik Schreiber - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.team.internal.ccvs.ui;
13
14
import org.eclipse.jface.dialogs.Dialog;
15
import org.eclipse.jface.dialogs.IDialogConstants;
16
import org.eclipse.jface.preference.PreferencePage;
17
import org.eclipse.jface.viewers.DoubleClickEvent;
18
import org.eclipse.jface.viewers.IDoubleClickListener;
19
import org.eclipse.jface.viewers.ISelectionChangedListener;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.jface.viewers.LabelProvider;
22
import org.eclipse.jface.viewers.ListViewer;
23
import org.eclipse.jface.viewers.SelectionChangedEvent;
24
import org.eclipse.jface.viewers.Viewer;
25
import org.eclipse.jface.viewers.ViewerSorter;
26
import org.eclipse.jface.window.Window;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.layout.GridData;
29
import org.eclipse.swt.layout.GridLayout;
30
import org.eclipse.swt.widgets.Button;
31
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.swt.widgets.Event;
34
import org.eclipse.swt.widgets.Label;
35
import org.eclipse.swt.widgets.List;
36
import org.eclipse.swt.widgets.Listener;
37
import org.eclipse.swt.widgets.Text;
38
import org.eclipse.team.core.TeamException;
39
import org.eclipse.ui.IWorkbench;
40
import org.eclipse.ui.IWorkbenchPreferencePage;
41
42
public class CommentTemplatesPreferencePage extends PreferencePage implements
43
		IWorkbenchPreferencePage, ISelectionChangedListener {
44
45
	private ListViewer viewer;
46
	private Button editButton;
47
	private Button removeButton;
48
	private Text preview;
49
50
	protected Control createContents(Composite ancestor) {
51
		Composite parent = new Composite(ancestor, SWT.NONE);
52
		GridLayout layout = new GridLayout();
53
		layout.marginWidth = 0;
54
		layout.marginHeight = 0;
55
		layout.numColumns = 1;
56
		parent.setLayout(layout);
57
		parent.setLayoutData(new GridData(GridData.FILL_BOTH));
58
59
		createListAndButtons(parent);
60
61
		Label previewLabel = new Label(parent, SWT.NONE);
62
		previewLabel.setText(CVSUIMessages.CommentTemplatesPreferencePage_Preview);
63
		
64
		preview = new Text(parent, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER);
65
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
66
		gd.heightHint = convertHeightInCharsToPixels(5);
67
		preview.setLayoutData(gd);
68
		
69
		Dialog.applyDialogFont(ancestor);
70
		
71
		return parent;
72
	}
73
74
	private Composite createListAndButtons(Composite parent) {
75
		Composite listAndButtons = new Composite(parent, SWT.NONE);
76
		GridLayout layout = new GridLayout();
77
		layout.marginWidth = 0;
78
		layout.marginHeight = 0;
79
		layout.numColumns = 2;
80
		listAndButtons.setLayout(layout);
81
		listAndButtons.setLayoutData(new GridData(GridData.FILL_BOTH));
82
		
83
		viewer = new ListViewer(listAndButtons);
84
		viewer.setLabelProvider(new LabelProvider() {
85
			public String getText(Object element) {
86
				String template = (String) element;
87
				return HistoryView.flattenText(template);
88
			}
89
		});
90
		viewer.addSelectionChangedListener(this);
91
		viewer.setSorter(new ViewerSorter() {
92
			public int compare(Viewer viewer, Object e1, Object e2) {
93
				String template1 = HistoryView.flattenText((String) e1);
94
				String template2 = HistoryView.flattenText((String) e2);
95
				return template1.compareToIgnoreCase(template2);
96
			}
97
		});
98
		viewer.addDoubleClickListener(new IDoubleClickListener() {
99
			public void doubleClick(DoubleClickEvent event) {
100
				editTemplate();
101
			}
102
		});
103
		List list = viewer.getList();
104
		list.setLayoutData(new GridData(GridData.FILL_BOTH));
105
		
106
		// populate list
107
		String[] templates =
108
			CVSUIPlugin.getPlugin().getRepositoryManager().getCommentTemplates();
109
		for (int i = 0; i < templates.length; i++) {
110
			viewer.add(templates[i]);
111
		}
112
113
		createButtons(listAndButtons);
114
		return listAndButtons;
115
	}
116
117
	private void createButtons(Composite parent) {
118
		Composite buttons = new Composite(parent, SWT.NONE);
119
		buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
120
		GridLayout layout = new GridLayout();
121
		layout.marginHeight = 0;
122
		layout.marginWidth = 0;
123
		buttons.setLayout(layout);
124
125
		Button newButton = new Button(buttons, SWT.PUSH);
126
		newButton.setText(CVSUIMessages.CommentTemplatesPreferencePage_New);
127
		GridData data = new GridData();
128
		data.horizontalAlignment = GridData.FILL;
129
		int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
130
		data.widthHint = Math.max(widthHint,
131
				newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
132
		newButton.setLayoutData(data);
133
		newButton.setEnabled(true);
134
		newButton.addListener(SWT.Selection, new Listener() {
135
			public void handleEvent(Event event) {
136
				newTemplate();
137
			}
138
		});
139
140
		editButton = new Button(buttons, SWT.PUSH);
141
		editButton.setText(CVSUIMessages.CommentTemplatesPreferencePage_Edit);
142
		data = new GridData();
143
		data.horizontalAlignment = GridData.FILL;
144
		widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
145
		data.widthHint = Math.max(widthHint,
146
				editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
147
		editButton.setLayoutData(data);
148
		editButton.setEnabled(false);
149
		editButton.addListener(SWT.Selection, new Listener() {
150
			public void handleEvent(Event e) {
151
				editTemplate();
152
			}
153
		});
154
155
		removeButton = new Button(buttons, SWT.PUSH);
156
		removeButton.setText(CVSUIMessages.CommentTemplatesPreferencePage_Remove);
157
		data = new GridData();
158
		data.horizontalAlignment = GridData.FILL;
159
		widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
160
		data.widthHint = Math.max(widthHint,
161
				removeButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
162
		removeButton.setLayoutData(data);
163
		removeButton.setEnabled(false);
164
		removeButton.addListener(SWT.Selection, new Listener() {
165
			public void handleEvent(Event e) {
166
				remove();
167
			}
168
		});
169
	}
170
	
171
	public void init(IWorkbench workbench) {
172
		setDescription(CVSUIMessages.CommentTemplatesPreferencePage_Description);
173
	}
174
175
	public void selectionChanged(SelectionChangedEvent event) {
176
		IStructuredSelection selection = (IStructuredSelection) event.getSelection();
177
		switch (selection.size()) {
178
			case 0:
179
				editButton.setEnabled(false);
180
				removeButton.setEnabled(false);
181
				preview.setText(""); //$NON-NLS-1$
182
				break;
183
			
184
			case 1:
185
				editButton.setEnabled(true);
186
				removeButton.setEnabled(true);
187
				preview.setText((String) selection.getFirstElement());
188
				break;
189
			
190
			default:
191
				editButton.setEnabled(false);
192
				removeButton.setEnabled(true);
193
				preview.setText(""); //$NON-NLS-1$
194
				break;
195
		}
196
	}
197
	
198
	void newTemplate() {
199
		CommentTemplateEditDialog dialog = new CommentTemplateEditDialog(
200
				getShell(),
201
				CVSUIMessages.CommentTemplatesPreferencePage_EditCommentTemplateTitle,
202
				CVSUIMessages.CommentTemplatesPreferencePage_EditCommentTemplateMessage,
203
				"", null); //$NON-NLS-1$
204
		if (dialog.open() == Window.OK) {
205
			viewer.add(dialog.getValue());
206
		}
207
	}
208
209
	void editTemplate() {
210
		IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
211
		if (selection.size() == 1) {
212
			String oldTemplate = (String) selection.getFirstElement();
213
			CommentTemplateEditDialog dialog = new CommentTemplateEditDialog(
214
					getShell(),
215
					CVSUIMessages.CommentTemplatesPreferencePage_EditCommentTemplateTitle,
216
					CVSUIMessages.CommentTemplatesPreferencePage_EditCommentTemplateMessage,
217
					oldTemplate, null);
218
			if (dialog.open() == Window.OK) {
219
				viewer.remove(oldTemplate);
220
				viewer.add(dialog.getValue());
221
			}
222
		}
223
	}
224
	
225
	void remove() {
226
		IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
227
		viewer.remove(selection.toArray());
228
	}
229
	
230
	public boolean performOk() {
231
		int numTemplates = viewer.getList().getItemCount();
232
		String[] templates = new String[numTemplates];
233
		for (int i = 0; i < numTemplates; i++) {
234
			templates[i] = (String) viewer.getElementAt(i);
235
		}
236
		try {
237
			CVSUIPlugin.getPlugin().getRepositoryManager()
238
				.replaceAndSaveCommentTemplates(templates);
239
		} catch (TeamException e) {
240
			// TODO: handle save error
241
		}
242
		
243
		return super.performOk();
244
	}
245
}
(-)src/org/eclipse/team/internal/ccvs/ui/repo/CommentTemplatesContentHandler.java (+82 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 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.team.internal.ccvs.ui.repo;
13
14
import java.util.Vector;
15
16
import org.xml.sax.Attributes;
17
import org.xml.sax.helpers.DefaultHandler;
18
19
class CommentTemplatesContentHandler extends DefaultHandler {
20
21
	private StringBuffer buffer;
22
	private Vector comments;
23
	public CommentTemplatesContentHandler() {
24
	}
25
26
	/**
27
	 * @see ContentHandler#characters(char[], int, int)
28
	 */
29
	public void characters(char[] chars, int startIndex, int length) {
30
		if (buffer == null) return;
31
		buffer.append(chars, startIndex, length);
32
	}
33
34
	/**
35
	 * @see ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
36
	 */
37
	public void startElement(
38
			String namespaceURI,
39
			String localName,
40
			String qName,
41
			Attributes atts) {
42
		
43
		String elementName = getElementName(localName, qName);
44
		if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_COMMENT)) {
45
			buffer = new StringBuffer();
46
			return;
47
		} 
48
		if (elementName.equals(RepositoryManager.ELEMENT_COMMENT_TEMPLATES)) {
49
			comments = new Vector();
50
			return;
51
		}
52
	}
53
	
54
	/**
55
	 * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
56
	 */
57
	public void endElement(String namespaceURI, String localName, String qName) {
58
		String elementName = getElementName(localName, qName);
59
		if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_COMMENT)) {
60
			comments.add(buffer.toString());
61
			buffer = null;
62
			return;
63
		} 
64
		if (elementName.equals(RepositoryManager.ELEMENT_COMMENT_TEMPLATES)) {
65
			RepositoryManager.commentTemplates = new String[comments.size()];
66
			comments.copyInto(RepositoryManager.commentTemplates);
67
			return;
68
		} 
69
	}
70
	
71
	/*
72
	 * Couldn't figure out from the SAX API exactly when localName vs. qName is used.
73
	 * However, the XML for project sets doesn't use namespaces so either of the two names
74
	 * is fine. Therefore, use whichever one is provided.
75
	 */
76
	private String getElementName(String localName, String qName) {
77
		if (localName != null && localName.length() > 0) {
78
			return localName;
79
		}
80
		return qName;
81
	}
82
}

Return to bug 102461