KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
25 import java.util.SortedMap JavaDoc;
26 import java.util.TreeMap JavaDoc;
27
28 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
29 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeValueProviderRelation;
30 import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager.ValueEditorExtension;
31 import org.eclipse.jface.dialogs.Dialog;
32 import org.eclipse.jface.dialogs.IDialogConstants;
33 import org.eclipse.swt.events.ModifyEvent;
34 import org.eclipse.swt.events.ModifyListener;
35 import org.eclipse.swt.widgets.Combo;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Control;
38 import org.eclipse.swt.widgets.Shell;
39
40
41 public class AttributeValueEditorDialog extends Dialog
42 {
43
44     private AttributeValueProviderRelation relation;
45
46     private SortedMap JavaDoc<String JavaDoc, ValueEditorExtension> class2ValueEditorProxyMap;
47
48     private String JavaDoc[] attributeTypesAndOids;
49
50     private SortedMap JavaDoc<String JavaDoc, String JavaDoc> vpName2classMap;
51
52     private AttributeValueProviderRelation returnRelation;
53
54     private Combo typeOrOidCombo;
55
56     private Combo valueEditorCombo;
57
58
59     public AttributeValueEditorDialog( Shell parentShell, AttributeValueProviderRelation relation,
60         SortedMap JavaDoc<String JavaDoc, ValueEditorExtension> class2ValueEditorProxyMap, String JavaDoc[] attributeTypesAndOids )
61     {
62         super( parentShell );
63         this.relation = relation;
64         this.class2ValueEditorProxyMap = class2ValueEditorProxyMap;
65         this.attributeTypesAndOids = attributeTypesAndOids;
66
67         this.returnRelation = null;
68
69         this.vpName2classMap = new TreeMap JavaDoc<String JavaDoc, String JavaDoc>();
70         for ( Iterator JavaDoc<ValueEditorExtension> it = this.class2ValueEditorProxyMap.values().iterator(); it.hasNext(); )
71         {
72             ValueEditorExtension vp = it.next();
73             vpName2classMap.put( vp.name, vp.className );
74         }
75     }
76
77
78     protected void configureShell( Shell newShell )
79     {
80         super.configureShell( newShell );
81         newShell.setText( "Attribute Value Editor" );
82     }
83
84
85     protected void okPressed()
86     {
87         this.returnRelation = new AttributeValueProviderRelation( this.typeOrOidCombo.getText(), this.vpName2classMap
88             .get( this.valueEditorCombo.getText() ) );
89         super.okPressed();
90     }
91
92
93     protected Control createDialogArea( Composite parent )
94     {
95
96         Composite composite = ( Composite ) super.createDialogArea( parent );
97
98         Composite c = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
99         BaseWidgetUtils.createLabel( c, "Attribute Type or OID:", 1 );
100         this.typeOrOidCombo = BaseWidgetUtils.createCombo( c, this.attributeTypesAndOids, -1, 1 );
101         if ( this.relation != null && this.relation.getAttributeNumericOidOrType() != null )
102         {
103             this.typeOrOidCombo.setText( this.relation.getAttributeNumericOidOrType() );
104         }
105         this.typeOrOidCombo.addModifyListener( new ModifyListener()
106         {
107             public void modifyText( ModifyEvent e )
108             {
109                 validate();
110             }
111         } );
112
113         BaseWidgetUtils.createLabel( c, "Value Editor:", 1 );
114         this.valueEditorCombo = BaseWidgetUtils.createReadonlyCombo( c, vpName2classMap.keySet()
115             .toArray( new String JavaDoc[0] ), -1, 1 );
116         if ( this.relation != null && this.relation.getValueProviderClassname() != null
117             && this.class2ValueEditorProxyMap.containsKey( this.relation.getValueProviderClassname() ) )
118         {
119             this.valueEditorCombo.setText( ( this.class2ValueEditorProxyMap.get( this.relation
120                 .getValueProviderClassname() ) ).name );
121         }
122         this.valueEditorCombo.addModifyListener( new ModifyListener()
123         {
124             public void modifyText( ModifyEvent e )
125             {
126                 validate();
127             }
128         } );
129
130         return composite;
131     }
132
133
134     private void validate()
135     {
136         super.getButton( IDialogConstants.OK_ID ).setEnabled(
137             !"".equals( this.valueEditorCombo.getText() ) && !"".equals( this.typeOrOidCombo.getText() ) );
138     }
139
140
141     public AttributeValueProviderRelation getRelation()
142     {
143         return returnRelation;
144     }
145
146 }
147
Popular Tags