1 20 package org.apache.directory.ldapstudio.apacheds.configuration.dialogs; 21 22 23 import org.apache.directory.ldapstudio.apacheds.configuration.editor.AttributeValueObject; 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.layout.GridData; 29 import org.eclipse.swt.layout.GridLayout; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.Control; 32 import org.eclipse.swt.widgets.Label; 33 import org.eclipse.swt.widgets.Shell; 34 import org.eclipse.swt.widgets.Text; 35 import org.eclipse.ui.PlatformUI; 36 37 38 44 public class AttributeValueDialog extends Dialog 45 { 46 47 private AttributeValueObject attributeValueObject; 48 49 50 private boolean dirty = false; 51 52 private Text attributeText; 54 private Text valueText; 55 56 57 60 public AttributeValueDialog( AttributeValueObject attributeValueObject ) 61 { 62 super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); 63 this.attributeValueObject = attributeValueObject; 64 } 65 66 67 70 protected void configureShell( Shell newShell ) 71 { 72 super.configureShell( newShell ); 73 newShell.setText( "Attribute Value Dialog" ); 74 } 75 76 77 80 protected Control createDialogArea( Composite parent ) 81 { 82 Composite composite = new Composite( parent, SWT.NONE ); 83 GridLayout layout = new GridLayout( 2, false ); 84 composite.setLayout( layout ); 85 composite.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) ); 86 87 Label attributeLabel = new Label( composite, SWT.NONE ); 88 attributeLabel.setText( "Attribute:" ); 89 90 attributeText = new Text( composite, SWT.BORDER ); 91 attributeText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 92 93 Label valueLabel = new Label( composite, SWT.NONE ); 94 valueLabel.setText( "Value:" ); 95 96 valueText = new Text( composite, SWT.BORDER ); 97 valueText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 98 99 initFromInput(); 100 addListeners(); 101 102 return composite; 103 } 104 105 106 109 private void initFromInput() 110 { 111 String attribute = attributeValueObject.getAttribute(); 112 attributeText.setText( ( attribute == null ) ? "" : attribute ); 113 114 Object value = attributeValueObject.getValue(); 115 valueText.setText( ( value == null ) ? "" : value.toString() ); 116 } 117 118 119 122 private void addListeners() 123 { 124 attributeText.addModifyListener( new ModifyListener() 125 { 126 public void modifyText( ModifyEvent e ) 127 { 128 dirty = true; 129 } 130 } ); 131 132 valueText.addModifyListener( new ModifyListener() 133 { 134 public void modifyText( ModifyEvent e ) 135 { 136 dirty = true; 137 } 138 } ); 139 } 140 141 142 145 protected void okPressed() 146 { 147 attributeValueObject.setId( attributeText.getText() ); 148 attributeValueObject.setValue( valueText.getText() ); 149 150 super.okPressed(); 151 } 152 153 154 160 public AttributeValueObject getAttributeValueObject() 161 { 162 return attributeValueObject; 163 } 164 165 166 172 public boolean isDirty() 173 { 174 return dirty; 175 } 176 } 177 | Popular Tags |