KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > valueeditors > objectclass > ObjectClassDialog


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

53 public class ObjectClassDialog extends Dialog
54 {
55
56     /** The dialog title */
57     public static final String JavaDoc DIALOG_TITLE = "Object Class Editor";
58
59     /** The schema. */
60     private Schema schema;
61
62     /** The initial value. */
63     private String JavaDoc initialValue;
64
65     /** The object class combo field. */
66     private DecoratedField objectClassComboField;
67
68     /** The object class combo. */
69     private Combo objectClassCombo;
70
71     /** The object class content proposal adapter */
72     private ContentProposalAdapter objectClassCPA;
73
74     /** The return value. */
75     private String JavaDoc returnValue;
76
77
78     /**
79      * Creates a new instance of ObjectClassDialog.
80      *
81      * @param parentShell the parent shell
82      * @param schema the schema
83      * @param initialValue the initial value
84      */

85     public ObjectClassDialog( Shell parentShell, Schema schema, String JavaDoc 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     /**
96      * {@inheritDoc}
97      */

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     /**
107      * {@inheritDoc}
108      */

109     protected void createButtonsForButtonBar( Composite parent )
110     {
111         super.createButtonsForButtonBar( parent );
112     }
113
114
115     /**
116      * {@inheritDoc}
117      */

118     protected void okPressed()
119     {
120         returnValue = objectClassCombo.getText();
121         super.okPressed();
122     }
123
124
125     /**
126      * {@inheritDoc}
127      */

128     protected Control createDialogArea( Composite parent )
129     {
130         // create composite
131
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         // combo widget
137
String JavaDoc[] 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 JavaDoc[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         // content proposal adapter
158
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     /**
169      * Gets the object class.
170      *
171      * @return the object class, null if canceled
172      */

173     public String JavaDoc getObjectClass()
174     {
175         return returnValue;
176     }
177 }
178
Popular Tags