1 20 package org.apache.directory.ldapstudio.apacheds.configuration.editor; 21 22 23 import org.apache.directory.ldapstudio.apacheds.configuration.model.Interceptor; 24 import org.eclipse.jface.viewers.ISelection; 25 import org.eclipse.jface.viewers.IStructuredSelection; 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.events.ModifyEvent; 28 import org.eclipse.swt.events.ModifyListener; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.layout.GridLayout; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.Text; 33 import org.eclipse.ui.forms.IDetailsPage; 34 import org.eclipse.ui.forms.IFormPart; 35 import org.eclipse.ui.forms.IManagedForm; 36 import org.eclipse.ui.forms.widgets.FormToolkit; 37 import org.eclipse.ui.forms.widgets.Section; 38 import org.eclipse.ui.forms.widgets.TableWrapData; 39 import org.eclipse.ui.forms.widgets.TableWrapLayout; 40 41 42 48 public class InterceptorDetailsPage implements IDetailsPage 49 { 50 51 private InterceptorsMasterDetailsBlock masterDetailsBlock; 52 53 54 private IManagedForm mform; 55 56 57 private Interceptor input; 58 59 60 private boolean dirty = false; 61 62 private Text nameText; 64 private Text classText; 65 66 68 private ModifyListener textModifyListener = new ModifyListener() 69 { 70 public void modifyText( ModifyEvent e ) 71 { 72 masterDetailsBlock.setEditorDirty(); 73 dirty = true; 74 } 75 }; 76 77 78 84 public InterceptorDetailsPage( InterceptorsMasterDetailsBlock imdb ) 85 { 86 masterDetailsBlock = imdb; 87 } 88 89 90 93 public void createContents( Composite parent ) 94 { 95 FormToolkit toolkit = mform.getToolkit(); 96 TableWrapLayout layout = new TableWrapLayout(); 97 layout.topMargin = 5; 98 layout.leftMargin = 5; 99 layout.rightMargin = 2; 100 layout.bottomMargin = 2; 101 parent.setLayout( layout ); 102 103 createDetailsSection( parent, toolkit ); 104 } 105 106 107 115 private void createDetailsSection( Composite parent, FormToolkit toolkit ) 116 { 117 Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); 118 section.marginWidth = 10; 119 section.setText( "Interceptor Details" ); section.setDescription( "Set the properties of the interceptor." ); TableWrapData td = new TableWrapData( TableWrapData.FILL, TableWrapData.TOP ); 122 td.grabHorizontal = true; 123 section.setLayoutData( td ); 124 Composite client = toolkit.createComposite( section ); 125 toolkit.paintBordersFor( client ); 126 GridLayout glayout = new GridLayout( 3, false ); 127 client.setLayout( glayout ); 128 section.setClient( client ); 129 130 toolkit.createLabel( client, "Name:" ); 132 nameText = toolkit.createText( client, "" ); 133 nameText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 134 135 toolkit.createLabel( client, "Class:" ); 137 classText = toolkit.createText( client, "" ); 138 classText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 139 } 140 141 142 145 private void addListeners() 146 { 147 nameText.addModifyListener( textModifyListener ); 148 classText.addModifyListener( textModifyListener ); 149 } 150 151 152 155 private void removeListeners() 156 { 157 nameText.removeModifyListener( textModifyListener ); 158 classText.removeModifyListener( textModifyListener ); 159 } 160 161 162 165 public void selectionChanged( IFormPart part, ISelection selection ) 166 { 167 IStructuredSelection ssel = ( IStructuredSelection ) selection; 168 if ( ssel.size() == 1 ) 169 { 170 input = ( Interceptor ) ssel.getFirstElement(); 171 } 172 else 173 { 174 input = null; 175 } 176 refresh(); 177 } 178 179 180 183 public void commit( boolean onSave ) 184 { 185 if ( input != null ) 186 { 187 input.setName( nameText.getText() ); 188 input.setClassType( classText.getText() ); 189 } 190 } 191 192 193 196 public void dispose() 197 { 198 } 199 200 201 204 public void initialize( IManagedForm form ) 205 { 206 this.mform = form; 207 } 208 209 210 213 public boolean isDirty() 214 { 215 return dirty; 216 } 217 218 219 222 public boolean isStale() 223 { 224 return false; 225 } 226 227 228 231 public void refresh() 232 { 233 removeListeners(); 234 235 String name = input.getName(); 237 nameText.setText( ( name == null ) ? "" : name ); 238 239 String classType = input.getClassType(); 241 classText.setText( ( classType == null ) ? "" : classType ); 242 243 addListeners(); 244 } 245 246 247 250 public void setFocus() 251 { 252 nameText.setFocus(); 253 } 254 255 256 259 public boolean setFormInput( Object input ) 260 { 261 return false; 262 } 263 } 264 | Popular Tags |