KickJava   Java API By Example, From Geeks To Geeks.

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


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 Schema Elements 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 SchemaElementsViewSortDialog extends Dialog
49 {
50     /** The title of the dialog */
51     private static final String JavaDoc DIALOG_TITLE = Messages
52         .getString( "SchemaElementsViewSortDialog.Schema_Elements_View_Sorting" ); //$NON-NLS-1$
53

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

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

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

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

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

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

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

164     private void initFieldsFromPreferences()
165     {
166         IPreferenceStore store = Activator.getDefault().getPreferenceStore();
167
168         int grouping = store.getInt( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_GROUPING );
169         if ( grouping == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_GROUPING_ATFIRST )
170         {
171             atFirstButton.setSelection( true );
172         }
173         else if ( grouping == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_GROUPING_OCFIRST )
174         {
175             ocFirstButton.setSelection( true );
176         }
177         else if ( grouping == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_GROUPING_MIXED )
178         {
179             mixedButton.setSelection( true );
180         }
181
182         int sortingBy = store.getInt( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_BY );
183         if ( sortingBy == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_BY_FIRSTNAME )
184         {
185             sortingCombo.select( 0 );
186         }
187         else if ( sortingBy == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_BY_OID )
188         {
189             sortingCombo.select( 1 );
190         }
191
192         int sortingOrder = store.getInt( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_ORDER );
193         if ( sortingOrder == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_ORDER_ASCENDING )
194         {
195             ascendingButton.setSelection( true );
196         }
197         else if ( sortingOrder == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_ORDER_DESCENDING )
198         {
199             descendingButton.setSelection( true );
200         }
201
202     }
203
204
205     /* (non-Javadoc)
206      * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
207      */

208     protected void buttonPressed( int buttonId )
209     {
210         if ( buttonId == IDialogConstants.OK_ID )
211         {
212             IPreferenceStore store = Activator.getDefault().getPreferenceStore();
213             if ( ( atFirstButton.getSelection() ) & ( !ocFirstButton.getSelection() ) & ( !mixedButton.getSelection() ) )
214             {
215                 store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_GROUPING,
216                     PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_GROUPING_ATFIRST );
217             }
218             else if ( ( !atFirstButton.getSelection() ) & ( ocFirstButton.getSelection() )
219                 & ( !mixedButton.getSelection() ) )
220             {
221                 store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_GROUPING,
222                     PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_GROUPING_OCFIRST );
223             }
224             else if ( ( !atFirstButton.getSelection() ) & ( !ocFirstButton.getSelection() )
225                 & ( mixedButton.getSelection() ) )
226             {
227                 store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_GROUPING,
228                     PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_GROUPING_MIXED );
229             }
230
231             if ( sortingCombo.getItem( sortingCombo.getSelectionIndex() ).equals( SORTING_FISTNAME ) )
232             {
233                 store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_BY,
234                     PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_BY_FIRSTNAME );
235             }
236             else if ( sortingCombo.getItem( sortingCombo.getSelectionIndex() ).equals( SORTING_OID ) )
237             {
238                 store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_BY,
239                     PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_BY_OID );
240             }
241
242             if ( ascendingButton.getSelection() && !descendingButton.getSelection() )
243             {
244                 store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_ORDER,
245                     PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_ORDER_ASCENDING );
246             }
247             else if ( !ascendingButton.getSelection() && descendingButton.getSelection() )
248             {
249                 store.setValue( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_ORDER,
250                     PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_ORDER_DESCENDING );
251             }
252         }
253
254         super.buttonPressed( buttonId );
255     }
256 }
257
Popular Tags