1 package com.quantum.actions;
3 import java.io.BufferedReader;
5 import java.io.FileReader;
6 import java.io.IOException;
8 import com.quantum.ImageStore;
9 import com.quantum.Messages;
10 import com.quantum.QuantumPlugin;
11 import com.quantum.view.LogProxy;
12 import com.quantum.view.SQLLogView;
13 import com.quantum.view.SQLQueryView;
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.widgets.FileDialog;
20 import org.eclipse.ui.IViewActionDelegate;
21 import org.eclipse.ui.IViewPart;
27 public class ImportQueryAction extends Action implements IViewActionDelegate {
31 public ImportQueryAction() {
32 setText(Messages.getString("sqlqueryview.importQuery"));
33 setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.IMPORT));
34 setToolTipText(Messages.getString("sqlqueryview.importQuery"));
38 * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
40 public void init(IViewPart view) {
41 this.view = (SQLQueryView) view;
42 dialog = new FileDialog(view.getSite().getShell(), SWT.OPEN);
43 dialog.setFilterExtensions(new String[]{"*.sql", "*.ddl", "*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
44 dialog.setFilterNames(new String[]{Messages.getString("filedialog.sqlFiles"), //$NON-NLS-1$
45 Messages.getString("filedialog.ddlFiles"), Messages.getString("filedialog.allfiles")}); //$NON-NLS-1$ //$NON-NLS-2$
49 * @see org.eclipse.ui.IActionDelegate#run(IAction)
51 public void run(IAction action) {
56 dialog.setFilterPath(QuantumPlugin.getDefault().getPreferenceStore().getString("quantum.dialogs.importquery.path"));
57 String filename = dialog.open();
58 if (filename != null) {
59 QuantumPlugin.getDefault().getPreferenceStore().setValue("quantum.dialogs.importquery.path", filename);
62 File importFile = new File(filename);
63 FileReader fileReader = new FileReader(importFile);
64 BufferedReader reader = new BufferedReader(fileReader);
66 StringBuffer buffer = new StringBuffer();
68 while ((line = reader.readLine()) != null) {
72 view.setQuery(buffer.toString());
74 } catch (IOException e) {
75 LogProxy.getInstance().addText(SQLLogView.ERROR, e.toString());
82 * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
84 public void selectionChanged(IAction action, ISelection selection) {