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

(-)org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java (-5 / +53 lines)
Lines 125-137 Link Here
125
        
125
        
126
        private final String fMessage;
126
        private final String fMessage;
127
        private final String [] fComments;
127
        private final String [] fComments;
128
        private final String[] fPermanentComments;
128
        private final Combo fCombo;
129
        private final Combo fCombo;
129
        
130
        
130
        
131
        
131
        public ComboBox(Composite composite, String message, String [] options) {
132
        public ComboBox(Composite composite, String message, String [] options,
133
                String[] permanentComments) {
132
            
134
            
133
            fMessage= message;
135
            fMessage= message;
134
            fComments= options;
136
            fComments= options;
137
            fPermanentComments = permanentComments;
135
            
138
            
136
            fCombo = new Combo(composite, SWT.READ_ONLY);
139
            fCombo = new Combo(composite, SWT.READ_ONLY);
137
            fCombo.setLayoutData(SWTUtils.createHFillGridData());
140
            fCombo.setLayoutData(SWTUtils.createHFillGridData());
Lines 141-146 Link Here
141
            for (int i = 0; i < fComments.length; i++) {
144
            for (int i = 0; i < fComments.length; i++) {
142
                fCombo.add(HistoryView.flattenText(fComments[i]));
145
                fCombo.add(HistoryView.flattenText(fComments[i]));
143
            }
146
            }
147
            for (int i = 0; i < fPermanentComments.length; i++) {
148
                fCombo.add(HistoryView.flattenText(fPermanentComments[i]));
149
            }
144
            fCombo.setText(fMessage);
150
            fCombo.setText(fMessage);
145
            
151
            
146
            // We don't want to have an initial selection
152
            // We don't want to have an initial selection
Lines 150-159 Link Here
150
        }
156
        }
151
        
157
        
152
        public void widgetSelected(SelectionEvent e) {
158
        public void widgetSelected(SelectionEvent e) {
153
            final int index = fCombo.getSelectionIndex();
159
            int index = fCombo.getSelectionIndex();
154
            if (index > 0) {
160
            if (index > 0) {
161
                index--;
155
                setChanged();
162
                setChanged();
156
                notifyObservers(fComments[index - 1]);
163
                String message;
164
                if (index < fComments.length) {
165
                    message = fComments[index];
166
                } else {
167
                    message = fPermanentComments[index - fComments.length];
168
                }
169
                notifyObservers(message);
157
            }
170
            }
158
        }
171
        }
159
        
172
        
Lines 178-193 Link Here
178
        public void setEnabled(boolean enabled) {
191
        public void setEnabled(boolean enabled) {
179
            fCombo.setEnabled(enabled);
192
            fCombo.setEnabled(enabled);
180
        }
193
        }
194
195
        public boolean isPermanent(String comment) {
196
            for (int i = 0; i < fPermanentComments.length; i++) {
197
                if (fPermanentComments[i].equals(comment)) {
198
                    return true;
199
                }
200
            }
201
            return false;
202
        }
203
    }
204
    
205
    private static final class PermanentCheckbox implements Observer {
206
        private Button fKeepPermanent;
207
        
208
        private PermanentCheckbox(Composite parent, String label) {
209
            fKeepPermanent = new Button(parent, SWT.CHECK | SWT.LEFT);
210
            fKeepPermanent.setText(label);
211
        }
212
        
213
        public void update(Observable o, Object arg) {
214
            ComboBox cb = (ComboBox) o;
215
            boolean permanent = cb.isPermanent((String) arg);
216
            fKeepPermanent.setSelection(permanent);
217
        }
218
219
        public boolean getSelection() {
220
            return fKeepPermanent.getSelection();
221
        }
181
    }
222
    }
182
    
223
    
183
    private static final String EMPTY_MESSAGE= CVSUIMessages.CommitCommentArea_0; //$NON-NLS-1$
224
    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$
225
    private static final String COMBO_MESSAGE= CVSUIMessages.CommitCommentArea_1; //$NON-NLS-1$
226
    private static final String KEEP_PERMANENT_MESSAGE= CVSUIMessages.CommitCommentArea_5; //$NON-NLS-1$
