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;
37 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
39 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
40 this.workbenchPart = targetPart;
43 protected Shell getShell() {
44 return this.workbenchPart.getSite().getShell();
48 * This method is called when a new selection has been made on one
51 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
53 public void selectionChanged(IAction action, ISelection selection) {
54 if (selection instanceof IStructuredSelection) {
55 IStructuredSelection structuredSelection =
56 (IStructuredSelection) selection;
57 List list = new ArrayList();
59 for (Iterator i = structuredSelection.iterator(); i.hasNext();) {
60 Object temp = i.next();
61 if (temp != null && temp instanceof IFile) {
65 this.files = (IFile[]) list.toArray(new IFile[list.size()]);
70 * @see com.quantum.actions.BaseSQLAction#getQueries()
72 protected List getQueries() throws IOException, CoreException {
73 List list = new ArrayList();
74 for (int i = 0, length = this.files == null ? 0 : this.files.length; i < length; i++) {
75 String fileContents = InputStreamHelper.readIntoString(this.files[i].getContents());
76 List queryList = SQLParser.parse(fileContents);
77 list.addAll(queryList);
82 protected IStatusLineManager getStatusLineManager() {
83 if (this.workbenchPart instanceof IViewPart) {
84 return ((IViewPart) this.workbenchPart).getViewSite().getActionBars().getStatusLineManager();
91 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
93 public void run(IAction action) {