KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > 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.schemas.view.search;
22
23
24 import org.apache.directory.ldapstudio.schemas.Messages;
25 import org.apache.directory.ldapstudio.schemas.PluginConstants;
26 import org.apache.directory.ldapstudio.schemas.view.views.SearchView;
27 import org.eclipse.jface.dialogs.DialogPage;
28 import org.eclipse.search.ui.ISearchPage;
29 import org.eclipse.search.ui.ISearchPageContainer;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.events.ModifyEvent;
32 import org.eclipse.swt.events.ModifyListener;
33 import org.eclipse.swt.layout.GridData;
34 import org.eclipse.swt.layout.GridLayout;
35 import org.eclipse.swt.widgets.Button;
36 import org.eclipse.swt.widgets.Combo;
37 import org.eclipse.swt.widgets.Composite;
38 import org.eclipse.swt.widgets.Group;
39 import org.eclipse.swt.widgets.Label;
40 import org.eclipse.ui.PlatformUI;
41
42
43 /**
44  * This class implements the Search Page.
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
50 {
51     private ISearchPageContainer container;
52
53     // UI Fields
54
private Combo searchCombo;
55     private Button allMetadataButton;
56     private Button nameButton;
57     private Button oidButton;
58     private Button descriptionButon;
59
60
61     /* (non-Javadoc)
62      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
63      */

64     public void createControl( Composite parent )
65     {
66         parent.setLayout( new GridLayout() );
67
68         Label label = new Label( parent, SWT.NONE );
69         label.setText( Messages.getString( "SearchPage.Search_string" ) ); //$NON-NLS-1$
70
label.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
71
72         searchCombo = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER );
73         searchCombo.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
74         searchCombo.addModifyListener( new ModifyListener()
75         {
76             public void modifyText( ModifyEvent arg0 )
77             {
78                 validate();
79             }
80         } );
81
82         Group scopeGroup = new Group( parent, SWT.NONE );
83         scopeGroup.setLayout( new GridLayout( 4, false ) );
84         scopeGroup.setText( Messages.getString( "SearchPage.Scope" ) ); //$NON-NLS-1$
85
scopeGroup.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
86
87         allMetadataButton = new Button( scopeGroup, SWT.RADIO );
88         allMetadataButton.setText( Messages.getString( "SearchPage.All_metada" ) ); //$NON-NLS-1$
89
allMetadataButton.setSelection( true );
90
91         nameButton = new Button( scopeGroup, SWT.RADIO );
92         nameButton.setText( Messages.getString( "SearchPage.Name" ) ); //$NON-NLS-1$
93

94         oidButton = new Button( scopeGroup, SWT.RADIO );
95         oidButton.setText( Messages.getString( "SearchPage.OID" ) ); //$NON-NLS-1$
96

97         descriptionButon = new Button( scopeGroup, SWT.RADIO );
98         descriptionButon.setText( Messages.getString( "SearchPage.Description" ) ); //$NON-NLS-1$
99

100         initSearchHistory();
101
102         super.setControl( parent );
103     }
104
105
106     /**
107      * Initializes the Search History.
108      */

109     private void initSearchHistory()
110     {
111         searchCombo.setItems( SearchView.loadHistory( PluginConstants.PREFS_SEARCH_VIEW_SEARCH_HISTORY ) );
112     }
113
114
115     /* (non-Javadoc)
116      * @see org.eclipse.search.ui.ISearchPage#performAction()
117      */

118     public boolean performAction()
119     {
120         SearchView searchView = ( SearchView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
121             .findView( SearchView.ID );
122
123         String JavaDoc scope = null;
124
125         if ( allMetadataButton.getSelection() )
126         {
127             scope = SearchView.SEARCH_ALL;
128         }
129         else if ( nameButton.getSelection() )
130         {
131             scope = SearchView.SEARCH_NAME;
132         }
133         else if ( oidButton.getSelection() )
134         {
135             scope = SearchView.SEARCH_OID;
136         }
137         else if ( descriptionButon.getSelection() )
138         {
139             scope = SearchView.SEARCH_DESC;
140         }
141
142         searchView.setSearch( searchCombo.getText(), scope );
143
144         return true;
145     }
146
147
148     /* (non-Javadoc)
149      * @see org.eclipse.search.ui.ISearchPage#setContainer(org.eclipse.search.ui.ISearchPageContainer)
150      */

151     public void setContainer( ISearchPageContainer container )
152     {
153         this.container = container;
154     }
155
156
157     /* (non-Javadoc)
158      * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
159      */

160     public void setVisible( boolean visible )
161     {
162         validate();
163         super.setVisible( visible );
164     }
165
166
167     /**
168      * Verifies if the page is valid.
169      *
170      * @return
171      * true if the page is valid
172      */

173     private boolean isValid()
174     {
175         return ( ( searchCombo.getText() != null ) && ( !"".equals( searchCombo.getText() ) ) ); //$NON-NLS-1$
176
}
177
178
179     /**
180      * Validates the page.
181      */

182     private void validate()
183     {
184         container.setPerformActionEnabled( isValid() );
185     }
186
187 }
188
Popular Tags