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.view.bookmark.EntityNode;
11 import org.eclipse.jface.dialogs.MessageDialog;
12 import org.eclipse.jface.viewers.IStructuredSelection;
13 import org.eclipse.swt.widgets.Shell;
14 import org.eclipse.ui.IViewPart;
15 import org.eclipse.ui.actions.SelectionListenerAction;
21 public class DeleteAllRowsAction extends SelectionListenerAction {
22 private IViewPart view;
25 * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
27 public DeleteAllRowsAction(IViewPart view) {
28 super(Messages.getString(DeleteAllRowsAction.class.getName() + ".text"));
34 Table table = getTable();
36 boolean flag = MessageDialog.openConfirm(
37 view.getSite().getShell(),
38 Messages.getString(DeleteAllRowsAction.class.getName() + ".confirmTitle"),
39 Messages.getString(DeleteAllRowsAction.class.getName() + ".confirmText",
40 new Object[] { table.getCondQualifiedName() }));
42 table.deleteAllRows();
45 } catch (SQLException e) {
46 ExceptionDisplayDialog.openError(getShell(),
47 Messages.getString("ExecuteAgainstAction.title"),
48 Messages.getString("ExecuteAgainstAction.ConnectionException"), 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();