KickJava   Java API By Example, From Geeks To Geeks.

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


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.entryeditor;
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.layout.GridData;
34 import org.eclipse.swt.widgets.Button;
35 import org.eclipse.swt.widgets.Combo;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Control;
38 import org.eclipse.swt.widgets.Group;
39 import org.eclipse.swt.widgets.Shell;
40
41
42 /**
43  * This class represents the dialog used to change the entry editors's default sort preferences.
44  *
45  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
46  * @version $Rev$, $Date$
47  */

48 public class EntryEditorWidgetSorterDialog extends Dialog
49 {
50
51     /** The Constant DIALOG_TITLE. */
52     public static final String JavaDoc DIALOG_TITLE = "Entry Editor Sorting";
53
54     /** The Constant SORT_BY_NONE. */
55     public static final String JavaDoc SORT_BY_NONE = "No Default Sorting";
56
57     /** The Constant SORT_BY_ATTRIBUTE. */
58     public static final String JavaDoc SORT_BY_ATTRIBUTE = "Attribute Description";
59
60     /** The Constant SORT_BY_VALUE. */
61     public static final String JavaDoc SORT_BY_VALUE = "Value";
62
63     /** The preferences. */
64     private EntryEditorWidgetPreferences preferences;
65
66     /** The object class and must attributes first button. */
67     private Button objectClassAndMustAttributesFirstButton;
68
69     /** The operational attributes last button. */
70     private Button operationalAttributesLastButton;
71
72     /** The sort by combo. */
73     private Combo sortByCombo;
74
75     /** The sort acending button. */
76     private Button sortAcendingButton;
77
78     /** The sort descending button. */
79     private Button sortDescendingButton;
80
81
82     /**
83      * Creates a new instance of EntryEditorWidgetSorterDialog.
84      *
85      * @param parentShell the parent shell
86      * @param preferences the preferences
87      */

88     public EntryEditorWidgetSorterDialog( Shell parentShell, EntryEditorWidgetPreferences preferences )
89     {
90         super( parentShell );
91         this.preferences = preferences;
92     }
93
94
95     /**
96      * {@inheritDoc}
97      *
98      * This implementation calls its super implementation and sets the dialog's title.
99      */

100     protected void configureShell( Shell newShell )
101     {
102         super.configureShell( newShell );
103         newShell.setText( DIALOG_TITLE );
104     }
105
106
107     /**
108      * {@inheritDoc}
109      *
110      * This implementation saves the changed settings when OK is pressed.
111      */

112     protected void buttonPressed( int buttonId )
113     {
114         if ( buttonId == IDialogConstants.OK_ID )
115         {
116             IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore();
117             store.setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OBJECTCLASS_AND_MUST_ATTRIBUTES_FIRST,
118                 objectClassAndMustAttributesFirstButton.getSelection() );
119             store.setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OPERATIONAL_ATTRIBUTES_LAST,
120                 operationalAttributesLastButton.getSelection() );
121             store.setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_ORDER, sortDescendingButton
122                 .getSelection() ? BrowserCoreConstants.SORT_ORDER_DESCENDING
123                 : BrowserCoreConstants.SORT_ORDER_ASCENDING );
124             store.setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_BY,
125                 sortByCombo.getSelectionIndex() == 2 ? BrowserCoreConstants.SORT_BY_VALUE : sortByCombo
126                     .getSelectionIndex() == 1 ? BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION
127                     : BrowserCoreConstants.SORT_BY_NONE );
128         }
129
130         super.buttonPressed( buttonId );
131     }
132
133
134     /**
135      * {@inheritDoc}
136      */

137     protected Control createDialogArea( Composite parent )
138     {
139         Composite composite = ( Composite ) super.createDialogArea( parent );
140
141         Group group = BaseWidgetUtils.createGroup( composite, "Group attributes", 1 );
142         GridData gd = new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL );
143         gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
144         group.setLayoutData( gd );
145
146         objectClassAndMustAttributesFirstButton = BaseWidgetUtils.createCheckbox( group,
147             "ObjectClass and must attributes first", 1 );
148         objectClassAndMustAttributesFirstButton.setSelection( preferences.isObjectClassAndMustAttributesFirst() );
149
150         operationalAttributesLastButton = BaseWidgetUtils.createCheckbox( group, "Operational attributes last", 1 );
151         operationalAttributesLastButton.setSelection( preferences.isOperationalAttributesLast() );
152
153         Group sortingGroup = BaseWidgetUtils.createGroup( composite, "Sort attributes", 1 );
154
155         Composite sortByComposite = BaseWidgetUtils.createColumnContainer( sortingGroup, 4, 1 );
156         BaseWidgetUtils.createLabel( sortByComposite, "Sort by", 1 );
157         sortByCombo = BaseWidgetUtils.createReadonlyCombo( sortByComposite, new String JavaDoc[]
158             { SORT_BY_NONE, SORT_BY_ATTRIBUTE, SORT_BY_VALUE }, 0, 1 );
159         sortByCombo.select( preferences.getDefaultSortBy() == BrowserCoreConstants.SORT_BY_VALUE ? 2 : preferences
160             .getDefaultSortBy() == BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION ? 1 : 0 );
161         sortByCombo.addSelectionListener( new SelectionAdapter()
162         {
163             public void widgetSelected( SelectionEvent e )
164             {
165                 sortAcendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
166                 sortDescendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
167             }
168         } );
169
170         sortAcendingButton = BaseWidgetUtils.createRadiobutton( sortByComposite, "Ascending", 1 );
171         sortAcendingButton
172             .setSelection( preferences.getDefaultSortOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING );
173         sortAcendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
174
175         sortDescendingButton = BaseWidgetUtils.createRadiobutton( sortByComposite, "Descending", 1 );
176         sortDescendingButton
177             .setSelection( preferences.getDefaultSortOrder() == BrowserCoreConstants.SORT_ORDER_DESCENDING );
178         sortDescendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
179
180         BaseWidgetUtils.createSpacer( composite, 2 );
181
182         BaseWidgetUtils.createLabel( composite,
183             "Please click to table headers to sort by attribute description or value.", 1 );
184
185         applyDialogFont( composite );
186         return composite;
187     }
188
189 }
190
Popular Tags