1 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 52 public class BrowserSorterDialog extends Dialog 53 { 54 55 56 public static final String DIALOG_TITLE = "Browser Sorting"; 57 58 59 public static final String SORT_BY_NONE = "No Sorting"; 60 61 62 public static final String SORT_BY_RDN = "RDN"; 63 64 65 public static final String SORT_BY_RDN_VALUE = "RDN Value"; 66 67 68 private BrowserPreferences preferences; 69 70 71 private Combo sortByCombo; 72 73 74 private Button sortAcendingButton; 75 76 77 private Button sortDescendingButton; 78 79 80 private Button leafEntriesFirstButton; 81 82 83 private Button metaEntriesLastButton; 84 85 86 private Text sortLimitText; 87 88 89 95 public BrowserSorterDialog( Shell parentShell, BrowserPreferences preferences ) 96 { 97 super( parentShell ); 98 this.preferences = preferences; 99 } 100 101 102 107 protected void configureShell( Shell newShell ) 108 { 109 super.configureShell( newShell ); 110 newShell.setText( DIALOG_TITLE ); 111 } 112 113 114 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 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 } 149 150 super.buttonPressed( buttonId ); 151 } 152 153 154 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 [] 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 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 |