1 20 package org.apache.directory.ldapstudio.aciitemeditor.widgets; 21 22 23 import java.util.ArrayList ; 24 import java.util.List ; 25 26 import org.apache.directory.shared.ldap.aci.AuthenticationLevel; 27 import org.eclipse.jface.viewers.ArrayContentProvider; 28 import org.eclipse.jface.viewers.ComboViewer; 29 import org.eclipse.jface.viewers.IStructuredSelection; 30 import org.eclipse.jface.viewers.LabelProvider; 31 import org.eclipse.jface.viewers.StructuredSelection; 32 import org.eclipse.swt.SWT; 33 import org.eclipse.swt.events.ModifyEvent; 34 import org.eclipse.swt.events.ModifyListener; 35 import org.eclipse.swt.events.SelectionAdapter; 36 import org.eclipse.swt.events.SelectionEvent; 37 import org.eclipse.swt.events.TypedEvent; 38 import org.eclipse.swt.layout.GridData; 39 import org.eclipse.swt.layout.GridLayout; 40 import org.eclipse.swt.widgets.Button; 41 import org.eclipse.swt.widgets.Combo; 42 import org.eclipse.swt.widgets.Composite; 43 import org.eclipse.swt.widgets.Label; 44 import org.eclipse.swt.widgets.Spinner; 45 import org.eclipse.swt.widgets.Text; 46 47 48 61 public class ACIItemGeneralComposite extends Composite 62 { 63 64 private Composite composite = null; 65 66 67 private Label identificationTagLabel = null; 68 69 70 private Text identificationTagText = null; 71 72 73 private Label precedenceLabel = null; 74 75 76 private Spinner precedenceSpinner = null; 77 78 79 private Label authenticationLevelLabel = null; 80 81 82 private Combo authenticationLevelCombo = null; 83 84 88 private ComboViewer authenticationLevelComboViewer = null; 89 90 91 private Label userOrItemFirstLabel = null; 92 93 94 private Button userFirstRadioButton = null; 95 96 97 private Button itemFirstRadioButton = null; 98 99 100 private List <WidgetModifyListener> listenerList = new ArrayList <WidgetModifyListener>(); 101 102 103 109 public ACIItemGeneralComposite( Composite parent, int style ) 110 { 111 super( parent, style ); 112 113 GridLayout layout = new GridLayout(); 114 layout.horizontalSpacing = 0; 115 layout.verticalSpacing = 0; 116 layout.marginHeight = 0; 117 layout.marginWidth = 0; 118 setLayout( layout ); 119 120 GridData layoutData = new GridData(); 121 layoutData.horizontalAlignment = GridData.FILL; 122 layoutData.grabExcessHorizontalSpace = true; 123 layoutData.verticalAlignment = GridData.CENTER; 124 setLayoutData( layoutData ); 125 126 createComposite(); 127 } 128 129 130 134 private void createComposite() 135 { 136 137 GridData identificationTagGridData = new GridData(); 138 identificationTagGridData.grabExcessHorizontalSpace = true; 139 identificationTagGridData.verticalAlignment = GridData.CENTER; 140 identificationTagGridData.horizontalSpan = 2; 141 identificationTagGridData.horizontalAlignment = GridData.FILL; 142 143 GridData precedenceGridData = new GridData(); 144 precedenceGridData.grabExcessHorizontalSpace = true; 145 precedenceGridData.verticalAlignment = GridData.CENTER; 146 precedenceGridData.horizontalSpan = 2; 147 precedenceGridData.horizontalAlignment = GridData.BEGINNING; 148 precedenceGridData.widthHint = 3 * 12; 149 150 GridData authenticationLevelGridData = new GridData(); 151 authenticationLevelGridData.grabExcessHorizontalSpace = true; 152 authenticationLevelGridData.verticalAlignment = GridData.CENTER; 153 authenticationLevelGridData.horizontalSpan = 2; 154 authenticationLevelGridData.horizontalAlignment = GridData.FILL; 155 156 GridLayout gridLayout = new GridLayout(); 157 gridLayout.numColumns = 3; 158 GridData gridData = new GridData(); 159 gridData.horizontalAlignment = GridData.FILL; 160 gridData.grabExcessHorizontalSpace = true; 161 gridData.verticalAlignment = GridData.CENTER; 162 163 composite = new Composite( this, SWT.NONE ); 164 composite.setLayout( gridLayout ); 165 composite.setLayoutData( gridData ); 166 167 identificationTagLabel = new Label( composite, SWT.NONE ); 168 identificationTagLabel.setText( Messages.getString( "ACIItemGeneralComposite.idTag.label" ) ); identificationTagText = new Text( composite, SWT.BORDER ); 170 identificationTagText.setLayoutData( identificationTagGridData ); 171 identificationTagText.addModifyListener( new ModifyListener() 172 { 173 public void modifyText( ModifyEvent event ) 174 { 175 fire( event ); 176 } 177 } ); 178 179 precedenceLabel = new Label( composite, SWT.NONE ); 180 precedenceLabel.setText( Messages.getString( "ACIItemGeneralComposite.precedence.label" ) ); precedenceSpinner = new Spinner( composite, SWT.BORDER ); 182 precedenceSpinner.setMinimum( 0 ); 183 precedenceSpinner.setMaximum( 255 ); 184 precedenceSpinner.setDigits( 0 ); 185 precedenceSpinner.setIncrement( 1 ); 186 precedenceSpinner.setPageIncrement( 10 ); 187 precedenceSpinner.setSelection( 0 ); 188 precedenceSpinner.setLayoutData( precedenceGridData ); 189 precedenceSpinner.addModifyListener( new ModifyListener() 190 { 191 public void modifyText( ModifyEvent event ) 192 { 193 fire( event ); 194 } 195 } ); 196 197 authenticationLevelLabel = new Label( composite, SWT.NONE ); 198 authenticationLevelLabel.setText( Messages.getString( "ACIItemGeneralComposite.authLevel.label" ) ); authenticationLevelCombo = new Combo( composite, SWT.READ_ONLY ); 200 authenticationLevelCombo.setLayoutData( authenticationLevelGridData ); 201 AuthenticationLevel[] authenticationLevels = new AuthenticationLevel[3]; 202 authenticationLevels[0] = AuthenticationLevel.NONE; 203 authenticationLevels[1] = AuthenticationLevel.SIMPLE; 204 authenticationLevels[2] = AuthenticationLevel.STRONG; 205 authenticationLevelComboViewer = new ComboViewer( authenticationLevelCombo ); 206 authenticationLevelComboViewer.setContentProvider( new ArrayContentProvider() ); 207 authenticationLevelComboViewer.setLabelProvider( new LabelProvider() ); 208 authenticationLevelComboViewer.setInput( authenticationLevels ); 209 authenticationLevelComboViewer.setSelection( new StructuredSelection( AuthenticationLevel.NONE ) ); 210 authenticationLevelCombo.addModifyListener( new ModifyListener() 211 { 212 public void modifyText( ModifyEvent event ) 213 { 214 fire( event ); 215 } 216 } ); 217 218 userOrItemFirstLabel = new Label( composite, SWT.NONE ); 219 userOrItemFirstLabel.setText( Messages.getString( "ACIItemGeneralComposite.userOrItemFirst.label" ) ); userFirstRadioButton = new Button( composite, SWT.RADIO ); 221 userFirstRadioButton.setText( Messages.getString( "ACIItemGeneralComposite.userFirst.label" ) ); userFirstRadioButton.addSelectionListener( new SelectionAdapter() 223 { 224 public void widgetSelected( SelectionEvent event ) 225 { 226 fire( event ); 227 } 228 } ); 229 itemFirstRadioButton = new Button( composite, SWT.RADIO ); 230 itemFirstRadioButton.setText( Messages.getString( "ACIItemGeneralComposite.itemFirst.label" ) ); itemFirstRadioButton.addSelectionListener( new SelectionAdapter() 232 { 233 public void widgetSelected( SelectionEvent event ) 234 { 235 fire( event ); 236 } 237 } ); 238 239 } 240 241 242 247 public void addWidgetModifyListener( WidgetModifyListener listener ) 248 { 249 checkWidget(); 250 if ( listener == null ) 251 SWT.error( SWT.ERROR_NULL_ARGUMENT ); 252 listenerList.add( listener ); 253 } 254 255 256 261 public void removeWidgetModifyListener( WidgetModifyListener listener ) 262 { 263 checkWidget(); 264 if ( listener == null ) 265 SWT.error( SWT.ERROR_NULL_ARGUMENT ); 266 listenerList.remove( listener ); 267 } 268 269 270 275 private void fire( TypedEvent event ) 276 { 277 for ( WidgetModifyListener listener : listenerList ) 278 { 279 listener.widgetModified( new WidgetModifyEvent( this ) ); 280 } 281 } 282 283 284 289 public String getIdentificationTag() 290 { 291 return identificationTagText.getText(); 292 } 293 294 295 300 public void setIdentificationTag( String identificationTag ) 301 { 302 identificationTagText.setText( identificationTag ); 303 } 304 305 306 311 public int getPrecedence() 312 { 313 return precedenceSpinner.getSelection(); 314 } 315 316 317 322 public void setPrecedence( int precedence ) 323 { 324 precedenceSpinner.setSelection( precedence ); 325 } 326 327 328 333 public AuthenticationLevel getAuthenticationLevel() 334 { 335 IStructuredSelection selection = ( IStructuredSelection ) authenticationLevelComboViewer.getSelection(); 336 return ( AuthenticationLevel ) selection.getFirstElement(); 337 } 338 339 340 345 public void setAuthenticationLevel( AuthenticationLevel authenticationLevel ) 346 { 347 IStructuredSelection selection = new StructuredSelection( authenticationLevel ); 348 authenticationLevelComboViewer.setSelection( selection ); 349 } 350 351 352 357 public boolean isUserFirst() 358 { 359 return userFirstRadioButton.getSelection(); 360 } 361 362 363 366 public void setUserFirst() 367 { 368 userFirstRadioButton.setSelection( true ); 369 itemFirstRadioButton.setSelection( false ); 370 } 371 372 373 378 public boolean isItemFirst() 379 { 380 return itemFirstRadioButton.getSelection(); 381 } 382 383 384 387 public void setItemFirst() 388 { 389 itemFirstRadioButton.setSelection( true ); 390 userFirstRadioButton.setSelection( false ); 391 } 392 393 } 394 | Popular Tags |