KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > widgets > browser > BrowserSorterDialog


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.browser.common.widgets.browser;
22
23
24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
25 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
26 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
27 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
28 import org.eclipse.jface.dialogs.Dialog;
29 import org.eclipse.jface.dialogs.IDialogConstants;
30 import org.eclipse.jface.preference.IPreferenceStore;
31 import org.eclipse.swt.events.SelectionAdapter;
32 import org.eclipse.swt.events.SelectionEvent;
33 import org.eclipse.swt.events.VerifyEvent;
34 import org.eclipse.swt.events.VerifyListener;
35 import org.eclipse.swt.layout.GridData;
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.Shell;
43 import org.eclipse.swt.widgets.Text;
44
45
46 /**
47  * This class represents the dialog used to change the browser's sort settings.
48  *
49  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
50  * @version $Rev$, $Date$
51  */

52 public class BrowserSorterDialog extends Dialog
53 {
54
55     /** The dialog title. */
56     public static final String JavaDoc DIALOG_TITLE = "Browser Sorting";
57
58     /** The Constant SORT_BY_NONE. */
59     public static final String JavaDoc SORT_BY_NONE = "No Sorting";
60
61     /** The Constant SORT_BY_RDN. */
62     public static final String JavaDoc SORT_BY_RDN = "RDN";
63
64     /** The Constant SORT_BY_RDN_VALUE. */
65     public static final String JavaDoc SORT_BY_RDN_VALUE = "RDN Value";
66
67     /** The browser preferences. */
68     private BrowserPreferences preferences;
69
70     /** The sort by combo. */
71     private Combo sortByCombo;
72
73     /** The sort acending button. */
74     private Button sortAcendingButton;
75
76     /** The sort descending button. */
77     private Button sortDescendingButton;
78
79     /** The leaf entries first button. */
80     private Button leafEntriesFirstButton;
81
82     /** The meta entries last button. */
83     private Button metaEntriesLastButton;
84
85     /** The sort limit text. */
86     private Text sortLimitText;
87
88
89     /**
90      * Creates a new instance of BrowserSorterDialog.
91      *
92      * @param parentShell the parent shell
93      * @param preferences the browser preferences
94      */

95     public BrowserSorterDialog( Shell parentShell, BrowserPreferences preferences )
96     {
97         super( parentShell );
98         this.preferences = preferences;
99     }
100
101
102     /**
103      * {@inheritDoc}
104      *
105      * This implementation calls its super implementation and sets the dialog title.
106      */

107     protected void configureShell( Shell newShell )
108     {
109         super.configureShell( newShell );
110         newShell.setText( DIALOG_TITLE );
111     }
112
113
114     /**
115      * {@inheritDoc}
116      *
117      * This implementation save the changed settings when OK is pressed.
118      */

119     protected void buttonPressed( int buttonId )
120     {
121         if ( buttonId == IDialogConstants.OK_ID )
122         {
123             int sortLimit = preferences.getSortLimit();
124             try
125             {
126                 sortLimit = Integer.parseInt( sortLimitText.getText().trim() );
127             }
128             catch ( NumberFormatException JavaDoc nfe )
129             {
130             }
131
132             IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore();
133             store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_LEAF_ENTRIES_FIRST, leafEntriesFirstButton
134                 .getSelection() );
135             store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_META_ENTRIES_LAST, metaEntriesLastButton
136                 .getSelection() );
137             store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_LIMIT, sortLimit );
138             store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_ORDER,
139                 sortDescendingButton.getSelection() ? BrowserCoreConstants.SORT_ORDER_DESCENDING
140                     : BrowserCoreConstants.SORT_ORDER_ASCENDING );
141             store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BY,
142                 sortByCombo.getSelectionIndex() == 2 ? BrowserCoreConstants.SORT_BY_RDN_VALUE : sortByCombo
143                     .getSelectionIndex() == 1 ? BrowserCoreConstants.SORT_BY_RDN : BrowserCoreConstants.SORT_BY_NONE );
144         }
145         else
146         {
147             // no changes
148
}
149
150         super.buttonPressed( buttonId );
151     }
152
153
154     /**
155      * {@inheritDoc}
156      */

