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
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
|
/* ************************************************************************
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)
#embed(qx.icontheme/16/status/folder-open.png)
#embed(qx.icontheme/16/places/folder.png)
************************************************************************ */
/**
* qx.ui.treefullcontrol.TreeFolder objects are tree rows which may contain
* sub-trees
*
* @param
* treeRowStructure -
* An instance of qx.ui.treefullcontrol.TreeRowStructure, defining the
* structure of this tree row.
*
* @event treeOpenWithContent {qx.event.type.DataEvent}
* @event treeOpenWhileEmpty {qx.event.type.DataEvent}
* @event treeClose {qx.event.type.DataEvent}
*/
qx.OO.defineClass("qx.ui.treefullcontrol.TreeFolder", qx.ui.treefullcontrol.AbstractTreeElement,
function(treeRowStructure)
{
qx.ui.treefullcontrol.AbstractTreeElement.call(this, treeRowStructure);
// Save the tree row field order. We'll need it to create children structure.
this._treeRowStructureFields = treeRowStructure._fields;
this._iconObject.setAppearance("tree-folder-icon");
this._labelObject.setAppearance("tree-folder-label");
this.addEventListener("dblclick", this._ondblclick);
// Remapping of add/remove methods
this.add = this.addToFolder;
this.addBefore = this.addBeforeToFolder;
this.addAfter = this.addAfterToFolder;
this.addAt = this.addAtToFolder;
this.addAtBegin = this.addAtBeginToFolder;
this.addAtEnd = this.addAtEndToFolder;
});
/*
---------------------------------------------------------------------------
PROPERTIES
---------------------------------------------------------------------------
*/
qx.OO.changeProperty({ name : "appearance",
type : "string",
defaultValue : "tree-folder"
});
qx.OO.changeProperty({ name : "icon",
type : "string"
});
qx.OO.changeProperty({ name : "iconSelected",
type : "string"
});
qx.OO.addProperty({ name : "open",
type : "boolean",
defaultValue : false
});
qx.OO.addProperty({ name : "alwaysShowPlusMinusSymbol",
type : "boolean",
defaultValue : false
});
/*
---------------------------------------------------------------------------
UTILITIES
---------------------------------------------------------------------------
*/
qx.Proto.hasContent = function() {
return (this._containerObject &&
this._containerObject.getChildrenLength() > 0);
}
qx.Proto.open = function()
{
if (this.getOpen()) {
return;
}
if (this.hasContent())
{
// If there are listeners waiting for a treeOpenWithContent event...
if (this.getTree().hasEventListeners("treeOpenWithContent")) {
// ... then issue the event
this.getTree().dispatchEvent(new qx.event.type.DataEvent("treeOpenWithContent", this), true);
}
this.getTopLevelWidget().setGlobalCursor("progress");
qx.client.Timer.once(this._openCallback, this, 0);
}
else
{
// If there are listeners waiting for a treeOpenWithContent event...
if (this.getTree().hasEventListeners("treeOpenWhileEmpty")) {
// ... then issue the event
this.getTree().dispatchEvent(new qx.event.type.DataEvent("treeOpenWhileEmpty", this), true);
}
this.setOpen(true);
}
}
qx.Proto.close = function()
{
// If there are listeners waiting for a treeClose event...
if (this.getTree().hasEventListeners("treeClose")) {
// ... then issue the event
this.getTree().dispatchEvent(new qx.event.type.DataEvent("treeClose", this), true);
}
this.setOpen(false);
}
qx.Proto.toggle = function()
{
this.getOpen() ? this.close() : this.open();
}
qx.Proto._openCallback = function()
{
this.setOpen(true);
qx.ui.core.Widget.flushGlobalQueues();
this.getTopLevelWidget().setGlobalCursor(null);
}
/*
---------------------------------------------------------------------------
CHILDREN HANDLING
---------------------------------------------------------------------------
*/
qx.Proto._createChildrenStructure = function()
{
this.setAppearance(this instanceof qx.ui.treefullcontrol.Tree
? "tree-container"
: "tree-folder-container");
if (!this._horizontalLayout)
{
this.setOrientation("vertical");
// Create a horizontal layout for this tree row
this._horizontalLayout = new qx.ui.layout.HorizontalBoxLayout;
this._horizontalLayout.setWidth(null);
this._horizontalLayout.setParent(this);
this._horizontalLayout.setAnonymous(true);
this._horizontalLayout.setAppearance(this instanceof qx.ui.treefullcontrol.Tree
? "tree"
: "tree-folder");
// Move the row fields into the horizontal layout
for (var i = 0; i < this._treeRowStructureFields.length; i++)
{
this._treeRowStructureFields[i].setParent(this._horizontalLayout);
}
// We don't need the tree row structure any more.
this._treeRowStructureFields = null;
}
if (!this._containerObject)
{
// Create a veritcal box layout for all of this folder's children
this._containerObject = new qx.ui.layout.VerticalBoxLayout;
this._containerObject.setWidth(null);
this._containerObject.setAnonymous(true);
// it should be faster to first handle display,
// because the default display value is true and if we first
// setup the parent the logic do all to make the
// widget first visible and then, if the folder is not
// opened again invisible.
this._containerObject.setDisplay(this.getOpen());
this._containerObject.setParent(this);
// remap remove* functions
this.remapChildrenHandlingTo(this._containerObject);
}
}
qx.Proto._handleChildMove = function(vChild, vRelationIndex, vRelationChild)
{
if (vChild.isDisplayable())
{
var vChildren = this._containerObject.getChildren();
var vOldChildIndex = vChildren.indexOf(vChild);
if (vOldChildIndex != -1)
{
if (vRelationChild) {
vRelationIndex = vChildren.indexOf(vRelationChild);
}
if (vRelationIndex == vChildren.length-1)
{
vChild._updateIndent();
// Update indent of previous last child
this._containerObject.getLastVisibleChild()._updateIndent();
}
else if (vChild._wasLastVisibleChild)
{
vChild._updateIndent();
// Update indent for new last child
var vPreviousSibling = vChild.getPreviousVisibleSibling();
if (vPreviousSibling) {
vPreviousSibling._updateIndent();
}
}
}
}
}
qx.Proto.addToFolder = function()
{
this._createChildrenStructure();
if (this._containerObject) {
return this._containerObject.add.apply(this._containerObject, arguments);
}
}
qx.Proto.addBeforeToFolder = function(vChild, vBefore)
{
this._createChildrenStructure();
if (this._containerObject)
{
this._handleChildMove(vChild, null, vBefore);
return this._containerObject.addBefore.apply(this._containerObject,
arguments);
}
}
qx.Proto.addAfterToFolder = function(vChild, vAfter)
{
this._createChildrenStructure();
if (this._containerObject)
{
this._handleChildMove(vChild, null, vAfter);
return this._containerObject.addAfter.apply(this._containerObject,
arguments);
}
}
qx.Proto.addAtToFolder = function(vChild, vIndex)
{
this._createChildrenStructure();
if (this._containerObject)
{
this._handleChildMove(vChild, vIndex);
return this._containerObject.addAt.apply(this._containerObject, arguments);
}
}
qx.Proto.addAtBeginToFolder = function(vChild) {
return this.addAtToFolder(vChild, 0);
}
qx.Proto.addAtEndToFolder = function(vChild)
{
this._createChildrenStructure();
if (this._containerObject)
{
var vLast = this._containerObject.getLastChild();
if (vLast)
{
this._handleChildMove(vChild, null, vLast);
return this._containerObject.addAfter.call(this._containerObject,
vChild,
vLast);
}
else
{
return this.addAtBeginToFolder(vChild);
}
}
}
qx.Proto._remappingChildTable = [ "remove", "removeAt", "removeAll" ];
/*
---------------------------------------------------------------------------
CHILDREN UTILITIES
---------------------------------------------------------------------------
*/
qx.Proto.getContainerObject = function()
{
return this._containerObject;
}
qx.Proto.getHorizontalLayout = function()
{
return this._horizontalLayout;
}
qx.Proto.getFirstVisibleChildOfFolder = function()
{
if (this._containerObject) {
return this._containerObject.getFirstChild();
}
}
qx.Proto.getLastVisibleChildOfFolder = function()
{
if (this._containerObject) {
return this._containerObject.getLastChild();
}
}
qx.Proto.getItems = function()
{
var a = [this];
if (this._containerObject)
{
var ch = this._containerObject.getVisibleChildren();
for (var i=0, chl=ch.length; i<chl; i++) {
a = a.concat(ch[i].getItems());
}
}
return a;
}
/*
---------------------------------------------------------------------------
MODIFIER
---------------------------------------------------------------------------
*/
qx.Proto._evalCurrentIcon = function()
{
if (this.getSelected()) {
return this.getIconSelected() || "icon/16/status/folder-open.png";
} else {
return this.getIcon() || "icon/16/places/folder.png";
}
}
qx.Proto._modifyOpen = function(propValue, propOldValue, propData)
{
// we need the whole indent process if certain tree lines are to be excluded
if (this.getTree().getExcludeSpecificTreeLines().length > 0) {
this._updateIndent();
} else {
this._updateLastColumn();
}
if (this._containerObject) {
this._containerObject.setDisplay(propValue);
}
return true;
}
qx.Proto._modifyAlwaysShowPlusMinusSymbol = function(propValue, propOldValue, propData)
{
var t = this.getTree();
if (t) {
// we need the whole indent process if only certain tree lines are to be
// excluded
if (t.getExcludeSpecificTreeLines().length > 0) {
this._updateIndent();
} else {
this._updateLastColumn();
}
}
return true;
}
qx.Proto._updateLastColumn = function()
{
if (this._indentObject)
{
var vElement = this._indentObject.getElement();
if (vElement && vElement.firstChild) {
vElement.firstChild.src =
(this.BASE_URI +
this.getIndentSymbol(this.getTree().getUseTreeLines(), 0, 0, 0) +
".gif");
}
}
}
/*
---------------------------------------------------------------------------
EVENT LISTENERS
---------------------------------------------------------------------------
*/
qx.Proto._onmousedown = function(e)
{
var vOriginalTarget = e.getOriginalTarget();
switch(vOriginalTarget)
{
case this._indentObject:
if (this._indentObject.getElement().firstChild == e.getDomTarget())
{
this.getTree().getManager().handleMouseDown(this, e);
this.toggle();
}
break;
case this._containerObject:
break;
case this:
if (this._containerObject) {
break;
}
// no break here
default:
this.getTree().getManager().handleMouseDown(this, e);
}
e.stopPropagation();
}
qx.Proto._onmouseup = function(e)
{
var vOriginalTarget = e.getOriginalTarget();
switch(vOriginalTarget)
{
case this._indentObject:
case this._containerObject:
case this:
break;
default:
if (!this.getTree().getUseDoubleClick()) {
this.open();
}
}
}
qx.Proto._ondblclick = function(e)
{
if (!this.getTree().getUseDoubleClick()) {
return;
}
this.toggle();
e.stopPropagation();
}
/*
---------------------------------------------------------------------------
INDENT HELPER
---------------------------------------------------------------------------
*/
qx.Proto.getIndentSymbol = function(vUseTreeLines,
vColumn,
vFirstColumn,
vLastColumn)
{
var vLevel = this.getLevel();
var vExcludeList = this.getTree().getExcludeSpecificTreeLines();
var vExclude = vExcludeList[vLastColumn - vColumn - 1];
if (vColumn == vFirstColumn)
{
if (this.hasContent() || this.getAlwaysShowPlusMinusSymbol())
{
// If tree lines were not requested, don't display them
if (!vUseTreeLines)
{
return this.getOpen() ? "minus" : "plus";
}
// If this is the first level under the root...
if (vLevel == 1) {
// ... and the root is not being displayed and this is the first
// child...
var vParentFolder = this.getParentFolder();
if (vParentFolder &&
!vParentFolder._horizontalLayout.getVisibility() &&
this.isFirstChild())
{
//... then if this is also the last (i.e. only) child, use no tree
// lines; otherwise, use descender lines but no ascender.
if (this.isLastChild() || vExclude === true)
{
return this.getOpen() ? "only_minus" : "only_plus";
}
else
{
return this.getOpen() ? "start_minus" : "start_plus";
}
}
}
if (vExclude === true)
{
return this.getOpen() ? "only_minus" : "only_plus";
}
else if (this.isLastChild())
{
return this.getOpen() ? "end_minus" : "end_plus";
}
else
{
return this.getOpen() ? "cross_minus" : "cross_plus";
}
}
else if (vUseTreeLines && ! (vExclude === true))
{
return this.isLastChild() ? "end" : "cross";
}
}
else
{
if (vUseTreeLines && ! this.isLastChild()) {
if (vExclude === true) {
return null;
}
return "line";
}
return null;
}
}
qx.Proto._updateIndent = function()
{
// Intentionally bypass superclass; the _updateIndent we want is in TreeFile
qx.ui.treefullcontrol.TreeFile.prototype._updateIndent.call(this);
if (!this._containerObject) {
return;
}
var ch = this._containerObject.getVisibleChildren();
for (var i=0, l=ch.length; i<l; i++) {
ch[i]._updateIndent();
}
}
/*
---------------------------------------------------------------------------
DISPOSER
---------------------------------------------------------------------------
*/
qx.Proto.dispose = function()
{
if (this.getDisposed()) {
return;
}
this.removeEventListener("dblclick", this._ondblclick);
if (this._horizontalLayout)
{
this._horizontalLayout.dispose();
this._horizontalLayout = null;
}
if (this._containerObject)
{
this._containerObject.dispose();
this._containerObject = null;
}
return qx.ui.treefullcontrol.AbstractTreeElement.prototype.dispose.call(this);
}
|