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.Composite; 38 import org.eclipse.swt.widgets.Control; 39 import org.eclipse.swt.widgets.DirectoryDialog; 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 import org.eclipse.ui.PlatformUI; 46 47 48 53 public class SchemasEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage 54 { 55 private Button specificCoreSchemasCheckbox; 57 private Label specificCoreSchemasLabel; 58 private Text specificCoreSchemasText; 59 private Button specificCoreSchemasButton; 60 private Button defaultOidCheckbox; 61 private Label defaultOidLabel; 62 private Text defaultOidText; 63 64 65 68 public SchemasEditorPreferencePage() 69 { 70 super(); 71 setPreferenceStore( Activator.getDefault().getPreferenceStore() ); 72 setDescription( Messages 73 .getString( "SchemasEditorPreferencePage.General_settings_for_the_Schemas_Editor_Plugin" ) ); } 75 76 77 80 protected Control createContents( Composite parent ) 81 { 82 83 Group specificCoreSchemasGroup = new Group( parent, SWT.NONE ); 85 specificCoreSchemasGroup.setText( Messages.getString( "SchemasEditorPreferencePage.Core_Schemas" ) ); specificCoreSchemasGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 87 specificCoreSchemasGroup.setLayout( new GridLayout( 3, false ) ); 88 89 specificCoreSchemasCheckbox = new Button( specificCoreSchemasGroup, SWT.CHECK ); 91 specificCoreSchemasCheckbox.setText( Messages 92 .getString( "SchemasEditorPreferencePage.Use_specific_core_schemas" ) ); specificCoreSchemasCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false, 3, 1 ) ); 94 95 specificCoreSchemasLabel = new Label( specificCoreSchemasGroup, SWT.NONE ); 97 specificCoreSchemasLabel.setText( Messages.getString( "SchemasEditorPreferencePage.Core_schemas_directory" ) ); 99 specificCoreSchemasText = new Text( specificCoreSchemasGroup, SWT.BORDER ); 101 specificCoreSchemasText.setEditable( false ); 102 specificCoreSchemasText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 103 104 specificCoreSchemasButton = new Button( specificCoreSchemasGroup, SWT.PUSH ); 106 specificCoreSchemasButton.setText( Messages.getString( "SchemasEditorPreferencePage.Browse..." ) ); 108 Group defaultOidGroup = new Group( parent, SWT.NONE ); 110 defaultOidGroup.setText( Messages.getString( "SchemasEditorPreferencePage.Default_OID" ) ); defaultOidGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 112 defaultOidGroup.setLayout( new GridLayout( 2, false ) ); 113 114 defaultOidCheckbox = new Button( defaultOidGroup, SWT.CHECK ); 116 defaultOidCheckbox.setText( Messages 117 .getString( "SchemasEditorPreferencePage.Automatically_prefix_new_elements_with_this_OID" ) ); defaultOidCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false, 2, 1 ) ); 119 120 defaultOidLabel = new Label( defaultOidGroup, SWT.NONE ); 122 defaultOidLabel.setText( Messages.getString( "SchemasEditorPreferencePage.Your_organizations_default_OID" ) ); 124 defaultOidText = new Text( defaultOidGroup, SWT.BORDER ); 126 defaultOidText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 127 128 initFieldsFromPreferences(); 129 130 initListeners(); 131 132 applyDialogFont( parent ); 133 134 return parent; 135 } 136 137 138 141 private void initFieldsFromPreferences() 142 { 143 IPreferenceStore store = Activator.getDefault().getPreferenceStore(); 144 145 specificCoreSchemasCheckbox 146 .setSelection( store.getBoolean( PluginConstants.PREFS_SCHEMAS_EDITOR_SPECIFIC_CORE ) ); 147 specificCoreSchemasLabel.setEnabled( specificCoreSchemasCheckbox.getSelection() ); 148 specificCoreSchemasText.setEnabled( specificCoreSchemasCheckbox.getSelection() ); 149 specificCoreSchemasText 150 .setText( store.getString( PluginConstants.PREFS_SCHEMAS_EDITOR_SPECIFIC_CORE_DIRECTORY ) ); 151 specificCoreSchemasButton.setEnabled( specificCoreSchemasCheckbox.getSelection() ); 152 153 defaultOidCheckbox.setSelection( store.getBoolean( PluginConstants.PREFS_SCHEMAS_EDITOR_AUTO_OID ) ); 154 defaultOidLabel.setEnabled( defaultOidCheckbox.getSelection() ); 155 defaultOidText.setEnabled( defaultOidCheckbox.getSelection() ); 156 defaultOidText.setText( store.getString( PluginConstants.PREFS_SCHEMAS_EDITOR_COMPANY_OID ) ); 157 } 158 159 160 163 private void initListeners() 164 { 165 specificCoreSchemasCheckbox.addSelectionListener( new SelectionAdapter() 166 { 167 public void widgetSelected( SelectionEvent e ) 168 { 169 specificCoreSchemasLabel.setEnabled( specificCoreSchemasCheckbox.getSelection() ); 170 specificCoreSchemasText.setEnabled( specificCoreSchemasCheckbox.getSelection() ); 171 specificCoreSchemasButton.setEnabled( specificCoreSchemasCheckbox.getSelection() ); 172 } 173 } ); 174 175 specificCoreSchemasButton.addSelectionListener( new SelectionAdapter() 176 { 177 public void widgetSelected( SelectionEvent e ) 178 { 179 DirectoryDialog dd = new DirectoryDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow() 180 .getShell() ); 181 dd.setFilterPath( System.getProperty( "user.home" ) ); String selectedFolder = dd.open(); 183 if ( selectedFolder != null ) 184 { 185 specificCoreSchemasText.setText( selectedFolder ); 186 } 187 } 188 } ); 189 190 defaultOidCheckbox.addSelectionListener( new SelectionAdapter() 191 { 192 public void widgetSelected( SelectionEvent e ) 193 { 194 defaultOidLabel.setEnabled( defaultOidCheckbox.getSelection() ); 195 defaultOidText.setEnabled( defaultOidCheckbox.getSelection() ); 196 } 197 } ); 198 199 defaultOidText.addVerifyListener( new VerifyListener() 200 { 201 public void verifyText( VerifyEvent e ) 202 { 203 if ( !e.text.matches( "([0-9]*\\.?)*" ) ) { 205 e.doit = false; 206 } 207 } 208 } ); 209 } 210 211 212 215 public boolean performOk() 216 { 217 IPreferenceStore store = Activator.getDefault().getPreferenceStore(); 218 219 store.setValue( PluginConstants.PREFS_SCHEMAS_EDITOR_SPECIFIC_CORE, specificCoreSchemasCheckbox.getSelection() ); 220 store 221 .setValue( PluginConstants.PREFS_SCHEMAS_EDITOR_SPECIFIC_CORE_DIRECTORY, specificCoreSchemasText.getText() ); 222 223 store.setValue( PluginConstants.PREFS_SCHEMAS_EDITOR_AUTO_OID, defaultOidCheckbox.getSelection() ); 224 store.setValue( PluginConstants.PREFS_SCHEMAS_EDITOR_COMPANY_OID, defaultOidText.getText() ); 225 226 return super.performOk(); 227 } 228 229 230 233 protected void performDefaults() 234 { 235 IPreferenceStore store = Activator.getDefault().getPreferenceStore(); 236 237 specificCoreSchemasCheckbox.setSelection( store 238 .getDefaultBoolean( PluginConstants.PREFS_SCHEMAS_EDITOR_SPECIFIC_CORE ) ); 239 specificCoreSchemasLabel.setEnabled( specificCoreSchemasCheckbox.getSelection() ); 240 specificCoreSchemasText.setEnabled( specificCoreSchemasCheckbox.getSelection() ); 241 specificCoreSchemasText.setText( store 242 .getDefaultString( PluginConstants.PREFS_SCHEMAS_EDITOR_SPECIFIC_CORE_DIRECTORY ) ); 243 specificCoreSchemasButton.setEnabled( specificCoreSchemasCheckbox.getSelection() ); 244 245 defaultOidCheckbox.setSelection( store.getDefaultBoolean( PluginConstants.PREFS_SCHEMAS_EDITOR_AUTO_OID ) ); 246 defaultOidLabel.setEnabled( defaultOidCheckbox.getSelection() ); 247 defaultOidText.setEnabled( defaultOidCheckbox.getSelection() ); 248 defaultOidText.setText( store.getDefaultString( PluginConstants.PREFS_SCHEMAS_EDITOR_COMPANY_OID ) ); 249 } 250 251 252 255 public void init( IWorkbench workbench ) 256 { 257 } 258 } 259 | Popular Tags |