SFA browser basic functionality
[sfa-gui.git] / SfaBrowser.py
index 778b448..14e8fc0 100644 (file)
@@ -1,13 +1,70 @@
 from Sink import Sink, SinkInfo
+from pyjamas.ui.Tree import Tree, TreeItem
+from pyjamas.ui.PopupPanel import PopupPanel
 from pyjamas.ui.HTML import HTML
+from SfaData import PlanetLabData
+
+class PopupRecord(PopupPanel):
+    def __init__(self, record):
+        PopupPanel.__init__(self, True)
+        contents = HTML("<pre>" + record + "</pre>")
+        self.setWidget(contents)
+        
+        self.setStyleName("ks-popups-Popup")
+
+class SfaItem(TreeItem):
+    def __init__(self, hrn, authority = False):
+        self.isAuthority = authority
+        self.hrn = hrn
+        last = hrn.split('.')[-1]
+        self.label = last
+        TreeItem.__init__(self, self.label)
+
+        if self.isAuthority:
+            self.addItem(PendingItem())
+
+class PendingItem(TreeItem):
+    def __init__(self):
+        TreeItem.__init__(self, "Please wait...")
+
+    def isPendingItem(self):
+        return True
 
 class SfaBrowser(Sink):
     def __init__(self):
 
         Sink.__init__(self)
 
-        text="Not implemented yet"
-        self.initWidget(HTML(text, True))
+        self.data = PlanetLabData()
+
+        self.tree = Tree()
+        
+        item = SfaItem("plc", True)
+        self.tree.addItem(item)
+
+        item = SfaItem("ple", True)
+        self.tree.addItem(item)
+
+        self.tree.addTreeListener(self)
+
+        self.initWidget(self.tree)
+
+
+    def onTreeItemSelected(self, item):
+        record = self.data.getRecord(item.hrn)
+        p = PopupRecord(record)
+        left = item.getAbsoluteLeft() + 10
+        top = item.getAbsoluteTop() + 10
+        p.setPopupPosition(left, top)
+        p.show()
+
+    def onTreeItemStateChanged(self, item):
+        child = item.getChild(0)
+        if hasattr(child, "isPendingItem"):
+            item.removeItem(child)
+            hrns = self.data.listChildren(item.hrn)
+            for (hrn, kind) in hrns:
+                item.addItem(SfaItem(hrn, (kind=="(authority)")))
 
     def onShow(self):
         pass