1 20 21 package org.apache.directory.ldapstudio.browser.common.dialogs.preferences; 22 23 24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator; 25 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants; 26 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 27 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants; 28 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin; 29 import org.eclipse.core.runtime.Preferences; 30 import org.eclipse.jface.preference.PreferencePage; 31 import org.eclipse.swt.events.SelectionAdapter; 32 import org.eclipse.swt.events.SelectionEvent; 33 import org.eclipse.swt.events.VerifyEvent; 34 import org.eclipse.swt.events.VerifyListener; 35 import org.eclipse.swt.layout.GridData; 36 import org.eclipse.swt.widgets.Button; 37 import org.eclipse.swt.widgets.Combo; 38 import org.eclipse.swt.widgets.Composite; 39 import org.eclipse.swt.widgets.Control; 40 import org.eclipse.swt.widgets.Group; 41 import org.eclipse.swt.widgets.Label; 42 import org.eclipse.swt.widgets.Text; 43 import org.eclipse.ui.IWorkbench; 44 import org.eclipse.ui.IWorkbenchPreferencePage; 45 46 47 public class BrowserPreferencePage extends PreferencePage implements IWorkbenchPreferencePage 48 { 49 50 private static final String DN = "DN"; 51 52 private static final String RDN = "RDN"; 53 54 private static final String RDN_VALUE = "RDN value"; 55 56 private Combo entryLabelCombo; 57 58 private Button entryAbbreviateButton; 59 60 private Text entryAbbreviateMaxLengthText; 61 62 private Combo searchResultLabelCombo; 63 64 private Button searchResultAbbreviateButton; 65 66 private Text searchResultAbbreviateMaxLengthText; 67 68 private Button enableFoldingButton; 69 70 private Label foldingSizeLabel; 71 72 private Text foldingSizeText; 73 74 private Button expandBaseEntriesButton;; 75 76 private Button checkForChildrenButton; 77 78 private Button showAliasAndReferralObjectsButton; 79 80 private Button fetchSubentriesButton; 81 82 83 public BrowserPreferencePage() 84 { 85 super(); 86 super.setPreferenceStore( BrowserCommonActivator.getDefault().getPreferenceStore() ); 87 super.setDescription( "General settings for the LDAP browser view:" ); 88 } 89 90 91 public void init( IWorkbench workbench ) 92 { 93 } 94 95 96 protected Control createContents( Composite parent ) 97 { 98 99 Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); 100 101 BaseWidgetUtils.createSpacer( composite, 1 ); 102 BaseWidgetUtils.createSpacer( composite, 1 ); 103 Group entryLabelGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ), 104 "Entry label", 1 ); 105 106 Composite entryLabelComposite = BaseWidgetUtils.createColumnContainer( entryLabelGroup, 3, 1 ); 107 BaseWidgetUtils.createLabel( entryLabelComposite, "Use ", 1 ); 108 entryLabelCombo = BaseWidgetUtils.createCombo( entryLabelComposite, new String [] 109 { DN, RDN, RDN_VALUE }, 0, 1 ); 110 entryLabelCombo.setLayoutData( new GridData() ); 111 entryLabelCombo 112 .select( getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL ) == BrowserCommonConstants.SHOW_RDN_VALUE ? 2 113 : getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL ) == BrowserCommonConstants.SHOW_RDN ? 1 114 : 0 ); 115 BaseWidgetUtils.createLabel( entryLabelComposite, " as entry label", 1 ); 116 117 Composite entryAbbreviateComposite = BaseWidgetUtils.createColumnContainer( entryLabelGroup, 3, 1 ); 118 entryAbbreviateButton = BaseWidgetUtils.createCheckbox( entryAbbreviateComposite, "Limit label length to ", 1 ); 119 entryAbbreviateButton.setSelection( getPreferenceStore().getBoolean( 120 BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE ) ); 121 entryAbbreviateButton.addSelectionListener( new SelectionAdapter() 122 { 123 public void widgetSelected( SelectionEvent e ) 124 { 125 updateEnabled(); 126 } 127 } ); 128 entryAbbreviateMaxLengthText = BaseWidgetUtils.createText( entryAbbreviateComposite, getPreferenceStore() 129 .getString( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH ), 3, 1 ); 130 entryAbbreviateMaxLengthText.setEnabled( entryAbbreviateButton.getSelection() ); 131 entryAbbreviateMaxLengthText.addVerifyListener( new VerifyListener() 132 { 133 public void verifyText( VerifyEvent e ) 134 { 135 if ( !e.text.matches( "[0-9]*" ) ) 136 { 137 e.doit = false; 138 } 139 if ( "".equals( entryAbbreviateMaxLengthText.getText() ) && e.text.matches( "[0]" ) ) 140 { 141 e.doit = false; 142 } 143 } 144 } ); 145 BaseWidgetUtils.createLabel( entryAbbreviateComposite, " characters", 1 ); 146 147 BaseWidgetUtils.createSpacer( composite, 1 ); 148 BaseWidgetUtils.createSpacer( composite, 1 ); 149 Group searchResultLabelGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 150 1, 1 ), "Search result label", 1 ); 151 152 Composite searchResultLabelComposite = BaseWidgetUtils.createColumnContainer( searchResultLabelGroup, 3, 1 ); 153 BaseWidgetUtils.createLabel( searchResultLabelComposite, "Use ", 1 ); 154 searchResultLabelCombo = BaseWidgetUtils.createCombo( searchResultLabelComposite, new String [] 155 { DN, RDN, RDN_VALUE }, 0, 1 ); 156 searchResultLabelCombo.setLayoutData( new GridData() ); 157 searchResultLabelCombo 158 .select( getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL ) == BrowserCommonConstants.SHOW_RDN_VALUE ? 2 159 : getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL ) == BrowserCommonConstants.SHOW_RDN ? 1 160 : 0 ); 161 BaseWidgetUtils.createLabel( searchResultLabelComposite, " as search result label", 1 ); 162 163 Composite searchResultAbbreviateComposite = BaseWidgetUtils 164 .createColumnContainer( searchResultLabelGroup, 3, 1 ); 165 searchResultAbbreviateButton = BaseWidgetUtils.createCheckbox( searchResultAbbreviateComposite, 166 "Limit label length to ", 1 ); 167 searchResultAbbreviateButton.setSelection( getPreferenceStore().getBoolean( 168 BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE ) ); 169 searchResultAbbreviateButton.addSelectionListener( new SelectionAdapter() 170 { 171 public void widgetSelected( SelectionEvent e ) 172 { 173 updateEnabled(); 174 } 175 } ); 176 searchResultAbbreviateMaxLengthText = BaseWidgetUtils 177 .createText( searchResultAbbreviateComposite, getPreferenceStore().getString( 178 BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH ), 3, 1 ); 179 searchResultAbbreviateMaxLengthText.setEnabled( searchResultAbbreviateButton.getSelection() ); 180 searchResultAbbreviateMaxLengthText.addVerifyListener( new VerifyListener() 181 { 182 public void verifyText( VerifyEvent e ) 183 { 184 if ( !e.text.matches( "[0-9]*" ) ) 185 { 186 e.doit = false; 187 } 188 if ( "".equals( searchResultAbbreviateMaxLengthText.getText() ) && e.text.matches( "[0]" ) ) 189 { 190 e.doit = false; 191 } 192 } 193 } ); 194 BaseWidgetUtils.createLabel( searchResultAbbreviateComposite, " characters", 1 ); 195 196 BaseWidgetUtils.createSpacer( composite, 1 ); 197 BaseWidgetUtils.createSpacer( composite, 1 ); 198 Group foldingGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ), 199 "Folding", 1 ); 200 Composite pagingGroupComposite = BaseWidgetUtils.createColumnContainer( foldingGroup, 2, 1 ); 201 enableFoldingButton = BaseWidgetUtils.createCheckbox( pagingGroupComposite, "Enable folding", 2 ); 202 enableFoldingButton.setSelection( getPreferenceStore().getBoolean( 203 BrowserCommonConstants.PREFERENCE_BROWSER_ENABLE_FOLDING ) ); 204 enableFoldingButton.addSelectionListener( new SelectionAdapter() 205 { 206 public void widgetSelected( SelectionEvent e ) 207 { 208 updateEnabled(); 209 } 210 } ); 211 foldingSizeLabel = BaseWidgetUtils.createLabel( pagingGroupComposite, "Folding size: ", 1 ); 212 foldingSizeLabel.setEnabled( enableFoldingButton.getSelection() ); 213 foldingSizeText = BaseWidgetUtils.createText( pagingGroupComposite, getPreferenceStore().getString( 214 BrowserCommonConstants.PREFERENCE_BROWSER_FOLDING_SIZE ), 4, 1 ); 215 foldingSizeText.setEnabled( enableFoldingButton.getSelection() ); 216 foldingSizeText.addVerifyListener( new VerifyListener() 217 { 218 public void verifyText( VerifyEvent e ) 219 { 220 if ( !e.text.matches( "[0-9]*" ) ) 221 { 222 e.doit = false; 223 } 224 if ( "".equals( foldingSizeText.getText() ) && e.text.matches( "[0]" ) ) 225 { 226 e.doit = false; 227 } 228 } 229 } ); 230 231 BaseWidgetUtils.createSpacer( composite, 1 ); 232 BaseWidgetUtils.createSpacer( composite, 1 ); 233 expandBaseEntriesButton = BaseWidgetUtils.createCheckbox( composite, 234 "Expand base entries when opening connection", 1 ); 235 expandBaseEntriesButton.setSelection( getPreferenceStore().getBoolean( 236 BrowserCommonConstants.PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES ) ); 237 Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences(); 238 checkForChildrenButton = BaseWidgetUtils.createCheckbox( composite, "Check for children", 1 ); 239 checkForChildrenButton 240 .setSelection( coreStore.getBoolean( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN ) ); 241 showAliasAndReferralObjectsButton = BaseWidgetUtils.createCheckbox( composite, 242 "Show alias and referral objects", 1 ); 243 showAliasAndReferralObjectsButton.setSelection( coreStore 244 .getBoolean( BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS ) ); 245 fetchSubentriesButton = BaseWidgetUtils.createCheckbox( composite, 246 "Fetch subentries (requires additional search request)", 1 ); 247 fetchSubentriesButton.setSelection( coreStore.getBoolean( BrowserCoreConstants.PREFERENCE_FETCH_SUBENTRIES ) ); 248 249 updateEnabled(); 250 251 applyDialogFont( composite ); 252 253 return composite; 254 } 255 256 257 private void updateEnabled() 258 { 259 entryAbbreviateMaxLengthText.setEnabled( entryAbbreviateButton.getSelection() ); 260 searchResultAbbreviateMaxLengthText.setEnabled( searchResultAbbreviateButton.getSelection() ); 261 foldingSizeText.setEnabled( enableFoldingButton.getSelection() ); 262 foldingSizeLabel.setEnabled( enableFoldingButton.getSelection() ); 263 } 264 265 266 public boolean performOk() 267 { 268 269 Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences(); 270 coreStore.setValue( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN, this.checkForChildrenButton 271 .getSelection() ); 272 coreStore.setValue( BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS, 273 this.showAliasAndReferralObjectsButton.getSelection() ); 274 coreStore 275 .setValue( BrowserCoreConstants.PREFERENCE_FETCH_SUBENTRIES, this.fetchSubentriesButton.getSelection() ); 276 BrowserCorePlugin.getDefault().savePluginPreferences(); 277 278 getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES, 279 this.expandBaseEntriesButton.getSelection() ); 280 281 getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_ENABLE_FOLDING, 282 this.enableFoldingButton.getSelection() ); 283 getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_FOLDING_SIZE, 284 this.foldingSizeText.getText().trim() ); 285 286 getPreferenceStore().setValue( 287 BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL, 288 this.entryLabelCombo.getSelectionIndex() == 2 ? BrowserCommonConstants.SHOW_RDN_VALUE : this.entryLabelCombo 289 .getSelectionIndex() == 1 ? BrowserCommonConstants.SHOW_RDN : BrowserCommonConstants.SHOW_DN ); 290 getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE, 291 this.entryAbbreviateButton.getSelection() ); 292 getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH, 293 this.entryAbbreviateMaxLengthText.getText().trim() ); 294 295 getPreferenceStore().setValue( 296 BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL, 297 this.searchResultLabelCombo.getSelectionIndex() == 2 ? BrowserCommonConstants.SHOW_RDN_VALUE 298 : this.searchResultLabelCombo.getSelectionIndex() == 1 ? BrowserCommonConstants.SHOW_RDN 299 : BrowserCommonConstants.SHOW_DN ); 300 getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE, 301 this.searchResultAbbreviateButton.getSelection() ); 302 getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH, 303 this.searchResultAbbreviateMaxLengthText.getText().trim() ); 304 305 return true; 306 } 307 308 309 protected void performDefaults() 310 { 311 312 entryLabelCombo 313 .select( getPreferenceStore().getDefaultInt( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL ) == BrowserCommonConstants.SHOW_RDN_VALUE ? 2 314 : getPreferenceStore().getDefaultInt( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL ) == BrowserCommonConstants.SHOW_RDN ? 1 315 : 0 ); 316 entryAbbreviateButton.setSelection( getPreferenceStore().getDefaultBoolean( 317 BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE ) ); 318 entryAbbreviateMaxLengthText.setText( getPreferenceStore().getDefaultString( 319 BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH ) ); 320 321 searchResultLabelCombo 322 .select( getPreferenceStore().getDefaultInt( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL ) == BrowserCommonConstants.SHOW_RDN_VALUE ? 2 323 : getPreferenceStore().getDefaultInt( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL ) == BrowserCommonConstants.SHOW_RDN ? 1 324 : 0 ); 325 searchResultAbbreviateButton.setSelection( getPreferenceStore().getDefaultBoolean( 326 BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE ) ); 327 searchResultAbbreviateMaxLengthText.setText( getPreferenceStore().getDefaultString( 328 BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH ) ); 329 330 enableFoldingButton.setSelection( getPreferenceStore().getDefaultBoolean( 331 BrowserCommonConstants.PREFERENCE_BROWSER_ENABLE_FOLDING ) ); 332 foldingSizeText.setText( getPreferenceStore().getDefaultString( 333 BrowserCommonConstants.PREFERENCE_BROWSER_FOLDING_SIZE ) ); 334 335 expandBaseEntriesButton.setSelection( getPreferenceStore().getDefaultBoolean( 336 BrowserCommonConstants.PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES ) ); 337 Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences(); 338 checkForChildrenButton.setSelection( coreStore 339 .getDefaultBoolean( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN ) ); 340 showAliasAndReferralObjectsButton.setSelection( coreStore 341 .getDefaultBoolean( BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS ) ); 342 fetchSubentriesButton.setSelection( coreStore 343 .getDefaultBoolean( BrowserCoreConstants.PREFERENCE_FETCH_SUBENTRIES ) ); 344 345 updateEnabled(); 346 347 super.performDefaults(); 348 } 349 350 } 351 | Popular Tags |