1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Netscape Public License
5
* Version 1.1 (the "License"); you may not use this file except in
6
* compliance with the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/NPL/
9
* Software distributed under the License is distributed on an "AS IS" basis,
10
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
* for the specific language governing rights and limitations under the
14
* The Original Code is mozilla.org code.
16
* The Initial Developer of the Original Code is
17
* Netscape Communications Corporation.
18
* Portions created by the Initial Developer are Copyright (C) 2001
19
* the Initial Developer. All Rights Reserved.
22
* Joe Hewitt <hewitt@netscape.com> (original author)
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
39
/***************************************************************
40
* ColumnsDialog --------------------------------------------
41
* Dialog box for editing the columns in the DOM Viewer tree.
42
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44
****************************************************************/
46
//////////// global variables /////////////////////
59
//////////// global constants ////////////////////
61
//////////////////////////////////////////////////
63
window.addEventListener("load", ColumnsDialog_initialize, false);
64
window.addEventListener("unload", ColumnsDialog_destroy, false);
66
function ColumnsDialog_initialize()
68
dialog = new ColumnsDialog();
72
function ColumnsDialog_destroy()
77
////////////////////////////////////////////////////////////////////////////
78
//// class ColumnsDialog
80
function ColumnsDialog()
82
this.mViewer = window.arguments[0];
83
this.mColBoxHash = {};
86
ColumnsDialog.prototype =
91
get box() { return this.mBox },
93
initialize: function()
95
// bug 56270 - dragSession.sourceDocument is null --
96
// causes me to code this very temporary, very nasty hack
97
// to make sure I get notified when a column is dropped
98
opener.viewer.mDOMTree.onClientDrop = ColumnsDialogDragDropOut;
100
this.buildContents();
102
// notify the dom viewer that we've opened
103
this.mViewer.onColumnsDialogReady(this);
108
// notify the dom viewer that we're going away
109
this.mViewer.onColumnsDialogClose(this);
112
buildContents: function()
114
var box = document.getElementById("bxColumns");
117
// create the special attribute box
118
var item = this.createAttrItem();
119
box.appendChild(item);
121
// add all boxes except those that are already
123
for (var i = 0; i < gColumnTitles.length; ++i)
124
if (!this.mViewer.hasColumn(gColumnTitles[i])) {
125
this.addItem(gColumnTitles[i]);
129
addItem: function(aValue)
131
if (!aValue || aValue.charAt(0) == "@")
134
item = this.createItem(aValue);
135
this.mColBoxHash[aValue] = item;
137
this.mBox.appendChild(item);
138
window.sizeToContent();
142
removeItem: function(aValue)
144
if (!aValue || aValue.charAt(0) == "@")
147
var colBox = this.mColBoxHash[aValue];
148
if (!colBox._isAttrCol) {
149
this.mBox.removeChild(colBox);
150
window.sizeToContent();
154
createItem: function(aValue)
156
var text = document.createElementNS(kXULNSURI, "text");
157
text._ColValue = aValue;
158
text._isColBox = true;
159
text._isAttrCol = false;
160
text.setAttribute("class", "column-selector");
161
text.setAttribute("value", aValue);
166
createAttrItem: function(aValue)
168
var box = document.createElementNS(kXULNSURI, "box");
169
box._isColBox = true;
170
box._isAttrCol = true;
171
box.setAttribute("class", "column-selector");
172
box.setAttribute("autostretch", "never");
174
var text = document.createElementNS(kXULNSURI, "text");
175
text.setAttribute("value", "Attr");
176
box.appendChild(text);
178
var txf = document.createElementNS(kXULNSURI, "textbox");
179
txf.setAttribute("class", "attr-column-selector");
180
txf.setAttribute("flex", 1);
181
box.appendChild(txf);
186
////////////////////////////////////////////////////////////////////////////
189
onDragGesture: function(aEvent)
191
var box = this.getBoxTarget(aEvent.target);
192
this.setDraggingBox(box);
193
if (!box) return false;
195
var column = this.getColumnValue(box);
196
if (!column) return false;
198
DNDUtils.invokeSession(aEvent.target, ["TreeBuilder/column-add"], [column]);
203
onDragDropOut: function()
205
var box = document.getElementById("bxColumns");
206
var value = this.mDraggingBox._ColValue;
207
this.setDraggingBox(null);
208
this.removeItem(value);
211
onDragDropIn: function(aEvent)
213
var data = DNDUtils.getData("TreeBuilder/column-remove", 0);
214
var string = XPCU.QI(data, "nsISupportsString");
215
this.addItem(string.data);
218
setDraggingBox: function(aBox)
220
if (this.mDraggingBox) {
221
this.mDraggingBox.removeAttribute("col-dragging");
224
this.mDraggingBox = aBox;
227
aBox.setAttribute("col-dragging", "true");
230
getBoxTarget: function(aNode)
233
while (node && !node._isColBox)
234
node = node.parentNode;
238
getColumnValue: function(aColBox)
240
if (aColBox._isAttrCol) {
241
var txf = aColBox.getElementsByTagName("textbox")[0];
242
return "@" + txf.value;
244
return aColBox._ColValue;
250
function ColumnsDialogDragDropOut()
252
dialog.onDragDropOut();