185
    
227
    
186
    public static final String OK_REQUESTED = "OkRequested";//$NON-NLS-1$
228
    public static final String OK_REQUESTED = "OkRequested";//$NON-NLS-1$
187
    public static final String COMMENT_MODIFIED = "CommentModified";//$NON-NLS-1$
229
    public static final String COMMENT_MODIFIED = "CommentModified";//$NON-NLS-1$
188
    
230
    
189
    private TextBox fTextBox;
231
    private TextBox fTextBox;
190
    private ComboBox fComboBox;
232
    private ComboBox fComboBox;
233
    private PermanentCheckbox fKeepPermanent;
191
    
234
    
192
    private IProject fMainProject;
235
    private IProject fMainProject;
193
    private String fProposedComment;
236
    private String fProposedComment;
Lines 205-214 Link Here
205
        
248
        
206
        fTextBox= new TextBox(fComposite, EMPTY_MESSAGE, getInitialComment());
249
        fTextBox= new TextBox(fComposite, EMPTY_MESSAGE, getInitialComment());
207
        
250
        
251
        fKeepPermanent = new PermanentCheckbox(fComposite, KEEP_PERMANENT_MESSAGE);
252
        
208
        final String [] comments = CVSUIPlugin.getPlugin().getRepositoryManager().getPreviousComments();
253
        final String [] comments = CVSUIPlugin.getPlugin().getRepositoryManager().getPreviousComments();
209
        fComboBox= new ComboBox(fComposite, COMBO_MESSAGE, comments);
254
        final String[] permanentComments = CVSUIPlugin.getPlugin().getRepositoryManager().getPermanentComments();
255
        fComboBox= new ComboBox(fComposite, COMBO_MESSAGE, comments, permanentComments);
210
        
256
        
211
        fComboBox.addObserver(fTextBox);
257
        fComboBox.addObserver(fTextBox);
258
        fComboBox.addObserver(fKeepPermanent);
212
    }
259
    }
213
    
260
    
214
    public String getComment(boolean save) {
261
    public String getComment(boolean save) {
Lines 218-224 Link Here
218
        
265
        
219
        final String stripped= strip(comment);
266
        final String stripped= strip(comment);
220
        if (save && comment.length() > 0)
267
        if (save && comment.length() > 0)
221
            CVSUIPlugin.getPlugin().getRepositoryManager().addComment(comment);
268
            CVSUIPlugin.getPlugin().getRepositoryManager().addComment(comment,
269
                    fKeepPermanent.getSelection());
222
270
223
        return stripped;
271
        return stripped;
224
    }
272
    }
(-)org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java (+1 lines)
Lines 815-820 Link Here
815
	public static String CommitCommentArea_2;
815
	public static String CommitCommentArea_2;
816
	public static String CommitCommentArea_3;
816
	public static String CommitCommentArea_3;
817
	public static String CommitCommentArea_4;
817
	public static String CommitCommentArea_4;
818
    public static String CommitCommentArea_5;
818
819
819
	public static String CheckoutProjectOperation_8;
820
	public static String CheckoutProjectOperation_8;
820
	public static String CheckoutProjectOperation_9;
821
	public static String CheckoutProjectOperation_9;
(-)org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/messages.properties (+1 lines)
Lines 853-858 Link Here
853
CommitCommentArea_2=Empty commit comment
853
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?
854
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?
855
CommitCommentArea_4=Re&member decision?
856
CommitCommentArea_5=Keep permanent
856
857
857
858
858
859
(-)org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/repo/PermanentCommentsContentHandler.java (+85 lines)
Line 0 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.SAXException;
17
import org.xml.sax.helpers.DefaultHandler;
18
import org.xml.sax.Attributes;
19
20
class PermanentCommentsContentHandler extends DefaultHandler {
21
22
	private StringBuffer buffer;
23
	private Vector comments;
24
	public PermanentCommentsContentHandler() {
25
	}
26
27
	/**
28
	 * @see ContentHandler#characters(char[], int, int)
29
	 */
30
	public void characters(char[] chars, int startIndex, int length) throws SAXException {
31
		if (buffer == null) return;
32
		buffer.append(chars, startIndex, length);
33
	}
34
35
	/**
36
	 * @see ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
37
	 */
38
	public void startElement(
39
			String namespaceURI,
40
			String localName,
41
			String qName,
42
			Attributes atts)
43
			throws SAXException {
44
		
45
		String elementName = getElementName(namespaceURI, localName, qName);
46
		if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_COMMENT)) {
47
			buffer = new StringBuffer();
48
			return;
49
		} 
