KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > aciitemeditor > ACIItemValueEditor


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 package org.apache.directory.ldapstudio.aciitemeditor;
21
22
23 import org.apache.directory.ldapstudio.aciitemeditor.dialogs.ACIItemDialog;
24 import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy;
25 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
26 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
27 import org.apache.directory.ldapstudio.browser.core.model.IValue;
28 import org.apache.directory.ldapstudio.valueeditors.AbstractDialogStringValueEditor;
29 import org.eclipse.swt.widgets.Shell;
30
31
32 /**
33  * The IValueEditor implementation of this plugin.
34  *
35  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
36  * @version $Rev$, $Date$
37  */

38 public class ACIItemValueEditor extends AbstractDialogStringValueEditor
39 {
40
41     /**
42      * The Constructor.
43      */

44     public ACIItemValueEditor()
45     {
46         super();
47     }
48
49
50     /**
51      * Opens the ACI item dialog.
52      *
53      * @param shell the shell
54      *
55      * @return true, if open dialog
56      */

57     public boolean openDialog( Shell shell )
58     {
59         Object JavaDoc value = getValue();
60         if ( value != null && value instanceof ACIItemValueWithContext )
61         {
62             ACIItemValueWithContext context = (ACIItemValueWithContext)value;
63             
64             ACIItemDialog dialog = new ACIItemDialog( shell, context );
65             if ( dialog.open() == ACIItemDialog.OK && !"".equals( dialog.getACIItemValue() ) ) //$NON-NLS-1$
66
{
67                 setValue( dialog.getACIItemValue() );
68                 return true;
69             }
70         }
71         return false;
72     }
73
74     
75     /**
76      * Returns a ACIItemValueContext with the connection
77      * and entry of the attribute hierarchy and an empty value if there
78      * are no values in attributeHierarchy.
79      *
80      * Returns a ACIItemValueContext with the connection
81      * and entry of the attribute hierarchy and a value if there is
82      * one value in attributeHierarchy.
83      *
84      * @param attributeHierarchy the attribute hierarchy
85      *
86      * @return the raw value
87      */

88     public Object JavaDoc getRawValue( AttributeHierarchy attributeHierarchy )
89     {
90         if ( attributeHierarchy == null )
91         {
92             return null;
93         }
94         else if ( attributeHierarchy.size() == 1 && attributeHierarchy.getAttribute().getValueSize() == 0 )
95         {
96             IEntry entry = attributeHierarchy.getAttribute().getEntry();
97             IConnection connection = entry.getConnection();
98             return new ACIItemValueWithContext( connection, entry, "" ); //$NON-NLS-1$
99
}
100         else if ( attributeHierarchy.size() == 1 && attributeHierarchy.getAttribute().getValueSize() == 1 )
101         {
102             IEntry entry = attributeHierarchy.getAttribute().getEntry();
103             IConnection connection = entry.getConnection();
104             String JavaDoc value = getDisplayValue( attributeHierarchy );
105             return new ACIItemValueWithContext( connection, entry, value );
106         }
107         else
108         {
109             return null;
110         }
111     }
112
113
114     /**
115      * Returns a ACIItemValueContext with the connection,
116      * entry and string value of the given value.
117      *
118      * @param value the value
119      *
120      * @return the raw value
121      */

122     public Object JavaDoc getRawValue( IValue value )
123     {
124         Object JavaDoc o = super.getRawValue( value );
125         if ( o != null && o instanceof String JavaDoc )
126         {
127             IEntry entry = value.getAttribute().getEntry();
128             IConnection connection = entry.getConnection();
129             String JavaDoc v = (String JavaDoc) o;
130             return new ACIItemValueWithContext( connection, entry, v );
131         }
132
133         return null;
134     }
135
136
137     /**
138      * Returns a ACIItemValueContext with the given
139      * connection, value and null entry.
140      *
141      * @param value the value
142      * @param connection the connection
143      *
144      * @return the raw value
145      */

146     public Object JavaDoc getRawValue( IConnection connection, Object JavaDoc value )
147     {
148         Object JavaDoc o = super.getRawValue( connection, value );
149         if ( o != null && o instanceof String JavaDoc )
150         {
151             String JavaDoc v = (String JavaDoc) o;
152             return new ACIItemValueWithContext( connection, null, v );
153         }
154
155         return null;
156     }
157
158 //
159
// /**
160
// * Returns always the string value.
161
// *
162
// * Reimplementation, because getRawValue() returns a
163
// * DnValueEditorRawValueWrapper.
164
// *
165
// * @param value the value
166
// *
167
// * @return the display value
168
// */
169
// public String getDisplayValue( IValue value )
170
// {
171
// if ( value == null )
172
// {
173
// return "NULL";
174
// }
175
//
176
// String displayValue = value.getStringValue();
177
// return displayValue;
178
// }
179

180 }
181
Popular Tags