1 20 21 package org.apache.directory.ldapstudio.schemas.view.preferences; 22 23 24 import org.apache.directory.ldapstudio.schemas.Activator; 25 import org.apache.directory.ldapstudio.schemas.Messages; 26 import org.apache.directory.ldapstudio.schemas.PluginConstants; 27 import org.eclipse.jface.preference.IPreferenceStore; 28 import org.eclipse.jface.preference.PreferencePage; 29 import org.eclipse.swt.SWT; 30 import org.eclipse.swt.events.SelectionAdapter; 31 import org.eclipse.swt.events.SelectionEvent; 32 import org.eclipse.swt.events.VerifyEvent; 33 import org.eclipse.swt.events.VerifyListener; 34 import org.eclipse.swt.layout.GridData; 35 import org.eclipse.swt.layout.GridLayout; 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 53 public class HierarchyViewPreferencePage extends PreferencePage implements IWorkbenchPreferencePage 54 { 55 56 public static final String ID = Activator.PLUGIN_ID + ".preferences.hierarchyView"; 58 59 private static final String FIRST_NAME = Messages.getString( "HierarchyViewPreferencePage.First_Name" ); 61 62 private static final String ALL_ALIASES = Messages.getString( "HierarchyViewPreferencePage.All_Aliases" ); 64 65 private static final String OID = Messages.getString( "HierarchyViewPreferencePage.OID" ); 67 private Combo labelCombo; 69 private Button limitButton; 70 private Text lengthText; 71 private Button secondaryLabelButtonDisplay; 72 private Combo secondaryLabelCombo; 73 private Button secondaryLabelLimitButton; 74 private Text secondaryLabelLengthText; 75 76 77 80 public HierarchyViewPreferencePage() 81 { 82 super(); 83 super.setPreferenceStore( Activator.getDefault().getPreferenceStore() ); 84 super 85 .setDescription( Messages 86 .getString( "HierarchyViewPreferencePage.General_settings_for_the_Hierarchy_View_of_the_Schemas_Editor_Plugin" ) ); } 88 89 90 93 protected Control createContents( Composite parent ) 94 { 95 Composite composite = new Composite( parent, SWT.NONE ); 96 GridLayout gl = new GridLayout( 1, false ); 97 gl.marginHeight = gl.marginWidth = 0; 98 composite.setLayout( gl ); 99 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 100 gd.horizontalSpan = 1; 101 composite.setLayoutData( gd ); 102 103 Group labelGroup = new Group( composite, SWT.NONE ); 105 labelGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 106 labelGroup.setText( Messages.getString( "HierarchyViewPreferencePage.Label" ) ); labelGroup.setLayout( new GridLayout() ); 108 Composite labelGroupComposite = new Composite( labelGroup, SWT.NONE ); 109 gl = new GridLayout( 1, false ); 110 gl.marginHeight = gl.marginWidth = 0; 111 labelGroupComposite.setLayout( gl ); 112 labelGroupComposite.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 113 114 Composite labelComposite = new Composite( labelGroupComposite, SWT.NONE ); 116 gl = new GridLayout( 3, false ); 117 gl.marginHeight = gl.marginWidth = 0; 118 labelComposite.setLayout( gl ); 119 gd = new GridData( GridData.FILL_HORIZONTAL ); 120 gd.horizontalSpan = 1; 121 labelComposite.setLayoutData( gd ); 122 123 Label useLabel = new Label( labelComposite, SWT.NONE ); 125 useLabel.setText( Messages.getString( "HierarchyViewPreferencePage.Use" ) ); 127 labelCombo = new Combo( labelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); 129 labelCombo.setLayoutData( new GridData() ); 130 labelCombo.setItems( new String [] 131 { FIRST_NAME, ALL_ALIASES, OID } ); 132 labelCombo.setEnabled( true ); 133 134 Label asLabel = new Label( labelComposite, SWT.NONE ); 136 asLabel.setText( Messages.getString( "HierarchyViewPreferencePage.as_label." ) ); 138 Composite abbreviateComposite = new Composite( labelGroupComposite, SWT.NONE ); 140 gl = new GridLayout( 3, false ); 141 gl.marginHeight = gl.marginWidth = 0; 142 abbreviateComposite.setLayout( gl ); 143 gd = new GridData( GridData.FILL_HORIZONTAL ); 144 gd.horizontalSpan = 1; 145 abbreviateComposite.setLayoutData( gd ); 146 147 limitButton = new Button( abbreviateComposite, SWT.CHECK ); 149 limitButton.setText( Messages.getString( "HierarchyViewPreferencePage.Limit_label_length_to" ) ); gd = new GridData(); 151 gd.horizontalSpan = 1; 152 limitButton.setLayoutData( gd ); 153 154 lengthText = new Text( abbreviateComposite, SWT.NONE | SWT.BORDER ); 156 GridData gridData = new GridData(); 157 gridData.horizontalSpan = 1; 158 gridData.widthHint = 9 * 3; 159 lengthText.setLayoutData( gridData ); 160 lengthText.setTextLimit( 3 ); 161 lengthText.addVerifyListener( new VerifyListener() 162 { 163 public void verifyText( VerifyEvent e ) 164 { 165 if ( !e.text.matches( "[0-9]*" ) ) { 167 e.doit = false; 168 } 169 if ( "".equals( lengthText.getText() ) && e.text.matches( "[0]" ) ) { 171 e.doit = false; 172 } 173 } 174 } ); 175 176 Label charactersLabel = new Label( abbreviateComposite, SWT.NONE ); 178 charactersLabel.setText( Messages.getString( "HierarchyViewPreferencePage.characters." ) ); 180 Group secondaryLabelGroup = new Group( composite, SWT.NONE ); 182 secondaryLabelGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 183 secondaryLabelGroup.setText( Messages.getString( "HierarchyViewPreferencePage.Secondary_label" ) ); secondaryLabelGroup.setLayout( new GridLayout() ); 185 Composite secondaryLabelGroupComposite = new Composite( secondaryLabelGroup, SWT.NONE ); 186 gl = new GridLayout( 1, false ); 187 gl.marginHeight = gl.marginWidth = 0; 188 secondaryLabelGroupComposite.setLayout( gl ); 189 secondaryLabelGroupComposite.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 190 191 secondaryLabelButtonDisplay = new Button( secondaryLabelGroupComposite, SWT.CHECK ); 192 secondaryLabelButtonDisplay.setText( Messages 193 .getString( "HierarchyViewPreferencePage.Display_secondary_label." ) ); 195 Composite secondaryLabelComposite = new Composite( secondaryLabelGroupComposite, SWT.NONE ); 197 gl = new GridLayout( 3, false ); 198 gl.marginHeight = gl.marginWidth = 0; 199 secondaryLabelComposite.setLayout( gl ); 200 gd = new GridData( GridData.FILL_HORIZONTAL ); 201 gd.horizontalSpan = 1; 202 secondaryLabelComposite.setLayoutData( gd ); 203 204 Label useLabel2 = new Label( secondaryLabelComposite, SWT.NONE ); 206 useLabel2.setText( Messages.getString( "HierarchyViewPreferencePage.Use" ) ); 208 secondaryLabelCombo = new Combo( secondaryLabelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); 210 secondaryLabelCombo.setLayoutData( new GridData() ); 211 secondaryLabelCombo.setItems( new String [] 212 { FIRST_NAME, ALL_ALIASES, OID } ); 213 secondaryLabelCombo.setEnabled( true ); 214 215 Label asLabel2 = new Label( secondaryLabelComposite, SWT.NONE ); 217 asLabel2.setText( Messages.getString( "HierarchyViewPreferencePage.as_secondary_label." ) ); 219 Composite abbreviateComposite2 = new Composite( secondaryLabelGroup, SWT.NONE ); 221 gl = new GridLayout( 3, false ); 222 gl.marginHeight = gl.marginWidth = 0; 223 abbreviateComposite2.setLayout( gl ); 224 gd = new GridData( GridData.FILL_HORIZONTAL ); 225 gd.horizontalSpan = 1; 226 abbreviateComposite2.setLayoutData( gd ); 227 228 secondaryLabelLimitButton = new Button( abbreviateComposite2, SWT.CHECK ); 230 secondaryLabelLimitButton.setText( Messages 231 .getString( "HierarchyViewPreferencePage.Limit_secondary_label_length_to" ) ); gd = new GridData(); 233 gd.horizontalSpan = 1; 234 secondaryLabelLimitButton.setLayoutData( gd ); 235 236 secondaryLabelLengthText = new Text( abbreviateComposite2, SWT.NONE | SWT.BORDER ); 238 gridData = new GridData(); 239 gridData.horizontalSpan = 1; 240 gridData.widthHint = 9 * 3; 241 secondaryLabelLengthText.setLayoutData( gridData ); 242 secondaryLabelLengthText.setTextLimit( 3 ); 243 secondaryLabelLengthText.addVerifyListener( new VerifyListener() 244 { 245 public void verifyText( VerifyEvent e ) 246 { 247 if ( !e.text.matches( "[0-9]*" ) ) { 249 e.doit = false; 250 } 251 if ( "".equals( secondaryLabelLengthText.getText() ) && e.text.matches( "[0]" ) ) { 253 e.doit = false; 254 } 255 } 256 } ); 257 258 Label secondaryLabelcharactersLabel = new Label( abbreviateComposite2, SWT.NONE ); 260 secondaryLabelcharactersLabel.setText( Messages.getString( "HierarchyViewPreferencePage.characters." ) ); 262 initFieldsFromPreferences(); 263 264 initListeners(); 265 266 applyDialogFont( parent ); 267 268 return parent; 269 } 270 271 272 275 private void initFieldsFromPreferences() 276 { 277 IPreferenceStore store = Activator.getDefault().getPreferenceStore(); 278 279 labelCombo.select( store.getInt( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL ) ); 280 limitButton.setSelection( store.getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE ) ); 281 lengthText.setEnabled( limitButton.getSelection() ); 282 lengthText.setText( store.getString( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE_MAX_LENGTH ) ); 283 284 secondaryLabelButtonDisplay.setSelection( store 285 .getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY ) ); 286 secondaryLabelCombo.select( store.getInt( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL ) ); 287 secondaryLabelLimitButton.setSelection( store 288 .getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE ) ); 289 secondaryLabelLengthText.setText( store 290 .getString( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ) ); 291 if ( store.getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY ) ) 292 { 293 secondaryLabelCombo.setEnabled( true ); 294 secondaryLabelLimitButton.setEnabled( true ); 295 secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); 296 } 297 else 298 { 299 secondaryLabelCombo.setEnabled( false ); 300 secondaryLabelLimitButton.setEnabled( false ); 301 secondaryLabelLengthText.setEnabled( false ); 302 } 303 } 304 305 306 309 private void initListeners() 310 { 311 limitButton.addSelectionListener( new SelectionAdapter() 312 { 313 public void widgetSelected( SelectionEvent e ) 314 { 315 lengthText.setEnabled( limitButton.getSelection() ); 316 } 317 } ); 318 319 secondaryLabelButtonDisplay.addSelectionListener( new SelectionAdapter() 320 { 321 public void widgetSelected( SelectionEvent e ) 322 { 323 if ( secondaryLabelButtonDisplay.getSelection() ) 324 { 325 secondaryLabelCombo.setEnabled( true ); 326 secondaryLabelLimitButton.setEnabled( true ); 327 secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); 328 } 329 else 330 { 331 secondaryLabelCombo.setEnabled( false ); 332 secondaryLabelLimitButton.setEnabled( false ); 333 secondaryLabelLengthText.setEnabled( false ); 334 } 335 } 336 } ); 337 338 secondaryLabelLimitButton.addSelectionListener( new SelectionAdapter() 339 { 340 public void widgetSelected( SelectionEvent e ) 341 { 342 secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); 343 } 344 } ); 345 } 346 347 348 351 protected void performDefaults() 352 { 353 IPreferenceStore store = Activator.getDefault().getPreferenceStore(); 354 355 labelCombo.select( store.getDefaultInt( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL ) ); 356 limitButton.setSelection( store.getDefaultBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE ) ); 357 lengthText.setEnabled( limitButton.getSelection() ); 358 lengthText.setText( store.getDefaultString( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE_MAX_LENGTH ) ); 359 360 secondaryLabelButtonDisplay.setSelection( store 361 .getDefaultBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY ) ); 362 secondaryLabelCombo.select( store.getDefaultInt( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL ) ); 363 secondaryLabelLimitButton.setSelection( store 364 .getDefaultBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE ) ); 365 secondaryLabelLengthText.setText( store 366 .getDefaultString( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ) ); 367 368 if ( secondaryLabelButtonDisplay.getSelection() ) 369 { 370 secondaryLabelCombo.setEnabled( true ); 371 secondaryLabelLimitButton.setEnabled( true ); 372 secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); 373 } 374 else 375 { 376 secondaryLabelCombo.setEnabled( false ); 377 secondaryLabelLimitButton.setEnabled( false ); 378 secondaryLabelLengthText.setEnabled( false ); 379 } 380 381 super.performDefaults(); 382 } 383 384 385 388 public boolean performOk() 389 { 390 IPreferenceStore store = Activator.getDefault().getPreferenceStore(); 391 392 if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( FIRST_NAME ) ) 393 { 394 store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL, 395 PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_FIRST_NAME ); 396 } 397 else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( ALL_ALIASES ) ) 398 { 399 store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL, 400 PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES ); 401 } 402 else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( OID ) ) 403 { 404 store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL, PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_OID ); 405 } 406 store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE, limitButton.getSelection() ); 407 store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE_MAX_LENGTH, lengthText.getText() ); 408 409 store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY, secondaryLabelButtonDisplay 410 .getSelection() ); 411 if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( FIRST_NAME ) ) 412 { 413 store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL, 414 PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_FIRST_NAME ); 415 } 416 else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( ALL_ALIASES ) ) 417 { 418 store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL, 419 PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES ); 420 } 421 else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( OID ) ) 422 { 423 store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL, 424 PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_OID ); 425 } 426 store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE, secondaryLabelLimitButton 427 .getSelection() ); 428 store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH, 429 secondaryLabelLengthText.getText() ); 430 431 return true; 432 } 433 434 435 438 public void init( IWorkbench workbench ) 439 { 440 } 441 } 442 | Popular Tags |