1 package com.quantum.actions;
3 import java.io.IOException;
4 import java.util.ArrayList;
5 import java.util.Iterator;
8 import com.quantum.sql.parser.SQLParser;
9 import com.quantum.util.io.InputStreamHelper;
11 import org.eclipse.core.resources.IFile;
12 import org.eclipse.core.runtime.CoreException;
13 import org.eclipse.jface.action.IAction;
14 import org.eclipse.jface.action.IStatusLineManager;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.swt.widgets.Shell;
18 import org.eclipse.ui.IObjectActionDelegate;
19 import org.eclipse.ui.IViewPart;
20 import org.eclipse.ui.IWorkbenchPart;
23 * This action can be executed against any .sql file, regardless of
24 * whether or not the Quantum perspective is open.
28 public class ExecuteAgainstAction extends BaseExecuteAction
29 implements IObjectActionDelegate {
31 private IFile[] files = null;
33 private IWorkbenchPart workbenchPart;
36 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
38 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
39 this.workbenchPart = targetPart;
42 protected Shell getShell() {
43 return this.workbenchPart.getSite().getShell();
47 * This method is called when a new selection has been made on one
50 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
52 public void selectionChanged(IAction action, ISelection selection) {
53 if (selection instanceof IStructuredSelection) {
54 IStructuredSelection structuredSelection =
55 (IStructuredSelection) selection;
56 List list = new ArrayList();
58 for (Iterator i = structuredSelection.iterator(); i.hasNext();) {
59 Object temp = i.next();
60 if (temp != null && temp instanceof IFile) {
64 this.files = (IFile[]) list.toArray(new IFile[list.size()]);
69 * @see com.quantum.actions.BaseSQLAction#getQueries()
71 protected List getQueries() throws IOException, CoreException {
72 List list = new ArrayList();
73 for (int i = 0, length = this.files == null ? 0 : this.files.length; i < length; i++) {
74 String fileContents = InputStreamHelper.readIntoString(this.files[i].getContents());
75 List queryList = SQLParser.parse(fileContents);
76 list.addAll(queryList);
81 protected IStatusLineManager getStatusLineManager() {
82 if (this.workbenchPart instanceof IViewPart) {
83 return ((IViewPart) this.workbenchPart).getViewSite().getActionBars().getStatusLineManager();
90 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
92 public void run(IAction action) {