50
		if (elementName.equals(RepositoryManager.ELEMENT_PERMANENT_COMMENTS)) {
51
			comments = new Vector();
52
			return;
53
		}
54
	}
55
	
56
	/**
57
	 * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
58
	 */
59
	public void endElement(String namespaceURI, String localName, String qName) {
60
		String elementName = getElementName(namespaceURI, localName, qName);
61
		if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_COMMENT)) {
62
			comments.add(buffer.toString());
63
			buffer = null;
64
			return;
65
		} 
66
		if (elementName.equals(RepositoryManager.ELEMENT_PERMANENT_COMMENTS)) {
67
			RepositoryManager.permanentComments = new String[comments.size()];
68
			comments.copyInto(RepositoryManager.permanentComments);
69
			return;
70
		} 
71
	}
72
	
73
	/*
74
	 * Couldn't figure out from the SAX API exactly when localName vs. qName is used.
75
	 * However, the XML for project sets doesn't use namespaces so either of the two names
76
	 * is fine. Therefore, use whichever one is provided.
77
	 */
78
	private String getElementName(String namespaceURI, String localName, String qName) {
79
		if (localName != null && localName.length() > 0) {
80
			return localName;
81
		} else {
82
			return qName;
83
		}
84
	}
85
}
(-)org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java (-11 / +131 lines)
Lines 47-54 Link Here
47
	// new state file
47
	// new state file
48
	private static final String REPOSITORIES_VIEW_FILE = "repositoriesView.xml"; //$NON-NLS-1$
48
	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$
49
	private static final String COMMENT_HIST_FILE = "commitCommentHistory.xml"; //$NON-NLS-1$
50
    private static final String PERMANENT_COMMENTS_FILE = "permanentComments.xml"; //$NON-NLS-1$
50
	static final String ELEMENT_COMMIT_COMMENT = "CommitComment"; //$NON-NLS-1$
51
	static final String ELEMENT_COMMIT_COMMENT = "CommitComment"; //$NON-NLS-1$
51
	static final String ELEMENT_COMMIT_HISTORY = "CommitComments"; //$NON-NLS-1$
52
	static final String ELEMENT_COMMIT_HISTORY = "CommitComments"; //$NON-NLS-1$
53
    static final String ELEMENT_PERMANENT_COMMENTS = "PermanentCommitComments"; //$NON-NLS-1$
52
54
53
	private Map repositoryRoots = new HashMap();
55
	private Map repositoryRoots = new HashMap();
54
	
56
	
Lines 56-61 Link Here
56
58
57
	// The previously remembered comment
59
	// The previously remembered comment
58
	static String[] previousComments = new String[0];
60
	static String[] previousComments = new String[0];
61
    static String[] permanentComments = new String[0];
59
	
62
	
60
	public static boolean notifyRepoView = true;
63
	public static boolean notifyRepoView = true;
61
	
64
	
