1 package com.quantum.actions;
3 import java.io.IOException;
4 import java.util.ArrayList;
5 import java.util.Iterator;
8 import com.quantum.ImageStore;
9 import com.quantum.Messages;
10 import com.quantum.model.Bookmark;
11 import com.quantum.model.BookmarkCollection;
12 import com.quantum.sql.SQLParser;
13 import com.quantum.ui.dialog.SimpleSelectionDialog;
14 import com.quantum.util.io.InputStreamHelper;
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.jface.action.IAction;
19 import org.eclipse.jface.action.IStatusLineManager;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.ui.IEditorPart;
24 import org.eclipse.ui.IObjectActionDelegate;
25 import org.eclipse.ui.IViewPart;
26 import org.eclipse.ui.IWorkbenchPart;
29 * This action can be executed against any .sql file, regardless of
30 * whether or not the Quantum perspective is open.
34 public class ExecuteAgainstAction extends BaseExecuteAction
35 implements IObjectActionDelegate {
37 private IFile[] files = null;
39 private IWorkbenchPart workbenchPart;
43 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
45 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
46 this.workbenchPart = targetPart;
49 protected Shell getShell() {
50 return this.workbenchPart.getSite().getShell();
54 * This method is called when a new selection has been made on one
57 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
59 public void selectionChanged(IAction action, ISelection selection) {
60 if (selection instanceof IStructuredSelection) {
61 IStructuredSelection structuredSelection =
62 (IStructuredSelection) selection;
63 List list = new ArrayList();
65 for (Iterator i = structuredSelection.iterator(); i.hasNext();) {
66 Object temp = i.next();
67 if (temp != null && temp instanceof IFile) {
71 this.files = (IFile[]) list.toArray(new IFile[list.size()]);
76 * @see com.quantum.actions.BaseSQLAction#getQueries()
78 protected List getQueries() throws IOException, CoreException {
79 List list = new ArrayList();
80 for (int i = 0, length = this.files == null ? 0 : this.files.length; i < length; i++) {
81 String fileContents = InputStreamHelper.readIntoString(this.files[i].getContents());
82 List queryList = SQLParser.parse(fileContents);
83 list.addAll(queryList);
88 protected IStatusLineManager getStatusLineManager() {
89 if (this.workbenchPart instanceof IViewPart) {
90 return ((IViewPart) this.workbenchPart).getViewSite().getActionBars().getStatusLineManager();
97 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
99 public void run(IAction action) {