Package muntjac :: Package ui :: Module twin_col_select
[hide private]
[frames] | no frames]

Source Code for Module muntjac.ui.twin_col_select

  1  # Copyright (C) 2012 Vaadin Ltd.  
  2  # Copyright (C) 2012 Richard Lincoln 
  3  #  
  4  # Licensed under the Apache License, Version 2.0 (the "License");  
  5  # you may not use this file except in compliance with the License.  
  6  # You may obtain a copy of the License at  
  7  #  
  8  #     http://www.apache.org/licenses/LICENSE-2.0  
  9  #  
 10  # Unless required by applicable law or agreed to in writing, software  
 11  # distributed under the License is distributed on an "AS IS" BASIS,  
 12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
 13  # See the License for the specific language governing permissions and  
 14  # limitations under the License. 
 15   
 16  """Defines a component with two lists: left side for available items 
 17  and right side for selected items.""" 
 18   
 19  from muntjac.ui.abstract_select import AbstractSelect 
 20   
 21  from muntjac.terminal.gwt.client.ui.v_twin_col_select import VTwinColSelect 
 22   
 23   
24 -class TwinColSelect(AbstractSelect):
25 """Multiselect component with two lists: left side for available items 26 and right side for selected items. 27 """ 28 29 CLIENT_WIDGET = None #ClientWidget(VTwinColSelect, LoadStyle.EAGER) 30
31 - def __init__(self, *args):
32 """ 33 @param args: tuple of the form 34 - () 35 - (caption) 36 - (caption, dataSource) 37 - (caption, options) 38 """ 39 self._columns = 0 40 self._rows = 0 41 self._leftColumnCaption = None 42 self._rightColumnCaption = None 43 44 super(TwinColSelect, self).__init__(*args)
45 46
47 - def setColumns(self, columns):
48 """Sets the number of columns in the editor. If the number of columns 49 is set 0, the actual number of displayed columns is determined 50 implicitly by the adapter. 51 52 The number of columns overrides the value set by setWidth. Only if 53 columns are set to 0 (default) the width set using 54 L{setWidth} or L{setWidth} is used. 55 56 @param columns: the number of columns to set. 57 """ 58 if columns < 0: 59 columns = 0 60 if self._columns != columns: 61 self._columns = columns 62 self.requestRepaint()
63 64
65 - def getColumns(self):
66 return self._columns
67 68
69 - def getRows(self):
70 return self._rows
71 72
73 - def setRows(self, rows):
74 """Sets the number of rows in the editor. If the number of rows is set 75 to 0, the actual number of displayed rows is determined implicitly by 76 the adapter. 77 78 If a height if set (using L{setHeight} or L{setHeight}) it overrides 79 the number of rows. Leave the height undefined to use this method. This 80 is the opposite of how L{setColumns} work. 81 82 @param rows: the number of rows to set. 83 """ 84 if rows < 0: 85 rows = 0 86 if self._rows != rows: 87 self._rows = rows 88 self.requestRepaint()
89 90
91 - def paintContent(self, target):
92 target.addAttribute('type', 'twincol') 93 94 # Adds the number of columns 95 if self._columns != 0: 96 target.addAttribute('cols', self._columns) 97 98 # Adds the number of rows 99 if self._rows != 0: 100 target.addAttribute('rows', self._rows) 101 102 # Right and left column captions and/or icons (if set) 103 lc = self.getLeftColumnCaption() 104 rc = self.getRightColumnCaption() 105 if lc is not None: 106 target.addAttribute(VTwinColSelect.ATTRIBUTE_LEFT_CAPTION, lc) 107 108 if rc is not None: 109 target.addAttribute(VTwinColSelect.ATTRIBUTE_RIGHT_CAPTION, rc) 110 111 super(TwinColSelect, self).paintContent(target)
112 113
114 - def setRightColumnCaption(self, rightColumnCaption):
115 """Sets the text shown above the right column. 116 117 @param rightColumnCaption: The text to show 118 """ 119 self._rightColumnCaption = rightColumnCaption 120 self.requestRepaint()
121 122
123 - def getRightColumnCaption(self):
124 """Returns the text shown above the right column. 125 126 @return: The text shown or null if not set. 127 """ 128 return self._rightColumnCaption
129 130
131 - def setLeftColumnCaption(self, leftColumnCaption):
132 """Sets the text shown above the left column. 133 134 @param leftColumnCaption: The text to show 135 """ 136 self._leftColumnCaption = leftColumnCaption 137 self.requestRepaint()
138 139
140 - def getLeftColumnCaption(self):
141 """Returns the text shown above the left column. 142 143 @return: The text shown or null if not set. 144 """ 145 return self._leftColumnCaption
146