Added Node selection and Sliver (attribute) configuration panels to
[sfa-gui.git] / LinkPanel.py
1 from pyjamas.ui.VerticalPanel import VerticalPanel
2 from pyjamas.ui.HorizontalPanel import HorizontalPanel
3 from pyjamas.ui.CaptionPanel import CaptionPanel
4 from pyjamas.ui.ListBox import ListBox
5 from pyjamas.ui.TextBox import TextBox
6 from pyjamas.ui.Button import Button
7 from pyjamas.ui.HTML import HTML
8 from pyjamas.ui import HasAlignment
9
10 class AddPanel(CaptionPanel):
11     def __init__(self, top):
12         CaptionPanel.__init__(self, "Add virtual link")
13         self.top = top
14
15         hp = HorizontalPanel()
16         self.end1 = ListBox()
17         self.end1.addItem("Endpoint 1")
18         for sliver in self.top.rspec.get_sliver_list():
19             self.end1.addItem(sliver)
20
21         self.end2 = ListBox()
22         self.end2.addItem("Endpoint 2")
23         for sliver in self.top.rspec.get_sliver_list():
24             self.end2.addItem(sliver)
25
26         self.bw = TextBox()
27         self.bw.setText("1000")
28
29         hp.add(self.end1)
30         hp.add(self.end2)
31         hp.add(self.bw)
32         hp.add(Button("Add", self.go))
33
34         self.add(hp)
35
36     def go(self, sender):
37         end1 = self.end1.getItemText(self.end1.getSelectedIndex())
38         end2 = self.end2.getItemText(self.end2.getSelectedIndex())
39         bw = self.bw.getText()
40
41         self.top.refresh()
42         
43
44 class VlinkPanel(HorizontalPanel):
45     def __init__(self, top, description, bw):
46         HorizontalPanel.__init__(self)
47         self.description = description
48         self.bw = bw
49         self.top = top
50
51         self.setSpacing(5)
52         self.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
53         b = Button("X", self.delete)
54         self.add(b)
55         self.add(HTML("%s (%s kbps)" % (self.description, self.bw)))
56
57     def delete(self, sender):
58         self.top.refresh()
59
60
61 class LinkPanel(VerticalPanel):
62     def __init__(self, sfadata, rspec):
63         VerticalPanel.__init__(self)
64         self.data = sfadata
65         self.rspec = rspec
66
67         self.refresh()
68
69     def refresh(self):
70         self.clear()
71         self.add(AddPanel(self))
72
73         cp = CaptionPanel("Virtual links")
74         vp = VerticalPanel()
75         vlinks = self.rspec.get_vlink_list()
76         for (desc, bw) in vlinks:
77             vp.add(VlinkPanel(self, desc, bw))
78         cp.add(vp)
79         self.add(cp)
80