KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > valueeditors > objectclass > ObjectClassValueEditor


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

40 public class ObjectClassValueEditor extends AbstractDialogStringValueEditor
41 {
42
43     /**
44      * {@inheritDoc}
45      *
46      * This implementation opens the ObjectClassDialog.
47      */

48     public boolean openDialog( Shell shell )
49     {
50         Object JavaDoc value = getValue();
51         if ( value != null && value instanceof ObjectClassValueEditorRawValueWrapper )
52         {
53             ObjectClassValueEditorRawValueWrapper wrapper = ( ObjectClassValueEditorRawValueWrapper ) value;
54             ObjectClassDialog dialog = new ObjectClassDialog( shell, wrapper.schema, wrapper.objectClass );
55             if ( dialog.open() == TextDialog.OK && !"".equals( dialog.getObjectClass() ) )
56             {
57                 setValue( dialog.getObjectClass() );
58                 return true;
59             }
60         }
61         return false;
62     }
63
64
65     /**
66      * {@inheritDoc}
67      *
68      * This implementation appends the kind of object class,
69      * on of structural, abstract, auxiliary or obsolete.
70      */

71     public String JavaDoc getDisplayValue( IValue value )
72     {
73         if ( getRawValue( value ) == null )
74         {
75             return "NULL";
76         }
77
78         String JavaDoc displayValue = value.getStringValue();
79
80         if ( !showRawValues() && !"".equals( displayValue ) )
81         {
82             Schema schema = value.getAttribute().getEntry().getConnection().getSchema();
83             ObjectClassDescription ocd = schema.getObjectClassDescription( displayValue );
84             if ( ocd.isStructural() )
85             {
86                 displayValue = displayValue + " (structural)";
87             }
88             else if ( ocd.isAbstract() )
89             {
90                 displayValue = displayValue + " (abstract)";
91             }
92             else if ( ocd.isAuxiliary() )
93             {
94                 displayValue = displayValue + " (auxiliary)";
95             }
96             else if ( ocd.isObsolete() )
97             {
98                 displayValue = displayValue + " (obsolete)";
99             }
100         }
101
102         return displayValue;
103     }
104
105
106     /**
107      * {@inheritDoc}
108      *
109      * Returns null.
110      * Modification in search result editor not supported.
111      */

112     public Object JavaDoc getRawValue( AttributeHierarchy attributeHierarchy )
113     {
114         return null;
115     }
116
117
118     /**
119      * {@inheritDoc}
120      *
121      * Returns a ObjectClassValueEditorRawValueWrapper.
122      */

123     public Object JavaDoc getRawValue( IValue value )
124     {
125         if ( value == null || !value.isString() || !value.getAttribute().isObjectClassAttribute() )
126         {
127             return null;
128         }
129         else
130         {
131             return getRawValue( value.getAttribute().getEntry().getConnection(), value.getStringValue() );
132         }
133     }
134
135
136     /**
137      * {@inheritDoc}
138      *
139      * Returns a ObjectClassValueEditorRawValueWrapper.
140      */

141     public Object JavaDoc getRawValue( IConnection connection, Object JavaDoc value )
142     {
143         Schema schema = null;
144         if ( connection != null )
145         {
146             schema = connection.getSchema();
147         }
148         if ( schema == null || value == null || !( value instanceof String JavaDoc ) )
149         {
150             return null;
151         }
152
153         String JavaDoc ocValue = ( String JavaDoc ) value;
154         ObjectClassValueEditorRawValueWrapper wrapper = new ObjectClassValueEditorRawValueWrapper( schema, ocValue );
155         return wrapper;
156     }
157
158     /**
159      * The ObjectClassValueEditorRawValueWrapper is used to pass contextual
160      * information to the opened ObjectClassDialog.
161      *
162      * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
163      * @version $Rev$, $Date$
164      */

165     private class ObjectClassValueEditorRawValueWrapper
166     {
167         /**
168          * The schema, used in ObjectClassDialog to build the list
169          * with possible object classes.
170          */

171         private Schema schema;
172
173         /** The object class, used as initial value in ObjectClassDialog. */
174         private String JavaDoc objectClass;
175
176
177         /**
178          * Creates a new instance of ObjectClassValueEditorRawValueWrapper.
179          *
180          * @param schema the schema
181          * @param objectClass the object class
182          */

183         private ObjectClassValueEditorRawValueWrapper( Schema schema, String JavaDoc objectClass )
184         {
185             super();
186             this.schema = schema;
187             this.objectClass = objectClass;
188         }
189     }
190
191 }
192
Popular Tags