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 SchemasViewSortDialog extends Dialog 49 { 50 51 private static final String DIALOG_TITLE = Messages.getString( "SchemasViewSortDialog.Schemas_View_Sorting" ); 53 54 private static final String SORTING_FISTNAME = Messages.getString( "SchemasViewSortDialog.First_Name" ); 56 57 private static final String SORTING_OID = Messages.getString( "SchemasViewSortDialog.OID" ); 59 private Button inFoldersButton; 61 private Button mixedButton; 62 private Combo sortingCombo; 63 private Button ascendingButton; 64 private Button descendingButton; 65 66 67 73 public SchemasViewSortDialog( Shell parentShell ) 74 { 75 super( parentShell ); 76 } 77 78 79 82 protected void configureShell( Shell newShell ) 83 { 84 super.configureShell( newShell ); 85 newShell.setText( DIALOG_TITLE ); 86 } 87 88 89 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 composite.setLayoutData( gd ); 98 99 Group groupingGroup = new Group( composite, SWT.NONE ); 101 groupingGroup.setLayoutData( new GridData( GridData.FILL_BOTH ) ); 102 groupingGroup.setText( Messages.getString( "SchemasViewSortDialog.Grouping" ) ); groupingGroup.setLayout( new GridLayout() ); 104 105 inFoldersButton = new Button( groupingGroup, SWT.RADIO ); 107 inFoldersButton.setText( Messages 108 .getString( "SchemasViewSortDialog.Group_attribute_types_and_object_classes_in_folders" ) ); inFoldersButton.setEnabled( true ); 110 111 mixedButton = new Button( groupingGroup, SWT.RADIO ); 113 mixedButton.setText( Messages.getString( "SchemasViewSortDialog.Mixed" ) ); mixedButton.setEnabled( true ); 115 116 Group sortingGroup = new Group( composite, SWT.NONE ); 118 sortingGroup.setLayoutData( new GridData( GridData.FILL_BOTH ) ); 119 sortingGroup.setText( Messages.getString( "SchemasViewSortDialog.Sorting" ) ); 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 Label sortByLabel = new Label( sortingGroupComposite, SWT.NONE ); 129 sortByLabel.setText( Messages.getString( "SchemasViewSortDialog.Sort_by" ) ); 131 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 [] 135 { SORTING_FISTNAME, SORTING_OID } ); 136 sortingCombo.setEnabled( true ); 137 138 ascendingButton = new Button( sortingGroupComposite, SWT.RADIO ); 140 ascendingButton.setText( Messages.getString( "SchemasViewSortDialog.Ascending" ) ); ascendingButton.setEnabled( true ); 142 143 descendingButton = new Button( sortingGroupComposite, SWT.RADIO ); 145 descendingButton.setText( Messages.getString( "SchemasViewSortDialog.Descending" ) ); descendingButton.setEnabled( true ); 147 148 initFieldsFromPreferences(); 149 150 applyDialogFont( composite ); 151 return composite; 152 } 153 154 155 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 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 |