1 package com.quantum.actions;
3 import java.io.IOException;
4 import java.sql.Connection;
5 import java.sql.SQLException;
7 import java.util.Vector;
9 import com.quantum.ImageStore;
10 import com.quantum.Messages;
11 import com.quantum.model.Bookmark;
12 import com.quantum.model.BookmarkCollection;
13 import com.quantum.sql.SQLParser;
14 import com.quantum.view.SQLQueryView;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.jface.action.Action;
18 import org.eclipse.jface.action.ActionContributionItem;
19 import org.eclipse.jface.action.IMenuCreator;
20 import org.eclipse.jface.action.IStatusLineManager;
21 import org.eclipse.jface.dialogs.MessageDialog;
22 import org.eclipse.swt.events.MenuAdapter;
23 import org.eclipse.swt.events.MenuEvent;
24 import org.eclipse.swt.widgets.Control;
25 import org.eclipse.swt.widgets.Menu;
26 import org.eclipse.swt.widgets.MenuItem;
27 import org.eclipse.swt.widgets.Shell;
30 * Executes a query from the QueryView
34 public class ExecuteAction extends BaseExecuteAction implements IMenuCreator {
35 private SQLQueryView view;
37 public ExecuteAction(SQLQueryView view) {
39 setActionDefinitionId("com.quantum.actions.ExecuteAction");
40 setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.PLAY));
41 setText(Messages.getString("sqlqueryview.executeQuery"));
42 setToolTipText(Messages.getString("sqlqueryview.executeQuery"));
48 protected void execute(Bookmark bookmark, Connection connection)
49 throws IOException, CoreException, SQLException {
51 boolean autoCommitPreference = this.view.isAutoCommitPreference();
52 boolean changed = false;
53 if (connection.getAutoCommit() != autoCommitPreference) {
54 connection.setAutoCommit(autoCommitPreference);
58 super.execute(bookmark, connection);
61 MessageDialog.openInformation(getShell(),
62 Messages.getString(ExecuteAction.class, "autocommitTitle"),
63 Messages.getString(ExecuteAction.class, "autocommitMessage",
64 new Object[] { bookmark.getName() }));
70 protected List getQueries() {
71 getStatusLineManager().setMessage(
72 Messages.getString(ExecuteAction.class, "parsing")); //$NON-NLS-1$
73 Vector queries = SQLParser.parse(view.getQuery());
80 protected IStatusLineManager getStatusLineManager() {
81 return this.view.getViewSite().getActionBars().getStatusLineManager();
84 protected Shell getShell() {
85 return this.view.getViewSite().getShell();
88 public void dispose() {
91 public Menu getMenu(Control parent) {
92 Menu menu = new Menu(parent);
94 * Add listener to repopulate the menu each time
95 * it is shown because the list of bookmarks may have changed.
97 menu.addMenuListener(new MenuAdapter() {
98 public void menuShown(MenuEvent e) {
99 Menu menu = (Menu)e.widget;
100 MenuItem[] items = menu.getItems();
101 for (int i=0; i < items.length; i++) {
110 public Menu getMenu(Menu parent) {
115 protected void fillMenu(Menu menu) {
116 Bookmark[] bookmarks = BookmarkCollection.getInstance().getBookmarks();
117 for (int i = 0, length = bookmarks == null ? 0 : bookmarks.length; i < length; i++) {
118 final Bookmark bookmark = bookmarks[i];
119 Action action = new Action() {
121 ExecuteAction.this.execute(bookmark);
124 action.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.BOOKMARK));
125 action.setText(bookmark.getName());
126 ActionContributionItem item = new ActionContributionItem(action);