<s> """<STR_LIT>""" <EOL> from pyjamas . ui . DockPanel import DockPanel <EOL> from pyjamas . ui . RootPanel import RootPanel <EOL> from pyjamas . ui . AbsolutePanel import AbsolutePanel <EOL> from pyjamas . ui . FlexTable import FlexTable <EOL> from pyjamas . ui . Button import Button <EOL> from pyjamas . ui . Label import Label <EOL> from pyjamas . ui . HorizontalPanel import HorizontalPanel <EOL> from pyjamas . ui . VerticalPanel import VerticalPanel <EOL> from pyjamas . ui . TextBox import TextBox <EOL> from pyjamas . ui . PasswordTextBox import PasswordTextBox <EOL> from pyjamas . ui . ListBox import ListBox <EOL> from pyjamas . ui . Tooltip import TooltipListener <EOL> from Grid import Grid <EOL> import ApplicationConstants <EOL> class PyJsApp ( object ) : <EOL> appFrame = None <EOL> def __init__ ( self ) : <EOL> self . appFrame = AppFrame ( ) <EOL> class AppFrame ( object ) : <EOL> userForm = None <EOL> userList = None <EOL> rolePanel = None <EOL> def __init__ ( self ) : <EOL> self . panel = DockPanel ( ) <EOL> self . userList = UserList ( self ) <EOL> self . userForm = UserForm ( self ) <EOL> self . rolePanel = RolePanel ( self ) <EOL> self . panel . add ( self . userList , DockPanel . NORTH ) <EOL> self . panel . add ( self . userForm , DockPanel . WEST ) <EOL> self . panel . add ( self . rolePanel , DockPanel . EAST ) <EOL> RootPanel ( ) . add ( self . panel ) <EOL> self . Show ( ) <EOL> def Show ( self ) : <EOL> pass <EOL> class RolePanel ( AbsolutePanel ) : <EOL> user = None <EOL> selectedRole = None <EOL> roleList = None <EOL> roleCombo = None <EOL> addBtn = None <EOL> removeBtn = None <EOL> def __init__ ( self , parent ) : <EOL> AbsolutePanel . __init__ ( self ) <EOL> self . roleList = ListBox ( ) <EOL> self . roleList . setWidth ( '<STR_LIT>' ) <EOL> self . roleList . setVisibleItemCount ( <NUM_LIT:6> ) <EOL> self . roleList . addChangeListener ( self . onListChange ) <EOL> self . roleCombo = ListBox ( ) <EOL> self . roleCombo . addKeyboardListener ( self ) <EOL> self . roleCombo . addChangeListener ( self . onComboChange ) <EOL> self . addBtn = Button ( "<STR_LIT>" ) <EOL> self . addBtn . setEnabled ( False ) <EOL> self . removeBtn = Button ( "<STR_LIT>" ) <EOL> self . removeBtn . setEnabled ( False ) <EOL> vpanel = VerticalPanel ( ) <EOL> vpanel . add ( self . roleList ) <EOL> hpanel = HorizontalPanel ( ) <EOL> hpanel . add ( self . roleCombo ) <EOL> hpanel . add ( self . addBtn ) <EOL> hpanel . add ( self . removeBtn ) <EOL> vpanel . add ( hpanel ) <EOL> self . add ( vpanel ) <EOL> self . clearForm ( ) <EOL> return <EOL> def clearForm ( self ) : <EOL> self . user = None <EOL> self . updateRoleList ( [ ] ) <EOL> self . roleCombo . setItemTextSelection ( None ) <EOL> def updateRoleList ( self , items ) : <EOL> self . roleList . clear ( ) <EOL> for item in items : <EOL> self . roleList . addItem ( item ) <EOL> def updateRoleCombo ( self , choices , default_ ) : <EOL> self . roleCombo . clear ( ) <EOL> for choice in choices : <EOL> self . roleCombo . addItem ( choice ) <EOL> self . roleCombo . selectValue ( default_ ) <EOL> def onComboChange ( self , sender , keyCode = None , modifiers = None ) : <EOL> selected = self . roleCombo . getSelectedItemText ( ) <EOL> if not selected or selected [ <NUM_LIT:0> ] == ApplicationConstants . ROLE_NONE_SELECTED or not self . user : <EOL> self . addBtn . setEnabled ( False ) <EOL> self . selectedRole = None <EOL> else : <EOL> self . addBtn . setEnabled ( True ) <EOL> self . selectedRole = selected [ <NUM_LIT:0> ] <EOL> self . removeBtn . setEnabled ( False ) <EOL> self . roleList . setItemTextSelection ( None ) <EOL> def onListChange ( self , sender ) : <EOL> selected = self . roleList . getSelectedItemText ( ) <EOL> if selected : <EOL> self . removeBtn . setEnabled ( True ) <EOL> self . selectedRole = selected [ <NUM_LIT:0> ] <EOL> else : <EOL> self . removeBtn . setEnabled ( False ) <EOL> self . selectedRole = None <EOL> self . addBtn . setEnabled ( False ) <EOL> self . roleCombo . setItemTextSelection ( None ) <EOL> def onClick ( self , sender ) : <EOL> pass <EOL> def onKeyUp ( self , sender , keyCode , modifiers ) : <EOL> if sender == self . roleCombo : <EOL> self . onComboChange ( sender ) <EOL> elif sender == self . roleList : <EOL> self . onListChange ( sender ) <EOL> def onKeyDown ( self , sender , keyCode , modifiers ) : <EOL> pass <EOL> def onKeyPress ( self , sender , keyCode , modifiers ) : <EOL> pass <EOL> class UserList ( AbsolutePanel ) : <EOL> userGrid = None <EOL> newBtn = None <EOL> deleteBtn = None <EOL> users = None <EOL> selectedUser = None <EOL> def __init__ ( self , parent ) : <EOL> AbsolutePanel . __init__ ( self ) <EOL> self . userGrid = Grid ( ) <EOL> self . userGrid . createGrid ( <NUM_LIT:6> , <NUM_LIT:6> ) <EOL> self . userGrid . addTableListener ( self ) <EOL> self . userGrid . setBorderWidth ( <NUM_LIT:2> ) <EOL> self . userGrid . setCellPadding ( <NUM_LIT:4> ) <EOL> self . userGrid . setCellSpacing ( <NUM_LIT:1> ) <EOL> self . userGrid . setColLabelValue ( <NUM_LIT:0> , "<STR_LIT>" ) <EOL> self . userGrid . setColLabelValue ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . userGrid . setColLabelValue ( <NUM_LIT:2> , "<STR_LIT>" ) <EOL> self . userGrid . setColLabelValue ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> self . userGrid . setColLabelValue ( <NUM_LIT:4> , "<STR_LIT>" ) <EOL> self . userGrid . setColLabelValue ( <NUM_LIT:5> , "<STR_LIT>" ) <EOL> self . newBtn = Button ( "<STR_LIT>" ) <EOL> self . deleteBtn = Button ( "<STR_LIT>" ) <EOL> self . deleteBtn . setEnabled ( False ) <EOL> self . add ( self . userGrid ) <EOL> self . add ( self . newBtn ) <EOL> self . add ( self . deleteBtn ) <EOL> return <EOL> def updateUserGrid ( self , users ) : <EOL> self . userGrid . clearGrid ( ) <EOL> self . users = users <EOL> for i in range ( len ( users ) ) : <EOL> self . userGrid . setCellValue ( i , <NUM_LIT:0> , users [ i ] . username ) <EOL> self . userGrid . setCellValue ( i , <NUM_LIT:1> , users [ i ] . fname ) <EOL> self . userGrid . setCellValue ( i , <NUM_LIT:2> , users [ i ] . lname ) <EOL> self . userGrid . setCellValue ( i , <NUM_LIT:3> , users [ i ] . email ) <EOL> self . userGrid . setCellValue ( i , <NUM_LIT:4> , users [ i ] . department ) <EOL> self . userGrid . setCellValue ( i , <NUM_LIT:5> , users [ i ] . password ) <EOL> def onCellClicked ( self , sender , row , col ) : <EOL> try : <EOL> if row > <NUM_LIT:0> and row <= len ( self . users ) : <EOL> self . selectedUser = self . users [ row - <NUM_LIT:1> ] <EOL> self . userGrid . selectRow ( row ) <EOL> self . deleteBtn . setEnabled ( True ) <EOL> else : <EOL> self . userGrid . selectRow ( - <NUM_LIT:1> ) <EOL> self . selectedUser = None <EOL> self . deleteBtn . setEnabled ( False ) <EOL> except IndexError : <EOL> pass <EOL> def deSelect ( self ) : <EOL> self . userGrid . selectRow ( - <NUM_LIT:1> ) <EOL> class UserForm ( AbsolutePanel ) : <EOL> MODE_ADD = "<STR_LIT>" ; <EOL> MODE_EDIT = "<STR_LIT>" ; <EOL> user = None <EOL> mode = None <EOL> usernameInput = None <EOL> firstInput = None <EOL> lastInput = None <EOL> emailInput = None <EOL> passwordInput = None <EOL> confirmInput = None <EOL> departmentCombo = None <EOL> addBtn = None <EOL> cancelBtn = None <EOL> def __init__ ( self , parent ) : <EOL> AbsolutePanel . __init__ ( self ) <EOL> ftable = FlexTable ( ) <EOL> ftable . setWidget ( <NUM_LIT:0> , <NUM_LIT:0> , Label ( "<STR_LIT>" , wordWrap = False ) ) <EOL> ftableFormatter = ftable . getFlexCellFormatter ( ) <EOL> self . firstInput = TextBox ( ) <EOL> self . firstInput . addChangeListener ( self . checkValid ) <EOL> self . firstInput . addKeyboardListener ( self ) <EOL> ftable . setWidget ( <NUM_LIT:0> , <NUM_LIT:1> , self . firstInput ) <EOL> ftable . setWidget ( <NUM_LIT:1> , <NUM_LIT:0> , Label ( "<STR_LIT>" , wordWrap = False ) ) <EOL> self . lastInput = TextBox ( ) <EOL> self . lastInput . addChangeListener ( self . checkValid ) <EOL> self . lastInput . addKeyboardListener ( self ) <EOL> ftable . setWidget ( <NUM_LIT:1> , <NUM_LIT:1> , self . lastInput ) <EOL> ftable . setWidget ( <NUM_LIT:2> , <NUM_LIT:0> , Label ( "<STR_LIT>" , wordWrap = False ) ) <EOL> self . emailInput = TextBox ( ) <EOL> self . emailInput . addChangeListener ( self . checkValid ) <EOL> self . emailInput . addKeyboardListener ( self ) <EOL> ftable . setWidget ( <NUM_LIT:2> , <NUM_LIT:1> , self . emailInput ) <EOL> w = Label ( "<STR_LIT>" , wordWrap = False ) <EOL> w . addMouseListener ( TooltipListener ( "<STR_LIT>" ) ) <EOL> ftable . setWidget ( <NUM_LIT:3> , <NUM_LIT:0> , w ) <EOL> self . usernameInput = TextBox ( ) <EOL> self . usernameInput . addChangeListener ( self . checkValid ) <EOL> self . usernameInput . addKeyboardListener ( self ) <EOL> ftable . setWidget ( <NUM_LIT:3> , <NUM_LIT:1> , self . usernameInput ) <EOL> w = Label ( "<STR_LIT>" , wordWrap = False ) <EOL> w . addMouseListener ( TooltipListener ( "<STR_LIT>" ) ) <EOL> ftable . setWidget ( <NUM_LIT:4> , <NUM_LIT:0> , w ) <EOL> self . passwordInput = PasswordTextBox ( ) <EOL> self . passwordInput . addChangeListener ( self . checkValid ) <EOL> self . passwordInput . addKeyboardListener ( self ) <EOL> ftable . setWidget ( <NUM_LIT:4> , <NUM_LIT:1> , self . passwordInput ) <EOL> w = Label ( "<STR_LIT>" , wordWrap = False ) <EOL> w . addMouseListener ( TooltipListener ( "<STR_LIT>" ) ) <EOL> ftable . setWidget ( <NUM_LIT:5> , <NUM_LIT:0> , w ) <EOL> self . confirmInput = PasswordTextBox ( ) <EOL> self . confirmInput . addChangeListener ( self . checkValid ) <EOL> self . confirmInput . addKeyboardListener ( self ) <EOL> ftable . setWidget ( <NUM_LIT:5> , <NUM_LIT:1> , self . confirmInput ) <EOL> w = Label ( "<STR_LIT>" , wordWrap = False ) <EOL> w . addMouseListener ( TooltipListener ( "<STR_LIT>" ) ) <EOL> ftable . setWidget ( <NUM_LIT:6> , <NUM_LIT:0> , w ) <EOL> self . departmentCombo = ListBox ( ) <EOL> self . departmentCombo . addChangeListener ( self . checkValid ) <EOL> self . departmentCombo . addKeyboardListener ( self ) <EOL> ftable . setWidget ( <NUM_LIT:6> , <NUM_LIT:1> , self . departmentCombo ) <EOL> hpanel = HorizontalPanel ( ) <EOL> self . addBtn = Button ( "<STR_LIT>" ) <EOL> self . addBtn . setEnabled ( False ) <EOL> hpanel . add ( self . addBtn ) <EOL> self . cancelBtn = Button ( "<STR_LIT>" ) <EOL> hpanel . add ( self . cancelBtn ) <EOL> ftable . setWidget ( <NUM_LIT:7> , <NUM_LIT:0> , hpanel ) <EOL> ftableFormatter . setColSpan ( <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> self . add ( ftable ) <EOL> self . clearForm ( ) <EOL> return <EOL> def clearForm ( self ) : <EOL> self . user = None <EOL> self . usernameInput . setText ( '<STR_LIT>' ) <EOL> self . firstInput . setText ( '<STR_LIT>' ) <EOL> self . lastInput . setText ( '<STR_LIT>' ) <EOL> self . emailInput . setText ( '<STR_LIT>' ) <EOL> self . passwordInput . setText ( '<STR_LIT>' ) <EOL> self . confirmInput . setText ( '<STR_LIT>' ) <EOL> self . departmentCombo . setItemTextSelection ( None ) <EOL> self . updateMode ( self . MODE_ADD ) <EOL> self . checkValid ( ) <EOL> def updateUser ( self , user ) : <EOL> def setText ( elem , value ) : <EOL> if value : <EOL> elem . setText ( value ) <EOL> else : <EOL> elem . setText ( "<STR_LIT>" ) <EOL> self . user = user <EOL> setText ( self . usernameInput , self . user . username ) <EOL> setText ( self . firstInput , self . user . fname ) <EOL> setText ( self . lastInput , self . user . lname ) <EOL> setText ( self . emailInput , self . user . email ) <EOL> setText ( self . passwordInput , self . user . password ) <EOL> setText ( self . confirmInput , self . user . password ) <EOL> self . departmentCombo . setItemTextSelection ( [ self . user . department ] ) <EOL> self . checkValid ( ) <EOL> def updateDepartmentCombo ( self , choices , default_ ) : <EOL> self . departmentCombo . clear ( ) <EOL> for choice in choices : <EOL> self . departmentCombo . addItem ( choice ) <EOL> self . departmentCombo . selectValue ( default_ ) <EOL> def updateMode ( self , mode ) : <EOL> self . mode = mode <EOL> if self . mode == self . MODE_ADD : <EOL> self . addBtn . setText ( "<STR_LIT>" ) <EOL> else : <EOL> self . addBtn . setText ( "<STR_LIT>" ) <EOL> def checkValid ( self , evt = None ) : <EOL> if self . enableSubmit ( self . usernameInput . getText ( ) , self . passwordInput . getText ( ) , self . confirmInput . getText ( ) , self . departmentCombo . getSelectedItemText ( True ) ) : <EOL> self . addBtn . setEnabled ( True ) <EOL> else : <EOL> self . addBtn . setEnabled ( False ) <EOL> def enableSubmit ( self , u , p , c , d ) : <EOL> return ( len ( u ) > <NUM_LIT:0> and len ( p ) > <NUM_LIT:0> and p == c and len ( d ) > <NUM_LIT:0> ) <EOL> def onClick ( self , sender ) : <EOL> pass <EOL> def onKeyUp ( self , sender , keyCode , modifiers ) : <EOL> self . checkValid ( ) <EOL> def onKeyDown ( self , sender , keyCode , modifiers ) : <EOL> pass <EOL> def onKeyPress ( self , sender , keyCode , modifiers ) : <EOL> pass </s>
