KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

107     protected void configureShell( Shell shell )
108     {
109         super.configureShell( shell );
110         shell.setText( Messages.getString("AttributeTypeAndValueDialog.title") ); //$NON-NLS-1$
111
shell.setImage( Activator.getDefault().getImage( Messages.getString("AttributeTypeAndValueDialog.icon") ) ); //$NON-NLS-1$
112
}
113
114
115     /**
116      * {@inheritDoc}
117      */

118     protected void createButtonsForButtonBar( Composite parent )
119     {
120         super.createButtonsForButtonBar( parent );
121     }
122
123
124     /**
125      * {@inheritDoc}
126      */

127     protected void okPressed()
128     {
129         returnAttributeType = attributeTypeCombo.getText();
130         returnValue = valueText.getText();
131         super.okPressed();
132     }
133
134
135     /**
136      * {@inheritDoc}
137      */

138     protected Control createDialogArea( Composite parent )
139     {
140         // create composite
141
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         // combo widget
148
String JavaDoc[] 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 JavaDoc[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         // content proposal adapter
169
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 ); //$NON-NLS-1$
175

176         valueText = BaseWidgetUtils.createText( composite, initialValue, 1 );
177
178         applyDialogFont( composite );
179         return composite;
180     }
181
182
183     /**
184      * Gets the attribute type.
185      *
186      * @return the attribute type, null if canceled
187      */

188     public String JavaDoc getAttributeType()
189     {
190         return returnAttributeType;
191     }
192
193
194     /**
195      * Gets the value.
196      *
197      * @return the value, null if canceled
198      */

199     public String JavaDoc getValue()
200     {
201         return returnValue;
202     }
203
204 }
205
Popular Tags