KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > preferences > SchemasEditorPreferencePage


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

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 /**
49  * Schema Preference Page.
50  * From there you can access schema related preferences.
51  *
52  */

53 public class SchemasEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
54 {
55     // UI fields
56
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     /**
66      * Creates a new instance of SchemasEditorPreferencePage.
67      */

68     public SchemasEditorPreferencePage()
69     {
70         super();
71         setPreferenceStore( Activator.getDefault().getPreferenceStore() );
72         setDescription( Messages
73             .getString( "SchemasEditorPreferencePage.General_settings_for_the_Schemas_Editor_Plugin" ) ); //$NON-NLS-1$
74
}
75
76
77     /* (non-Javadoc)
78      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
79      */

80     protected Control createContents( Composite parent )
81     {
82
83         // SPECIFIC CORE SCHEMAS Group
84
Group specificCoreSchemasGroup = new Group( parent, SWT.NONE );
85         specificCoreSchemasGroup.setText( Messages.getString( "SchemasEditorPreferencePage.Core_Schemas" ) ); //$NON-NLS-1$
86
specificCoreSchemasGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
87         specificCoreSchemasGroup.setLayout( new GridLayout( 3, false ) );
88
89         // SPECIFIC CORE SCHEMAS Checkbox
90
specificCoreSchemasCheckbox = new Button( specificCoreSchemasGroup, SWT.CHECK );
91         specificCoreSchemasCheckbox.setText( Messages
92             .getString( "SchemasEditorPreferencePage.Use_specific_core_schemas" ) ); //$NON-NLS-1$
93
specificCoreSchemasCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false, 3, 1 ) );
94
95         // SPECIFIC CORE SCHEMAS Label
96
specificCoreSchemasLabel = new Label( specificCoreSchemasGroup, SWT.NONE );
97         specificCoreSchemasLabel.setText( Messages.getString( "SchemasEditorPreferencePage.Core_schemas_directory" ) ); //$NON-NLS-1$
98

99         // SPECIFIC CORE SCHEMAS Text
100
specificCoreSchemasText = new Text( specificCoreSchemasGroup, SWT.BORDER );
101         specificCoreSchemasText.setEditable( false );
102         specificCoreSchemasText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
103
104         // SPECIFIC CORE SCHEMAS Button
105
specificCoreSchemasButton = new Button( specificCoreSchemasGroup, SWT.PUSH );
106         specificCoreSchemasButton.setText( Messages.getString( "SchemasEditorPreferencePage.Browse..." ) ); //$NON-NLS-1$
107

108         // DEFAULT OID Group
109
Group defaultOidGroup = new Group( parent, SWT.NONE );
110         defaultOidGroup.setText( Messages.getString( "SchemasEditorPreferencePage.Default_OID" ) ); //$NON-NLS-1$
111
defaultOidGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
112         defaultOidGroup.setLayout( new GridLayout( 2, false ) );
113
114         // DEFAULT OID Checkbox
115
defaultOidCheckbox = new Button( defaultOidGroup, SWT.CHECK );
116         defaultOidCheckbox.setText( Messages
117             .getString( "SchemasEditorPreferencePage.Automatically_prefix_new_elements_with_this_OID" ) ); //$NON-NLS-1$
118
defaultOidCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false, 2, 1 ) );
119
120         // DEFAULT OID Label
121
defaultOidLabel = new Label( defaultOidGroup, SWT.NONE );
122         defaultOidLabel.setText( Messages.getString( "SchemasEditorPreferencePage.Your_organizations_default_OID" ) ); //$NON-NLS-1$
123

124         // DEFAULT OID Text
125
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     /**
139      * Initializes the UI Fields from the preferences.
140      */

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     /**
161      * Initializes the listeners.
162      */

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" ) ); //$NON-NLS-1$
182
String JavaDoc 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]*\\.?)*" ) ) //$NON-NLS-1$
204
{
205                     e.doit = false;
206                 }
207             }
208         } );
209     }
210
211
212     /* (non-Javadoc)
213      * @see org.eclipse.jface.preference.PreferencePage#performOk()
214      */

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     /* (non-Javadoc)
231      * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
232      */

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     /* (non-Javadoc)
253      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
254      */

255     public void init( IWorkbench workbench )
256     {
257     }
258 }
259
Popular Tags