KickJava   Java API By Example, From Geeks To Geeks.

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


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.FilterWidgetDialog;
25 import org.apache.directory.ldapstudio.browser.common.dialogs.TextDialog;
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.eclipse.swt.widgets.Shell;
30
31
32 /**
33  * Implementation of IValueEditor for LDAP filters.
34  *
35  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
36  * @version $Rev$, $Date$
37  */

38 public class FilterValueEditor 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 FilterWidgetDialog.
48      */

49     public boolean openDialog( Shell shell )
50     {
51         Object JavaDoc value = getValue();
52         if ( value != null && value instanceof FilterValueEditorRawValueWrapper )
53         {
54             FilterValueEditorRawValueWrapper wrapper = ( FilterValueEditorRawValueWrapper ) value;
55             FilterWidgetDialog dialog = new FilterWidgetDialog( shell, Messages
56                 .getString( "FilterValueEditor.dialog.title" ), wrapper.filter, //$NON-NLS-1$
57
wrapper.connection );
58             if ( dialog.open() == TextDialog.OK && !EMPTY.equals( dialog.getFilter() ) )
59             {
60                 setValue( dialog.getFilter() );
61                 return true;
62             }
63         }
64         return false;
65     }
66
67
68     /**
69      * {@inheritDoc}
70      *
71      * Returns an AttributeTypeAndValueValueEditorRawValueWrapper.
72      */

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

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

104     private class FilterValueEditorRawValueWrapper
105     {
106         /**
107          * The connection, used in FilterDialog to build the list
108          * with possible attribute types.
109          */

110         private IConnection connection;
111
112         /** The filter, used as initial value in FilterDialog. */
113         private String JavaDoc filter;
114
115
116         /**
117          * Creates a new instance of FilterValueEditorRawValueWrapper.
118          *
119          * @param schema the schema
120          * @param attributeType the attribute type
121          */

122         private FilterValueEditorRawValueWrapper( IConnection connection, String JavaDoc filter )
123         {
124             this.connection = connection;
125             this.filter = filter;
126         }
127     }
128 }
129
Popular Tags