Lines 303-308 Link Here
303
	public void startup() {
306
	public void startup() {
304
		loadState();
307
		loadState();
305
		loadCommentHistory();
308
		loadCommentHistory();
309
        loadPermanentComments();
306
		CVSProviderPlugin.getPlugin().addRepositoryListener(new ICVSListener() {
310
		CVSProviderPlugin.getPlugin().addRepositoryListener(new ICVSListener() {
307
			public void repositoryAdded(ICVSRepositoryLocation root) {
311
			public void repositoryAdded(ICVSRepositoryLocation root) {
308
				rootAdded(root);
312
				rootAdded(root);
Lines 316-321 Link Here
316
	public void shutdown() throws TeamException {
320
	public void shutdown() throws TeamException {
317
		saveState();
321
		saveState();
318
		saveCommentHistory();
322
		saveCommentHistory();
323
        savePermanentComments();
319
	}
324
	}
320
	
325
	
321
	private void loadState() {
326
	private void loadState() {
Lines 372-377 Link Here
372
			CVSUIPlugin.log(e);
377
			CVSUIPlugin.log(e);
373
		}
378
		}
374
	}
379
	}
380
    private void loadPermanentComments() {
381
        IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(PERMANENT_COMMENTS_FILE);
382
        File file = pluginStateLocation.toFile();
383
        if (!file.exists()) return;
384
        try {
385
            BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
386
            try {
387
                readPermanentComments(is);
388
            } finally {
389
                is.close();
390
            }
391
        } catch (IOException e) {
392
            CVSUIPlugin.log(Status.ERROR, CVSUIMessages.RepositoryManager_ioException, e); //$NON-NLS-1$
393
        } catch (TeamException e) {
394
            CVSUIPlugin.log(e);
395
        }
396
    }
375
	
397
	
376
	protected void saveState() throws TeamException {
398
	protected void saveState() throws TeamException {
377
		IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation();
399
		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$
452
			throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_HIST_FILE }), ex); //$NON-NLS-1$
431
		}
453
		}
432
	}
454
	}
455
    private void readPermanentComments(InputStream stream) throws IOException, TeamException {
456
        try {
457
            SAXParserFactory factory = SAXParserFactory.newInstance();
458
            SAXParser parser = factory.newSAXParser();
459
            parser.parse(new InputSource(stream), new PermanentCommentsContentHandler());
460
        } catch (SAXException ex) {
461
            throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { PERMANENT_COMMENTS_FILE }), ex); //$NON-NLS-1$
462
        } catch (ParserConfigurationException ex) {
463
            throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { PERMANENT_COMMENTS_FILE }), ex); //$NON-NLS-1$
464
        }
465
    }
433
	
466
	
434
	private void readOldState(DataInputStream dis) throws IOException, TeamException {
467
	private void readOldState(DataInputStream dis) throws IOException, TeamException {
435
		int repoSize = dis.readInt();
468
		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$
545
		 		 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
		 }
546
		 }
514
	}
547
	}
548
    protected void savePermanentComments() throws TeamException {
549
        IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation();
550
        File tempFile = pluginStateLocation.append(PERMANENT_COMMENTS_FILE + ".tmp").toFile(); //$NON-NLS-1$
551
        File histFile = pluginStateLocation.append(PERMANENT_COMMENTS_FILE).toFile();
552
        try {
553
                 XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(tempFile)));
554
                 try {
555
                         writePermanentComments(writer);
556
                 } finally {
557
                         writer.close();
558
                 }
559
                 if (histFile.exists()) {
560
                         histFile.delete();
561
                 }
562
                 boolean renamed = tempFile.renameTo(histFile);
563
                 if (!renamed) {
564
                         throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_rename, new String[] { tempFile.getAbsolutePath() }), null)); //$NON-NLS-1$
565
                 }
566
         } catch (IOException e) {
567
                 throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_save, new String[] { histFile.getAbsolutePath() }), e)); //$NON-NLS-1$
568
         }
569
    }
515
	private void writeCommentHistory(XMLWriter writer) {
570
	private void writeCommentHistory(XMLWriter writer) {
516
		writer.startTag(ELEMENT_COMMIT_HISTORY, null, false);
571
		writer.startTag(ELEMENT_COMMIT_HISTORY, null, false);
517
		for (int i=0; i<previousComments.length && i<MAX_COMMENTS; i++)
572
		for (int i=0; i<previousComments.length && i<MAX_COMMENTS; i++)
518
			writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, previousComments[i]);
573
			writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, previousComments[i]);
519
		writer.endTag(ELEMENT_COMMIT_HISTORY);
574
		writer.endTag(ELEMENT_COMMIT_HISTORY);
