X-Git-Url: http://git.onelab.eu/?p=sfa-gui.git;a=blobdiff_plain;f=SfaBrowser.py;h=b2053e3c97a0c7e4179387144ae58e9a4862091f;hp=778b448a093280b20e5b174163558738480a0f30;hb=refs%2Fheads%2Fmarcoy-dev;hpb=070773be5d006ef8764f81c075fcc3f37a5ba4e7 diff --git a/SfaBrowser.py b/SfaBrowser.py index 778b448..b2053e3 100644 --- a/SfaBrowser.py +++ b/SfaBrowser.py @@ -1,13 +1,92 @@ 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 + +def alwaysDelegateFocus(elem): + return True + +class PopupRecord(PopupPanel): + def __init__(self, record): + PopupPanel.__init__(self, True) + contents = HTML("
" + record + "
") + self.setWidget(contents) + self.setStyleName("ks-popups-Popup") + +class SfaItem(TreeItem): + def __init__(self, hrn, kind, truncate = True): + self.kind = kind + self.hrn = hrn + if truncate: + hrn = hrn.split('.')[-1] + if self.kind == "(authority)": + self.label = "%s" % hrn + elif self.kind == "(slice)": + self.label = "%s" % hrn + elif self.kind == "(user)": + self.label = "%s" % hrn + else: + self.label = "%s" % hrn + + TreeItem.__init__(self, self.label) + + if self.kind == "(authority)": + 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() + self.tree.shouldTreeDelegateFocusToElement = alwaysDelegateFocus + + item = SfaItem("plc", "(authority)", truncate = False) + self.tree.addItem(item) + + item = SfaItem("plc.glc", "(authority)", truncate = False) + self.tree.addItem(item) + + item = SfaItem("plc.vini", "(authority)", truncate = False) + self.tree.addItem(item) + + item = SfaItem("ple", "(authority)", truncate = False) + self.tree.addItem(item) + + item = SfaItem("plj", "(authority)", truncate = False) + 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 = sorted(self.data.listChildren(item.hrn), + key=lambda hrn: hrn[0]) + for (hrn, kind) in hrns: + item.addItem(SfaItem(hrn, kind)) def onShow(self): pass