1 5 package org.hibernate.eclipse.console.actions; 6 7 import java.util.Iterator ; 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 21 public class CloseQueryPageAction extends SelectionListenerAction { 22 23 private final ISelectionProvider selectionProvider; 24 25 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 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 |