1 package net.sourceforge.phpdt.sql.actions;
3 import java.io.BufferedReader;
5 import java.io.FileReader;
6 import java.io.IOException;
8 import org.eclipse.jface.action.Action;
9 import org.eclipse.jface.action.IAction;
10 import org.eclipse.jface.viewers.ISelection;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.widgets.FileDialog;
13 import org.eclipse.ui.IViewActionDelegate;
14 import org.eclipse.ui.IViewPart;
16 import net.sourceforge.phpdt.sql.Messages;
17 import net.sourceforge.phpdt.sql.view.LogProxy;
18 import net.sourceforge.phpdt.sql.view.SQLLogView;
19 import net.sourceforge.phpdt.sql.view.SQLQueryView;
24 * To change this generated comment edit the template variable "typecomment":
25 * Window>Preferences>Java>Templates.
26 * To enable and disable the creation of type comments go to
27 * Window>Preferences>Java>Code Generation.
29 public class ImportQueryAction extends Action implements IViewActionDelegate {
33 * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
35 public void init(IViewPart view) {
36 this.view = (SQLQueryView) view;
37 dialog = new FileDialog(view.getSite().getShell(), SWT.OPEN);
38 dialog.setFilterExtensions(new String[]{"*.sql", "*.ddl", "*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
39 dialog.setFilterNames(new String[]{Messages.getString("filedialog.sqlFiles"), //$NON-NLS-1$
40 Messages.getString("filedialog.ddlFiles"), Messages.getString("filedialog.allfiles")}); //$NON-NLS-1$ //$NON-NLS-2$
44 * @see org.eclipse.ui.IActionDelegate#run(IAction)
46 public void run(IAction action) {
51 String filename = dialog.open();
52 if (filename != null) {
54 File importFile = new File(filename);
55 FileReader fileReader = new FileReader(importFile);
56 BufferedReader reader = new BufferedReader(fileReader);
58 StringBuffer buffer = new StringBuffer();
59 while ((line = reader.readLine()) != null) {
63 view.setQuery(buffer.toString());
65 } catch (IOException e) {
66 LogProxy.getInstance().addText(SQLLogView.ERROR, e.toString());
73 * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
75 public void selectionChanged(IAction action, ISelection selection) {