Changes for variablemodificatin
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / DeleteAllRowsAction.java
1 package com.quantum.actions;
2
3 import java.sql.SQLException;
4
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;
10
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;
16
17 /**
18  * @author root
19  *
20  */
21 public class DeleteAllRowsAction extends SelectionListenerAction {
22     private IViewPart view;
23     
24         /**
25          * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
26          */
27         public DeleteAllRowsAction(IViewPart view) {
28         super(Messages.getString(DeleteAllRowsAction.class.getName() + ".text"));
29                 this.view = view;
30         }
31
32         public void run() {
33         try {
34             Table table = getTable();
35                         if (table != null) {
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.getQualifiedName() }));
41                                 if (flag) {
42                                         table.deleteAllRows();
43                                 }
44                         }
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);
53         }
54         }
55
56     private Table getTable() {
57         EntityNode node = (EntityNode) getSelectedNonResources().get(0);
58         return node == null ? null : (Table) node.getEntity();
59     }
60     
61     
62
63     protected Shell getShell() {
64         return this.view.getViewSite().getShell();
65     }
66
67     /* (non-Javadoc)
68      * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
69      */
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();
75     }
76
77 }