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 SchemasViewPreferencePage extends PreferencePage implements IWorkbenchPreferencePage 54 { 55 56 public static final String ID = Activator.PLUGIN_ID + ".preferences.schemasView"; 58 59 private static final String FIRST_NAME = Messages.getString( "SchemasViewPreferencePage.First_Name" ); 61 62 private static final String ALL_ALIASES = Messages.getString( "SchemasViewPreferencePage.All_Aliases" ); 64 65 private static final String OID = Messages.getString( "SchemasViewPreferencePage.OID" ); 67 private Combo labelCombo; 69 private Button limitButton; 70 private Text lengthText; 71 72 73 76 public SchemasViewPreferencePage() 77 { 78 super(); 79 super.setPreferenceStore( Activator.getDefault().getPreferenceStore() ); 80 super 81 .setDescription( Messages 82 .getString( "SchemasViewPreferencePage.General_settings_for_the_Schemas_View_of_the_Schemas_Editor_Plugin" ) ); } 84 85 86 89 protected Control createContents( Composite parent ) 90 { 91 Composite composite = new Composite( parent, SWT.NONE ); 92 GridLayout gl = new GridLayout( 1, false ); 93 gl.marginHeight = gl.marginWidth = 0; 94 composite.setLayout( gl ); 95 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 96 gd.horizontalSpan = 1; 97 composite.setLayoutData( gd ); 98 99 Group labelGroup = new Group( composite, SWT.NONE ); 101 labelGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 102 labelGroup.setText( Messages.getString( "SchemasViewPreferencePage.Label" ) ); labelGroup.setLayout( new GridLayout() ); 104 Composite labelGroupComposite = new Composite( labelGroup, SWT.NONE ); 105 gl = new GridLayout( 1, false ); 106 gl.marginHeight = gl.marginWidth = 0; 107 labelGroupComposite.setLayout( gl ); 108 labelGroupComposite.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 109 110 Composite labelComposite = new Composite( labelGroupComposite, SWT.NONE ); 112 gl = new GridLayout( 3, false ); 113 gl.marginHeight = gl.marginWidth = 0; 114 labelComposite.setLayout( gl ); 115 gd = new GridData( GridData.FILL_HORIZONTAL ); 116 gd.horizontalSpan = 1; 117 labelComposite.setLayoutData( gd ); 118 119 Label useLabel = new Label( labelComposite, SWT.NONE ); 121 useLabel.setText( Messages.getString( "SchemasViewPreferencePage.Use" ) ); 123 labelCombo = new Combo( labelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); 125 labelCombo.setLayoutData( new GridData() ); 126 labelCombo.setItems( new String [] 127 { FIRST_NAME, ALL_ALIASES, OID } ); 128 labelCombo.setEnabled( true ); 129 130 Label asLabel = new Label( labelComposite, SWT.NONE ); 132 asLabel.setText( Messages.getString( "SchemasViewPreferencePage.as_label." ) ); 134 Composite abbreviateComposite = new Composite( labelGroupComposite, SWT.NONE ); 136 gl = new GridLayout( 3, false ); 137 gl.marginHeight = gl.marginWidth = 0; 138 abbreviateComposite.setLayout( gl ); 139 gd = new GridData( GridData.FILL_HORIZONTAL ); 140 gd.horizontalSpan = 1; 141 abbreviateComposite.setLayoutData( gd ); 142 143 limitButton = new Button( abbreviateComposite, SWT.CHECK ); 145 limitButton.setText( Messages.getString( "SchemasViewPreferencePage.Limit_label_length_to" ) ); gd = new GridData(); 147 gd.horizontalSpan = 1; 148 limitButton.setLayoutData( gd ); 149 150 lengthText = new Text( abbreviateComposite, SWT.NONE | SWT.BORDER ); 152 GridData gridData = new GridData(); 153 gridData.horizontalSpan = 1; 154 gridData.widthHint = 9 * 3; 155 lengthText.setLayoutData( gridData ); 156 lengthText.setTextLimit( 3 ); 157 lengthText.addVerifyListener( new VerifyListener() 158 { 159 public void verifyText( VerifyEvent e ) 160 { 161 if ( !e.text.matches( "[0-9]*" ) ) { 163 e.doit = false; 164 } 165 if ( "".equals( lengthText.getText() ) && e.text.matches( "[0]" ) ) { 167 e.doit = false; 168 } 169 } 170 } ); 171 172 Label charactersLabel = new Label( abbreviateComposite, SWT.NONE ); 174 charactersLabel.setText( Messages.getString( "SchemasViewPreferencePage.characters." ) ); 176 initFieldsFromPreferences(); 177 178 initListeners(); 179 180 applyDialogFont( parent ); 181 182 return parent; 183 } 184 185 186 189 private void initFieldsFromPreferences() 190 { 191 IPreferenceStore store = Activator.getDefault().getPreferenceStore(); 192 193 labelCombo.select( store.getInt( PluginConstants.PREFS_SCHEMAS_VIEW_LABEL ) ); 194 limitButton.setSelection( store.getBoolean( PluginConstants.PREFS_SCHEMAS_VIEW_ABBREVIATE ) ); 195 lengthText.setEnabled( limitButton.getSelection() ); 196 lengthText.setText( store.getString( PluginConstants.PREFS_SCHEMAS_VIEW_ABBREVIATE_MAX_LENGTH ) ); 197 } 198 199 200 203 private void initListeners() 204 { 205 limitButton.addSelectionListener( new SelectionAdapter() 206 { 207 public void widgetSelected( SelectionEvent e ) 208 { 209 lengthText.setEnabled( limitButton.getSelection() ); 210 } 211 } ); 212 } 213 214 215 218 protected void performDefaults() 219 { 220 IPreferenceStore store = Activator.getDefault().getPreferenceStore(); 221 222 labelCombo.select( store.getDefaultInt( PluginConstants.PREFS_SCHEMAS_VIEW_LABEL ) ); 223 limitButton.setSelection( store.getDefaultBoolean( PluginConstants.PREFS_SCHEMAS_VIEW_ABBREVIATE ) ); 224 lengthText.setEnabled( limitButton.getSelection() ); 225 lengthText.setText( store.getDefaultString( PluginConstants.PREFS_SCHEMAS_VIEW_ABBREVIATE_MAX_LENGTH ) ); 226 227 super.performDefaults(); 228 } 229 230 231 234 public boolean performOk() 235 { 236 IPreferenceStore store = Activator.getDefault().getPreferenceStore(); 237 238 if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( FIRST_NAME ) ) 239 { 240 store.setValue( PluginConstants.PREFS_SCHEMAS_VIEW_LABEL, 241 PluginConstants.PREFS_SCHEMAS_VIEW_LABEL_FIRST_NAME ); 242 } 243 else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( ALL_ALIASES ) ) 244 { 245 store.setValue( PluginConstants.PREFS_SCHEMAS_VIEW_LABEL, 246 PluginConstants.PREFS_SCHEMAS_VIEW_LABEL_ALL_ALIASES ); 247 } 248 else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( OID ) ) 249 { 250 store.setValue( PluginConstants.PREFS_SCHEMAS_VIEW_LABEL, PluginConstants.PREFS_SCHEMAS_VIEW_LABEL_OID ); 251 } 252 store.setValue( PluginConstants.PREFS_SCHEMAS_VIEW_ABBREVIATE, limitButton.getSelection() ); 253 store.setValue( PluginConstants.PREFS_SCHEMAS_VIEW_ABBREVIATE_MAX_LENGTH, lengthText.getText() ); 254 255 return true; 256 } 257 258 259 262 public void init( IWorkbench workbench ) 263 { 264 } 265 } 266 | Popular Tags |