Parent

Class Index [+]

Quicksearch

TaskJuggler::ReportTableCell

This class models the output format independent version of a cell in a TableReport. It belongs to a certain ReportTableLine and ReportTableColumn. Normally a cell contains text on a colored background. By help of the @special variable it can alternatively contain any object the provides the necessary output methods such as to_html.

Attributes

line[R]
data[RW]
category[RW]
hidden[RW]
alignment[RW]
padding[RW]
text[RW]
tooltip[RW]
showTooltipHint[RW]
iconTooltip[RW]
selfcontained[RW]
cellColor[RW]
indent[RW]
icon[RW]
fontSize[RW]
fontColor[RW]
bold[RW]
width[RW]
rows[RW]
columns[RW]
special[RW]

Public Class Methods

new(line, query, text = nil, headerCell = false) click to toggle source

Create the ReportTableCell object and initialize the attributes to some default values. line is the ReportTableLine this cell belongs to. text is the text that should appear in the cell. headerCell is a flag that must be true only for table header cells.

    # File lib/reports/ReportTableCell.rb, line 35
35:     def initialize(line, query, text = nil, headerCell = false)
36:       @line = line
37:       @line.addCell(self) if line
38: 
39:       # Specifies whether this is a header cell or not.
40:       @headerCell = headerCell
41:       # A copy of a Query object that is needed to access project data via the
42:       # query function.
43:       @query = query ? query.dup : nil
44:       # The cell textual content. This may be a String or a
45:       # RichTextIntermediate object.
46:       self.text = text || ''
47:       # A custom text for the tooltip.
48:       @tooltip = nil
49:       # Determines if the tooltip is triggered by an special hinting icon or
50:       # the whole cell.
51:       @showTooltipHint = true
52:       # The original data of the cell content (optional, nil if not provided)
53:       @data = nil
54:       # Determines the background color of the cell.
55:       @category = nil
56:       # True of the cell is hidden (because other cells span multiple rows or
57:       # columns)
58:       @hidden = false
59:       # How to horizontally align the cell
60:       @alignment = :center
61:       # Horizontal padding between frame and cell content
62:       @padding = 3
63:       # Whether or not to indent the cell. If not nil, it is a Fixnum
64:       # indicating the indentation level.
65:       @indent = nil
66:       # The basename of the icon file
67:       @icon = nil
68:       # A custom tooltip for the cell icon
69:       @iconTooltip = nil
70:       # Font size of the cell text in pixels
71:       @fontSize = nil
72:       # The background color of the cell. Overwrite the @category color.
73:       @cellColor = nil
74:       # The color of the cell text font.
75:       @fontColor = nil
76:       # True of a bold font is to be used for the cell text.
77:       @bold = false
78:       # The width of the column in pixels
79:       @width = nil
80:       # The number of rows the cell spans
81:       @rows = 1
82:       # The number of columns the cell spans
83:       @columns = 1
84:       # True of the resulting report should not contain any information from
85:       # other files.
86:       @selfcontained = false
87:       # Ignore everything and use this reference to generate the output.
88:       @special = nil
89:     end

Public Instance Methods

==(c) click to toggle source

Return true if two cells are similar enough so that they can be merged in the report to a single, wider cell. c is the cell to compare this cell with.

     # File lib/reports/ReportTableCell.rb, line 94
 94:     def ==(c)
 95:       @text == c.text &&
 96:       @tooltip == c.tooltip &&
 97:       @alignment == c.alignment &&
 98:       @padding == c.padding &&
 99:       @indent == c.indent &&
100:       @cellColor == c.cellColor &&
101:       @category == c.category
102:     end
to_csv(csv, columnIdx, lineIdx) click to toggle source

Add the text content of the cell to an Array of Arrays form of the table.

     # File lib/reports/ReportTableCell.rb, line 157
157:     def to_csv(csv, columnIdx, lineIdx)
158:       # We only support left indentation in CSV files as the spaces for right
159:       # indentation will be disregarded by most applications.
160:       indent = @indent && @alignment == :left ? '  ' * @indent : ''
161:       columns = 1
162:       if @special
163:         # This is for nested tables. They will be inserted as whole columns
164:         # in the existing table.
165:         csv[lineIdx][columnIdx] = nil
166:         columns = @special.to_csv(csv, columnIdx)
167:       else
168:         cell =
169:           if @data && @data.is_a?(String)
170:             @data
171:           elsif @text
172:             if @text.respond_to?('functionHandler')
173:               @text.setQuery(@query)
174:             end
175:             str = @text.to_s
176:             # Remove any trailing line breaks. These don't really make much
177:             # sense in CSV files.
178:             while str[1] == \n\
179:               str.chomp!
180:             end
181:             str
182:           end
183: 
184:         # Try to convert numbers and other types to their native Ruby type if
185:         # they are supported by CSVFile.
186:         native = CSVFile.strToNative(cell)
187: 
188:         # Only for String objects, we add the indentation.
189:         csv[lineIdx][columnIdx] = (native.is_a?(String) ? indent + native :
190:                                                           native)
191:       end
192: 
193:       return columns
194:     end
to_html() click to toggle source

