initial quantum version
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / DeleteObjectAction.java
1 package com.quantum.actions;
2
3 import java.util.Iterator;
4
5 import com.quantum.Messages;
6 import com.quantum.view.subset.ObjectNode;
7 import com.quantum.view.subset.SubsetNode;
8 import com.quantum.view.subset.SubsetView;
9
10 import org.eclipse.jface.action.Action;
11 import org.eclipse.jface.action.IAction;
12 import org.eclipse.jface.dialogs.MessageDialog;
13 import org.eclipse.jface.viewers.ISelection;
14 import org.eclipse.jface.viewers.StructuredSelection;
15 import org.eclipse.ui.IViewActionDelegate;
16 import org.eclipse.ui.IViewPart;
17
18 /**
19  * Deletes an entire object (Table) from the SubsetView
20  * @author root
21  *
22  */
23 public class DeleteObjectAction extends Action implements IViewActionDelegate  {
24         SubsetView view;
25         /**
26          * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
27          */
28         public void init(IViewPart view) {
29                 this.view = (SubsetView) view;
30         }
31
32         /**
33          * @see org.eclipse.ui.IActionDelegate#run(IAction)
34          */
35         public void run(IAction action) {
36                 run();
37         }
38         
39         public void run() {
40                 Object selection = view.getCurrent();
41                 if (selection instanceof SubsetNode) {
42                         SubsetNode node = (SubsetNode) selection;
43                         if (node != null) {
44                                 boolean flag = MessageDialog.openConfirm(view.getSite().getShell(), 
45                                                                 Messages.getString("DeleteObjectAction.DeleteSubset"),  //$NON-NLS-1$
46                                                                 Messages.getString("DeleteObjectAction.ConfirmDeleteSubset") + node.getName()); //$NON-NLS-1$
47                                 if (flag) {
48                                         view.deleteCurrent();
49                                 }
50                         }
51                 } else if (selection instanceof ObjectNode) {
52                         StructuredSelection allSelected = view.getSelection();
53                         Iterator iter = allSelected.iterator();
54                         if (! MessageDialog.openConfirm(view.getSite().getShell(), 
55                                                         Messages.getString("DeleteObjectAction.DeleteItems"),  //$NON-NLS-1$
56                                                         Messages.getString("DeleteObjectAction.ConfirmDeleteItems") )) //$NON-NLS-1$
57                                 return;
58                 
59                         while (iter.hasNext()) {
60                                 Object current = iter.next();
61                                 if (current instanceof ObjectNode) {
62                                         ObjectNode node = (ObjectNode) current;
63                                         if (node != null) {
64                                                         view.deleteObject(node);
65                                         }
66                                 }
67                         }
68                 }
69         }
70
71         /**
72          * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
73          */
74         public void selectionChanged(IAction action, ISelection selection) {
75         }
76
77 }