X-Git-Url: http://git.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/OpenQueryAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/OpenQueryAction.java new file mode 100644 index 0000000..8a78c6e --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/OpenQueryAction.java @@ -0,0 +1,43 @@ +package com.quantum.actions; + +import com.quantum.Messages; +import com.quantum.view.SQLQueryView; +import com.quantum.view.bookmark.QueryNode; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.actions.SelectionListenerAction; + +/** + * @author BC + */ +public class OpenQueryAction extends SelectionListenerAction { + + /** + * @param text + */ + public OpenQueryAction(IViewPart viewPart) { + super(Messages.getString(OpenQueryAction.class.getName() + ".text")); + } + + protected boolean updateSelection(IStructuredSelection selection) { + boolean enabled = super.updateSelection(selection); + enabled &= (selection.size() == 1 && + selection.getFirstElement() instanceof QueryNode); + return enabled; + } + public void run() { + SQLQueryView queryView = SQLQueryView.getInstance(); + if (queryView != null) { + queryView.setQuery(getQuery()); + } + } + private String getQuery() { + if (isEnabled()) { + QueryNode node = (QueryNode) getSelectedNonResources().get(0); + return node.getQuery(); + } else { + return null; + } + } +}