Turn the abstract cell representation into an HTML element tree.

     # File lib/reports/ReportTableCell.rb, line 105
105:     def to_html
106:       return nil if @hidden
107:       return @special.to_html if @special
108: 
109:       # Determine cell attributes
110:       attribs = { }
111:       attribs['rowspan'] = "#{@rows}" if @rows > 1
112:       attribs['colspan'] = "#{@columns}" if @columns > 1
113:       attribs['class'] = @category ? @category : 'tabcell'
114:       style = ''
115:       style += "background-color: #{@cellColor}; " if @cellColor
116:       attribs['style'] = style unless style.empty?
117:       cell = XMLElement.new('td', attribs)
118: 
119:       cell << (table = XMLElement.new('table',
120:         'class' => @category ? 'tj_table_cell' : 'tj_table_header_cell',
121:         'cellspacing' => '0', 'style' => cellStyle))
122:       table << (row = XMLElement.new('tr'))
123: 
124:       calculateIndentation
125: 
126:       # Insert a padding cell for the left side indentation.
127:       if @leftIndent && @leftIndent > 0
128:         row << XMLElement.new('td', 'style' => "width:#{@leftIndent}px; ")
129:       end
130:       row << cellIcon(cell)
131: 
132:       labelDiv, tooltip = cellLabel
133:       row << labelDiv
134: 
135:       # Overwrite the tooltip if the user has specified a custom tooltip.
136:       tooltip = @tooltip if @tooltip
137:       if tooltip && !tooltip.empty? && !@selfcontained
138:         if @showTooltipHint
139:           row << (td = XMLElement.new('td'))
140:           td << XMLElement.new('img', 'src' => 'icons/details.png',
141:                                'class' => 'tj_table_cell_tooltip')
142:           addHtmlTooltip(tooltip, td, cell)
143:         else
144:           addHtmlTooltip(tooltip, cell)
145:         end
146:       end
147: 
148:       # Insert a padding cell for the right side indentation.
149:       if @rightIndent && @rightIndent > 0
150:         row << XMLElement.new('td', 'style' => "width:#{@rightIndent}px; ")
151:       end
152: 
153:       cell
154:     end

Private Instance Methods

addHtmlTooltip(tooltip, trigger, hook = nil) click to toggle source
     # File lib/reports/ReportTableCell.rb, line 344
344:     def addHtmlTooltip(tooltip, trigger, hook = nil)
345:       return unless tooltip && !tooltip.empty? && !@selfcontained
346: 
347:       hook = trigger if hook.nil?
348:       if tooltip.respond_to?('functionHandler')
349:         tooltip.setQuery(@query)
350:       end
351:       if @query
352:         @query.attributeId = 'name'
353:         @query.process
354:         title = @query.to_s
355:       else
356:         title = ''
357:       end
358:       trigger['onclick'] = "TagToTip('ID#{trigger.object_id}', " +
359:                            "TITLE, '#{title}')"
360:       trigger['style'] = trigger['style'] ? trigger['style'] : 'cursor:help; '
361:       hook << (ltDiv = XMLElement.new('div',
362:                                       'class' => 'tj_tooltip_box',
363:                                        'style' => 'cursor:help',
364:                                        'id' => "ID#{trigger.object_id}"))
365:       ltDiv << (tooltip.respond_to?('to_html') ? tooltip.to_html :
366:                                                  XMLText.new(tooltip))
367:     end
calculateIndentation() click to toggle source
     # File lib/reports/ReportTableCell.rb, line 198
198:     def calculateIndentation
199:       # In tree sorting mode, some cells have to be indented to reflect the
200:       # tree nesting structure. The indentation is achieved with padding cells
201:       # and needs to be applied to the proper side depending on the alignment.
202:       @leftIndent = @rightIndent = 0
203:       if @indent && @alignment != :center
204:         if @alignment == :left
205:           @leftIndent = @indent * 8
206:         elsif @alignment == :right
207:           @rightIndent = (@line.table.maxIndent - @indent) * 8
208:         end
209:       end
210:     end
cellIcon(cell) click to toggle source
     # File lib/reports/ReportTableCell.rb, line 222
