1 11 package org.eclipse.team.internal.ui.preferences; 12 13 import com.ibm.icu.text.Collator; 14 import java.util.Arrays ; 15 import java.util.Comparator ; 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 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 { 39 42 public int compare(Object o1, Object o2) { 43 if (o1 instanceof IPerspectiveDescriptor && o2 instanceof IPerspectiveDescriptor) { 44 String id1= ((IPerspectiveDescriptor)o1).getLabel(); 45 String 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 62 public void createControl(Composite parent) { 63 super.createControl(parent); 64 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.SYNC_PREFERENCE_PAGE); 66 } 67 68 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 [][] { 103 {TeamUIMessages.SyncViewerPreferencePage_1, FLAT_LAYOUT}, 104 {TeamUIMessages.SyncViewerPreferencePage_2, TREE_LAYOUT}, 105 {TeamUIMessages.SyncViewerPreferencePage_3, COMPRESSED_LAYOUT} 106 }, 107 getFieldEditorParent(), true ); 108 addField(defaultLayout); 109 } 110 111 synchronizePerspectiveSwitch= new RadioGroupFieldEditor(SYNCHRONIZING_COMPLETE_PERSPECTIVE, TeamUIMessages.SyncViewerPreferencePage_13, 3, 112 new String [][] { 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 [][] 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 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 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 179 public void init(IWorkbench workbench) { 180 } 181 182 185 public void propertyChange(PropertyChangeEvent event) { 186 super.propertyChange(event); 190 } 191 192 195 public boolean performOk() { 196 TeamUIPlugin.getPlugin().savePluginPreferences(); 197 return super.performOk(); 198 } 199 200 203 protected void initialize() { 204 super.initialize(); 205 updateEnablements(); 206 } 207 208 protected void updateEnablements() { 209 } 213 214 217 private String [][] getPerspectiveNamesAndIds() { 218 219 IPerspectiveRegistry registry= PlatformUI.getWorkbench().getPerspectiveRegistry(); 220 IPerspectiveDescriptor[] perspectiveDescriptors= registry.getPerspectives(); 221 222 Arrays.sort(perspectiveDescriptors, new PerspectiveDescriptorComparator()); 223 224 String [][] table = new String [perspectiveDescriptors.length + 1][2]; 225 table[0][0] = TeamUIMessages.SynchronizationViewPreference_defaultPerspectiveNone; 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 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 |