1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
|
/* ************************************************************************
qooxdoo - the new era of web development
http://qooxdoo.org
Copyright:
2004-2007 1&1 Internet AG, Germany, http://www.1and1.org
2006 Derrell Lipman
License:
LGPL: http://www.gnu.org/licenses/lgpl.html
EPL: http://www.eclipse.org/org/documents/epl-v10.php
See the LICENSE file in the project's top-level directory for details.
Authors:
* Sebastian Werner (wpbasti)
* Andreas Ecker (ecker)
* Derrell Lipman (derrell)
************************************************************************ */
/* ************************************************************************
#module(ui_treefullcontrol)
************************************************************************ */
/**
* qx.ui.treefullcontrol.Tree objects are tree root nodes but act like
* TreeFolder.
*
* @param treeRowStructure An instance of qx.ui.treefullcontrol.TreeRowStructure,
* defining the structure of this tree row.
*/
qx.OO.defineClass("qx.ui.treefullcontrol.Tree", qx.ui.treefullcontrol.TreeFolder,
function(treeRowStructure)
{
qx.ui.treefullcontrol.TreeFolder.call(this, treeRowStructure);
// ************************************************************************
// INITILISIZE MANAGER
// ************************************************************************
this._manager = new qx.manager.selection.TreeFullControlSelectionManager(this);
this._iconObject.setAppearance("tree-icon");
this._labelObject.setAppearance("tree-label");
// ************************************************************************
// DEFAULT STATE
// ************************************************************************
// The tree should be open by default
this.setOpen(true);
// Fix vertical alignment of empty tree
this.addToFolder();
// ************************************************************************
// KEY EVENT LISTENER
// ************************************************************************
this.addEventListener("keydown", this._onkeydown);
this.addEventListener("keypress", this._onkeypress);
this.addEventListener("keyup", this._onkeyup);
});
/*
---------------------------------------------------------------------------
PROPERTIES
---------------------------------------------------------------------------
*/
qx.OO.addProperty({ name : "useDoubleClick",
type : "boolean",
defaultValue : false,
getAlias : "useDoubleClick"
});
qx.OO.addProperty({ name : "useTreeLines",
type : "boolean",
defaultValue : true,
getAlias : "useTreeLines"
});
/*!
In specific applications, it is desirable to omit tree lines for only
certain indentation levels. This property provides an array wherein the
index of the array corresponds to the indentation level, counted from left
to right; and the value of that element, if it contains, specifically, the
boolean value <i>true</i>, indicates that tree lines at that indentation
level are to be omitted. Any value of that element other than <i>true</i>,
or if an indentation level's index does not exist in the array, means that
tree lines should be displayed for that indentation level. (There are some
minor code efficiencies that are realized if this array is empty, so after
having set an element to <i>true</i> and desiring to reset the default
behavior, you should 'delete' the element rather than setting it to some
value other than <i>true</i>.)
If useTreeLines is <i>false</i>, then all tree lines are excluded and this
property is ignored.
*/
qx.OO.addProperty({ name : "excludeSpecificTreeLines",
type : "object",
defaultValue : []
});
/*!
Hide the root (Tree) node. This differs from the visibility property in
that this property hides *only* the current node, not the node's children.
*/
qx.OO.addProperty({ name : "hideNode",
type : "boolean",
defaultValue : false,
getAlias : "hideNode"
});
/*!
Whether the Root should have an open/close button. This may also be
used in conjunction with the hideNode property to provide for virtual root
nodes. In the latter case, be very sure that the virtual root nodes are
expanded programatically, since there will be no open/close button for the
user to open them.
*/
qx.OO.addProperty({ name : "rootOpenClose",
type : "boolean",
defaultValue : true
});
/*
---------------------------------------------------------------------------
MANAGER BINDING
---------------------------------------------------------------------------
*/
qx.Proto.getManager = function() {
return this._manager;
}
qx.Proto.getSelectedElement = function() {
return this.getManager().getSelectedItems()[0];
}
/*
---------------------------------------------------------------------------
QUEUE HANDLING
---------------------------------------------------------------------------
*/
qx.Proto.addChildToTreeQueue = function(vChild)
{
if (!vChild._isInTreeQueue && !vChild._isDisplayable) {
this.debug("Ignoring invisible child: " + vChild);
}
if (!vChild._isInTreeQueue && vChild._isDisplayable)
{
qx.ui.core.Widget.addToGlobalWidgetQueue(this);
if (!this._treeQueue) {
this._treeQueue = {};
}
this._treeQueue[vChild.toHashCode()] = vChild;
vChild._isInTreeQueue = true;
}
}
qx.Proto.removeChildFromTreeQueue = function(vChild)
{
if (vChild._isInTreeQueue)
{
if (this._treeQueue) {
delete this._treeQueue[vChild.toHashCode()];
}
delete vChild._isInTreeQueue;
}
}
qx.Proto.flushWidgetQueue = function() {
this.flushTreeQueue();
}
qx.Proto.flushTreeQueue = function()
{
if (!qx.lang.Object.isEmpty(this._treeQueue))
{
for (var vHashCode in this._treeQueue)
{
// this.debug("Flushing Tree Child: " + this._treeQueue[vHashCode]);
this._treeQueue[vHashCode].flushTree();
delete this._treeQueue[vHashCode]._isInTreeQueue;
}
delete this._treeQueue;
}
}
/*
---------------------------------------------------------------------------
MODIFIER
---------------------------------------------------------------------------
*/
qx.Proto._modifyUseTreeLines = function(propValue, propOldValue, propData)
{
if (this._initialLayoutDone) {
this._updateIndent();
}
return true;
}
qx.Proto._modifyHideNode = function(propValue, propOldValue, propData)
{
if (! propValue) {
this._horizontalLayout.setHeight(this._horizontalLayout.originalHeight);
this._horizontalLayout.show();
} else {
this._horizontalLayout.originalHeight = this._horizontalLayout.getHeight();
this._horizontalLayout.setHeight(0);
this._horizontalLayout.hide();
}
if (this._initialLayoutDone) {
this._updateIndent();
}
return true;
}
qx.Proto._modifyRootOpenClose = function(propValue, propOldValue, propData)
{
if (this._initialLayoutDone) {
this._updateIndent();
}
return true;
}
// Override getter so we can return a clone of the array. Otherwise, the
// setter finds the identical array (after user modifications) and the modify
// function doesn't get called.
qx.Proto.getExcludeSpecificTreeLines = function()
{
var vName = "excludeSpecificTreeLines";
var vUpName = qx.lang.String.toFirstUp(vName);
var vStorageField = "_value" + vUpName;
return this[vStorageField].slice(0);
}
qx.Proto._modifyExcludeSpecificTreeLines = function(propValue,
propOldValue,
propData)
{
if (this._initialLayoutDone) {
this._updateIndent();
}
return true;
}
/*
---------------------------------------------------------------------------
UTILITIES
---------------------------------------------------------------------------
*/
qx.Proto.getTree = function() {
return this;
}
qx.Proto.getParentFolder = function() {
return null;
}
qx.Proto.getLevel = function() {
return 0;
}
/*
---------------------------------------------------------------------------
COMMON CHECKERS
---------------------------------------------------------------------------
*/
qx.ui.treefullcontrol.Tree.isTreeFolder = function(vObject) {
return (vObject &&
vObject instanceof qx.ui.treefullcontrol.TreeFolder &&
!(vObject instanceof qx.ui.treefullcontrol.Tree));
}
qx.ui.treefullcontrol.Tree.isOpenTreeFolder = function(vObject) {
return (vObject instanceof qx.ui.treefullcontrol.TreeFolder &&
vObject.getOpen() &&
vObject.hasContent());
}
/*
---------------------------------------------------------------------------
EVENT HANDLER
---------------------------------------------------------------------------
*/
qx.Proto._onkeydown = function(e)
{
var vManager = this.getManager();
var vSelectedItem = vManager.getSelectedItem();
if (e.getKeyIdentifier() == "Enter")
{
e.preventDefault();
if (qx.ui.treefullcontrol.Tree.isTreeFolder(vSelectedItem)) {
return vSelectedItem.toggle();
}
}
}
qx.Proto._onkeypress = function(e)
{
var vManager = this.getManager();
var vSelectedItem = vManager.getSelectedItem();
switch(e.getKeyIdentifier())
{
case "Left":
e.preventDefault();
if (qx.ui.treefullcontrol.Tree.isTreeFolder(vSelectedItem))
{
if (!vSelectedItem.getOpen())
{
var vParent = vSelectedItem.getParentFolder();
if (vParent instanceof qx.ui.treefullcontrol.TreeFolder) {
if (!(vParent instanceof qx.ui.treefullcontrol.Tree)) {
vParent.close();
}
this.setSelectedElement(vParent);
}
}
else
{
return vSelectedItem.close();
}
}
else if (vSelectedItem instanceof qx.ui.treefullcontrol.TreeFile)
{
var vParent = vSelectedItem.getParentFolder();
if (vParent instanceof qx.ui.treefullcontrol.TreeFolder) {
if (!(vParent instanceof qx.ui.treefullcontrol.Tree)) {
vParent.close();
}
this.setSelectedElement(vParent);
}
}
break;
case "Right":
e.preventDefault();
if (qx.ui.treefullcontrol.Tree.isTreeFolder(vSelectedItem))
{
if (!vSelectedItem.getOpen())
{
return vSelectedItem.open();
}
else if (vSelectedItem.hasContent())
{
var vFirst = vSelectedItem.getFirstVisibleChildOfFolder();
this.setSelectedElement(vFirst);
if (vFirst instanceof qx.ui.tree.TreeFolder) {
vFirst.open();
}
return;
}
}
break;
default:
if (!this._fastUpdate)
{
this._fastUpdate = true;
this._oldItem = vSelectedItem;
}
vManager.handleKeyPress(e);
}
};
qx.Proto._onkeyup = function(e)
{
if (this._fastUpdate)
{
var vNewItem = this.getManager().getSelectedItem();
if (! vNewItem) {
return;
}
vNewItem.getIconObject().addState("selected");
delete this._fastUpdate;
delete this._oldItem;
}
}
qx.Proto.getLastTreeChild = function()
{
var vLast = this;
while (vLast instanceof qx.ui.treefullcontrol.AbstractTreeElement)
{
if (!(vLast instanceof qx.ui.treefullcontrol.TreeFolder) ||
!vLast.getOpen()) {
return vLast;
}
vLast = vLast.getLastVisibleChildOfFolder();
}
return null;
}
qx.Proto.getFirstTreeChild = function() {
return this;
}
qx.Proto.setSelectedElement = function(vElement)
{
var vManager = this.getManager();
vManager.setSelectedItem(vElement);
vManager.setLeadItem(vElement);
}
/* Override getHierarchy: do not add label if root node is hidden */
qx.Proto.getHierarchy = function(vArr)
{
if (! this.hideNode() && this._labelObject) {
vArr.unshift(this._labelObject.getHtml());
}
return vArr;
}
qx.Proto.getIndentSymbol = function(vUseTreeLines, vColumn, vLastColumn)
{
if (vColumn == vLastColumn &&
(this.hasContent() || this.getAlwaysShowPlusMinusSymbol()))
{
if (! vUseTreeLines)
{
return this.getOpen() ? "minus" : "plus";
}
else
{
return this.getOpen() ? "only_minus" : "only_plus";
}
}
else
{
return null;
}
}
/*
---------------------------------------------------------------------------
DISPOSER
---------------------------------------------------------------------------
*/
qx.Proto.dispose = function()
{
if (this.getDisposed()) {
return;
}
this.removeEventListener("keydown", this._onkeydown);
this.removeEventListener("keypress", this._onkeypress);
this.removeEventListener("keyup", this._onkeyup);
if (this._manager)
{
this._manager.dispose();
this._manager = null;
}
delete this._oldItem;
return qx.ui.treefullcontrol.TreeFolder.prototype.dispose.call(this);
}
|