OpenCirrus: Create the panel for making requests.
[sfa-gui.git] / SfaGUI.py
1 import pyjd # this is dummy in pyjs
2
3 from pyjamas.ui.Button import Button
4 from pyjamas.ui.RootPanel import RootPanel
5 from pyjamas.ui.HTML import HTML
6 from pyjamas.ui.DockPanel import DockPanel
7 from pyjamas.ui import HasAlignment
8 from pyjamas.ui.Hyperlink import Hyperlink
9 from pyjamas.ui.VerticalPanel import VerticalPanel
10 from pyjamas import Window
11 from SinkList import SinkList
12 from Configure import TopPanel
13 from pyjamas import History
14 import Welcome
15 import Slices
16 import Identities
17 import PlanetLab
18 import PLE
19 import PLJ
20 import GpENI
21 import VINI
22 import OpenCirrus
23 import SfaBrowser
24 import Configure
25
26 class SfaGUI:
27     def onHistoryChanged(self, token):
28         info = self.sink_list.find(token)
29         if info:
30             self.show(info, False)
31         else:
32             self.showInfo()
33
34     def onModuleLoad(self):
35         self.tp = TopPanel()
36         self.tp.setWidth("100%")
37
38         self.curInfo=''
39         self.curSink=None
40         self.description=HTML()
41         self.sink_list=SinkList()
42         self.panel=DockPanel()
43         self.loadSinks()
44         self.sinkContainer = DockPanel()
45         self.sinkContainer.setStyleName("ks-Sink")
46
47         vp=VerticalPanel()
48         vp.setWidth("100%")
49         vp.setHeight("100%")
50         vp.add(self.description)
51         vp.add(self.sinkContainer)
52
53         self.description.setStyleName("ks-Info")
54
55         self.panel.add(self.tp, DockPanel.NORTH)
56         self.panel.add(self.sink_list, DockPanel.WEST)
57         self.panel.add(vp, DockPanel.CENTER)
58
59         self.panel.setCellVerticalAlignment(self.sink_list, HasAlignment.ALIGN_TOP)
60         self.panel.setCellWidth(vp, "100%")
61         self.panel.setCellHeight(vp, "100%")
62
63         History.addHistoryListener(self)
64         RootPanel().add(self.panel)
65
66         #Show the initial screen.
67         initToken = History.getToken()
68         if len(initToken):
69             self.onHistoryChanged(initToken)
70         else:
71             self.showInfo()
72
73     def show(self, info, affectHistory):
74         if info == self.curInfo: return
75         self.curInfo = info
76
77         if self.curSink <> None:
78             self.curSink.onHide()
79             self.sinkContainer.remove(self.curSink)
80
81         self.curSink = info.getInstance()
82         self.sink_list.setSinkSelection(info.getName())
83         self.description.setHTML(info.getDescription())
84
85         if (affectHistory):
86             History.newItem(info.getName())
87
88         self.sinkContainer.add(self.curSink, DockPanel.CENTER)
89         self.sinkContainer.setCellWidth(self.curSink, "100%")
90         self.sinkContainer.setCellHeight(self.curSink, "100%")
91         self.sinkContainer.setCellVerticalAlignment(self.curSink, HasAlignment.ALIGN_TOP)
92         self.curSink.onShow()
93         
94     def loadSinks(self):
95         self.sink_list.addSink(Welcome.init())
96         #self.sink_list.addSink(Identities.init())
97         # self.sink_list.addSink(Slices.init())
98         self.sink_list.addSink(PlanetLab.init())
99         self.sink_list.addSink(PLE.init())
100         self.sink_list.addSink(PLJ.init())
101         self.sink_list.addSink(GpENI.init())
102         self.sink_list.addSink(VINI.init())
103         #self.sink_list.addSink(OpenCirrus.init())
104         self.sink_list.addSink(SfaBrowser.init())
105         self.sink_list.addSink(Configure.init())
106
107     def showInfo(self):
108         self.show(self.sink_list.find("Welcome"), False)
109
110
111
112
113 if __name__ == '__main__':
114     pyjd.setup("public/SfaGUI.html")
115     app = SfaGUI()
116     app.onModuleLoad()
117     pyjd.run()