KickJava   Java API By Example, From Geeks To Geeks.

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


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