KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > valueeditors > administrativerole > AdministrativeRoleDialog


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.administrativerole;
22
23
24 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
25 import org.apache.directory.ldapstudio.browser.common.widgets.ListContentProposalProvider;
26 import org.apache.directory.ldapstudio.valueeditors.ValueEditorsActivator;
27 import org.apache.directory.ldapstudio.valueeditors.ValueEditorsConstants;
28 import org.eclipse.jface.dialogs.Dialog;
29 import org.eclipse.jface.dialogs.IDialogConstants;
30 import org.eclipse.jface.fieldassist.ComboContentAdapter;
31 import org.eclipse.jface.fieldassist.ContentProposalAdapter;
32 import org.eclipse.jface.fieldassist.DecoratedField;
33 import org.eclipse.jface.fieldassist.FieldDecoration;
34 import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
35 import org.eclipse.jface.fieldassist.IControlCreator;
36 import org.eclipse.swt.SWT;
37 import org.eclipse.swt.layout.GridData;
38 import org.eclipse.swt.widgets.Combo;
39 import org.eclipse.swt.widgets.Composite;
40 import org.eclipse.swt.widgets.Control;
41 import org.eclipse.swt.widgets.Shell;
42
43
44 /**
45  * This class provides a dialog to enter or select an administrative role.
46  *
47  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
48  * @version $Rev$, $Date$
49  */

50 public class AdministrativeRoleDialog extends Dialog
51 {
52
53     /** The dialog title */
54     public static final String JavaDoc DIALOG_TITLE = "Administrative Role Editor";
55
56     /** The possible administrative role values. */
57     private static final String JavaDoc[] administrativeRoleValues = new String JavaDoc[]
58         { "autonomousArea", "accessControlSpecificArea", "accessControlInnerArea", "subschemaAdminSpecificArea",
59             "collectiveAttributeSpecificArea", "collectiveAttributeInnerArea", "triggerExecutionSpecificArea",
60             "triggerExecutionInnerArea" };
61
62     /** The initial value. */
63     private String JavaDoc initialValue;
64
65     /** The administrative role combo field. */
66     private DecoratedField administrativeRoleComboField;
67
68     /** The administrative role combo. */
69     private Combo administrativeRoleCombo;
70
71     /** The administrative role content proposal adapter */
72     private ContentProposalAdapter administrativeRoleCPA;
73
74     /** The return value. */
75     private String JavaDoc returnValue;
76
77
78     /**
79      * Creates a new instance of AdministrativeRoleDialog.
80      *
81      * @param parentShell the parent shell
82      * @param initialValue the initial value
83      */

84     public AdministrativeRoleDialog( Shell parentShell, String JavaDoc initialValue )
85     {
86         super( parentShell );
87         super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
88         this.initialValue = initialValue;
89         this.returnValue = null;
90     }
91
92
93     /**
94      * {@inheritDoc}
95      */

96     protected void configureShell( Shell shell )
97     {
98         super.configureShell( shell );
99         shell.setText( DIALOG_TITLE );
100         shell.setImage( ValueEditorsActivator.getDefault()
101             .getImage( ValueEditorsConstants.IMG_ADMINISTRATIVEROLEEDITOR ) );
102     }
103
104
105     /**
106      * {@inheritDoc}
107      */

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

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

127     protected Control createDialogArea( Composite parent )
128     {
129         // create composite
130
Composite composite = ( Composite ) super.createDialogArea( parent );
131         GridData gd = new GridData( GridData.FILL_BOTH );
132         gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
133         composite.setLayoutData( gd );
134
135         // combo widget
136
final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(
137             FieldDecorationRegistry.DEC_CONTENT_PROPOSAL );
138         administrativeRoleComboField = 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         administrativeRoleComboField.addFieldDecoration( fieldDecoration, SWT.TOP | SWT.LEFT, true );
148         administrativeRoleComboField.getLayoutControl()
149             .setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
150         administrativeRoleCombo = ( Combo ) administrativeRoleComboField.getControl();
151         administrativeRoleCombo.setItems( administrativeRoleValues );
152         administrativeRoleCombo.setText( initialValue );
153
154         // content proposal adapter
155
administrativeRoleCPA = new ContentProposalAdapter( administrativeRoleCombo, new ComboContentAdapter(),
156             new ListContentProposalProvider( administrativeRoleCombo.getItems() ), null, null );
157         administrativeRoleCPA.setFilterStyle( ContentProposalAdapter.FILTER_NONE );
158         administrativeRoleCPA.setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE );
159
160         applyDialogFont( composite );
161         return composite;
162     }
163
164
165     /**
166      * Gets the administrative role.
167      *
168      * @return the administrative role
169      */

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