1 package net.sourceforge.phpdt.sql.actions;
4 import java.io.FileWriter;
5 import java.io.IOException;
6 import java.io.PrintWriter;
7 import java.util.StringTokenizer;
9 import org.eclipse.jface.action.Action;
10 import org.eclipse.jface.action.IAction;
11 import org.eclipse.jface.viewers.ISelection;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.widgets.FileDialog;
14 import org.eclipse.ui.IViewActionDelegate;
15 import org.eclipse.ui.IViewPart;
17 import net.sourceforge.phpdt.sql.view.LogProxy;
18 import net.sourceforge.phpdt.sql.view.SQLLogView;
19 import net.sourceforge.phpdt.sql.view.SQLQueryView;
21 public class ExportQueryAction extends Action implements IViewActionDelegate {
25 * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
27 public void init(IViewPart view) {
28 this.view = (SQLQueryView) view;
29 dialog = new FileDialog(view.getSite().getShell(), SWT.SAVE);
30 dialog.setFilterExtensions(new String[]{"*.sql", "*.ddl", "*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
31 dialog.setFilterNames(new String[]{Messages.getString("filedialog.sqlFiles"), //$NON-NLS-1$
32 Messages.getString("filedialog.ddlFiles"), Messages.getString("filedialog.allfiles")}); //$NON-NLS-1$ //$NON-NLS-2$
36 * @see org.eclipse.ui.IActionDelegate#run(IAction)
38 public void run(IAction action) {
43 String filename = dialog.open();
44 if (filename != null) {
46 File exportFile = new File(filename);
47 FileWriter fileWriter = new FileWriter(exportFile);
48 PrintWriter writer = new PrintWriter(fileWriter);
49 String output = view.getQuery();
50 StringTokenizer tokenizer = new StringTokenizer(output, "\n");
51 while (tokenizer.hasMoreElements()) {
52 String line = (String) tokenizer.nextElement();
56 } catch (IOException e) {
57 LogProxy.getInstance().addText(SQLLogView.ERROR, e.toString());
64 * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
66 public void selectionChanged(IAction action, ISelection selection) {