520
	}
575
	}
576
    private void writePermanentComments(XMLWriter writer) {
577
        writer.startTag(ELEMENT_PERMANENT_COMMENTS, null, false);
578
        for (int i=0; i<permanentComments.length; i++)
579
            writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, permanentComments[i]);
580
        writer.endTag(ELEMENT_PERMANENT_COMMENTS);
581
    }
521
		 
582
		 
522
	public void addRepositoryListener(IRepositoryListener listener) {
583
	public void addRepositoryListener(IRepositoryListener listener) {
523
		listeners.add(listener);
584
		listeners.add(listener);
Lines 778-798 Link Here
778
		return previousComments;
839
		return previousComments;
779
	}
840
	}
780
841
842
    /**
843
     * Get list of permanent comments.
844
     */
845
    public String[] getPermanentComments() {
846
        return permanentComments;
847
    }
848
    
781
	/**
849
	/**
782
	 * Method addComment.
850
	 * Method addComment.
783
	 * @param string
851
	 * @param string
784
	 */
852
	 */
785
	public void addComment(String comment) {
853
	public void addComment(String comment, boolean permanent) {
786
		// Only add the comment if its not there already
854
        if (permanent) {
787
		if (containsComment(comment)) return;
855
            addPermanentComment(comment);
788
		// Insert the comment as the first element
856
        } else {
789
		String[] newComments = new String[Math.min(previousComments.length + 1, MAX_COMMENTS)];
857
            addComment(comment);
790
		newComments[0] = comment;
858
        }
791
		for (int i = 1; i < newComments.length; i++) {
859
	}
792
			newComments[i] = previousComments[i-1];
860
    
793
		}
861
    private void addPermanentComment(String comment) {
794
		previousComments = newComments;
862
        // Only add the comment if its not there already
795
	}
863
        if (containsPermanentComment(comment))
864
            return;
865
866
        // remove from list of regular comments if there
867
        if (containsComment(comment)) {
868
            List newComments = new ArrayList();
869
            for (int i = 0; i < previousComments.length; i++) {
870
                if (!previousComments[i].equals(comment))
871
                    newComments.add(previousComments[i]);
872
            }
873
            previousComments = (String[]) newComments.toArray(new String[0]);
874
        }
875
876
        // Insert the comment as first element
877
        String[] newComments = new String[permanentComments.length + 1];
878
        System.arraycopy(permanentComments, 0, newComments, 1, permanentComments.length);
879
        newComments[0] = comment;
880
        permanentComments = newComments;
881
    }
882
    
883
    private void addComment(String comment) {
884
        // Only add the comment if its not there already
885
        if (containsComment(comment))
886
            return;
887
888
        // remove from list of permanent comments if there
889
        if (containsPermanentComment(comment)) {
890
            List newComments = new ArrayList();
891
            for (int i = 0; i < permanentComments.length; i++) {
892
                if (!permanentComments[i].equals(comment))
893
                    newComments.add(permanentComments[i]);
894
            }
895
            permanentComments = (String[]) newComments.toArray(new String[0]);
896
        }
897
        
898
        // Insert the comment as the first element
899
        String[] newComments = new String[Math.min(
900
                previousComments.length + 1, MAX_COMMENTS)];
901
        newComments[0] = comment;
902
        for (int i = 1; i < newComments.length; i++) {
903
            newComments[i] = previousComments[i - 1];
904
        }
905
        previousComments = newComments;
906
    }
796
907
797
	private boolean containsComment(String comment) {
908
	private boolean containsComment(String comment) {
798
		for (int i = 0; i < previousComments.length; i++) {
909
		for (int i = 0; i < previousComments.length; i++) {
Lines 802-805 Link Here
802
		}
913
		}
803
		return false;
914
		return false;
804
	}
915
	}
916
    
917
    private boolean containsPermanentComment(String comment) {
918
        for (int i = 0; i < permanentComments.length; i++) {
919
            if (permanentComments[i].equals(comment)) {
920
                return true;
921
            }
922
        }
923
        return false;
924
    }
805
}
925
}

Return to bug 102461