KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > dialogs > FilterWidgetDialog


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.browser.common.dialogs;
22
23
24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
25 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
26 import org.apache.directory.ldapstudio.browser.common.widgets.search.FilterWidget;
27 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
28 import org.eclipse.jface.dialogs.Dialog;
29 import org.eclipse.jface.dialogs.IDialogConstants;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.layout.GridData;
32 import org.eclipse.swt.layout.GridLayout;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Control;
35 import org.eclipse.swt.widgets.Shell;
36
37
38 /**
39  * This dialog is used to enter a LDAP filter.
40  *
41  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
42  * @version $Rev$, $Date$
43  */

44 public class FilterWidgetDialog extends Dialog
45 {
46
47     /** The title */
48     private String JavaDoc title;
49
50     /** The connection, used for attribute completion. */
51     private IConnection connection;
52
53     /** The filter widget. */
54     private FilterWidget filterWidget;
55
56     /** The filter. */
57     private String JavaDoc filter;
58
59
60     /**
61      * Creates a new instance of FilterWidgetDialog.
62      *
63      * @param parentShell the parent shell
64      * @param title the dialog's title
65      * @param filter the inital filter
66      * @param connection the connection, used for attribute completion
67      */

68     public FilterWidgetDialog( Shell parentShell, String JavaDoc title, String JavaDoc filter, IConnection connection )
69     {
70         super( parentShell );
71         this.title = title;
72         this.filter = filter;
73         this.connection = connection;
74         setShellStyle( SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE );
75     }
76
77
78     /**
79      * Gets the filter.
80      *
81      * @return the filter
82      */

83     public String JavaDoc getFilter()
84     {
85         return filter;
86     }
87
88
89     /**
90      * {@inheritDoc}
91      */

92     protected void configureShell( Shell newShell )
93     {
94         super.configureShell( newShell );
95         newShell.setText( title );
96         newShell.setImage( BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_FILTER_EDITOR ) );
97     }
98
99
100     /**
101      * {@inheritDoc}
102      */

103     protected void buttonPressed( int buttonId )
104     {
105         if ( buttonId == IDialogConstants.OK_ID )
106         {
107             filter = filterWidget.getFilter();
108             filterWidget.saveDialogSettings();
109         }
110
111         // call super implementation
112
super.buttonPressed( buttonId );
113     }
114
115
116     /**
117      * {@inheritDoc}
118      */

119     protected Control createDialogArea( Composite parent )
120     {
121         Composite composite = ( Composite ) super.createDialogArea( parent );
122         GridData gd = new GridData( GridData.FILL_BOTH );
123         gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
124         composite.setLayoutData( gd );
125
126         Composite inner = new Composite( composite, SWT.NONE );
127         GridLayout gridLayout = new GridLayout( 2, false );
128         inner.setLayout( gridLayout );
129         gd = new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL );
130         gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
131         inner.setLayoutData( gd );
132
133         filterWidget = new FilterWidget( connection, filter != null ? filter : "" );
134         filterWidget.createWidget( inner );
135         filterWidget.setFocus();
136
137         return composite;
138     }
139
140 }
141
Popular Tags