KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > preferences > SyncViewerPreferencePage


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  *******************************************************************************/

11 package org.eclipse.team.internal.ui.preferences;
12
13 import com.ibm.icu.text.Collator;
14 import java.util.Arrays JavaDoc;
15 import java.util.Comparator JavaDoc;
16
17 import org.eclipse.jface.dialogs.Dialog;
18 import org.eclipse.jface.dialogs.MessageDialogWithToggle;
19 import org.eclipse.jface.preference.*;
20 import org.eclipse.jface.util.PropertyChangeEvent;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.*;
25 import org.eclipse.team.internal.ui.*;
26 import org.eclipse.ui.*;
27
28 /**
29  * This area provides the widgets for providing the CVS commit comment
30  */

31 public class SyncViewerPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage, IPreferenceIds {
32     
33     private BooleanFieldEditor showSyncInLabels = null;
34     private RadioGroupFieldEditor synchronizePerspectiveSwitch = null;
35     private RadioGroupFieldEditor defaultLayout = null;
36     private boolean includeDefaultLayout = true;
37     
38     private static class PerspectiveDescriptorComparator implements Comparator JavaDoc {
39         /*
40          * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
41          */

42         public int compare(Object JavaDoc o1, Object JavaDoc o2) {
43             if (o1 instanceof IPerspectiveDescriptor && o2 instanceof IPerspectiveDescriptor) {
44                 String JavaDoc id1= ((IPerspectiveDescriptor)o1).getLabel();
45                 String JavaDoc id2= ((IPerspectiveDescriptor)o2).getLabel();
46                 return Collator.getInstance().compare(id1, id2);
47             }
48             return 0;
49         }
50     }
51     
52     public SyncViewerPreferencePage() {
53         super(GRID);
54         setTitle(TeamUIMessages.SyncViewerPreferencePage_6);
55         setDescription(TeamUIMessages.SyncViewerPreferencePage_7);
56         setPreferenceStore(TeamUIPlugin.getPlugin().getPreferenceStore());
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
61      */

62     public void createControl(Composite parent) {
63         super.createControl(parent);
64         // set F1 help
65
PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.SYNC_PREFERENCE_PAGE);
66     }
67     
68     /* (non-Javadoc)
69      * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
70      */

71     public void createFieldEditors() {
72         showSyncInLabels = new BooleanFieldEditor(SYNCVIEW_VIEW_SYNCINFO_IN_LABEL, TeamUIMessages.SyncViewerPreferencePage_19, SWT.NONE, getFieldEditorParent());
73         addField(showSyncInLabels);
74         
75         addField(new BooleanFieldEditor(
76                 SHOW_AUTHOR_IN_COMPARE_EDITOR,
77                 TeamUIMessages.SyncViewerPreferencePage_43,
78                 BooleanFieldEditor.DEFAULT,
79                 getFieldEditorParent()));
80         
81         addField(new BooleanFieldEditor(
82                 MAKE_FILE_WRITTABLE_IF_CONTEXT_MISSING,
83                 TeamUIMessages.SyncViewerPreferencePage_44,
84                 BooleanFieldEditor.DEFAULT,
85                 getFieldEditorParent()));
86         
87         addField(new BooleanFieldEditor(
88                 REUSE_OPEN_COMPARE_EDITOR,
89                 TeamUIMessages.SyncViewerPreferencePage_45,
90                 BooleanFieldEditor.DEFAULT,
91                 getFieldEditorParent()));
92         
93         addField(new BooleanFieldEditor(
94                 RUN_IMPORT_IN_BACKGROUND,
95                 TeamUIMessages.SyncViewerPreferencePage_46,
96                 BooleanFieldEditor.DEFAULT,
97                 getFieldEditorParent()));
98         
99         if (isIncludeDefaultLayout()) {
100             defaultLayout = new RadioGroupFieldEditor(SYNCVIEW_DEFAULT_LAYOUT,
101                     TeamUIMessages.SyncViewerPreferencePage_0, 3,
102                     new String JavaDoc[][] {
103                         {TeamUIMessages.SyncViewerPreferencePage_1, FLAT_LAYOUT},
104                         {TeamUIMessages.SyncViewerPreferencePage_2, TREE_LAYOUT},
105                         {TeamUIMessages.SyncViewerPreferencePage_3, COMPRESSED_LAYOUT}
106                     },
107                     getFieldEditorParent(), true /* use a group */);
108             addField(defaultLayout);
109         }
110
111         synchronizePerspectiveSwitch= new RadioGroupFieldEditor(SYNCHRONIZING_COMPLETE_PERSPECTIVE, TeamUIMessages.SyncViewerPreferencePage_13, 3,
112                 new String JavaDoc[][] {
113                                 {TeamUIMessages.SyncViewerPreferencePage_14, MessageDialogWithToggle.ALWAYS},
114                                 {TeamUIMessages.SyncViewerPreferencePage_42, MessageDialogWithToggle.NEVER},
115                                 {TeamUIMessages.SyncViewerPreferencePage_16, MessageDialogWithToggle.PROMPT}
116                             },
117                             getFieldEditorParent(), true);
118         addField(synchronizePerspectiveSwitch);
119         
120         Group perspectiveGroup = createGroup(getFieldEditorParent(), TeamUIMessages.SyncViewerPreferencePage_15);
121         
122         createLabel(perspectiveGroup, TeamUIMessages.SynchronizationViewPreference_defaultPerspectiveDescription, 1);
123         
124         handleDeletedPerspectives();
125         String JavaDoc[][] perspectiveNamesAndIds = getPerspectiveNamesAndIds();
126         ComboFieldEditor comboEditor= new ComboFieldEditor(
127             SYNCVIEW_DEFAULT_PERSPECTIVE,
128             TeamUIMessages.SynchronizationViewPreference_defaultPerspectiveLabel,
129             perspectiveNamesAndIds,
130             perspectiveGroup);
131         addField(comboEditor);
132
133         Dialog.applyDialogFont(getFieldEditorParent());
134         updateLayout(perspectiveGroup);
135         getFieldEditorParent().layout(true);
136     }
137     
138     private Label createLabel(Composite parent, String JavaDoc title, int spacer) {
139         GridData data;
140         Label l = new Label(parent, SWT.WRAP);
141         l.setFont(parent.getFont());
142         data = new GridData();
143         data.horizontalSpan = 2;
144         if(spacer != 0) {
145             data.verticalSpan = spacer;
146         }
147         data.horizontalAlignment = GridData.FILL;
148         l.setLayoutData(data);
149         if(title != null) {
150             l.setText(title);
151         }
152         return l;
153     }
154
155     private Group createGroup(Composite parent, String JavaDoc title) {
156         Group display = new Group(parent, SWT.NONE);
157         updateLayout(display);
158         GridData data = new GridData();
159         data.horizontalSpan = 2;
160         data.horizontalAlignment = GridData.FILL;
161         display.setLayoutData(data);
162         display.setText(title);
163         return display;
164     }
165     
166     private void updateLayout(Composite composite) {
167         GridLayout layout = new GridLayout();
168         layout.numColumns = 2;
169         layout.marginWidth = 5;
170         layout.marginHeight =5;
171         layout.horizontalSpacing = 5;
172         layout.verticalSpacing = 5;
173         composite.setLayout(layout);
174     }
175
176     /* (non-Javadoc)
177      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
178      */

179     public void init(IWorkbench workbench) {
180     }
181         
182     /* (non-Javadoc)
183      * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
184      */

185     public void propertyChange(PropertyChangeEvent event) {
186         //if(event.getSource() == bkgScheduledRefresh || event.getSource() == scheduledDelay) {
187
// updateEnablements();
188
// }
189
super.propertyChange(event);
190     }
191             
192     /* (non-Javadoc)
193      * @see org.eclipse.jface.preference.IPreferencePage#performOk()
194      */

195     public boolean performOk() {
196         TeamUIPlugin.getPlugin().savePluginPreferences();
197         return super.performOk();
198     }
199     
200     /* (non-Javadoc)
201      * @see org.eclipse.jface.preference.FieldEditorPreferencePage#checkState()
202      */

203     protected void initialize() {
204         super.initialize();
205         updateEnablements();
206     }
207
208     protected void updateEnablements() {
209         //boolean enabled = bkgScheduledRefresh.getBooleanValue();
210
//scheduledDelay.setEnabled(enabled, refreshGroup);
211
//scheduledDelay.refreshValidState();
212
}
213     
214     /**
215      * Return a 2-dimensional array of perspective names and ids.
216      */

217     private String JavaDoc[][] getPerspectiveNamesAndIds() {
218     
219         IPerspectiveRegistry registry= PlatformUI.getWorkbench().getPerspectiveRegistry();
220         IPerspectiveDescriptor[] perspectiveDescriptors= registry.getPerspectives();
221     
222         Arrays.sort(perspectiveDescriptors, new PerspectiveDescriptorComparator());
223     
224         String JavaDoc[][] table = new String JavaDoc[perspectiveDescriptors.length + 1][2];
225         table[0][0] = TeamUIMessages.SynchronizationViewPreference_defaultPerspectiveNone; //;
226
table[0][1] = SYNCVIEW_DEFAULT_PERSPECTIVE_NONE;
227         for (int i = 0; i < perspectiveDescriptors.length; i++) {
228             table[i + 1][0] = perspectiveDescriptors[i].getLabel();
229             table[i + 1][1] = perspectiveDescriptors[i].getId();
230         }
231         return table;
232     }
233
234     private static void handleDeletedPerspectives() {
235         IPreferenceStore store= TeamUIPlugin.getPlugin().getPreferenceStore();
236         String JavaDoc id= store.getString(SYNCVIEW_DEFAULT_PERSPECTIVE);
237         if (PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(id) == null) {
238             store.putValue(SYNCVIEW_DEFAULT_PERSPECTIVE, SYNCVIEW_DEFAULT_PERSPECTIVE_NONE);
239         }
240     }
241
242     public boolean isIncludeDefaultLayout() {
243         return includeDefaultLayout;
244     }
245
246     public void setIncludeDefaultLayout(boolean includeDefaultLayout) {
247         this.includeDefaultLayout = includeDefaultLayout;
248     }
249 }
250
Popular Tags