updating SQL plugin with latest Quantum code
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / actions / DeleteObjectAction.java
diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/DeleteObjectAction.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/DeleteObjectAction.java
new file mode 100644 (file)
index 0000000..41b1ff0
--- /dev/null
@@ -0,0 +1,77 @@
+package net.sourceforge.phpdt.sql.actions;
+
+import java.util.Iterator;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.view.SubsetView;
+import net.sourceforge.phpdt.sql.view.bookmark.ObjectNode;
+import net.sourceforge.phpdt.sql.view.bookmark.SubsetNode;
+
+/**
+ * Deletes an entire object (Table) from the SubsetView
+ * @author root
+ *
+ */
+public class DeleteObjectAction extends Action implements IViewActionDelegate  {
+       SubsetView view;
+       /**
+        * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+        */
+       public void init(IViewPart view) {
+               this.view = (SubsetView) view;
+       }
+
+       /**
+        * @see org.eclipse.ui.IActionDelegate#run(IAction)
+        */
+       public void run(IAction action) {
+               run();
+       }
+       
+       public void run() {
+               Object selection = view.getCurrent();
+               if (selection instanceof SubsetNode) {
+                       SubsetNode node = (SubsetNode) selection;
+                       if (node != null) {
+                               boolean flag = MessageDialog.openConfirm(view.getSite().getShell(), 
+                                                               Messages.getString("DeleteObjectAction.DeleteSubset"),  //$NON-NLS-1$
+                                                               Messages.getString("DeleteObjectAction.ConfirmDeleteSubset") + node.getName()); //$NON-NLS-1$
+                               if (flag) {
+                                       view.deleteCurrent();
+                               }
+                       }
+               } else if (selection instanceof ObjectNode) {
+                       StructuredSelection allSelected = view.getSelection();
+                       Iterator iter = allSelected.iterator();
+                       if (! MessageDialog.openConfirm(view.getSite().getShell(), 
+                                                       Messages.getString("DeleteObjectAction.DeleteItems"),  //$NON-NLS-1$
+                                                       Messages.getString("DeleteObjectAction.ConfirmDeleteItems") )) //$NON-NLS-1$
+                               return;
+               
+                       while (iter.hasNext()) {
+                               Object current = iter.next();
+                               if (current instanceof ObjectNode) {
+                                       ObjectNode node = (ObjectNode) current;
+                                       if (node != null) {
+                                                       view.deleteObject(node);
+                                       }
+                               }
+                       }
+               }
+       }
+
+       /**
+        * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+        */
+       public void selectionChanged(IAction action, ISelection selection) {
+       }
+
+}