1 package com.quantum.actions;
3 import java.io.BufferedReader;
5 import java.io.FileReader;
6 import java.io.IOException;
8 import com.quantum.Messages;
9 import com.quantum.QuantumPlugin;
10 import com.quantum.view.LogProxy;
11 import com.quantum.view.SQLLogView;
12 import com.quantum.view.SQLQueryView;
14 import org.eclipse.jface.action.Action;
15 import org.eclipse.jface.action.IAction;
16 import org.eclipse.jface.viewers.ISelection;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.widgets.FileDialog;
19 import org.eclipse.ui.IViewActionDelegate;
20 import org.eclipse.ui.IViewPart;
26 public class ImportQueryAction extends Action implements IViewActionDelegate {
30 * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
32 public void init(IViewPart view) {
33 this.view = (SQLQueryView) view;
34 dialog = new FileDialog(view.getSite().getShell(), SWT.OPEN);
35 dialog.setFilterExtensions(new String[]{"*.sql", "*.ddl", "*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
36 dialog.setFilterNames(new String[]{Messages.getString("filedialog.sqlFiles"), //$NON-NLS-1$
37 Messages.getString("filedialog.ddlFiles"), Messages.getString("filedialog.allfiles")}); //$NON-NLS-1$ //$NON-NLS-2$
42 * @see org.eclipse.ui.IActionDelegate#run(IAction)
44 public void run(IAction action) {
49 dialog.setFilterPath(QuantumPlugin.getDefault().getPreferenceStore().getString("quantum.dialogs.importquery.path"));
50 String filename = dialog.open();
51 if (filename != null) {
52 QuantumPlugin.getDefault().getPreferenceStore().setValue("quantum.dialogs.importquery.path", filename);
55 File importFile = new File(filename);
56 FileReader fileReader = new FileReader(importFile);
57 BufferedReader reader = new BufferedReader(fileReader);
59 StringBuffer buffer = new StringBuffer();
61 while ((line = reader.readLine()) != null) {
65 view.setQuery(buffer.toString());
67 } catch (IOException e) {
68 LogProxy.getInstance().addText(SQLLogView.ERROR, e.toString());
75 * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
77 public void selectionChanged(IAction action, ISelection selection) {