KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > CVSPreferencesPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  * Philippe Ombredanne - bug 84808
11  * William Mitsuda (wmitsuda@gmail.com) - Bug 153879 [Wizards] configurable size of cvs commit comment history
12  * Brock Janiczak <brockj@tpg.com.au> - Bug 161536 Warn user when committing resources with problem markers
13  *******************************************************************************/

14
15 package org.eclipse.team.internal.ccvs.ui;
16
17 import com.ibm.icu.text.Collator;
18 import java.util.ArrayList JavaDoc;
19 import java.util.Arrays JavaDoc;
20 import java.util.Collections JavaDoc;
21 import java.util.Comparator JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.eclipse.jface.dialogs.*;
26 import org.eclipse.jface.dialogs.Dialog;
27 import org.eclipse.jface.preference.IPreferenceStore;
28 import org.eclipse.jface.preference.PreferencePage;
29 import org.eclipse.jface.util.PropertyChangeEvent;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.events.*;
32 import org.eclipse.swt.layout.GridLayout;
33 import org.eclipse.swt.widgets.*;
34 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
35 import org.eclipse.team.internal.ccvs.core.client.Command;
36 import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption;
37 import org.eclipse.team.internal.ccvs.core.client.Command.QuietOption;
38 import org.eclipse.team.internal.ui.SWTUtils;
39 import org.eclipse.ui.*;
40 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
41
42 /**
43  * CVS Preference Page
44  *
45  * Allows the configuration of CVS specific options.
46  * The currently supported options are:
47  * - Allow loading of CVS administration directory (CVSROOT)
48  *
49  * There are currently a couple of deficiencies:
50  * 1. The Repository view is not refreshed when the show CVSROOT option is changed
51  * 2. There is no help associated with the page
52  */

