KickJava   Java API By Example, From Geeks To Geeks.

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


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.valueeditors;
21
22
23
24 import org.apache.directory.ldapstudio.browser.common.dialogs.TextDialog;
25 import org.apache.directory.ldapstudio.browser.core.model.DN;
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.valueeditors.AbstractDialogStringValueEditor;
29 import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager;
30 import org.eclipse.swt.widgets.Shell;
31
32
33 /**
34  * ACI item editor specific value editor to edit the SubtreeSpecification.
35  *
36  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
37  * @version $Rev$, $Date$
38  */

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

43     private boolean refinementOrFilterVisible;
44
45
46     /**
47      * Default constructor, used by the {@link ValueEditorManager}.
48      */

49     public SubtreeValueEditor()
50     {
51         this.refinementOrFilterVisible = true;
52     }
53
54
55     /**
56      * Default constructor, used by the {@link ValueEditorManager}.
57      *
58      * @param refinementOrFilterVisible true if the refinement or filter widget should be visible
59      */

60     public SubtreeValueEditor( boolean refinementOrFilterVisible )
61     {
62         this.refinementOrFilterVisible = refinementOrFilterVisible;
63     }
64
65
66     /* (non-Javadoc)
67      * @see org.apache.directory.ldapstudio.valueeditors.AbstractDialogValueEditor#openDialog(org.eclipse.swt.widgets.Shell)
68      */

69     protected boolean openDialog( Shell shell )
70     {
71         Object JavaDoc value = getValue();
72         if ( value != null && value instanceof SubtreeSpecificationValueWrapper )
73         {
74             SubtreeSpecificationValueWrapper wrapper = ( SubtreeSpecificationValueWrapper ) value;
75
76             SubtreeSpecificationDialog dialog = new SubtreeSpecificationDialog( shell, wrapper.connection,
77                 wrapper.subentryDN, wrapper.subtreeSpecification, refinementOrFilterVisible );
78             if ( dialog.open() == TextDialog.OK && dialog.getSubtreeSpecificationValue() != null )
79             {
80                 setValue( dialog.getSubtreeSpecificationValue() );
81                 return true;
82             }
83         }
84         return false;
85     }
86
87
88     /* (non-Javadoc)
89      * @see org.apache.directory.ldapstudio.valueeditors.AbstractDialogStringValueEditor#getRawValue(org.apache.directory.ldapstudio.browser.core.model.IConnection, java.lang.Object)
90      */

91     public Object JavaDoc getRawValue( IValue value )
92     {
93         Object JavaDoc o = super.getRawValue( value );
94         if ( o != null && o instanceof String JavaDoc )
95         {
96             IConnection connection = value.getAttribute().getEntry().getConnection();
97             DN dn = value.getAttribute().getEntry().getDn();
98             return new SubtreeSpecificationValueWrapper( connection, dn, value.getStringValue() );
99         }
100
101         return null;
102     }
103
104
105     /* (non-Javadoc)
106      * @see org.apache.directory.ldapstudio.valueeditors.AbstractDialogStringValueEditor#getRawValue(org.apache.directory.ldapstudio.browser.core.model.IConnection, java.lang.Object)
107      */

108     public Object JavaDoc getRawValue( IConnection connection, Object JavaDoc value )
109     {
110         Object JavaDoc o = super.getRawValue( connection, value );
111         if ( o != null && o instanceof String JavaDoc )
112         {
113             return new SubtreeSpecificationValueWrapper( connection, null, ( String JavaDoc ) value );
114         }
115
116         return null;
117     }
118
119     /**
120      * The SubtreeSpecificationValueWrapper is used to pass contextual
121      * information to the opened SubtreeSpecificationDialog.
122      *
123      * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
124      * @version $Rev$, $Date$
125      */

126     private class SubtreeSpecificationValueWrapper
127     {
128         /** The connection, used in DnDialog to browse for an entry */
129         private IConnection connection;
130
131         /** The subentry's DN */
132         private DN subentryDN;
133
134         /** The subtreeSpecification */
135         private String JavaDoc subtreeSpecification;
136
137
138         /**
139          * Creates a new instance of SubtreeSpecificationValueWrapper.
140          *
141          * @param connection
142          * the connection
143          * @param subentryDn
144          * the DN of the subentry
145          * @param subtreeSpecification
146          * the subtreeSpecification
147          */

148         private SubtreeSpecificationValueWrapper( IConnection connection, DN subentryDN, String JavaDoc subtreeSpecification )
149         {
150             this.connection = connection;
151             this.subentryDN = subentryDN;
152             this.subtreeSpecification = subtreeSpecification;
153         }
154
155
156         /**
157          * {@inheritDoc}
158          */

159         public String JavaDoc toString()
160         {
161             return subtreeSpecification == null ? "" : subtreeSpecification; //$NON-NLS-1$
162
}
163
164     }
165 }
166
Popular Tags