KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > console > actions > CloseQueryPageAction


1 /*
2  * Created on 2004-11-01 by max
3  *
4  */

5 package org.hibernate.eclipse.console.actions;
6
7 import java.util.Iterator JavaDoc;
8
9 import org.eclipse.jface.viewers.ISelectionProvider;
10 import org.eclipse.jface.viewers.IStructuredSelection;
11 import org.eclipse.ui.actions.SelectionListenerAction;
12 import org.hibernate.console.ImageConstants;
13 import org.hibernate.console.KnownConfigurations;
14 import org.hibernate.console.QueryPage;
15 import org.hibernate.eclipse.console.utils.EclipseImages;
16
17 /**
18  * @author max
19  *
20  */

21 public class CloseQueryPageAction extends SelectionListenerAction {
22
23     private final ISelectionProvider selectionProvider;
24     
25     /**
26      * @param text
27      */

28     public CloseQueryPageAction(ISelectionProvider selectionProvider) {
29         super("");
30         this.selectionProvider = selectionProvider;
31         this.selectionProvider.addSelectionChangedListener(this);
32         setEnabled(!this.selectionProvider.getSelection().isEmpty());
33         
34         setImageDescriptor(EclipseImages.getImageDescriptor(ImageConstants.CLOSE));
35         setDisabledImageDescriptor(EclipseImages.getImageDescriptor(ImageConstants.CLOSE_DISABLED));
36         
37         setToolTipText("Close query page");
38     }
39
40     public void run() {
41         IStructuredSelection selection =
42             (IStructuredSelection) this.selectionProvider.getSelection();
43         if (!selection.isEmpty()) {
44             for (Iterator JavaDoc i = selection.iterator(); i.hasNext(); ) {
45                 KnownConfigurations.getInstance().getQueryPageModel().remove((QueryPage) i.next());
46             }
47         }
48     }
49
50     public boolean updateSelection(IStructuredSelection selection) {
51         return !selection.isEmpty();
52     }
53
54 }
55
Popular Tags