KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > search > SearchPage


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.ui.search;
22
23
24 import org.apache.directory.ldapstudio.browser.common.actions.SelectionUtils;
25 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
26 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyEvent;
27 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener;
28 import org.apache.directory.ldapstudio.browser.common.widgets.search.SearchPageWrapper;
29 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
30 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
31 import org.eclipse.jface.dialogs.DialogPage;
32 import org.eclipse.jface.dialogs.IDialogConstants;
33 import org.eclipse.jface.resource.ImageDescriptor;
34 import org.eclipse.search.ui.ISearchPage;
35 import org.eclipse.search.ui.ISearchPageContainer;
36 import org.eclipse.swt.layout.GridData;
37 import org.eclipse.swt.layout.GridLayout;
38 import org.eclipse.swt.widgets.Composite;
39 import org.eclipse.ui.PlatformUI;
40
41
42 /**
43  * This class implements the {@link ISearchPage} to perform an LDAP search.
44  * It uses the {@link SearchPageWrapper} to render all UI elements.
45  *
46  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
47  * @version $Rev$, $Date$
48  */

49 public class SearchPage extends DialogPage implements ISearchPage, WidgetModifyListener
50 {
51
52     /** The search page container. */
53     private ISearchPageContainer container;
54
55     /** The search. */
56     private ISearch search;
57
58     /** The search page wrapper. */
59     private SearchPageWrapper spw;
60
61
62     /**
63      * Gets the ID of the LDAP search page.
64      *
65      * @return the ID of the LDAP search page
66      */

67     public static String JavaDoc getId()
68     {
69         return SearchPage.class.getName();
70     }
71
72
73     /**
74      * {@inheritDoc}
75      */

76     public void dispose()
77     {
78         spw.removeWidgetModifyListener( this );
79         super.dispose();
80     }
81
82
83     /**
84      * Creates a new instance of SearchPage.
85      */

86     public SearchPage()
87     {
88     }
89
90
91     /**
92      * Creates a new instance of SearchPage.
93      *
94      * @param title the title
95      */

96     public SearchPage( String JavaDoc title )
97     {
98         super( title );
99     }
100
101
102     /**
103      * Creates a new instance of SearchPage.
104      *
105      * @param title the title
106      * @param image the image
107      */

108     public SearchPage( String JavaDoc title, ImageDescriptor image )
109     {
110         super( title, image );
111     }
112
113
114     /**
115      * {@inheritDoc}
116      */

117     public boolean performAction()
118     {
119         spw.saveToSearch( search );
120         if ( search.getConnection() != null )
121         {
122             search.getConnection().getSearchManager().addSearch( search );
123             return spw.performSearch( search );
124         }
125
126         return false;
127     }
128
129
130     /**
131      * {@inheritDoc}
132      */

133     public void setContainer( ISearchPageContainer container )
134     {
135         this.container = container;
136     }
137
138
139     /**
140      * {@inheritDoc}
141      */

142     public void createControl( Composite parent )
143     {
144         // declare search
145
search = SelectionUtils.getExampleSearch( container.getSelection() );
146
147         // create search page content
148
GridLayout gl = new GridLayout();
149         parent.setLayout( gl );
150         GridData gd = new GridData( GridData.FILL_BOTH );
151         gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
152         // gd.heightHint =
153
// convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
154
parent.setLayoutData( gd );
155
156         Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 );
157         spw = new SearchPageWrapper( SearchPageWrapper.NONE );
158         spw.createContents( composite );
159         spw.loadFromSearch( search );
160         spw.addWidgetModifyListener( this );
161
162         PlatformUI.getWorkbench().getHelpSystem().setHelp( composite,
163             BrowserUIPlugin.PLUGIN_ID + "." + "tools_search_dialog" );
164         PlatformUI.getWorkbench().getHelpSystem().setHelp( parent,
165             BrowserUIPlugin.PLUGIN_ID + "." + "tools_search_dialog" );
166
167         super.setControl( parent );
168     }
169
170
171     /**
172      * {@inheritDoc}
173      */

174     public void setVisible( boolean visible )
175     {
176         container.setPerformActionEnabled( spw.isValid() );
177         super.setVisible( visible );
178     }
179
180
181     /**
182      * {@inheritDoc}
183      */

184     public void widgetModified( WidgetModifyEvent event )
185     {
186         container.setPerformActionEnabled( spw.isValid() );
187     }
188
189 }
190
Popular Tags