Added some examples for context menu on Outline
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / actions / DeleteObjectAction.java
1 package net.sourceforge.phpdt.sql.actions;
2
3 import java.util.Iterator;
4
5 import org.eclipse.jface.action.Action;
6 import org.eclipse.jface.action.IAction;
7 import org.eclipse.jface.dialogs.MessageDialog;
8 import org.eclipse.jface.viewers.ISelection;
9 import org.eclipse.jface.viewers.StructuredSelection;
10 import org.eclipse.ui.IViewActionDelegate;
11 import org.eclipse.ui.IViewPart;
12
13 import net.sourceforge.phpdt.sql.Messages;
14 import net.sourceforge.phpdt.sql.view.SubsetView;
15 import net.sourceforge.phpdt.sql.view.bookmark.ObjectNode;
16 import net.sourceforge.phpdt.sql.view.bookmark.SubsetNode;
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 }