KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > views > SchemasViewSortDialog


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.views;
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.dialogs.Dialog;
28 import org.eclipse.jface.dialogs.IDialogConstants;
29 import org.eclipse.jface.preference.IPreferenceStore;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.layout.GridData;
32 import org.eclipse.swt.layout.GridLayout;
33 import org.eclipse.swt.widgets.Button;
34 import org.eclipse.swt.widgets.Combo;
35 import org.eclipse.swt.widgets.Composite;
36 import org.eclipse.swt.widgets.Control;
37 import org.eclipse.swt.widgets.Group;
38 import org.eclipse.swt.widgets.Label;
39 import org.eclipse.swt.widgets.Shell;
40
41
42 /**
43  * This class implements the Schemas View Sorter Dialog.
44  *
45  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
46  * @version $Rev$, $Date$
47  */

48 public class SchemasViewSortDialog extends Dialog
49 {
50     /** The title of the dialog */
51     private static final String JavaDoc DIALOG_TITLE = Messages.getString( "SchemasViewSortDialog.Schemas_View_Sorting" ); //$NON-NLS-1$
52

53     /** The Sorting First Name category */
54     private static final String JavaDoc SORTING_FISTNAME = Messages.getString( "SchemasViewSortDialog.First_Name" ); //$NON-NLS-1$
55

56     /** The Sorting OID category */
57     private static final String JavaDoc SORTING_OID = Messages.getString( "SchemasViewSortDialog.OID" ); //$NON-NLS-1$
58

59     // UI Fields
60
private Button inFoldersButton;
61     private Button mixedButton;
62     private Combo sortingCombo;
63     private Button ascendingButton;
64     private Button descendingButton;
65
66
67     /**
68      * Creates a new instance of SchemasViewSorterDialog.
69      *
70      * @param parentShell
71      * the parent shell
72      */

73     public SchemasViewSortDialog( Shell parentShell )
74     {
75         super( parentShell );
76     }
77
78
79     /* (non-Javadoc)
80      * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
81      */

82     protected void configureShell( Shell newShell )
83     {
84         super.configureShell( newShell );
85         newShell.setText( DIALOG_TITLE );
86     }
87
88
89     /* (non-Javadoc)
90      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
91      */

92     protected Control createDialogArea( Composite parent )
93     {
94         Composite composite = ( Composite ) super.createDialogArea( parent );
95         GridData gd = new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL );
96         // gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
97
composite.setLayoutData( gd );
98
99         // Grouping Group
100
Group groupingGroup = new Group( composite, SWT.NONE );
101         groupingGroup.setLayoutData( new GridData( GridData.FILL_BOTH ) );
102         groupingGroup.setText( Messages.getString( "SchemasViewSortDialog.Grouping" ) ); //$NON-NLS-1$
103
groupingGroup.setLayout( new GridLayout() );
104
105         // Attribute Types first Button
106
inFoldersButton = new Button( groupingGroup, SWT.RADIO );
107         inFoldersButton.setText( Messages
108             .getString( "SchemasViewSortDialog.Group_attribute_types_and_object_classes_in_folders" ) ); //$NON-NLS-1$
109
inFoldersButton.setEnabled( true );
110
111         // Mixed Button
112
mixedButton = new Button( groupingGroup, SWT.RADIO );
113         mixedButton.setText( Messages.getString( "SchemasViewSortDialog.Mixed" ) ); //$NON-NLS-1$
114
mixedButton.setEnabled( true );
115
116         // Sorting Group
117
Group sortingGroup = new Group( composite, SWT.NONE );
118         sortingGroup.setLayoutData( new GridData( GridData.FILL_BOTH ) );
119         sortingGroup.setText( Messages.getString( "SchemasViewSortDialog.Sorting" ) ); //$NON-NLS-1$
120
sortingGroup.setLayout( new GridLayout() );
121         Composite sortingGroupComposite = new Composite( sortingGroup, SWT.NONE );
122         GridLayout gl = new GridLayout( 4, false );
123         gl.marginHeight = gl.marginWidth = 0;
124         sortingGroupComposite.setLayout( gl );
125         sortingGroupComposite.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
126
127         // Sort by Label
128
Label sortByLabel = new Label( sortingGroupComposite, SWT.NONE );
129         sortByLabel.setText( Messages.getString( "SchemasViewSortDialog.Sort_by" ) ); //$NON-NLS-1$
130

131         // Sorting Combo
132
sortingCombo = new Combo( sortingGroupComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER );
133         sortingCombo.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
134         sortingCombo.setItems( new String JavaDoc[]
135             { SORTING_FISTNAME, SORTING_OID } );
136         sortingCombo.setEnabled( true );
137
138         // Ascending Button
139
ascendingButton = new Button( sortingGroupComposite, SWT.RADIO );
140         ascendingButton.setText( Messages.getString( "SchemasViewSortDialog.Ascending" ) ); //$NON-NLS-1$
141
ascendingButton.setEnabled( true );
142
143         // Descending Button
144
descendingButton = new Button( sortingGroupComposite, SWT.RADIO );
145         descendingButton.setText( Messages.getString( "SchemasViewSortDialog.Descending" ) ); //$NON-NLS-1$
146
descendingButton.setEnabled( true );
147
148         initFieldsFromPreferences();
149
150         applyDialogFont( composite );
151         return composite;
152     }
153
154
155     /**
156      * Initializes the fields for the stored preferences.
157      */

