1 package com.quantum.actions;
3 import java.sql.SQLException;
5 import com.quantum.Messages;
6 import com.quantum.model.ConnectionException;
7 import com.quantum.model.Table;
8 import com.quantum.ui.dialog.ExceptionDisplayDialog;
9 import com.quantum.ui.dialog.SQLExceptionDialog;
10 import com.quantum.view.bookmark.EntityNode;
12 import org.eclipse.jface.dialogs.MessageDialog;
13 import org.eclipse.jface.viewers.IStructuredSelection;
14 import org.eclipse.swt.widgets.Shell;
15 import org.eclipse.ui.IViewPart;
16 import org.eclipse.ui.actions.SelectionListenerAction;
22 public class DeleteAllRowsAction extends SelectionListenerAction {
23 private IViewPart view;
26 * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
28 public DeleteAllRowsAction(IViewPart view) {
29 super(Messages.getString(DeleteAllRowsAction.class.getName() + ".text"));
34 Table table = getTable();
37 boolean flag = MessageDialog.openConfirm(
38 view.getSite().getShell(),
39 Messages.getString(DeleteAllRowsAction.class.getName() + ".confirmTitle"),
40 Messages.getString(DeleteAllRowsAction.class.getName() + ".confirmText",
41 new Object[] { table.getQualifiedName() }));
43 table.deleteAllRows();
46 } catch (SQLException e) {
47 SQLExceptionDialog.openException(getShell(),
48 table == null ? null : table.getBookmark(), e);
49 } catch (ConnectionException e) {
50 ExceptionDisplayDialog.openError(getShell(),
51 Messages.getString("ExecuteAgainstAction.title"),
52 Messages.getString("ExecuteAgainstAction.ConnectionException"), e);
56 private Table getTable() {
57 EntityNode node = (EntityNode) getSelectedNonResources().get(0);
58 return node == null ? null : (Table) node.getEntity();
63 protected Shell getShell() {
64 return this.view.getViewSite().getShell();
68 * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
70 protected boolean updateSelection(IStructuredSelection selection) {
71 boolean enabled = super.updateSelection(selection);
72 return enabled && selection.size() == 1 &&
73 (selection.getFirstElement() instanceof EntityNode) &&
74 ((EntityNode) selection.getFirstElement()).isTable();