1 package com.quantum.view.bookmark;
3 import java.util.Iterator;
6 import com.quantum.ImageStore;
7 import com.quantum.Messages;
8 import com.quantum.model.BookmarkCollection;
10 import org.eclipse.jface.dialogs.MessageDialog;
11 import org.eclipse.jface.viewers.ISelectionProvider;
12 import org.eclipse.jface.viewers.IStructuredSelection;
13 import org.eclipse.ui.IViewPart;
14 import org.eclipse.ui.actions.SelectionListenerAction;
20 public class DeleteAction extends SelectionListenerAction {
22 private IViewPart view;
24 public DeleteAction(IViewPart view, ISelectionProvider selectionProvider) {
25 super(Messages.getString(DeleteAction.class.getName() + ".text"));
26 setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.DELETE));
28 selectionProvider.addSelectionChangedListener(this);
32 if (isEachSelectionInstanceOf(getSelectedNonResources().iterator(), BookmarkNode.class)) {
34 } else if (isEachSelectionInstanceOf(getSelectedNonResources().iterator(), QueryNode.class)) {
42 private void deleteQueries() {
43 List nodes = getSelectedNonResources();
44 for (Iterator i = nodes.iterator(); i.hasNext();) {
45 QueryNode queryNode = (QueryNode) i.next();
46 if (queryNode != null) {
47 queryNode.getBookmark().removeQuery(queryNode.getQuery());
55 private void deleteBookmarks() {
56 List bookmarkNodes = getSelectedNonResources();
57 boolean flag = MessageDialog.openConfirm(view.getSite().getShell(),
58 Messages.getString(getClass(), "confirmTitle"),
59 Messages.getString(getClass(), "confirmText"));
61 for (Iterator i = bookmarkNodes.iterator(); flag && i.hasNext();) {
62 BookmarkNode bookmarkNode = (BookmarkNode) i.next();
63 if (bookmarkNode != null) {
64 BookmarkCollection.getInstance().removeBookmark(bookmarkNode.getBookmark());
69 public boolean updateSelection(IStructuredSelection selection) {
70 return isEachSelectionInstanceOf(selection.iterator(), BookmarkNode.class) ||
71 isEachSelectionInstanceOf(selection.iterator(), QueryNode.class);
77 * @param selectionClass
80 private boolean isEachSelectionInstanceOf(Iterator selection, Class selectionClass) {
81 boolean result = true;
82 for (Iterator i = selection; result && i.hasNext(); ) {
83 result &= (selectionClass.isInstance(i.next()));