KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > dialogs > preferences > AttributeDialog


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.browser.common.dialogs.preferences;
22
23
24 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
25 import org.apache.directory.ldapstudio.browser.core.model.schema.BinaryAttribute;
26
27 import org.eclipse.jface.dialogs.Dialog;
28 import org.eclipse.jface.dialogs.IDialogConstants;
29 import org.eclipse.swt.events.ModifyEvent;
30 import org.eclipse.swt.events.ModifyListener;
31 import org.eclipse.swt.widgets.Combo;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Control;
34 import org.eclipse.swt.widgets.Shell;
35
36
37 public class AttributeDialog extends Dialog
38 {
39
40     private BinaryAttribute currentAttribute;
41
42     private String JavaDoc[] attributeTypesAndOids;
43
44     private BinaryAttribute returnAttribute;
45
46     private Combo typeOrOidCombo;
47
48
49     public AttributeDialog( Shell parentShell, BinaryAttribute currentAttribute, String JavaDoc[] attributeNamesAndOids )
50     {
51         super( parentShell );
52         this.currentAttribute = currentAttribute;
53         this.attributeTypesAndOids = attributeNamesAndOids;
54
55         this.returnAttribute = null;
56     }
57
58
59     protected void configureShell( Shell newShell )
60     {
61         super.configureShell( newShell );
62         newShell.setText( "Select Attribute Type or OID" );
63     }
64
65
66     protected void okPressed()
67     {
68         this.returnAttribute = new BinaryAttribute( typeOrOidCombo.getText() );
69         super.okPressed();
70     }
71
72
73     protected Control createDialogArea( Composite parent )
74     {
75
76         Composite composite = ( Composite ) super.createDialogArea( parent );
77
78         Composite c = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
79         BaseWidgetUtils.createLabel( c, "Attribute Type or OID:", 1 );
80         this.typeOrOidCombo = BaseWidgetUtils.createCombo( c, this.attributeTypesAndOids, -1, 1 );
81         if ( this.currentAttribute != null )
82         {
83             this.typeOrOidCombo.setText( currentAttribute.getAttributeNumericOidOrName() );
84         }
85         this.typeOrOidCombo.addModifyListener( new ModifyListener()
86         {
87             public void modifyText( ModifyEvent e )
88             {
89                 validate();
90             }
91         } );
92
93         return composite;
94     }
95
96
97     private void validate()
98     {
99         super.getButton( IDialogConstants.OK_ID ).setEnabled( !"".equals( this.typeOrOidCombo.getText() ) );
100     }
101
102
103     public BinaryAttribute getAttribute()
104     {
105         return returnAttribute;
106     }
107
108 }
109
Popular Tags