KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > visualcontent > ui > nodetree > SearchAction


1 /**
2  * VC Browser - Visualizes the content of a JSR 170 compatible repository
3  * Copyright (C) 2006 Sandro Böhme
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * 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, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.visualcontent.ui.nodetree;
19
20 import javax.jcr.RepositoryException;
21 import javax.jcr.Session;
22 import javax.jcr.query.InvalidQueryException;
23 import javax.jcr.query.Query;
24 import javax.jcr.query.QueryResult;
25
26 import org.eclipse.core.runtime.IStatus;
27 import org.eclipse.jface.action.IAction;
28 import org.eclipse.jface.dialogs.ErrorDialog;
29 import org.eclipse.jface.dialogs.InputDialog;
30 import org.eclipse.jface.dialogs.MessageDialog;
31 import org.eclipse.jface.viewers.ISelection;
32 import org.eclipse.swt.widgets.Shell;
33 import org.eclipse.ui.IViewActionDelegate;
34 import org.eclipse.ui.IViewPart;
35 import org.eclipse.ui.PlatformUI;
36 import org.visualcontent.ui.UiPlugin;
37
38 public class SearchAction implements IViewActionDelegate {
39
40     private NodeTreeViewPart nodeTreeView;
41
42     public void init(IViewPart view) {
43         nodeTreeView = (NodeTreeViewPart) view;
44     }
45
46     public void run(IAction action) {
47         Session jcrSession = nodeTreeView.getJcrSession();
48         Shell shell=nodeTreeView.getSite().getShell();
49         if (jcrSession==null){
50             MessageDialog.openInformation(shell,"Please connect to a repository first.","Please connect to a repository in order to perform a search.");
51         } else {
52             String JavaDoc title="Search Criteria";
53             String JavaDoc dialogMessage="Please specify an XPath query. It's specified starting from page 95 in the JSR 170 Specification. Here is an example:";
54             //String initialValue="//element(*, nt:resource)[jcr:contains(.,'JSR 170')]";
55
String JavaDoc initialValue="//element(*, nt:nodeType)";
56             InputDialog inputDialog = new InputDialog(shell,title,dialogMessage,initialValue,null);
57             int dialogResult = inputDialog.open();
58             if (dialogResult == InputDialog.OK){
59                 String JavaDoc language = Query.XPATH;
60                 String JavaDoc statement = inputDialog.getValue();
61                 Query query =null;
62                 try {
63                     query = jcrSession.getWorkspace().getQueryManager().createQuery(statement, language);
64                     SearchJob searchJob = new SearchJob("Search for '"+statement+"' in the repository.",query,nodeTreeView);
65                     searchJob.schedule();
66                 } catch (InvalidQueryException e) {
67                     UiPlugin.getDefault().showError("Could not create the query.",e);
68                 } catch (RepositoryException e) {
69                     UiPlugin.getDefault().showError("Could not create the query.",e);
70                 }
71             }
72         }
73     }
74
75     public void selectionChanged(IAction action, ISelection selection) {
76         // TODO Auto-generated method stub
77

78     }
79
80 }
81
Popular Tags