initial quantum version
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / RemoveFromQuickListAction.java
diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/RemoveFromQuickListAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/RemoveFromQuickListAction.java
new file mode 100644 (file)
index 0000000..a677733
--- /dev/null
@@ -0,0 +1,56 @@
+package com.quantum.actions;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import com.quantum.Messages;
+import com.quantum.view.bookmark.EntityNode;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.actions.SelectionListenerAction;
+
+/**
+ * <p>This action takes an EntityNode and adds a copy of it to the quicklist
+ * of a bookmark.</p>
+ * 
+ * @author bcholmes
+ */
+public class RemoveFromQuickListAction extends SelectionListenerAction  {
+    private IViewPart view;
+    private List entities = Collections.synchronizedList(new ArrayList());
+
+    public RemoveFromQuickListAction(IViewPart view) {
+        super(Messages.getString(RemoveFromQuickListAction.class.getName() + ".text"));
+        this.view = view;
+    }
+
+    public void run() {
+        for (Iterator i = this.entities.iterator(); i.hasNext(); ) {
+            EntityNode entityNode = (EntityNode) i.next();
+            entityNode.getBookmark().removeQuickListEntry(entityNode.getEntity());
+        }
+    }
+
+    /**
+     * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+     */
+    public boolean updateSelection(IStructuredSelection selection) {
+        boolean enabled = super.updateSelection(selection);
+        this.entities.clear();
+        for (Iterator i = selection.iterator(); enabled && i.hasNext(); ) {
+            Object object = i.next();
+            if (object != null && object instanceof EntityNode) {
+                EntityNode node = (EntityNode) object;
+                enabled &= node.getBookmark().isInQuickList(node.getEntity());
+                this.entities.add(node);
+            } else {
+                enabled = false;
+            }
+        }
+        
+        return enabled;
+    }
+}