53 public class CVSPreferencesPage extends PreferencePage implements IWorkbenchPreferencePage {
54     
55     public static class PerspectiveDescriptorComparator implements Comparator JavaDoc {
56         public int compare(Object JavaDoc o1, Object JavaDoc o2) {
57             if (o1 instanceof IPerspectiveDescriptor && o2 instanceof IPerspectiveDescriptor) {
58                 String JavaDoc id1= ((IPerspectiveDescriptor)o1).getLabel();
59                 String JavaDoc id2= ((IPerspectiveDescriptor)o2).getLabel();
60                 return Collator.getInstance().compare(id1, id2);
61             }
62             return 0;
63         }
64     }
65     
66     
67     private abstract class Field {
68         protected final String JavaDoc fKey;
69         public Field(String JavaDoc key) { fFields.add(this); fKey= key; }
70         public abstract void initializeValue(IPreferenceStore store);
71         public abstract void performOk(IPreferenceStore store);
72         public void performDefaults(IPreferenceStore store) {
73             store.setToDefault(fKey);
74             initializeValue(store);
75         }
76     }
77     
78     private class Checkbox extends Field {
79         
80         private final Button fCheckbox;
81         
82         public Checkbox(Composite composite, String JavaDoc key, String JavaDoc label, String JavaDoc helpID) {
83             super(key);
84             fCheckbox= new Button(composite, SWT.CHECK);
85             fCheckbox.setText(label);
86             PlatformUI.getWorkbench().getHelpSystem().setHelp(fCheckbox, helpID);
87         }
88         
89         public void initializeValue(IPreferenceStore store) {
90             fCheckbox.setSelection(store.getBoolean(fKey));
91         }
92         
93         public void performOk(IPreferenceStore store) {
94             store.setValue(fKey, fCheckbox.getSelection());
95         }
96     }
97
98     private abstract class ComboBox extends Field {
99         protected final Combo fCombo;
100         private final String JavaDoc [] fLabels;
101         private final List JavaDoc fValues;
102         
103         public ComboBox(Composite composite, String JavaDoc key, String JavaDoc text, String JavaDoc helpID, String JavaDoc [] labels, Object JavaDoc [] values) {
104             super(key);
105             fLabels= labels;
106             fValues= Arrays.asList(values);
107             
108             final Label label= SWTUtils.createLabel(composite, text);
109             fCombo= new Combo(composite, SWT.READ_ONLY);
110             fCombo.setLayoutData(SWTUtils.createHFillGridData());
111             fCombo.setItems(labels);
112             
113             if (((GridLayout)composite.getLayout()).numColumns > 1) {
114                 label.setLayoutData(SWTUtils.createGridData(SWT.DEFAULT, SWT.DEFAULT, false, false));
115             }
116             
117             PlatformUI.getWorkbench().getHelpSystem().setHelp(fCombo, helpID);
118         }
119         
120         public Combo getCombo() {
121             return fCombo;
122         }
123         
124         public void initializeValue(IPreferenceStore store) {
125             final Object JavaDoc value= getValue(store, fKey);
126             final int index= fValues.indexOf(value);
127             if (index >= 0 && index < fLabels.length)
128                 fCombo.select(index);
129             else
130                 fCombo.select(0);
131         }
132         
133         public void performOk(IPreferenceStore store) {
134             saveValue(store, fKey, fValues.get(fCombo.getSelectionIndex()));
135         }
136         
137         protected abstract void saveValue(IPreferenceStore store, String JavaDoc key, Object JavaDoc object);
138         protected abstract Object JavaDoc getValue(IPreferenceStore store, String JavaDoc key);
139     }
140     
141     private class IntegerComboBox extends ComboBox {
142         public IntegerComboBox(Composite composite, String JavaDoc key, String JavaDoc label, String JavaDoc helpID, String JavaDoc[] labels, Integer JavaDoc [] values) {
143             super(composite, key, label, helpID, labels, values);
144         }
145
146         protected void saveValue(IPreferenceStore store, String JavaDoc key, Object JavaDoc object) {
147             store.setValue(key, ((Integer JavaDoc)object).intValue());
148         }
149         
150         protected Object JavaDoc getValue(IPreferenceStore store, String JavaDoc key) {
151             return new Integer JavaDoc(store.getInt(key));
152         }
153     }
154     
155     private class StringComboBox extends ComboBox {
156         
157         public StringComboBox(Composite composite, String JavaDoc key, String JavaDoc label, String JavaDoc helpID, String JavaDoc [] labels, String JavaDoc [] values) {
158             super(composite, key, label, helpID, labels, values);
159         }
160
161         protected Object JavaDoc getValue(IPreferenceStore store, String JavaDoc key) {
162             return store.getString(key);
163         }
164         
165         protected void saveValue(IPreferenceStore store, String JavaDoc key, Object JavaDoc object) {
166             store.setValue(key, (String JavaDoc)object);
167         }
168     }
169
170     private abstract class RadioButtons extends Field {
171         protected final Button [] fButtons;
172         private final String JavaDoc [] fLabels;
173         private final List JavaDoc fValues;
174         private final Group fGroup;
175         
176         public RadioButtons(Composite composite, String JavaDoc key, String JavaDoc label, String JavaDoc helpID, String JavaDoc [] labels, Object JavaDoc [] values) {
177             super(key);
178             fLabels= labels;
179             fValues= Arrays.asList(values);
180             
181             fGroup= SWTUtils.createHFillGroup(composite, label, SWTUtils.MARGINS_DEFAULT, labels.length);
182             
183             
184             fButtons= new Button [labels.length];
185             for (int i = 0; i < fLabels.length; i++) {
186                 fButtons[i]= new Button(fGroup, SWT.RADIO);
187                 fButtons[i].setLayoutData(SWTUtils.createGridData(SWT.DEFAULT, SWT.DEFAULT, false, false));
188                 fButtons[i].setText(labels[i]);
189             }
190             SWTUtils.equalizeControls(SWTUtils.createDialogPixelConverter(composite), fButtons, 0, fButtons.length - 2);
191             PlatformUI.getWorkbench().getHelpSystem().setHelp(fGroup, helpID);
192         }
193         
194         public void initializeValue(IPreferenceStore store) {
195             final Object JavaDoc value= loadValue(store, fKey);
196             final int index= fValues.indexOf(value);
197             for (int i = 0; i < fButtons.length; i++) {
198                 Button b = fButtons[i];
199                 b.setSelection(index == i);
200             }
201         }
202
203         public void performOk(IPreferenceStore store) {
204             for (int i = 0; i < fButtons.length; ++i) {
205                 if (fButtons[i].getSelection()) {
206                     saveValue(store, fKey, fValues.get(i));
207                     return;
208                 }
209             }
210         }
211         
212         public Control getControl() {
213             return fGroup;
214         }
215         
216         protected abstract Object JavaDoc loadValue(IPreferenceStore store, String JavaDoc key);
217
218         protected abstract void saveValue(IPreferenceStore store, String JavaDoc key, Object JavaDoc value);
219     }
220
221     private class IntegerRadioButtons extends RadioButtons {
222
223         public IntegerRadioButtons(Composite composite, String JavaDoc key, String JavaDoc label, String JavaDoc helpID, String JavaDoc[] labels, Integer JavaDoc [] values) {
224             super(composite, key, label, helpID, labels, values);
225         }
226
227         protected Object JavaDoc loadValue(IPreferenceStore store, String JavaDoc key) {
228             return new Integer JavaDoc(store.getInt(key));
229         }
230
231         protected void saveValue(IPreferenceStore store, String JavaDoc key, Object JavaDoc value) {
232             store.setValue(key, ((Integer JavaDoc)value).intValue());
233         }
234     }
235     
236     private class StringRadioButtons extends RadioButtons {
237
238         public StringRadioButtons(Composite composite, String JavaDoc key, String JavaDoc label, String JavaDoc helpID, String JavaDoc[] labels, String JavaDoc [] values) {
239             super(composite, key, label, helpID, labels, values);
240         }
241
242         protected Object JavaDoc loadValue(IPreferenceStore store, String JavaDoc key) {
243             return store.getString(key);
244         }
245
246         protected void saveValue(IPreferenceStore store, String JavaDoc key, Object JavaDoc value) {
247             store.setValue(key, (String JavaDoc)value);
248         }
249     }
250     
251     private abstract class TextField extends Field implements ModifyListener {
252         protected final Text fText;
253         
254         public TextField(Composite composite, String JavaDoc key, String JavaDoc text, String JavaDoc helpID) {
255             super(key);
256             
257             final Label label= new Label(composite, SWT.WRAP);
258             label.setText(text);
259             label.setLayoutData(SWTUtils.createGridData(SWT.DEFAULT, SWT.DEFAULT, false, false));
260             
261             fText= SWTUtils.createText(composite);
262             fText.addModifyListener(this);
263             
264             if (helpID != null)
265                 PlatformUI.getWorkbench().getHelpSystem().setHelp(fText, helpID);
266         }
267         
268         public Text getControl() {
269             return fText;
270         }
271         
272         public void initializeValue(IPreferenceStore store) {
273             final String JavaDoc value= store.getString(fKey);
274             fText.setText(value);
275         }
276         
277         public void performOk(IPreferenceStore store) {
278             store.setValue(fKey, fText.getText());
279         }
280         
281         public void modifyText(ModifyEvent e) {
282             modifyText(fText);
283         }
284         
285         protected abstract void modifyText(Text text);
286     }
287     
288     private final String JavaDoc [] KSUBST_VALUES;
289     private final String JavaDoc [] KSUBST_LABELS;
290     
291     private final String JavaDoc [] COMPRESSION_LABELS;
292     private final Integer JavaDoc [] COMPRESSION_VALUES;
293     
294     protected final ArrayList JavaDoc fFields;
295     private final String JavaDoc [] PERSPECTIVE_VALUES;
296     private final String JavaDoc [] PERSPECTIVE_LABELS;
297     private final String JavaDoc [] YES_NO_PROMPT;
298     
299     public CVSPreferencesPage() {
300         fFields= new ArrayList JavaDoc();
301         
302         final KSubstOption[] options = KSubstOption.getAllKSubstOptions();
303         final ArrayList JavaDoc KSUBST_MODES= new ArrayList JavaDoc();
304         for (int i = 0; i < options.length; i++) {
305             final KSubstOption option = options[i];
306             if (!option.isBinary()) {
307                 KSUBST_MODES.add(option);
308             }
309         }
310         Collections.sort(KSUBST_MODES, new Comparator JavaDoc() {
311             public int compare(Object JavaDoc a, Object JavaDoc b) {
312                 final String JavaDoc aKey = ((KSubstOption) a).getLongDisplayText();
313                 final String JavaDoc bKey = ((KSubstOption) b).getLongDisplayText();
314                 return aKey.compareTo(bKey);
315             }
316         });
317         
318         KSUBST_LABELS= new String JavaDoc[KSUBST_MODES.size()];
319         KSUBST_VALUES= new String JavaDoc[KSUBST_MODES.size()];
320         int index= 0;
321         for (Iterator JavaDoc iter = KSUBST_MODES.iterator(); iter.hasNext();) {
322             KSubstOption mod = (KSubstOption) iter.next();
323             KSUBST_LABELS[index]= mod.getLongDisplayText();
324             final String JavaDoc mode= mod.toMode().trim();
325             KSUBST_VALUES[index]= mode.length() != 0 ? mode : "-kkv"; //$NON-NLS-1$
326
++index;
327         }
328     
329         COMPRESSION_LABELS = new String JavaDoc[] { CVSUIMessages.CVSPreferencesPage_0,
330                 CVSUIMessages.CVSPreferencesPage_1,
331                 CVSUIMessages.CVSPreferencesPage_2,
332                 CVSUIMessages.CVSPreferencesPage_3,
333                 CVSUIMessages.CVSPreferencesPage_4,
334                 CVSUIMessages.CVSPreferencesPage_5,
335                 /* CVSUIMessages.CVSPreferencesPage_6, // Disallow 6 through 9 due to server bug (see bug 15724)
336                 CVSUIMessages.CVSPreferencesPage_7,
337                 CVSUIMessages.CVSPreferencesPage_8,
338                 CVSUIMessages.CVSPreferencesPage_9 */
};
339         COMPRESSION_VALUES= new Integer JavaDoc [COMPRESSION_LABELS.length];
340         for (int i = 0; i < COMPRESSION_VALUES.length; i++) {
341             COMPRESSION_VALUES[i]= new Integer JavaDoc(i);
342         }
343         
344         final IPerspectiveDescriptor [] perspectives= PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives();
345         PERSPECTIVE_VALUES= new String JavaDoc[perspectives.length + 1];
346         PERSPECTIVE_LABELS= new String JavaDoc [perspectives.length + 1];
347         Arrays.sort(perspectives, new PerspectiveDescriptorComparator());
348         PERSPECTIVE_VALUES[0]= ICVSUIConstants.OPTION_NO_PERSPECTIVE;
349         PERSPECTIVE_LABELS[0]= CVSUIMessages.CVSPreferencesPage_10;
350         for (int i = 0; i < perspectives.length; i++) {
351             PERSPECTIVE_VALUES[i + 1]= perspectives[i].getId();
352             PERSPECTIVE_LABELS[i + 1]= perspectives[i].getLabel();
353         }
354         
355         YES_NO_PROMPT= new String JavaDoc [] { CVSUIMessages.CVSPreferencesPage_11, CVSUIMessages.CVSPreferencesPage_12, CVSUIMessages.CVSPreferencesPage_13 }; //
356
/**
357          * Handle deleted perspectives
358          */

359         final IPreferenceStore store= CVSUIPlugin.getPlugin().getPreferenceStore();
360         final String JavaDoc id= store.getString(ICVSUIConstants.PREF_DEFAULT_PERSPECTIVE_FOR_SHOW_ANNOTATIONS);
361         if (PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(id) == null) {
362             store.putValue(ICVSUIConstants.PREF_DEFAULT_PERSPECTIVE_FOR_SHOW_ANNOTATIONS, ICVSUIConstants.OPTION_NO_PERSPECTIVE);
363         }
364     }
365
366     protected Control createContents(Composite parent) {
367         
368         // create a tab folder for the page
369
final TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
370         tabFolder.setLayoutData(SWTUtils.createHFillGridData());
371
372         createGeneralTab(tabFolder);
373         createFilesFoldersTab(tabFolder);
374         createConnectionTab(tabFolder);
375         createPromptingTab(tabFolder);
376         
377         initializeValues();
378         
379         Dialog.applyDialogFont(parent);
380         
381         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.GENERAL_PREFERENCE_PAGE);
382         return tabFolder;
383     }
384
385     private Composite createGeneralTab(final TabFolder tabFolder) {
386         final Composite composite = SWTUtils.createHFillComposite(tabFolder, SWTUtils.MARGINS_DEFAULT);
387         final TabItem tab= new TabItem(tabFolder, SWT.NONE);
388         tab.setText(CVSUIMessages.CVSPreferencesPage_14);
389         tab.setControl(composite);
390         new Checkbox(composite, ICVSUIConstants.PREF_DETERMINE_SERVER_VERSION, CVSUIMessages.CVSPreferencesPage_15, IHelpContextIds.PREF_DETERMINE_SERVER_VERSION);
391         new Checkbox(composite, ICVSUIConstants.PREF_CONFIRM_MOVE_TAG, CVSUIMessages.CVSPreferencesPage_16, IHelpContextIds.PREF_CONFIRM_MOVE_TAG);
392         new Checkbox(composite, ICVSUIConstants.PREF_DEBUG_PROTOCOL, CVSUIMessages.CVSPreferencesPage_17, IHelpContextIds.PREF_DEBUG_PROTOCOL);
393         new Checkbox(composite, ICVSUIConstants.PREF_AUTO_REFRESH_TAGS_IN_TAG_SELECTION_DIALOG, CVSUIMessages.CVSPreferencesPage_18, IHelpContextIds.PREF_AUTOREFRESH_TAG);
394         new Checkbox(composite, ICVSUIConstants.PREF_AUTO_SHARE_ON_IMPORT, CVSUIMessages.CVSPreferencesPage_44, null);
395         new Checkbox(composite, ICVSUIConstants.PREF_USE_PROJECT_NAME_ON_CHECKOUT, CVSUIMessages.CVSPreferencesPage_45, null);
396         
397         final Composite textComposite= SWTUtils.createHFillComposite(composite, SWTUtils.MARGINS_NONE, 2);
398         new TextField(
399                 textComposite,
400                 ICVSUIConstants.PREF_COMMIT_FILES_DISPLAY_THRESHOLD,
401                 CVSUIMessages.CVSPreferencesPage_20,
402                 null) {
403             protected void modifyText(Text text) {
404                 // Parse the timeout value
405
try {
406                     final int x = Integer.parseInt(text.getText());
407                     if (x >= 0) {
408                         setErrorMessage(null);
409                         setValid(true);
410                     } else {
411                         setErrorMessage(CVSUIMessages.CVSPreferencesPage_21);
412                         setValid(false);
413                     }
414                 } catch (NumberFormatException JavaDoc ex) {
415                     setErrorMessage(CVSUIMessages.CVSPreferencesPage_22);
416                     setValid(false);
417                 }
418             }
419         };
420         new TextField(
421                 textComposite,
422                 ICVSUIConstants.PREF_COMMIT_COMMENTS_MAX_HISTORY,
423                 CVSUIMessages.CVSPreferencesPage_47,
424                 null) {
425             protected void modifyText(Text text) {
426                 try {
427                     final int x = Integer.parseInt(text.getText());
428                     if (x > 0) {
429                         setErrorMessage(null);
430                         setValid(true);
431                     } else {
432                         setErrorMessage(CVSUIMessages.CVSPreferencesPage_48);
433                         setValid(false);
434                     }
435                 } catch (NumberFormatException JavaDoc ex) {
436                     setErrorMessage(CVSUIMessages.CVSPreferencesPage_49);
437                     setValid(false);
438                 }
439             }
440         };
441         
442         return composite;
443     }
444     
445     private Composite createConnectionTab(final TabFolder tabFolder) {
446         final Composite composite = SWTUtils.createHFillComposite(tabFolder, SWTUtils.MARGINS_DEFAULT);
447         final TabItem tab= new TabItem(tabFolder, SWT.NONE);
448         tab.setText(CVSUIMessages.CVSPreferencesPage_19);
449         tab.setControl(composite);
450         
451         final Composite textComposite= SWTUtils.createHFillComposite(composite, SWTUtils.MARGINS_NONE, 2);
452         new TextField(
453                 textComposite,
454                 ICVSUIConstants.PREF_TIMEOUT,
455                 CVSUIMessages.CVSPreferencesPage_23,
456                 IHelpContextIds.PREF_COMMS_TIMEOUT) {
457             protected void modifyText(Text text) {
458                 // Parse the timeout value
459
try {
460                     final int x = Integer.parseInt(text.getText());
461                     if (x >= 0) {
462                         setErrorMessage(null);
463                         setValid(true);
464                     } else {
465                         setErrorMessage(CVSUIMessages.CVSPreferencesPage_24);
466                         setValid(false);
467                     }
468                 } catch (NumberFormatException JavaDoc ex) {
469                     setErrorMessage(CVSUIMessages.CVSPreferencesPage_25);
470                     setValid(false);
471                 }
472             }
473         };
474         
475         final ComboBox quietnessCombo = new IntegerComboBox(
476                 textComposite,
477                 ICVSUIConstants.PREF_QUIETNESS,
478                 CVSUIMessages.CVSPreferencesPage_26,
479                 IHelpContextIds.PREF_QUIET,
480                 new String JavaDoc [] { CVSUIMessages.CVSPreferencesPage_27, CVSUIMessages.CVSPreferencesPage_28, CVSUIMessages.CVSPreferencesPage_29 }, //
481
new Integer JavaDoc [] { new Integer JavaDoc(0), new Integer JavaDoc(1), new Integer JavaDoc(2)});
482         
483         quietnessCombo.getCombo().addSelectionListener(new SelectionListener() {
484             public void widgetSelected(SelectionEvent e) {
485                 if (getQuietnessOptionFor(quietnessCombo.getCombo().getSelectionIndex()).equals(Command.SILENT)) {
486                     MessageDialog.openWarning(getShell(), CVSUIMessages.CVSPreferencesPage_30, CVSUIMessages.CVSPreferencesPage_31); //
487
}
488             }
489             public void widgetDefaultSelected(SelectionEvent e) {
490                 widgetSelected(e);
491             }
492         });
493
494         new IntegerComboBox(
495                 textComposite,
496                 ICVSUIConstants.PREF_COMPRESSION_LEVEL,
497                 CVSUIMessages.CVSPreferencesPage_32,
498                 IHelpContextIds.PREF_COMPRESSION,
499                 COMPRESSION_LABELS, COMPRESSION_VALUES);
500         
501         SWTUtils.createPreferenceLink((IWorkbenchPreferenceContainer) getContainer(), composite, CVSUIMessages.CVSPreferencesPage_52, CVSUIMessages.CVSPreferencesPage_53);
502         
503         SWTUtils.createPreferenceLink((IWorkbenchPreferenceContainer) getContainer(), composite, CVSUIMessages.CVSPreferencesPage_54, CVSUIMessages.CVSPreferencesPage_55);
504
505         return composite;
506     }
507
508     
509     private Composite createFilesFoldersTab(final TabFolder tabFolder) {
510         final Composite composite = SWTUtils.createHFillComposite(tabFolder, SWTUtils.MARGINS_DEFAULT);
511         final TabItem tab= new TabItem(tabFolder, SWT.NONE);
512         tab.setText(CVSUIMessages.CVSPreferencesPage_33);
513         tab.setControl(composite);
514         new Checkbox(composite, ICVSUIConstants.PREF_REPOSITORIES_ARE_BINARY, CVSUIMessages.CVSPreferencesPage_34, IHelpContextIds.PREF_TREAT_NEW_FILE_AS_BINARY);
515         new Checkbox(composite, ICVSUIConstants.PREF_USE_PLATFORM_LINEEND, CVSUIMessages.CVSPreferencesPage_35, IHelpContextIds.PREF_LINEEND);
516         new Checkbox(composite, ICVSUIConstants.PREF_PRUNE_EMPTY_DIRECTORIES, CVSUIMessages.CVSPreferencesPage_36, IHelpContextIds.PREF_PRUNE);
517         new Checkbox(composite, ICVSUIConstants.PREF_REPLACE_UNMANAGED, CVSUIMessages.CVSPreferencesPage_37, IHelpContextIds.PREF_REPLACE_DELETE_UNMANAGED);
518         SWTUtils.createPlaceholder(composite, 1);
519         final Composite bottom= SWTUtils.createHFillComposite(composite, SWTUtils.MARGINS_NONE, 2);
520         new StringComboBox(
521                 bottom,
522                 ICVSUIConstants.PREF_TEXT_KSUBST,
523                 CVSUIMessages.CVSPreferencesPage_38,
524                 IHelpContextIds.PREF_KEYWORDMODE,
525                 KSUBST_LABELS, KSUBST_VALUES);
526         
527         return composite;
528     }
529     
530     private Composite createPromptingTab(final TabFolder tabFolder) {
531
532         final Composite composite = SWTUtils.createHFillComposite(tabFolder, SWTUtils.MARGINS_DEFAULT, 1);
533         final TabItem tab= new TabItem(tabFolder, SWT.NONE);
534         tab.setText(CVSUIMessages.CVSPreferencesPage_39);
535         tab.setControl(composite);
536         
537         new StringRadioButtons(
538                 composite,
539                 ICVSUIConstants.PREF_ALLOW_EMPTY_COMMIT_COMMENTS,
540                 CVSUIMessages.CVSPreferencesPage_40,
541                 IHelpContextIds.PREF_ALLOW_EMPTY_COMMIT_COMMENTS,
542                 YES_NO_PROMPT,
543                 new String JavaDoc [] { MessageDialogWithToggle.ALWAYS, MessageDialogWithToggle.NEVER, MessageDialogWithToggle.PROMPT });
544         
545         new IntegerRadioButtons(composite,
546                 ICVSUIConstants.PREF_SAVE_DIRTY_EDITORS,
547                 CVSUIMessages.CVSPreferencesPage_41,
548                 IHelpContextIds.PREF_SAVE_DIRTY_EDITORS,
549                 YES_NO_PROMPT,
550                 new Integer JavaDoc [] { new Integer JavaDoc(ICVSUIConstants.OPTION_AUTOMATIC), new Integer JavaDoc(ICVSUIConstants.OPTION_NEVER), new Integer JavaDoc(ICVSUIConstants.OPTION_PROMPT)});
551         
552         new StringRadioButtons(
553                 composite,
554                 ICVSUIConstants.PREF_INCLUDE_CHANGE_SETS_IN_COMMIT,
555                 CVSUIMessages.CVSPreferencesPage_46,
556                 IHelpContextIds.PREF_INCLUDE_CHANGE_SETS_IN_COMMIT,
557                 YES_NO_PROMPT,
558                 new String JavaDoc [] { MessageDialogWithToggle.ALWAYS, MessageDialogWithToggle.NEVER, MessageDialogWithToggle.PROMPT }
559                 );
560         
561         new StringRadioButtons(
562                 composite,
563                 ICVSUIConstants.PREF_ALLOW_COMMIT_WITH_WARNINGS,
564                 CVSUIMessages.CVSPreferencesPage_50,
565                 IHelpContextIds.PREF_INCLUDE_CHANGE_SETS_IN_COMMIT,
566                 YES_NO_PROMPT,
567                 new String JavaDoc [] { MessageDialogWithToggle.ALWAYS, MessageDialogWithToggle.NEVER, MessageDialogWithToggle.PROMPT }
568                 );
569
570         new StringRadioButtons(
571                 composite,
572                 ICVSUIConstants.PREF_ALLOW_COMMIT_WITH_ERRORS,
573                 CVSUIMessages.CVSPreferencesPage_51,
574                 IHelpContextIds.PREF_INCLUDE_CHANGE_SETS_IN_COMMIT,
575                 YES_NO_PROMPT,
576                 new String JavaDoc [] { MessageDialogWithToggle.ALWAYS, MessageDialogWithToggle.NEVER, MessageDialogWithToggle.PROMPT }
577                 );
578         SWTUtils.createPlaceholder(composite, 1);
579       
580         return composite;
581     }
582     
583     /**
584      * Initializes states of the controls from the preference store.
585      */

