1 20 21 package org.apache.directory.ldapstudio.aciitemeditor.valueeditors; 22 23 24 import java.util.Arrays ; 25 26 import org.apache.directory.ldapstudio.aciitemeditor.Activator; 27 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 28 import org.apache.directory.ldapstudio.browser.common.widgets.ListContentProposalProvider; 29 import org.apache.directory.ldapstudio.browser.core.model.schema.Schema; 30 import org.eclipse.jface.dialogs.Dialog; 31 import org.eclipse.jface.dialogs.IDialogConstants; 32 import org.eclipse.jface.fieldassist.ComboContentAdapter; 33 import org.eclipse.jface.fieldassist.ContentProposalAdapter; 34 import org.eclipse.jface.fieldassist.DecoratedField; 35 import org.eclipse.jface.fieldassist.FieldDecoration; 36 import org.eclipse.jface.fieldassist.FieldDecorationRegistry; 37 import org.eclipse.jface.fieldassist.IControlCreator; 38 import org.eclipse.swt.SWT; 39 import org.eclipse.swt.layout.GridData; 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 45 46 52 public class AttributeTypeDialog extends Dialog 53 { 54 55 56 private Schema schema; 57 58 59 private String initialValue; 60 61 62 private DecoratedField attributeTypeComboField; 63 64 65 private Combo attributeTypeCombo; 66 67 68 private ContentProposalAdapter attributeTypeCPA; 69 70 71 private String returnValue; 72 73 74 81 public AttributeTypeDialog( Shell parentShell, Schema schema, String initialValue ) 82 { 83 super( parentShell ); 84 super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); 85 this.initialValue = initialValue; 86 this.schema = schema; 87 this.returnValue = null; 88 } 89 90 91 94 protected void configureShell( Shell shell ) 95 { 96 super.configureShell( shell ); 97 shell.setText( Messages.getString("AttributeTypeDialog.title") ); shell.setImage( Activator.getDefault().getImage( Messages.getString("AttributeTypeDialog.icon") ) ); } 100 101 102 105 protected void createButtonsForButtonBar( Composite parent ) 106 { 107 super.createButtonsForButtonBar( parent ); 108 } 109 110 111 114 protected void okPressed() 115 { 116 returnValue = attributeTypeCombo.getText(); 117 super.okPressed(); 118 } 119 120 121 124 protected Control createDialogArea( Composite parent ) 125 { 126 Composite composite = ( Composite ) super.createDialogArea( parent ); 128 GridData gd = new GridData( GridData.FILL_BOTH ); 129 gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); 130 composite.setLayoutData( gd ); 131 132 String [] allAtNames = schema.getAttributeTypeDescriptionNames(); 134 Arrays.sort( allAtNames ); 135 136 final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration( 137 FieldDecorationRegistry.DEC_CONTENT_PROPOSAL ); 138 attributeTypeComboField = new DecoratedField( composite, SWT.NONE, new IControlCreator() 139 { 140 public Control createControl( Composite parent, int style ) 141 { 142 Combo combo = BaseWidgetUtils.createCombo( parent, new String [0], -1, 1 ); 143 combo.setVisibleItemCount( 20 ); 144 return combo; 145 } 146 } ); 147 attributeTypeComboField.addFieldDecoration( fieldDecoration, SWT.TOP | SWT.LEFT, true ); 148 attributeTypeComboField.getLayoutControl().setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) ); 149 attributeTypeCombo = ( Combo ) attributeTypeComboField.getControl(); 150 attributeTypeCombo.setItems( allAtNames ); 151 attributeTypeCombo.setText( initialValue ); 152 153 attributeTypeCPA = new ContentProposalAdapter( attributeTypeCombo, new ComboContentAdapter(), 155 new ListContentProposalProvider( attributeTypeCombo.getItems() ), null, null ); 156 attributeTypeCPA.setFilterStyle( ContentProposalAdapter.FILTER_NONE ); 157 attributeTypeCPA.setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE ); 158 159 applyDialogFont( composite ); 160 return composite; 161 } 162 163 164 169 public String getAttributeType() 170 { 171 return returnValue; 172 } 173 } 174 | Popular Tags |