KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > aciitemeditor > valueeditors > AttributeTypeValueEditor


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.aciitemeditor.valueeditors;
22
23
24 import org.apache.directory.ldapstudio.browser.common.dialogs.TextDialog;
25 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
26 import org.apache.directory.ldapstudio.browser.core.model.IValue;
27 import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
28 import org.apache.directory.ldapstudio.valueeditors.AbstractDialogStringValueEditor;
29 import org.eclipse.swt.widgets.Shell;
30
31
32 /**
33  * Implementation of IValueEditor for attribute types.
34  *
35  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
36  * @version $Rev$, $Date$
37  */

38 public class AttributeTypeValueEditor extends AbstractDialogStringValueEditor
39 {
40
41     private static final String JavaDoc EMPTY = ""; //$NON-NLS-1$
42

43
44     /**
45      * {@inheritDoc}
46      *
47      * This implementation opens the AttributeTypeDialog.
48      */

49     public boolean openDialog( Shell shell )
50     {
51         Object JavaDoc value = getValue();
52         if ( value != null && value instanceof AttributeTypeValueEditorRawValueWrapper )
53         {
54             AttributeTypeValueEditorRawValueWrapper wrapper = ( AttributeTypeValueEditorRawValueWrapper ) value;
55             AttributeTypeDialog dialog = new AttributeTypeDialog( shell, wrapper.schema, wrapper.attributeType );
56             if ( dialog.open() == TextDialog.OK && !EMPTY.equals( dialog.getAttributeType() ) )
57             {
58                 setValue( dialog.getAttributeType() );
59                 return true;
60             }
61         }
62         return false;
63     }
64
65
66     /**
67      * {@inheritDoc}
68      *
69      * Returns an AttributeTypeAndValueValueEditorRawValueWrapper.
70      */

71     public Object JavaDoc getRawValue( IValue value )
72     {
73         return value != null ? getRawValue( value.getAttribute().getEntry().getConnection(), value.getStringValue() )
74             : null;
75     }
76
77
78     /**
79      * {@inheritDoc}
80      *
81      * Returns a AttributeTypeValueEditorRawValueWrapper.
82      */

83     public Object JavaDoc getRawValue( IConnection connection, Object JavaDoc value )
84     {
85         Schema schema = null;
86         if ( connection != null )
87         {
88             schema = connection.getSchema();
89         }
90         if ( schema == null || value == null || !( value instanceof String JavaDoc ) )
91         {
92             return null;
93         }
94
95         String JavaDoc atValue = ( String JavaDoc ) value;
96         AttributeTypeValueEditorRawValueWrapper wrapper = new AttributeTypeValueEditorRawValueWrapper( schema, atValue );
97         return wrapper;
98     }
99
100     /**
101      * The AttributeTypeValueEditorRawValueWrapper is used to pass contextual
102      * information to the opened AttributeTypeDialog.
103      *
104      * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
105      * @version $Rev$, $Date$
106      */

107     private class AttributeTypeValueEditorRawValueWrapper
108     {
109         /**
110          * The schema, used in AttributeTypeDialog to build the list
111          * with possible attribute types.
112          */

113         private Schema schema;
114
115         /** The attribute type, used as initial value in AttributeTypeDialog. */
116         private String JavaDoc attributeType;
117
118
119         /**
120          * Creates a new instance of AttributeTypeValueEditorRawValueWrapper.
121          *
122          * @param schema the schema
123          * @param attributeType the attribute type
124          */

125         private AttributeTypeValueEditorRawValueWrapper( Schema schema, String JavaDoc attributeType )
126         {
127             super();
128             this.schema = schema;
129             this.attributeType = attributeType;
130         }
131     }
132
133 }
134
Popular Tags