KickJava   Java API By Example, From Geeks To Geeks.

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


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 Schemas View
49  *
50  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
51  * @version $Rev$, $Date$
52  */

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

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

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

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

67     // UI fields
68
private Combo labelCombo;
69     private Button limitButton;
70     private Text lengthText;
71
72
73     /**
74      * Creates a new instance of SchemasViewPreferencePage.
75      */

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" ) ); //$NON-NLS-1$
83
}
84
85
86     /* (non-Javadoc)
87      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
88      */

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         // Label Group
100
Group labelGroup = new Group( composite, SWT.NONE );
101         labelGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
102         labelGroup.setText( Messages.getString( "SchemasViewPreferencePage.Label" ) ); //$NON-NLS-1$
103
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         // Label row composite
111
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         // Use Label
120
Label useLabel = new Label( labelComposite, SWT.NONE );
121         useLabel.setText( Messages.getString( "SchemasViewPreferencePage.Use" ) ); //$NON-NLS-1$
122

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

134         // Abbreviate row composite
135
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         // Limit label lenght to Label
144
limitButton = new Button( abbreviateComposite, SWT.CHECK );
145         limitButton.setText( Messages.getString( "SchemasViewPreferencePage.Limit_label_length_to" ) ); //$NON-NLS-1$
146
gd = new GridData();
147         gd.horizontalSpan = 1;
148         limitButton.setLayoutData( gd );
149
150         // Lenght Text
151
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]*" ) ) //$NON-NLS-1$
162
{
163                     e.doit = false;
164                 }
165                 if ( "".equals( lengthText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$
166
{
167                     e.doit = false;
168                 }
169             }
170         } );
171
172         // Characters Label
173
Label charactersLabel = new Label( abbreviateComposite, SWT.NONE );
174         charactersLabel.setText( Messages.getString( "SchemasViewPreferencePage.characters." ) ); //$NON-NLS-1$
175

176         initFieldsFromPreferences();
177
178         initListeners();
179
180         applyDialogFont( parent );
181
182         return parent;
183     }
184
185
186     /**
187      * Initializes the fields from the preferences store.
188      */

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     /**
201      * Initializes the listeners.
202      */

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

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

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

262     public void init( IWorkbench workbench )
263     {
264     }
265 }
266
Popular Tags