show HTML files as local resources (no 'http://' url prefix)
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / ViewTableAction.java
1 package com.quantum.actions;
2
3 import com.quantum.ImageStore;
4 import com.quantum.Messages;
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 Entity entity;
19     
20         public ViewTableAction(IViewPart view) {
21         super(Messages.getString(ViewTableAction.class, "text"));
22         setImageDescriptor(
23                         ImageStore.getImageDescriptor(ImageStore.OPEN_TABLE));
24         }
25
26         public void run() {
27                 TableView.getInstance().loadTable(this.entity);
28         // TODO: reinstate this
29 //              } else if (view instanceof SubsetView){
30 //                      SubsetView subsetView = (SubsetView) view;
31 //                      node = (TreeNode) subsetView.getCurrent();
32 //                      if (!(node instanceof ObjectNode)) return;
33 //                      ObjectNode objectNode = (ObjectNode) node;
34 //
35 //                      String query = objectNode.getQuery();
36 //                      
37 //                      SQLResults results = ViewHelper.tryGetResults(view, objectNode.getConnection(), query);
38 //                      if (results != null && ! results.isError()) 
39 //                              TableView.getInstance().loadQuery(bookmark.getBookmark(), results);
40 //
41         }
42
43         public boolean updateSelection(IStructuredSelection selection) {
44         boolean enabled = super.updateSelection(selection);
45         enabled &= (selection.size() == 1);
46         
47         if (enabled) {
48             Object object = selection.getFirstElement();
49             if (object != null && object instanceof EntityNode) {
50                 EntityNode entityNode = (EntityNode) object;
51                 this.entity = entityNode.getEntity();
52                 enabled &= (entityNode.isTable() || entityNode.isView());
53             }
54         }
55         return enabled;
56         }
57 }