added button to start tests.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / ViewTableAction.java
1 package com.quantum.actions;
2
3 import com.quantum.Messages;
4 import com.quantum.QuantumPlugin;
5 import com.quantum.model.Entity;
6 import com.quantum.view.bookmark.EntityNode;
7 import com.quantum.view.tableview.TableView;
8
9 import org.eclipse.jface.viewers.IStructuredSelection;
10 import org.eclipse.ui.IViewPart;
11 import org.eclipse.ui.actions.SelectionListenerAction;
12
13 /**
14  * @author root
15  * Implements action for "View Table"
16 */
17 public class ViewTableAction extends SelectionListenerAction {
18     private IViewPart view;
19     private Entity entity;
20     
21         public ViewTableAction(IViewPart view) {
22         super(Messages.getString(ViewTableAction.class.getName() + ".text"));
23                 this.view = view;
24         setImageDescriptor(
25             QuantumPlugin.getImageDescriptor("table.gif")); //$NON-NLS-1$
26         }
27
28         public void run() {
29                 TableView.getInstance().loadTable(this.entity);
30         // TODO: reinstate this
31 //              } else if (view instanceof SubsetView){
32 //                      SubsetView subsetView = (SubsetView) view;
33 //                      node = (TreeNode) subsetView.getCurrent();
34 //                      if (!(node instanceof ObjectNode)) return;
35 //                      ObjectNode objectNode = (ObjectNode) node;
36 //
37 //                      String query = objectNode.getQuery();
38 //                      
39 //                      SQLResults results = ViewHelper.tryGetResults(view, objectNode.getConnection(), query);
40 //                      if (results != null && ! results.isError()) 
41 //                              TableView.getInstance().loadQuery(bookmark.getBookmark(), results);
42 //
43         }
44
45         public boolean updateSelection(IStructuredSelection selection) {
46         boolean enabled = super.updateSelection(selection);
47         enabled &= (selection.size() == 1);
48         
49         if (enabled) {
50             Object object = selection.getFirstElement();
51             if (object != null && object instanceof EntityNode) {
52                 EntityNode entityNode = (EntityNode) object;
53                 this.entity = entityNode.getEntity();
54                 enabled &= (entityNode.isTable() || entityNode.isView());
55             }
56         }
57         return enabled;
58         }
59 }