158     private void initFieldsFromPreferences()
159     {
160         IPreferenceStore store = Activator.getDefault().getPreferenceStore();
161
162         int grouping = store.getInt( PluginConstants.PREFS_SCHEMAS_VIEW_GROUPING );
163         if ( grouping == PluginConstants.PREFS_SCHEMAS_VIEW_GROUPING_FOLDERS )
164         {
165             inFoldersButton.setSelection( true );
166         }
167         else if ( grouping == PluginConstants.PREFS_SCHEMAS_VIEW_GROUPING_MIXED )
168         {
169             mixedButton.setSelection( true );
170         }
171
172         int sortingBy = store.getInt( PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_BY );
173         if ( sortingBy == PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_BY_FIRSTNAME )
174         {
175             sortingCombo.select( 0 );
176         }
177         else if ( sortingBy == PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_BY_OID )
178         {
179             sortingCombo.select( 1 );
180         }
181
182         int sortingOrder = store.getInt( PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_ORDER );
183         if ( sortingOrder == PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_ORDER_ASCENDING )
184         {
185             ascendingButton.setSelection( true );
186         }
187         else if ( sortingOrder == PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_ORDER_DESCENDING )
188         {
189             descendingButton.setSelection( true );
190         }
191
192     }
193
194
195     /* (non-Javadoc)
196      * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
197      */

198     protected void buttonPressed( int buttonId )
199     {
200         if ( buttonId == IDialogConstants.OK_ID )
201         {
202             IPreferenceStore store = Activator.getDefault().getPreferenceStore();
203             if ( ( inFoldersButton.getSelection() ) & ( !mixedButton.getSelection() ) )
204             {
205                 store.setValue( PluginConstants.PREFS_SCHEMAS_VIEW_GROUPING,
206                     PluginConstants.PREFS_SCHEMAS_VIEW_GROUPING_FOLDERS );
207             }
208             else if ( ( !inFoldersButton.getSelection() ) & ( mixedButton.getSelection() ) )
209             {
210                 store.setValue( PluginConstants.PREFS_SCHEMAS_VIEW_GROUPING,
211                     PluginConstants.PREFS_SCHEMAS_VIEW_GROUPING_MIXED );
212             }
213
214             if ( sortingCombo.getItem( sortingCombo.getSelectionIndex() ).equals( SORTING_FISTNAME ) )
215             {
216                 store.setValue( PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_BY,
217                     PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_BY_FIRSTNAME );
218             }
219             else if ( sortingCombo.getItem( sortingCombo.getSelectionIndex() ).equals( SORTING_OID ) )
220             {
221                 store.setValue( PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_BY,
222                     PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_BY_OID );
223             }
224
225             if ( ascendingButton.getSelection() && !descendingButton.getSelection() )
226             {
227                 store.setValue( PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_ORDER,
228                     PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_ORDER_ASCENDING );
229             }
230             else if ( !ascendingButton.getSelection() && descendingButton.getSelection() )
231             {
232                 store.setValue( PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_ORDER,
233                     PluginConstants.PREFS_SCHEMAS_VIEW_SORTING_ORDER_DESCENDING );
234             }
235         }
236
237         super.buttonPressed( buttonId );
238     }
239 }
240
Popular Tags