| 1 20 21 package org.apache.directory.ldapstudio.valueeditors.objectclass; 22 23 24 import java.util.Arrays ; 25 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.apache.directory.ldapstudio.valueeditors.ValueEditorsActivator; 30 import org.apache.directory.ldapstudio.valueeditors.ValueEditorsConstants; 31 import org.eclipse.jface.dialogs.Dialog; 32 import org.eclipse.jface.dialogs.IDialogConstants; 33 import org.eclipse.jface.fieldassist.ComboContentAdapter; 34 import org.eclipse.jface.fieldassist.ContentProposalAdapter; 35 import org.eclipse.jface.fieldassist.DecoratedField; 36 import org.eclipse.jface.fieldassist.FieldDecoration; 37 import org.eclipse.jface.fieldassist.FieldDecorationRegistry; 38 import org.eclipse.jface.fieldassist.IControlCreator; 39 import org.eclipse.swt.SWT; 40 import org.eclipse.swt.layout.GridData; 41 import org.eclipse.swt.widgets.Combo; 42 import org.eclipse.swt.widgets.Composite; 43 import org.eclipse.swt.widgets.Control; 44 import org.eclipse.swt.widgets.Shell; 45 46 47 53 public class ObjectClassDialog extends Dialog 54 { 55 56 57 public static final String DIALOG_TITLE = "Object Class Editor"; 58 59 60 private Schema schema; 61 62 63 private String initialValue; 64 65 66 private DecoratedField objectClassComboField; 67 68 69 private Combo objectClassCombo; 70 71 72 private ContentProposalAdapter objectClassCPA; 73 74 75 private String returnValue; 76 77 78 85 public ObjectClassDialog( Shell parentShell, Schema schema, String initialValue ) 86 { 87 super( parentShell ); 88 super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); 89 this.initialValue = initialValue; 90 this.schema = schema; 91 this.returnValue = null; 92 } 93 94 95 98 protected void configureShell( Shell shell ) 99 { 100 super.configureShell( shell ); 101 shell.setText( DIALOG_TITLE ); 102 shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_OCDEDITOR ) ); 103 } 104 105 106 109 protected void createButtonsForButtonBar( Composite parent ) 110 { 111 super.createButtonsForButtonBar( parent ); 112 } 113 114 115 118 protected void okPressed() 119 { 120 returnValue = objectClassCombo.getText(); 121 super.okPressed(); 122 } 123 124 125 128 protected Control createDialogArea( Composite parent ) 129 { 130 Composite composite = ( Composite ) super.createDialogArea( parent ); 132 GridData gd = new GridData( GridData.FILL_BOTH ); 133 gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); 134 composite.setLayoutData( gd ); 135 136 String [] allOcNames = schema.getObjectClassDescriptionNames(); 138 Arrays.sort( allOcNames ); 139 140 final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration( 141 FieldDecorationRegistry.DEC_CONTENT_PROPOSAL ); 142 objectClassComboField = new DecoratedField( composite, SWT.NONE, new IControlCreator() 143 { 144 public Control createControl( Composite parent, int style ) 145 { 146 Combo combo = BaseWidgetUtils.createCombo( parent, new String [0], -1, 1 ); 147 combo.setVisibleItemCount( 20 ); 148 return combo; 149 } 150 } ); 151 objectClassComboField.addFieldDecoration( fieldDecoration, SWT.TOP | SWT.LEFT, true ); 152 objectClassComboField.getLayoutControl().setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) ); 153 objectClassCombo = ( Combo ) objectClassComboField.getControl(); 154 objectClassCombo.setItems( allOcNames ); 155 objectClassCombo.setText( initialValue ); 156 157 objectClassCPA = new ContentProposalAdapter( objectClassCombo, new ComboContentAdapter(), 159 new ListContentProposalProvider( objectClassCombo.getItems() ), null, null ); 160 objectClassCPA.setFilterStyle( ContentProposalAdapter.FILTER_NONE ); 161 objectClassCPA.setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE ); 162 163 applyDialogFont( composite ); 164 return composite; 165 } 166 167 168 173 public String getObjectClass() 174 { 175 return returnValue; 176 } 177 } 178 | Popular Tags |