KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > aciitemeditor > valueeditors > AttributeTypeDialog


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.aciitemeditor.valueeditors;
22
23
24 import java.util.Arrays JavaDoc;
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 /**
47  * This class provides a dialog to enter or select an attribute type.
48  *
49  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
50  * @version $Rev$, $Date$
51  */

52 public class AttributeTypeDialog extends Dialog
53 {
54
55     /** The schema. */
56     private Schema schema;
57
58     /** The initial value. */
59     private String JavaDoc initialValue;
60
61     /** The attribute type combo field. */
62     private DecoratedField attributeTypeComboField;
63
64     /** The attribute type combo. */
65     private Combo attributeTypeCombo;
66
67     /** The attribute type content proposal adapter */
68     private ContentProposalAdapter attributeTypeCPA;
69
70     /** The return value. */
71     private String JavaDoc returnValue;
72
73
74     /**
75      * Creates a new instance of AttributeTypeDialog.
76      *
77      * @param parentShell the parent shell
78      * @param schema the schema
79      * @param initialValue the initial value
80      */

81     public AttributeTypeDialog( Shell parentShell, Schema schema, String JavaDoc 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     /**
92      * {@inheritDoc}
93      */

94     protected void configureShell( Shell shell )
95     {
96         super.configureShell( shell );
97         shell.setText( Messages.getString("AttributeTypeDialog.title") ); //$NON-NLS-1$
98
shell.setImage( Activator.getDefault().getImage( Messages.getString("AttributeTypeDialog.icon") ) ); //$NON-NLS-1$
99
}
100
101
102     /**
103      * {@inheritDoc}
104      */

105     protected void createButtonsForButtonBar( Composite parent )
106     {
107         super.createButtonsForButtonBar( parent );
108     }
109
110
111     /**
112      * {@inheritDoc}
113      */

114     protected void okPressed()
115     {
116         returnValue = attributeTypeCombo.getText();
117         super.okPressed();
118     }
119
120
121     /**
122      * {@inheritDoc}
123      */

124     protected Control createDialogArea( Composite parent )
125     {
126         // create composite
127
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         // combo widget
133
String JavaDoc[] 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 JavaDoc[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         // content proposal adapter
154
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     /**
165      * Gets the attribute type.
166      *
167      * @return the attribute type, null if canceled
168      */

169     public String JavaDoc getAttributeType()
170     {
171         return returnValue;
172     }
173 }
174
Popular Tags