latest quantum sources 2.3.2
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / RemoveFromQuickListAction.java
1 package com.quantum.actions;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.Iterator;
6 import java.util.List;
7
8 import com.quantum.Messages;
9 import com.quantum.view.bookmark.EntityNode;
10
11 import org.eclipse.jface.viewers.IStructuredSelection;
12 import org.eclipse.ui.IViewPart;
13 import org.eclipse.ui.actions.SelectionListenerAction;
14
15 /**
16  * <p>This action takes an EntityNode and adds a copy of it to the quicklist
17  * of a bookmark.</p>
18  * 
19  * @author bcholmes
20  */
21 public class RemoveFromQuickListAction extends SelectionListenerAction  {
22     private List entities = Collections.synchronizedList(new ArrayList());
23
24     public RemoveFromQuickListAction(IViewPart view) {
25         super(Messages.getString(RemoveFromQuickListAction.class.getName() + ".text"));
26     }
27
28     public void run() {
29         for (Iterator i = this.entities.iterator(); i.hasNext(); ) {
30             EntityNode entityNode = (EntityNode) i.next();
31             entityNode.getBookmark().removeQuickListEntry(entityNode.getEntity());
32         }
33     }
34
35     /**
36      * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
37      */
38     public boolean updateSelection(IStructuredSelection selection) {
39         boolean enabled = super.updateSelection(selection);
40         this.entities.clear();
41         for (Iterator i = selection.iterator(); enabled && i.hasNext(); ) {
42             Object object = i.next();
43             if (object != null && object instanceof EntityNode) {
44                 EntityNode node = (EntityNode) object;
45                 enabled &= node.getBookmark().isInQuickList(node.getEntity());
46                 this.entities.add(node);
47             } else {
48                 enabled = false;
49             }
50         }
51         
52         return enabled;
53     }
54 }