222:     def cellIcon(cell)
223:       if @icon && !@selfcontained
224:         td = XMLElement.new('td', 'class' => 'tj_table_cell_icon')
225:         td << XMLElement.new('img', 'src' => "icons/#{@icon}.png",
226:                                     'alt' => "Icon")
227:         addHtmlTooltip(@iconTooltip, td, cell)
228:         return td
229:       end
230: 
231:       nil
232:     end
cellLabel() click to toggle source
     # File lib/reports/ReportTableCell.rb, line 234
234:     def cellLabel
235:       # If we have a RichText content and a width limit, we enable line
236:       # wrapping.
237:       #                Overfl. Wrap. Height Width
238:       # Fixed Height:    x      -      x     -
239:       # Fixed Width:     x      x      -     x
240:       # Both:            x      -      x     x
241:       # None:            -      x      -     -
242:       fixedHeight = @line && @line.table.equiLines
243:       fixedWidth = !@width.nil?
244:       style = ''
245:       style += "overflow:hidden; " if fixedHeight || fixedWidth
246:       style += "white-space:#{fixedWidth && !fixedHeight ?
247:                               'normal' : 'nowrap'}; "
248:       if fixedHeight && !fixedWidth
249:         style += "height:#{@line.height - 3}px; "
250:       end
251:       style += 'font-weight:bold; ' if @bold
252:       style += "font-size: #{@fontSize}px; " if fontSize
253:       if @fontColor
254:         style += "color:#{@fontColor}; "
255:       end
256: 
257:       return nil, nil if @text.nil? || @text.empty?
258: 
259:       tooltip = nil
260: 
261:       # @text can be a String or a RichText (with or without embedded
262:       # queries). To find out if @text has multiple lines, we need to expand
263:       # it and convert it to a plain text again.
264:       textAsString =
265:         if @text.is_a?(RichTextIntermediate)
266:           # @text is a RichText.
267:           if @text.respond_to?('functionHandler')
268:             @text.setQuery(@query)
269:           end
270:           @text.to_s
271:         else
272:           @text
273:         end
274: 
275:       return nil, nil if textAsString.empty?
276: 
277:       if @width
278:         # We have 4 pixels padding on each side of the cell.
279:         labelWidth = @width - 8
280:         labelWidth -= @leftIndent if @leftIndent
281:         labelWidth -= @rightIndent if @rightIndent
282:         if !@selfcontained
283:           # The icons are 20 pixels width including padding.
284:           labelWidth -= 20 if @icon
285:           labelWidth -= 20 if tooltip || @tooltip
286:         end
287:       else
288:         labelWidth = nil
289:       end
290:       shortText, singleLine = shortVersion(textAsString, labelWidth)
291: 
292:       if (@line && @line.table.equiLines && (!singleLine || @width )) &&
293:           !@headerCell
294:         # The cell is size-limited. We only put a shortened plain-text version
295:         # in the cell and provide the full content via a tooltip.
296:         # Header cells are never shortened.
297:         tooltip = @text if shortText != textAsString
298:         tl = XMLText.new(shortText)
299:       else
300:         tl = (@text.is_a?(RichTextIntermediate) ? @text.to_html :
301:                                                   XMLText.new(@text))
302:       end
303: 
304:       if labelWidth
305:         style += "min-width: #{labelWidth}px; max-width: #{labelWidth}px; "
306:       end
307: 
308:       td = XMLElement.new('td', 'class' => 'tj_table_cell_label',
309:                                 'style' => style)
310:       td << tl
311: 
312:       return td, tooltip
313:     end
cellStyle() click to toggle source

Determine cell style

     # File lib/reports/ReportTableCell.rb, line 213
213:     def cellStyle
214:       style = "text-align:#{@alignment.to_s}; "
215:       if @line && @line.table.equiLines
216:         style += "height:#{@line.height - 7}px; "
217:       end
218: 
219:       style
220:     end
shortVersion(itext, width) click to toggle source

Convert a RichText String into a small one-line plain text version that fits the column.

     # File lib/reports/ReportTableCell.rb, line 317
317:     def shortVersion(itext, width)
318:       text = itext.to_s
319:       singleLine = true
320:       modified = false
321:       if text.include?("\n")
322:         text = text[0, text.index("\n")]
323:         singleLine = false
324:         modified = true
325:       end
326:       if width
327:         widthWithoutIcon = width - 20
328:         # Assuming an average character width of 7 pixels
329:         maxChars = widthWithoutIcon / 7
330:         if text.length > maxChars
331:           if maxChars > 0
332:             text = text[0, maxChars]
333:           else
334:             text = ''
335:           end
336:           modified = true
337:         end
338:       end
339:       # Add three dots to show that there is more info available.
340:       text += "..." if modified
341:       [ text, singleLine ]
342:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.