157     protected Control createDialogArea( Composite parent )
158     {
159
160         Composite composite = ( Composite ) super.createDialogArea( parent );
161         GridData gd = new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL );
162         gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
163         composite.setLayoutData( gd );
164
165         Group groupingGroup = BaseWidgetUtils.createGroup( composite, "Group entries", 1 );
166
167         leafEntriesFirstButton = BaseWidgetUtils.createCheckbox( groupingGroup, "Leaf enties first", 1 );
168         leafEntriesFirstButton
169             .setToolTipText( "This option displays entries without children before entries with children." );
170         leafEntriesFirstButton.setSelection( preferences.isLeafEntriesFirst() );
171
172         metaEntriesLastButton = BaseWidgetUtils.createCheckbox( groupingGroup, "Meta entries last", 1 );
173         metaEntriesLastButton
174             .setToolTipText( "This option displays meta entries after normal entries. Meta entries are e.g. the root DSE or the schema entry." );
175         metaEntriesLastButton.setSelection( preferences.isMetaEntriesLast() );
176
177         Group sortingGroup = BaseWidgetUtils.createGroup( composite, "Sort entries", 1 );
178
179         Composite sortByComposite = BaseWidgetUtils.createColumnContainer( sortingGroup, 4, 1 );
180         BaseWidgetUtils.createLabel( sortByComposite, "Sort by", 1 );
181         sortByCombo = BaseWidgetUtils.createReadonlyCombo( sortByComposite, new String JavaDoc[]
182             { SORT_BY_NONE, SORT_BY_RDN, SORT_BY_RDN_VALUE }, 0, 1 );
183         sortByCombo.select( preferences.getSortBy() == BrowserCoreConstants.SORT_BY_RDN_VALUE ? 2 : preferences
184             .getSortBy() == BrowserCoreConstants.SORT_BY_RDN ? 1 : 0 );
185         sortByCombo.addSelectionListener( new SelectionAdapter()
186         {
187             public void widgetSelected( SelectionEvent e )
188             {
189                 sortAcendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
190                 sortDescendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
191                 sortLimitText.setEnabled( sortByCombo.getSelectionIndex() != 0 );
192             }
193         } );
194
195         sortAcendingButton = BaseWidgetUtils.createRadiobutton( sortByComposite, "Ascending", 1 );
196         sortAcendingButton.setSelection( preferences.getSortOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING );
197         sortAcendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
198
199         sortDescendingButton = BaseWidgetUtils.createRadiobutton( sortByComposite, "Descending", 1 );
200         sortDescendingButton.setSelection( preferences.getSortOrder() == BrowserCoreConstants.SORT_ORDER_DESCENDING );
201         sortDescendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
202
203         Composite sortLimitComposite = BaseWidgetUtils.createColumnContainer( sortingGroup, 2, 1 );
204         String JavaDoc sortLimitTooltip = "If there are more than the specified number of children they won't be sorted. Hint: For performance reason the maximum value should be 10.000!";
205         Label sortLimitLabel = BaseWidgetUtils.createLabel( sortLimitComposite, "Sort limit:", 1 );
206         sortLimitLabel.setToolTipText( sortLimitTooltip );
207         sortLimitText = BaseWidgetUtils.createText( sortLimitComposite, "" + preferences.getSortLimit(), 5, 1 );
208         sortLimitText.setToolTipText( sortLimitTooltip );
209         sortLimitText.setEnabled( sortByCombo.getSelectionIndex() != 0 );
210         sortLimitText.addVerifyListener( new VerifyListener()
211         {
212             public void verifyText( VerifyEvent e )
213             {
214                 if ( !e.text.matches( "[0-9]*" ) )
215                 {
216                     e.doit = false;
217                 }
218             }
219         } );
220
221         applyDialogFont( composite );
222         return composite;
223     }
224
225 }
226
Popular Tags