1/*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * @constructor
33 * @extends {WebInspector.DataGridNode}
34 * @param {function(number, number)} callback
35 * @param {number} startPosition
36 * @param {number} endPosition
37 * @param {number} chunkSize
38 */
39WebInspector.ShowMoreDataGridNode = function(callback, startPosition, endPosition, chunkSize)
40{
41    WebInspector.DataGridNode.call(this, {summaryRow:true}, false);
42    this._callback = callback;
43    this._startPosition = startPosition;
44    this._endPosition = endPosition;
45    this._chunkSize = chunkSize;
46
47    this.showNext = document.createElement("button");
48    this.showNext.setAttribute("type", "button");
49    this.showNext.addEventListener("click", this._showNextChunk.bind(this), false);
50    this.showNext.textContent = WebInspector.UIString("Show %d before", this._chunkSize);
51
52    this.showAll = document.createElement("button");
53    this.showAll.setAttribute("type", "button");
54    this.showAll.addEventListener("click", this._showAll.bind(this), false);
55
56    this.showLast = document.createElement("button");
57    this.showLast.setAttribute("type", "button");
58    this.showLast.addEventListener("click", this._showLastChunk.bind(this), false);
59    this.showLast.textContent = WebInspector.UIString("Show %d after", this._chunkSize);
60
61    this._updateLabels();
62    this.selectable = false;
63}
64
65WebInspector.ShowMoreDataGridNode.prototype = {
66    _showNextChunk: function()
67    {
68        this._callback(this._startPosition, this._startPosition + this._chunkSize);
69    },
70
71    _showAll: function()
72    {
73        this._callback(this._startPosition, this._endPosition);
74    },
75
76    _showLastChunk: function()
77    {
78        this._callback(this._endPosition - this._chunkSize, this._endPosition);
79    },
80
81    _updateLabels: function()
82    {
83        var totalSize = this._endPosition - this._startPosition;
84        if (totalSize > this._chunkSize) {
85            this.showNext.classList.remove("hidden");
86            this.showLast.classList.remove("hidden");
87        } else {
88            this.showNext.classList.add("hidden");
89            this.showLast.classList.add("hidden");
90        }
91        this.showAll.textContent = WebInspector.UIString("Show all %d", totalSize);
92    },
93
94    /** override */
95    createCells: function()
96    {
97        this._hasCells = false;
98        WebInspector.DataGridNode.prototype.createCells.call(this);
99    },
100
101    /**
102     * @override
103     * @param {string} columnIdentifier
104     * @return {!Element}
105     */
106    createCell: function(columnIdentifier)
107    {
108        var cell = this.createTD(columnIdentifier);
109        if (!this._hasCells) {
110            this._hasCells = true;
111            if (this.depth)
112                cell.style.setProperty("padding-left", (this.depth * this.dataGrid.indentWidth) + "px");
113            cell.appendChild(this.showNext);
114            cell.appendChild(this.showAll);
115            cell.appendChild(this.showLast);
116        }
117        return cell;
118    },
119
120    /**
121     * @param {number} from
122     */
123    setStartPosition: function(from)
124    {
125        this._startPosition = from;
126        this._updateLabels();
127    },
128
129    /**
130     * @param {number} to
131     */
132    setEndPosition: function(to)
133    {
134        this._endPosition = to;
135        this._updateLabels();
136    },
137
138    /**
139     * @override
140     * @return {number}
141     */
142    nodeSelfHeight: function()
143    {
144        return 32;
145    },
146
147    dispose: function()
148    {
149    },
150
151    __proto__: WebInspector.DataGridNode.prototype
152}
153
154