1 20 package org.apache.directory.ldapstudio.aciitemeditor.valueeditors; 21 22 23 import java.util.Arrays ; 24 25 import org.apache.directory.ldapstudio.aciitemeditor.Activator; 26 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 27 import org.apache.directory.ldapstudio.browser.common.widgets.ListContentProposalProvider; 28 import org.apache.directory.ldapstudio.browser.core.model.schema.Schema; 29 import org.eclipse.jface.dialogs.Dialog; 30 import org.eclipse.jface.dialogs.IDialogConstants; 31 import org.eclipse.jface.fieldassist.ComboContentAdapter; 32 import org.eclipse.jface.fieldassist.ContentProposalAdapter; 33 import org.eclipse.jface.fieldassist.DecoratedField; 34 import org.eclipse.jface.fieldassist.FieldDecoration; 35 import org.eclipse.jface.fieldassist.FieldDecorationRegistry; 36 import org.eclipse.jface.fieldassist.IControlCreator; 37 import org.eclipse.swt.SWT; 38 import org.eclipse.swt.layout.GridData; 39 import org.eclipse.swt.layout.GridLayout; 40 import org.eclipse.swt.widgets.Combo; 41 import org.eclipse.swt.widgets.Composite; 42 import org.eclipse.swt.widgets.Control; 43 import org.eclipse.swt.widgets.Shell; 44 import org.eclipse.swt.widgets.Text; 45 46 47 53 public class AttributeTypeAndValueDialog extends Dialog 54 { 55 56 57 private Schema schema; 58 59 60 private String initialAttributeType; 61 62 63 private String initialValue; 64 65 66 private DecoratedField attributeTypeComboField; 67 68 69 private Combo attributeTypeCombo; 70 71 72 private ContentProposalAdapter attributeTypeCPA; 73 74 75 private Text valueText; 76 77 78 private String returnAttributeType; 79 80 81 private String returnValue; 82 83 84 92 public AttributeTypeAndValueDialog( Shell parentShell, Schema schema, String initialAttributeType, 93 String initialValue ) 94 { 95 super( parentShell ); 96 super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); 97 this.initialAttributeType = initialAttributeType; 98 this.initialValue = initialValue; 99 this.schema = schema; 100 this.returnValue = null; 101 } 102 103 104 107 protected void configureShell( Shell shell ) 108 { 109 super.configureShell( shell ); 110 shell.setText( Messages.getString("AttributeTypeAndValueDialog.title") ); shell.setImage( Activator.getDefault().getImage( Messages.getString("AttributeTypeAndValueDialog.icon") ) ); } 113 114 115 118 protected void createButtonsForButtonBar( Composite parent ) 119 { 120 super.createButtonsForButtonBar( parent ); 121 } 122 123 124 127 protected void okPressed() 128 { 129 returnAttributeType = attributeTypeCombo.getText(); 130 returnValue = valueText.getText(); 131 super.okPressed(); 132 } 133 134 135 138 protected Control createDialogArea( Composite parent ) 139 { 140 Composite composite = ( Composite ) super.createDialogArea( parent ); 142 GridData gd = new GridData( GridData.FILL_BOTH ); 143 gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); 144 composite.setLayoutData( gd ); 145 composite.setLayout( new GridLayout( 3, false ) ); 146 147 String [] allAtNames = schema.getAttributeTypeDescriptionNames(); 149 Arrays.sort( allAtNames ); 150 151 final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration( 152 FieldDecorationRegistry.DEC_CONTENT_PROPOSAL ); 153 attributeTypeComboField = new DecoratedField( composite, SWT.NONE, new IControlCreator() 154 { 155 public Control createControl( Composite parent, int style ) 156 { 157 Combo combo = BaseWidgetUtils.createCombo( parent, new String [0], -1, 1 ); 158 combo.setVisibleItemCount( 20 ); 159 return combo; 160 } 161 } ); 162 attributeTypeComboField.addFieldDecoration( fieldDecoration, SWT.TOP | SWT.LEFT, true ); 163 attributeTypeComboField.getLayoutControl().setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) ); 164 attributeTypeCombo = ( Combo ) attributeTypeComboField.getControl(); 165 attributeTypeCombo.setItems( allAtNames ); 166 attributeTypeCombo.setText( initialAttributeType ); 167 168 attributeTypeCPA = new ContentProposalAdapter( attributeTypeCombo, new ComboContentAdapter(), 170 new ListContentProposalProvider( attributeTypeCombo.getItems() ), null, null ); 171 attributeTypeCPA.setFilterStyle( ContentProposalAdapter.FILTER_NONE ); 172 attributeTypeCPA.setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE ); 173 174 BaseWidgetUtils.createLabel( composite, " = ", 1 ); 176 valueText = BaseWidgetUtils.createText( composite, initialValue, 1 ); 177 178 applyDialogFont( composite ); 179 return composite; 180 } 181 182 183 188 public String getAttributeType() 189 { 190 return returnAttributeType; 191 } 192 193 194 199 public String getValue() 200 { 201 return returnValue; 202 } 203 204 } 205 | Popular Tags |