Salome HOME
Fix for problem: SIGSEGV appears if to select group after opening "Edit Group" dialog...
[modules/smesh.git] / doc / salome / tui / SMESH / sources / static / treeview.js
1 //**************************************************************** 
2 // You are free to copy the "Folder-Tree" script as long as you  
3 // keep this copyright notice: 
4 // Script found in: http://www.geocities.com/Paris/LeftBank/2178/ 
5 // Author: Marcelino Alves Martins (martins@hks.com) December '97. 
6 //**************************************************************** 
7  
8 //Log of changes: 
9 //       17 Feb 98 - Fix initialization flashing problem with Netscape
10 //       
11 //       27 Jan 98 - Root folder starts open; support for USETEXTLINKS; 
12 //                   make the ftien4 a js file 
13 //       
14 // DvH:  Dec 2000 -  Made some minor changes to support external 
15 //                   references
16  
17 // Definition of class Folder 
18 // ***************************************************************** 
19  
20 function Folder(folderDescription, tagName, hreference) //constructor 
21
22   //constant data 
23   this.desc = folderDescription 
24   this.tagName = tagName
25   this.hreference = hreference 
26   this.id = -1   
27   this.navObj = 0  
28   this.iconImg = 0  
29   this.nodeImg = 0  
30   this.isLastNode = 0 
31  
32   //dynamic data 
33   this.isOpen = true 
34   this.iconSrc = "ftv2folderopen.png"   
35   this.children = new Array 
36   this.nChildren = 0 
37  
38   //methods 
39   this.initialize = initializeFolder 
40   this.setState = setStateFolder 
41   this.addChild = addChild 
42   this.createIndex = createEntryIndex 
43   this.hide = hideFolder 
44   this.display = display 
45   this.renderOb = drawFolder 
46   this.totalHeight = totalHeight 
47   this.subEntries = folderSubEntries 
48   this.outputLink = outputFolderLink 
49
50  
51 function setStateFolder(isOpen) 
52
53   var subEntries 
54   var totalHeight 
55   var fIt = 0 
56   var i=0 
57  
58   if (isOpen == this.isOpen) 
59     return 
60  
61   if (browserVersion == 2)  
62   { 
63     totalHeight = 0 
64     for (i=0; i < this.nChildren; i++) 
65       totalHeight = totalHeight + this.children[i].navObj.clip.height 
66       subEntries = this.subEntries() 
67     if (this.isOpen) 
68       totalHeight = 0 - totalHeight 
69     for (fIt = this.id + subEntries + 1; fIt < nEntries; fIt++) 
70       indexOfEntries[fIt].navObj.moveBy(0, totalHeight) 
71   }  
72   this.isOpen = isOpen 
73   propagateChangesInState(this) 
74
75  
76 function propagateChangesInState(folder) 
77 {   
78   var i=0 
79  
80   if (folder.isOpen) 
81   { 
82     if (folder.nodeImg) 
83       if (folder.isLastNode) 
84         folder.nodeImg.src = "ftv2mlastnode.png" 
85       else 
86           folder.nodeImg.src = "ftv2mnode.png" 
87     folder.iconImg.src = "ftv2folderopen.png" 
88     for (i=0; i<folder.nChildren; i++) 
89       folder.children[i].display() 
90   } 
91   else 
92   { 
93     if (folder.nodeImg) 
94       if (folder.isLastNode) 
95         folder.nodeImg.src = "ftv2plastnode.png" 
96       else 
97           folder.nodeImg.src = "ftv2pnode.png" 
98     folder.iconImg.src = "ftv2folderclosed.png" 
99     for (i=0; i<folder.nChildren; i++) 
100       folder.children[i].hide() 
101   }  
102
103  
104 function hideFolder() 
105
106   if (browserVersion == 1 || browserVersion == 3) { 
107     if (this.navObj.style.display == "none") 
108       return 
109     this.navObj.style.display = "none" 
110   } else { 
111     if (this.navObj.visibility == "hidden") 
112       return 
113     this.navObj.visibility = "hidden" 
114   } 
115    
116   this.setState(0) 
117
118  
119 function initializeFolder(level, lastNode, leftSide) 
120
121 var j=0 
122 var i=0 
123 var numberOfFolders 
124 var numberOfDocs 
125 var nc 
126       
127   nc = this.nChildren 
128    
129   this.createIndex() 
130  
131   var auxEv = "" 
132  
133   if (browserVersion > 0) 
134     auxEv = "<a href='javascript:clickOnNode("+this.id+")'>" 
135   else 
136     auxEv = "<a>" 
137  
138   if (level>0) 
139     if (lastNode) //the last 'brother' in the children array 
140     { 
141       this.renderOb(leftSide + auxEv + "<img name='nodeIcon" + this.id + "' src='ftv2mlastnode.png' width=16 height=22 border=0></a>") 
142 //    leftSide = leftSide + "<img src='ftv2blank.png' width=16 height=22>"  
143       this.isLastNode = 1 
144     } 
145     else 
146     { 
147       this.renderOb(leftSide + auxEv + "<img name='nodeIcon" + this.id + "' src='ftv2mnode.png' width=16 height=22 border=0></a>") 
148       leftSide = leftSide + "<img src='ftv2vertline.png' width=16 height=22>" 
149       this.isLastNode = 0 
150     } 
151   else 
152     this.renderOb("") 
153    
154   if (nc > 0) 
155   { 
156     level = level + 1 
157     for (i=0 ; i < this.nChildren; i++)  
158     { 
159       if (i == this.nChildren-1) 
160         this.children[i].initialize(level, 1, leftSide) 
161       else 
162         this.children[i].initialize(level, 0, leftSide) 
163       } 
164   } 
165
166  
167 function drawFolder(leftSide) 
168
169   if (browserVersion == 2) { 
170     if (!doc.yPos) 
171       doc.yPos=8 
172     doc.write("<layer id='folder" + this.id + "' top=" + doc.yPos + " visibility=hidden>") 
173   } 
174   if (browserVersion == 3) 
175   {
176     doc.write("<div id='folder" + this.id + "' style='visibility:hide;'>") 
177   }
178    
179   doc.write("\n<table ") 
180   if (browserVersion == 1) 
181     doc.write(" id='folder" + this.id + "' style='position:block;' ") 
182   doc.write(" border=0 cellspacing=0 cellpadding=0>") 
183   doc.write("\n<tr><td>") 
184   doc.write(leftSide) 
185   this.outputLink() 
186   doc.write("<img name='folderIcon" + this.id + "' ") 
187   doc.write("src='" + this.iconSrc+"' border=0></a>") 
188   doc.write("</td>\n<td valign=middle nowrap>") 
189   if (USETEXTLINKS) 
190   { 
191     this.outputLink() 
192     doc.write(this.desc + "</a>") 
193   } 
194   else 
195     doc.write(this.desc)
196
197 /*! 
198   if (this.tagName!="")
199   {
200     doc.write(" [external]")
201   }
202 */
203   doc.write("</td>")  
204   doc.write("\n</table>\n") 
205    
206   if (browserVersion == 2) { 
207     doc.write("</layer>") 
208   } 
209   if (browserVersion == 3) { 
210     doc.write("</div>") 
211   } 
212  
213   if (browserVersion == 1) { 
214     this.navObj = doc.all["folder"+this.id] 
215     this.iconImg = doc.all["folderIcon"+this.id] 
216     this.nodeImg = doc.all["nodeIcon"+this.id] 
217   } else if (browserVersion == 2) { 
218     this.navObj = doc.layers["folder"+this.id] 
219     this.iconImg = this.navObj.document.images["folderIcon"+this.id] 
220     this.nodeImg = this.navObj.document.images["nodeIcon"+this.id] 
221     doc.yPos=doc.yPos+this.navObj.clip.height 
222   } else if (browserVersion == 3) {
223     this.navObj = doc.getElementById("folder"+this.id)
224     this.iconImg = doc.images.namedItem("folderIcon"+this.id)
225     this.nodeImg = doc.images.namedItem("nodeIcon"+this.id)
226   }
227
228  
229 function outputFolderLink() 
230
231   if (this.hreference) 
232   { 
233     doc.write("<a ")
234     if (this.tagName)
235     {
236       doc.write("doxygen='" + this.tagName + "' ");
237     }
238     doc.write("href='" + this.hreference + "' TARGET=\"basefrm\" ") 
239     if (browserVersion > 0) 
240       doc.write("onClick='javascript:clickOnFolder("+this.id+")'") 
241     doc.write(">") 
242   } 
243   else 
244     doc.write("<a>") 
245
246  
247 function addChild(childNode) 
248
249   this.children[this.nChildren] = childNode 
250   this.nChildren++ 
251   return childNode 
252
253  
254 function folderSubEntries() 
255
256   var i = 0 
257   var se = this.nChildren 
258  
259   for (i=0; i < this.nChildren; i++){ 
260     if (this.children[i].children) //is a folder 
261       se = se + this.children[i].subEntries() 
262   } 
263  
264   return se 
265
266  
267  
268 // Definition of class Item (a document or link inside a Folder) 
269 // ************************************************************* 
270  
271 function Item(itemDescription, tagName, itemLink) // Constructor 
272
273   // constant data 
274   this.desc = itemDescription 
275   this.tagName = tagName
276   this.link = itemLink 
277   this.id = -1 //initialized in initalize() 
278   this.navObj = 0 //initialized in render() 
279   this.iconImg = 0 //initialized in render() 
280   this.iconSrc = "ftv2doc.png" 
281  
282   // methods 
283   this.initialize = initializeItem 
284   this.createIndex = createEntryIndex 
285   this.hide = hideItem 
286   this.display = display 
287   this.renderOb = drawItem 
288   this.totalHeight = totalHeight 
289
290  
291 function hideItem() 
292
293   if (browserVersion == 1 || browserVersion == 3) { 
294     if (this.navObj.style.display == "none") 
295       return 
296     this.navObj.style.display = "none" 
297   } else { 
298     if (this.navObj.visibility == "hidden") 
299       return 
300     this.navObj.visibility = "hidden" 
301   }     
302
303  
304 function initializeItem(level, lastNode, leftSide) 
305 {  
306   this.createIndex() 
307  
308   if (level>0) 
309     if (lastNode) //the last 'brother' in the children array 
310     { 
311       this.renderOb(leftSide + "<img src='ftv2lastnode.png' width=16 height=22>") 
312       leftSide = leftSide + "<img src='ftv2blank.png' width=16 height=22>"  
313     } 
314     else 
315     { 
316       this.renderOb(leftSide + "<img src='ftv2node.png' width=16 height=22>") 
317       leftSide = leftSide + "<img src='ftv2vertline.png' width=16 height=22>" 
318     } 
319   else 
320     this.renderOb("")   
321
322  
323 function drawItem(leftSide) 
324
325   if (browserVersion == 2) 
326     doc.write("<layer id='item" + this.id + "' top=" + doc.yPos + " visibility=hidden>") 
327   if (browserVersion == 3) 
328     doc.write("<div id='item" + this.id + "' style='display:block;'>") 
329      
330   doc.write("\n<table ") 
331   if (browserVersion == 1) 
332     doc.write(" id='item" + this.id + "' style='position:block;' ") 
333   doc.write(" border=0 cellspacing=0 cellpadding=0>\n") 
334   doc.write("<tr><td>") 
335   doc.write(leftSide) 
336   if (this.link!="")
337   {
338     doc.write("<a href=" + this.link + ">") 
339   }
340   doc.write("<img id='itemIcon"+this.id+"' ") 
341   doc.write("src='"+this.iconSrc+"' border=0>") 
342   if (this.link!="")
343   {
344     doc.write("</a>")
345   } 
346   doc.write("</td>\n<td valign=middle nowrap>") 
347   if (USETEXTLINKS && this.link!="") 
348     doc.write("<a href=" + this.link + ">" + this.desc + "</a>") 
349   else 
350     doc.write(this.desc) 
351 /*!
352   if (this.tagName!="")
353   {
354     doc.write(" [external]");
355   }
356 */
357   doc.write("\n</table>\n") 
358    
359   if (browserVersion == 2) 
360     doc.write("</layer>") 
361   if (browserVersion == 3) 
362     doc.write("</div>")
363  
364   if (browserVersion == 1) { 
365     this.navObj = doc.all["item"+this.id] 
366     this.iconImg = doc.all["itemIcon"+this.id] 
367   } else if (browserVersion == 2) { 
368     this.navObj = doc.layers["item"+this.id] 
369     this.iconImg = this.navObj.document.images["itemIcon"+this.id] 
370     doc.yPos=doc.yPos+this.navObj.clip.height 
371   } else if (browserVersion == 3) {
372     this.navObj = doc.getElementById("item"+this.id)
373     this.iconImg = doc.images.namedItem("itemIcon"+this.id)
374   }
375
376  
377  
378 // Methods common to both objects (pseudo-inheritance) 
379 // ******************************************************** 
380  
381 function display() 
382
383   if (browserVersion == 1 || browserVersion == 3) 
384     this.navObj.style.display = "block" 
385   else 
386     this.navObj.visibility = "show" 
387
388  
389 function createEntryIndex() 
390
391   this.id = nEntries 
392   indexOfEntries[nEntries] = this 
393   nEntries++ 
394
395  
396 // total height of subEntries open 
397 function totalHeight() //used with browserVersion == 2 
398
399   var h = this.navObj.clip.height 
400   var i = 0 
401    
402   if (this.isOpen) //is a folder and _is_ open 
403     for (i=0 ; i < this.nChildren; i++)  
404       h = h + this.children[i].totalHeight() 
405  
406   return h 
407
408  
409  
410 // Events 
411 // ********************************************************* 
412  
413 function clickOnFolder(folderId) 
414
415   var clicked = indexOfEntries[folderId] 
416  
417   if (!clicked.isOpen) 
418     clickOnNode(folderId) 
419  
420   return  
421  
422   if (clicked.isSelected) 
423     return 
424
425  
426 function clickOnNode(folderId) 
427
428   var clickedFolder = 0 
429   var state = 0 
430  
431   clickedFolder = indexOfEntries[folderId] 
432   state = clickedFolder.isOpen 
433  
434   clickedFolder.setState(!state) //open<->close  
435
436  
437 function initializeDocument() 
438
439   doc = document;
440   if (doc.all) 
441     browserVersion = 1 //IE4   
442   else 
443     if (doc.layers) 
444       browserVersion = 2 //NS4 
445     else if(navigator.userAgent.toLowerCase().indexOf('gecko') != -1)
446         browserVersion = 3 //mozilla
447       else 
448         browserVersion = 0 //other 
449
450   foldersTree.initialize(0, 1, "") 
451   foldersTree.display()
452   
453   if (browserVersion > 0) 
454   { 
455     if(browserVersion != 3)
456       doc.write("<layer top="+indexOfEntries[nEntries-1].navObj.top+">&nbsp;</layer>") 
457  
458     // close the whole tree 
459     clickOnNode(0) 
460     // open the root folder 
461     clickOnNode(0) 
462   } 
463
464  
465 // Auxiliary Functions for Folder-Treee backward compatibility 
466 // ********************************************************* 
467  
468 function gFld(description, tagName, hreference) 
469
470   folder = new Folder(description, tagName, hreference) 
471   return folder 
472
473  
474 function gLnk(description, tagName, linkData) 
475
476   fullLink = "" 
477  
478   if (linkData!="")
479   {
480     fullLink = "'"+linkData+"' target=\"basefrm\"" 
481   } 
482  
483   linkItem = new Item(description, tagName, fullLink)   
484   return linkItem 
485
486  
487 function insFld(parentFolder, childFolder) 
488
489   return parentFolder.addChild(childFolder) 
490
491  
492 function insDoc(parentFolder, document) 
493
494   parentFolder.addChild(document) 
495
496  
497 // Global variables 
498 // **************** 
499  
500 USETEXTLINKS = 1
501 indexOfEntries = new Array 
502 nEntries = 0 
503 doc = document 
504 browserVersion = 0 
505 selectedFolder=0