KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > dialogs > properties > SearchPropertyPage


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.dialogs.properties;
22
23
24 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
25 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyEvent;
26 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener;
27 import org.apache.directory.ldapstudio.browser.common.widgets.search.SearchPageWrapper;
28 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
29 import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateEvent;
30 import org.apache.directory.ldapstudio.browser.core.internal.model.Search;
31 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
32 import org.apache.directory.ldapstudio.browser.core.utils.Utils;
33
34 import org.eclipse.swt.widgets.Composite;
35 import org.eclipse.swt.widgets.Control;
36 import org.eclipse.ui.IWorkbenchPropertyPage;
37 import org.eclipse.ui.dialogs.PropertyPage;
38
39
40 public class SearchPropertyPage extends PropertyPage implements IWorkbenchPropertyPage, WidgetModifyListener
41 {
42
43     private ISearch search;
44
45     private SearchPageWrapper spw;
46
47
48     public SearchPropertyPage()
49     {
50         super();
51         super.noDefaultAndApplyButton();
52     }
53
54
55     public void dispose()
56     {
57         this.spw.removeWidgetModifyListener( this );
58         super.dispose();
59     }
60
61
62     protected Control createContents( Composite parent )
63     {
64
65         // declare search
66
ISearch search = ( ISearch ) getElement();
67         if ( search != null )
68         {
69             this.search = search;
70         }
71         else
72         {
73             this.search = new Search();
74         }
75
76         super.setMessage( "Search " + Utils.shorten( search.getName(), 30 ) );
77
78         Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 );
79
80         this.spw = new SearchPageWrapper( SearchPageWrapper.CONNECTION_READONLY );
81         this.spw.createContents( composite );
82         this.spw.loadFromSearch( this.search );
83         this.spw.addWidgetModifyListener( this );
84
85         return composite;
86     }
87
88
89     public boolean performOk()
90     {
91         boolean modified = this.spw.saveToSearch( this.search );
92         if ( modified && this.search.getConnection() != null && this.search.getConnection().isOpened() )
93         {
94             // send update event to force saving of new search parameters.
95
EventRegistry.fireSearchUpdated( new SearchUpdateEvent( this.search,
96                 SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ), this );
97
98             return this.spw.performSearch( this.search );
99         }
100
101         return true;
102     }
103
104
105     public void widgetModified( WidgetModifyEvent event )
106     {
107         setValid( this.spw.isValid() );
108     }
109
110 }
111
Popular Tags