1 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 48 public class SchemaElementsViewSortDialog extends Dialog 49 { 50 51 private static final String DIALOG_TITLE = Messages 52 .getString( "SchemaElementsViewSortDialog.Schema_Elements_View_Sorting" ); 54 55 private static final String SORTING_FISTNAME = Messages.getString( "SchemaElementsViewSortDialog.First_Name" ); 57 58 private static final String SORTING_OID = Messages.getString( "SchemaElementsViewSortDialog.OID" ); 60 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 75 public SchemaElementsViewSortDialog( Shell parentShell ) 76 { 77 super( parentShell ); 78 } 79 80 81 84 protected void configureShell( Shell newShell ) 85 { 86 super.configureShell( newShell ); 87 newShell.setText( DIALOG_TITLE ); 88 } 89 90 91 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 composite.setLayoutData( gd ); 100 101 Group groupingGroup = new Group( composite, SWT.NONE ); 103 groupingGroup.setLayoutData( new GridData( GridData.FILL_BOTH ) ); 104 groupingGroup.setText( Messages.getString( "SchemaElementsViewSortDialog.Grouping" ) ); groupingGroup.setLayout( new GridLayout() ); 106 107 atFirstButton = new Button( groupingGroup, SWT.RADIO ); 109 atFirstButton.setText( Messages.getString( "SchemaElementsViewSortDialog.Attribute_Types_first" ) ); atFirstButton.setEnabled( true ); 111 112 ocFirstButton = new Button( groupingGroup, SWT.RADIO ); 114 ocFirstButton.setText( Messages.getString( "SchemaElementsViewSortDialog.Object_Classes_first" ) ); ocFirstButton.setEnabled( true ); 116 117 mixedButton = new Button( groupingGroup, SWT.RADIO ); 119 mixedButton.setText( Messages.getString( "SchemaElementsViewSortDialog.Mixed" ) ); mixedButton.setEnabled( true ); 121 122 Group sortingGroup = new Group( composite, SWT.NONE ); 124 sortingGroup.setLayoutData( new GridData( GridData.FILL_BOTH ) ); 125 sortingGroup.setText( Messages.getString( "SchemaElementsViewSortDialog.Sorting" ) ); 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 Label sortByLabel = new Label( sortingGroupComposite, SWT.NONE ); 135 sortByLabel.setText( Messages.getString( "SchemaElementsViewSortDialog.Sort_by" ) ); 137 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 [] 141 { SORTING_FISTNAME, SORTING_OID } ); 142 sortingCombo.setEnabled( true ); 143 144 ascendingButton = new Button( sortingGroupComposite, SWT.RADIO ); 146 ascendingButton.setText( Messages.getString( "SchemaElementsViewSortDialog.Ascending" ) ); ascendingButton.setEnabled( true ); 148 149 descendingButton = new Button( sortingGroupComposite, SWT.RADIO ); 151 descendingButton.setText( Messages.getString( "SchemaElementsViewSortDialog.Descending" ) ); descendingButton.setEnabled( true ); 153 154 initFieldsFromPreferences(); 155 156 applyDialogFont( composite ); 157 return composite; 158 } 159 160 161 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 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 |