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.view.LogProxy;
17 import net.sourceforge.phpdt.sql.view.SQLLogView;
18 import net.sourceforge.phpdt.sql.view.SQLQueryView;
23 * To change this generated comment edit the template variable "typecomment":
24 * Window>Preferences>Java>Templates.
25 * To enable and disable the creation of type comments go to
26 * Window>Preferences>Java>Code Generation.
28 public class ImportQueryAction extends Action implements IViewActionDelegate {
32 * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
34 public void init(IViewPart view) {
35 this.view = (SQLQueryView) view;
36 dialog = new FileDialog(view.getSite().getShell(), SWT.OPEN);
37 dialog.setFilterExtensions(new String[]{"*.sql", "*.ddl", "*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
38 dialog.setFilterNames(new String[]{Messages.getString("filedialog.sqlFiles"), //$NON-NLS-1$
39 Messages.getString("filedialog.ddlFiles"), Messages.getString("filedialog.allfiles")}); //$NON-NLS-1$ //$NON-NLS-2$
43 * @see org.eclipse.ui.IActionDelegate#run(IAction)
45 public void run(IAction action) {
50 String filename = dialog.open();
51 if (filename != null) {
53 File importFile = new File(filename);
54 FileReader fileReader = new FileReader(importFile);
55 BufferedReader reader = new BufferedReader(fileReader);
57 StringBuffer buffer = new StringBuffer();
58 while ((line = reader.readLine()) != null) {
62 view.setQuery(buffer.toString());
64 } catch (IOException e) {
65 LogProxy.getInstance().addText(SQLLogView.ERROR, e.toString());
72 * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
74 public void selectionChanged(IAction action, ISelection selection) {