KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 /**
48  * This class implements the Preference page for the Schema Elements View
49  *
50  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
51  * @version $Rev$, $Date$
52  */

53 public class SchemaElementsViewPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
54 {
55     /** The preference page ID */
56     public static final String JavaDoc ID = Activator.PLUGIN_ID + ".preferences.schemaElementsView"; //$NON-NLS-1$
57

58     /** The First Name category */
59     private static final String JavaDoc FIRST_NAME = Messages.getString( "SchemaElementsViewPreferencePage.First_Name" ); //$NON-NLS-1$
60

61     /** The All Aliases category */
62     private static final String JavaDoc ALL_ALIASES = Messages.getString( "SchemaElementsViewPreferencePage.All_Aliases" ); //$NON-NLS-1$
63

64     /** The OID category */
65     private static final String JavaDoc OID = Messages.getString( "SchemaElementsViewPreferencePage.OID" ); //$NON-NLS-1$
66

67     // UI fields
68
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     /**
78      * Creates a new instance of SchemaElementsViewPreferencePage.
79      */

80     public SchemaElementsViewPreferencePage()
81     {
82         super();
83         super.setPreferenceStore( Activator.getDefault().getPreferenceStore() );
84         super
85             .setDescription( Messages
86                 .getString( "SchemaElementsViewPreferencePage.General_settings_for_the_Schema_Elements_View_of_the_Schemas_Editor_Plugin" ) ); //$NON-NLS-1$
87
}
88
89
90     /* (non-Javadoc)
91      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
92      */

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         // Label Group
104
Group labelGroup = new Group( composite, SWT.NONE );
105         labelGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
106         labelGroup.setText( Messages.getString( "SchemaElementsViewPreferencePage.Label" ) ); //$NON-NLS-1$
107
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         // Label row composite
115
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         // Use Label
124
Label useLabel = new Label( labelComposite, SWT.NONE );
125         useLabel.setText( Messages.getString( "SchemaElementsViewPreferencePage.Use" ) ); //$NON-NLS-1$
126

127         // Label Combo
128
labelCombo = new Combo( labelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER );
129         labelCombo.setLayoutData( new GridData() );
130         labelCombo.setItems( new String JavaDoc[]
131             { FIRST_NAME, ALL_ALIASES, OID } );
132         labelCombo.setEnabled( true );
133
134         // As label Label
135
Label asLabel = new Label( labelComposite, SWT.NONE );
136         asLabel.setText( Messages.getString( "SchemaElementsViewPreferencePage.as_label." ) ); //$NON-NLS-1$
137

138         // Abbreviate row composite
139
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         // Limit label lenght to Label
148
limitButton = new Button( abbreviateComposite, SWT.CHECK );
149         limitButton.setText( Messages.getString( "SchemaElementsViewPreferencePage.Limit_label_length_to" ) ); //$NON-NLS-1$
150
gd = new GridData();
151         gd.horizontalSpan = 1;
152         limitButton.setLayoutData( gd );
153
154         // Lenght Text
155
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]*" ) ) //$NON-NLS-1$
166
{
167                     e.doit = false;
168                 }
169                 if ( "".equals( lengthText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$
170
{
171                     e.doit = false;
172                 }
173             }
174         } );
175
176         // Characters Label
177
Label charactersLabel = new Label( abbreviateComposite, SWT.NONE );
178         charactersLabel.setText( Messages.getString( "SchemaElementsViewPreferencePage.characters." ) ); //$NON-NLS-1$
179

180         // Secondary Label Group
181
Group secondaryLabelGroup = new Group( composite, SWT.NONE );
182         secondaryLabelGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
183         secondaryLabelGroup.setText( Messages.getString( "SchemaElementsViewPreferencePage.Secondary_label" ) ); //$NON-NLS-1$
184
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( "SchemaElementsViewPreferencePage.Display_secondary_label." ) ); //$NON-NLS-1$
194

195         // Label row composite
196
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         // Use Label
205
Label useLabel2 = new Label( secondaryLabelComposite, SWT.NONE );
206         useLabel2.setText( Messages.getString( "SchemaElementsViewPreferencePage.Use" ) ); //$NON-NLS-1$
207

208         // Label Combo
209
secondaryLabelCombo = new Combo( secondaryLabelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER );
210         secondaryLabelCombo.setLayoutData( new GridData() );
211         secondaryLabelCombo.setItems( new String JavaDoc[]
212             { FIRST_NAME, ALL_ALIASES, OID } );
213         secondaryLabelCombo.setEnabled( true );
214
215         // As label Label
216
Label asLabel2 = new Label( secondaryLabelComposite, SWT.NONE );
217         asLabel2.setText( Messages.getString( "SchemaElementsViewPreferencePage.as_secondary_label." ) ); //$NON-NLS-1$
218

