1 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 title="Search Criteria"; 53 String 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:nodeType)"; 56 InputDialog inputDialog = new InputDialog(shell,title,dialogMessage,initialValue,null); 57 int dialogResult = inputDialog.open(); 58 if (dialogResult == InputDialog.OK){ 59 String language = Query.XPATH; 60 String 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 78 } 79 80 } 81 | Popular Tags |