586     private void initializeValues() {
587         final IPreferenceStore store = getPreferenceStore();
588         for (Iterator JavaDoc iter = fFields.iterator(); iter.hasNext();) {
589             ((Field)iter.next()).initializeValue(store);
590         }
591     }
592
593     public void init(IWorkbench workbench) {
594     }
595
596     public boolean performOk() {
597
598         final IPreferenceStore store = getPreferenceStore();
599         for (Iterator JavaDoc iter = fFields.iterator(); iter.hasNext();) {
600             ((Field) iter.next()).performOk(store);
601         }
602
603         CVSProviderPlugin.getPlugin().setReplaceUnmanaged(store.getBoolean(ICVSUIConstants.PREF_REPLACE_UNMANAGED));
604         CVSProviderPlugin.getPlugin().setPruneEmptyDirectories(store.getBoolean(ICVSUIConstants.PREF_PRUNE_EMPTY_DIRECTORIES));
605         CVSProviderPlugin.getPlugin().setTimeout(store.getInt(ICVSUIConstants.PREF_TIMEOUT));
606         CVSProviderPlugin.getPlugin().setQuietness(getQuietnessOptionFor(store.getInt(ICVSUIConstants.PREF_QUIETNESS)));
607         CVSProviderPlugin.getPlugin().setCompressionLevel(store.getInt(ICVSUIConstants.PREF_COMPRESSION_LEVEL));
608         CVSProviderPlugin.getPlugin().setDebugProtocol(store.getBoolean(ICVSUIConstants.PREF_DEBUG_PROTOCOL));
609         CVSProviderPlugin.getPlugin().setRepositoriesAreBinary(store.getBoolean(ICVSUIConstants.PREF_REPOSITORIES_ARE_BINARY));
610         KSubstOption oldKSubst = CVSProviderPlugin.getPlugin().getDefaultTextKSubstOption();
611         KSubstOption newKSubst = KSubstOption.fromMode(store.getString(ICVSUIConstants.PREF_TEXT_KSUBST));
612         CVSProviderPlugin.getPlugin().setDefaultTextKSubstOption(newKSubst);
613         CVSProviderPlugin.getPlugin().setUsePlatformLineend(store.getBoolean(ICVSUIConstants.PREF_USE_PLATFORM_LINEEND));
614         CVSProviderPlugin.getPlugin().setDetermineVersionEnabled(store.getBoolean(ICVSUIConstants.PREF_DETERMINE_SERVER_VERSION));
615         CVSProviderPlugin.getPlugin().setAutoshareOnImport(store.getBoolean(ICVSUIConstants.PREF_AUTO_SHARE_ON_IMPORT));
616         
617         // changing the default keyword substitution mode for text files may affect
618
// information displayed in the decorators
619
if (! oldKSubst.equals(newKSubst)) {
620             CVSUIPlugin.broadcastPropertyChange(new PropertyChangeEvent(this, CVSUIPlugin.P_DECORATORS_CHANGED, null, null));
621         }
622         
623         CVSUIPlugin.getPlugin().savePluginPreferences();
624         return true;
625     }
626
627     protected void performDefaults() {
628         super.performDefaults();
629         final IPreferenceStore store = getPreferenceStore();
630         for (Iterator JavaDoc iter = fFields.iterator(); iter.hasNext();) {
631             ((Field) iter.next()).performDefaults(store);
632         }
633     }
634
635    /**
636     * Returns preference store that belongs to the our plugin.
637     * This is important because we want to store
638     * our preferences separately from the desktop.
639     *
640     * @return the preference store for this plugin
641     */

642     protected IPreferenceStore doGetPreferenceStore() {
643         return CVSUIPlugin.getPlugin().getPreferenceStore();
644     }
645     
646     protected static QuietOption getQuietnessOptionFor(int option) {
647         switch (option) {
648             case 0: return Command.VERBOSE;
649             case 1: return Command.PARTLY_QUIET;
650             case 2: return Command.SILENT;
651         }
652         return null;
653     }
654 }
655
Popular Tags