219         // Abbreviate row composite
220
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         // Limit label lenght to Label
229
secondaryLabelLimitButton = new Button( abbreviateComposite2, SWT.CHECK );
230         secondaryLabelLimitButton.setText( Messages
231             .getString( "SchemaElementsViewPreferencePage.Limit_secondary_label_length_to" ) ); //$NON-NLS-1$
232
gd = new GridData();
233         gd.horizontalSpan = 1;
234         secondaryLabelLimitButton.setLayoutData( gd );
235
236         // Lenght Text
237
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]*" ) ) //$NON-NLS-1$
248
{
249                     e.doit = false;
250                 }
251                 if ( "".equals( secondaryLabelLengthText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$
252
{
253                     e.doit = false;
254                 }
255             }
256         } );
257
258         // Characters Label
259
Label secondaryLabelcharactersLabel = new Label( abbreviateComposite2, SWT.NONE );
260         secondaryLabelcharactersLabel.setText( Messages.getString( "SchemaElementsViewPreferencePage.characters." ) ); //$NON-NLS-1$
261

262         initFieldsFromPreferences();
263
264         initListeners();
265
266         applyDialogFont( parent );
267
268         return parent;
269     }
270
271
272     /**
273      * Initializes the fields from the preferences store.
274      */

275     private void initFieldsFromPreferences()
276     {
277         IPreferenceStore store = Activator.getDefault().getPreferenceStore();
278
279         labelCombo.select( store.getInt( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL ) );
280         limitButton.setSelection( store.getBoolean( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_ABBREVIATE ) );
281         lengthText.setEnabled( limitButton.getSelection() );
282         lengthText.setText( store.getString( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_ABBREVIATE_MAX_LENGTH ) );
283
284         secondaryLabelButtonDisplay.setSelection( store
285             .getBoolean( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_DISPLAY ) );
286         secondaryLabelCombo.select( store.getInt( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL ) );
287         secondaryLabelLimitButton.setSelection( store
288             .getBoolean( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_ABBREVIATE ) );
289         secondaryLabelLengthText.setText( store
290             .getString( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ) );
291         if ( store.getBoolean( PluginConstants.PREFS_SCHEMA_ELEMENTS_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     /**
307      * Initializes the listeners.
308      */

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

351     protected void performDefaults()
352     {
353         IPreferenceStore store = Activator.getDefault().getPreferenceStore();
354
355         labelCombo.select( store.getDefaultInt( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL ) );
356         limitButton.setSelection( store.getDefaultBoolean( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_ABBREVIATE ) );
357         lengthText.setEnabled( limitButton.getSelection() );
358         lengthText.setText( store.getDefaultString( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_ABBREVIATE_MAX_LENGTH ) );
359
360         secondaryLabelButtonDisplay.setSelection( store
361             .getDefaultBoolean( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_DISPLAY ) );
362         secondaryLabelCombo.select( store.getDefaultInt( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL ) );
363         secondaryLabelLimitButton.setSelection( store
364             .getDefaultBoolean( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_ABBREVIATE ) );
365         secondaryLabelLengthText.setText( store
366             .getDefaultString( PluginConstants.PREFS_SCHEMA_ELEMENTS_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     /* (non-Javadoc)
386      * @see org.eclipse.jface.preference.PreferencePage#performOk()
387      */

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_SCHEMA_ELEMENTS_VIEW_LABEL,
395                 PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_FIRST_NAME );
396         }
397         else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( ALL_ALIASES ) )
398         {
399             store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL,
400                 PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_ALL_ALIASES );
401         }
402         else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( OID ) )
403         {
404             store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL,
405                 PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_OID );
406         }
407         store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_ABBREVIATE, limitButton.getSelection() );
408         store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_ABBREVIATE_MAX_LENGTH, lengthText.getText() );
409
410         store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_DISPLAY, secondaryLabelButtonDisplay
411             .getSelection() );
412         if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( FIRST_NAME ) )
413         {
414             store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL,
415                 PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_FIRST_NAME );
416         }
417         else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( ALL_ALIASES ) )
418         {
419             store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL,
420                 PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_ALL_ALIASES );
421         }
422         else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( OID ) )
423         {
424             store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL,
425                 PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_OID );
426         }
427         store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_ABBREVIATE,
428             secondaryLabelLimitButton.getSelection() );
429         store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH,
430             secondaryLabelLengthText.getText() );
431
432         return true;
433     }
434
435
436     /* (non-Javadoc)
437      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
438      */

439     public void init( IWorkbench workbench )
440     {
441     }
442 }
443
Popular Tags