reduce warnings due to core.runtime deprecations
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / OpenQueryAction.java
1 package com.quantum.actions;
2
3 import com.quantum.Messages;
4 import com.quantum.view.SQLQueryView;
5 import com.quantum.view.bookmark.QueryNode;
6
7 import org.eclipse.jface.viewers.IStructuredSelection;
8 import org.eclipse.ui.IViewPart;
9 import org.eclipse.ui.actions.SelectionListenerAction;
10
11 /**
12  * @author BC
13  */
14 public class OpenQueryAction extends SelectionListenerAction {
15
16     /**
17      * @param text
18      */
19     public OpenQueryAction(IViewPart viewPart) {
20         super(Messages.getString(OpenQueryAction.class.getName() + ".text"));
21     }
22
23     protected boolean updateSelection(IStructuredSelection selection) {
24         boolean enabled = super.updateSelection(selection);
25         enabled &= (selection.size() == 1 &&
26             selection.getFirstElement() instanceof QueryNode);
27         return enabled;
28     }
29     public void run() {
30         SQLQueryView queryView = SQLQueryView.getInstance();
31         if (queryView != null) {
32             queryView.setQuery(getQuery());
33         }
34     }
35     private String getQuery() {
36         if (isEnabled()) {
37             QueryNode node = (QueryNode) getSelectedNonResources().get(0);
38             return node.getQuery();
39         } else {
40             return null;
41         }
42     }
43 }