a6777336d622700d49eabc22c81f968fad275485
[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 IViewPart view;
23     private List entities = Collections.synchronizedList(new ArrayList());
24
25     public RemoveFromQuickListAction(IViewPart view) {
26         super(Messages.getString(RemoveFromQuickListAction.class.getName() + ".text"));
27         this.view = view;
28     }
29
30     public void run() {
31         for (Iterator i = this.entities.iterator(); i.hasNext(); ) {
32             EntityNode entityNode = (EntityNode) i.next();
33             entityNode.getBookmark().removeQuickListEntry(entityNode.getEntity());
34         }
35     }
36
37     /**
38      * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
39      */
40     public boolean updateSelection(IStructuredSelection selection) {
41         boolean enabled = super.updateSelection(selection);
42         this.entities.clear();
43         for (Iterator i = selection.iterator(); enabled && i.hasNext(); ) {
44             Object object = i.next();
45             if (object != null && object instanceof EntityNode) {
46                 EntityNode node = (EntityNode) object;
47                 enabled &= node.getBookmark().isInQuickList(node.getEntity());
48                 this.entities.add(node);
49             } else {
50                 enabled = false;
51             }
52         }
53         
54         return enabled;
55     }
56 }