1 20 package org.apache.directory.ldapstudio.apacheds.configuration.dialogs; 21 22 23 import org.apache.directory.ldapstudio.apacheds.configuration.model.IndexedAttribute; 24 import org.eclipse.jface.dialogs.Dialog; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.events.ModifyEvent; 27 import org.eclipse.swt.events.ModifyListener; 28 import org.eclipse.swt.events.VerifyEvent; 29 import org.eclipse.swt.events.VerifyListener; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.layout.GridLayout; 32 import org.eclipse.swt.widgets.Composite; 33 import org.eclipse.swt.widgets.Control; 34 import org.eclipse.swt.widgets.Label; 35 import org.eclipse.swt.widgets.Shell; 36 import org.eclipse.swt.widgets.Text; 37 import org.eclipse.ui.PlatformUI; 38 39 40 46 public class IndexedAttributeDialog extends Dialog 47 { 48 49 private IndexedAttribute indexedAttribute; 50 51 52 private boolean dirty = false; 53 54 private Text attributeIdText; 56 private Text cacheSizeText; 57 58 59 62 public IndexedAttributeDialog( IndexedAttribute indexedAttribute ) 63 { 64 super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); 65 this.indexedAttribute = indexedAttribute; 66 } 67 68 69 72 protected void configureShell( Shell newShell ) 73 { 74 super.configureShell( newShell ); 75 newShell.setText( "Indexed Attribute Dialog" ); 76 } 77 78 79 82 protected Control createDialogArea( Composite parent ) 83 { 84 Composite composite = new Composite( parent, SWT.NONE ); 85 GridLayout layout = new GridLayout( 2, false ); 86 composite.setLayout( layout ); 87 composite.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) ); 88 89 Label attributeIdLabel = new Label( composite, SWT.NONE ); 90 attributeIdLabel.setText( "Attribute ID:" ); 91 92 attributeIdText = new Text( composite, SWT.BORDER ); 93 attributeIdText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 94 95 Label cacheSizeLabel = new Label( composite, SWT.NONE ); 96 cacheSizeLabel.setText( "Cache Size:" ); 97 98 cacheSizeText = new Text( composite, SWT.BORDER ); 99 cacheSizeText.addVerifyListener( new VerifyListener() 100 { 101 public void verifyText( VerifyEvent e ) 102 { 103 if ( !e.text.matches( "[0-9]*" ) ) { 105 e.doit = false; 106 } 107 } 108 } ); 109 cacheSizeText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 110 111 initFromInput(); 112 addListeners(); 113 114 return composite; 115 } 116 117 118 121 private void initFromInput() 122 { 123 String attributeId = indexedAttribute.getAttributeId(); 124 attributeIdText.setText( ( attributeId == null ) ? "" : attributeId ); 125 cacheSizeText.setText( "" + indexedAttribute.getCacheSize() ); 126 } 127 128 129 132 private void addListeners() 133 { 134 attributeIdText.addModifyListener( new ModifyListener() 135 { 136 public void modifyText( ModifyEvent e ) 137 { 138 dirty = true; 139 } 140 } ); 141 142 cacheSizeText.addModifyListener( new ModifyListener() 143 { 144 public void modifyText( ModifyEvent e ) 145 { 146 dirty = true; 147 } 148 } ); 149 } 150 151 152 155 protected void okPressed() 156 { 157 indexedAttribute.setAttributeId( attributeIdText.getText() ); 158 try 159 { 160 indexedAttribute.setCacheSize( Integer.parseInt( cacheSizeText.getText() ) ); 161 } 162 catch ( NumberFormatException e ) 163 { 164 } 166 167 super.okPressed(); 168 } 169 170 171 177 public IndexedAttribute getIndexedAttribute() 178 { 179 return indexedAttribute; 180 } 181 182 183 189 public boolean isDirty() 190 { 191 return dirty; 192 } 193 } 194 | Popular Tags |