473,503 Members | 11,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I add the JavaScript code into the Plug-in tool?

4 New Member
I need to invoke the javascript code to obtain the subtree.
Refer to the code from https://developer.mozilla.org/en-US/...e_View_Details,
I do the following steps:
1) I build a new file named "imagestree.js"

Expand|Select|Wrap|Line Numbers
  1. var treeView = {
  2.  
  3.   childData : {
  4.     Solids: ["Silver", "Gold", "Lead"],
  5.     Liquids: ["Mercury"],
  6.     Gases: ["Helium", "Nitrogen"],
  7.     Images: ["ami-0000","ami-0002"],
  8.     Name: ["SCIEx"],
  9.     Gold: ["zhong","guo"]
  10.   },
  11.  
  12.   visibleData : [
  13.     ["Solids", true, false],
  14.     ["Liquids", true, false],
  15.     ["Gases", true, false],
  16.     ["Images", true, false],
  17.     ["Name", true, false],
  18.     ["Gold", true, false],
  19.   ],
  20.  
  21.   treeBox: null,
  22.   selection: null,
  23.  
  24.   get rowCount()                     { return this.visibleData.length; },
  25.   setTree: function(treeBox)         { this.treeBox = treeBox; },
  26.   getCellText: function(idx, column) { return this.visibleData[idx][0]; },
  27.   isContainer: function(idx)         { return this.visibleData[idx][1]; },
  28.   isContainerOpen: function(idx)     { return this.visibleData[idx][2]; },
  29.   isContainerEmpty: function(idx)    { return false; },
  30.   isSeparator: function(idx)         { return false; },
  31.   isSorted: function()               { return false; },
  32.   isEditable: function(idx, column)  { return false; },
  33.  
  34.   getParentIndex: function(idx) {
  35.     if (this.isContainer(idx)) return -1;
  36.     for (var t = idx - 1; t >= 0 ; t--) {
  37.       if (this.isContainer(t)) return t;
  38.     }
  39.   },
  40.   getLevel: function(idx) {
  41.     if (this.isContainer(idx)) return 0;
  42.     return 1;
  43.   },
  44.   hasNextSibling: function(idx, after) {
  45.     var thisLevel = this.getLevel(idx);
  46.     for (var t = after + 1; t < this.visibleData.length; t++) {
  47.       var nextLevel = this.getLevel(t);
  48.       if (nextLevel == thisLevel) return true;
  49.       if (nextLevel < thisLevel) break;
  50.     }
  51.     return false;
  52.   },
  53.   toggleOpenState: function(idx) {
  54.     var item = this.visibleData[idx];
  55.     if (!item[1]) return;
  56.  
  57.     if (item[2]) {
  58.       item[2] = false;
  59.  
  60.       var thisLevel = this.getLevel(idx);
  61.       var deletecount = 0;
  62.       for (var t = idx + 1; t < this.visibleData.length; t++) {
  63.         if (this.getLevel(t) > thisLevel) deletecount++;
  64.         else break;
  65.       }
  66.       if (deletecount) {
  67.         this.visibleData.splice(idx + 1, deletecount);
  68.         this.treeBox.rowCountChanged(idx + 1, -deletecount);
  69.       }
  70.     }
  71.     else {
  72.       item[2] = true;
  73.  
  74.       var label = this.visibleData[idx][0];
  75.       var toinsert = this.childData[label];
  76.       for (var i = 0; i < toinsert.length; i++) {
  77.         this.visibleData.splice(idx + i + 1, 0, [toinsert[i], false]);
  78.       }
  79.       this.treeBox.rowCountChanged(idx + 1, toinsert.length);
  80.     }
  81.     this.treeBox.invalidateRow(idx);
  82.   },
  83.   getImageSrc: function(idx, column) {},
  84.   getProgressMode : function(idx,column) {},
  85.   getCellValue: function(idx, column) {},
  86.   cycleHeader: function(col, elem) {},
  87.   selectionChanged: function() {},
  88.   cycleCell: function(idx, column) {},
  89.   performAction: function(action) {},
  90.   performActionOnCell: function(action, index, column) {},
  91.   getRowProperties: function(idx, prop) {},
  92.   getCellProperties: function(idx, column, prop) {},
  93.   getColumnProperties: function(column, element, prop) {},
  94. };
  95.  
  96. function tree() {
  97.   document.getElementById("elementList").view = treeView;
  98. }

2) Then I want to invoke the function "tree()" in the "image.xul" file, where should I put the code?

Expand|Select|Wrap|Line Numbers
  1. <overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  2. <script type="application/x-javascript" src="imagestree.js" />
  3.   <tabpanel id="images_tab" flex="1">
  4.     <vbox flex="1">
  5.       <hbox flex="2">
  6.        <groupbox flex="3" orient="vertical">
  7.           <caption label="schemes;" />
  8.            <tree id="elementList" flex="1">
  9.         <treecols>
  10.           <treecol id="element" label="Element" primary="true" flex="1"/>
  11.         </treecols>
  12.         <treechildren/>
  13.     </tree>
  14.         </groupbox>
3) For example, I add the code with the "onfocus" event:

Expand|Select|Wrap|Line Numbers
  1. <overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onfocus="tree()">
However, it can not works.

So how can I handle this problem?
Aug 17 '12 #1
6 1599
gits
5,390 Recognized Expert Moderator Expert
i didn't go through all the code - but to get a first working view of your example i suggest to use the following xul-file:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE window []>
  3. <?xml-stylesheet href="chrome://global/skin/" style="text/css"?>
  4.  
  5. <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="tree();">
  6.     <script type="application/x-javascript" src="imagestree.js" />
  7.  
  8.     <groupbox flex="3" orient="vertical">
  9.         <caption label="schemes;" />
  10.         <tree id="elementList" flex="1">
  11.             <treecols>
  12.                 <treecol id="element" label="Element" primary="true" flex="1"/>
  13.             </treecols>
  14.             <treechildren/>
  15.         </tree>
  16.     </groupbox>
  17. </window>
  18.  
now - is that what you want to achieve? and if not please explain in more detail what the problem is.

PS: in your trieview implementation it might be necessary to request enhanced privileges:

Expand|Select|Wrap|Line Numbers
  1. function tree() {
  2.     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  3.     document.getElementById("elementList").view = treeView;
  4. }
  5.  
Aug 17 '12 #2
mathswww
4 New Member
Thanks for your reply, still I have two problems:
1) Since I use a "main.xul" file to add this "image.xul" as an overlay, it seems hard for me to invoke the function in the "image.xul" file.
2) I want to know how can I implement a nesting tree,
while the example is only for two levels. If I want to
implment a tree with tree levels, how can I define the
childData in the "image.js" file.
Aug 18 '12 #3
gits
5,390 Recognized Expert Moderator Expert
1. the overlay is included during parsetime and the code in the overlay is ready to use in your 'main.xul's onload-event - so just call the code in that onload-event

2. a multilevel tree looks like this:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE window []>
  3. <?xml-stylesheet href="chrome://global/skin/" style="text/css"?>
  4.  
  5. <window id="sixt" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="">
  6.  
  7. <tree flex="1">
  8.     <treecols>
  9.         <treecol label="col 1" flex="1" primary="true"/>
  10.         <treecol label="col 2" flex="2"/>
  11.     </treecols>
  12.     <treechildren>
  13.         <treeitem container="true">
  14.             <treerow>
  15.                 <treecell label="foo" />
  16.                 <treecell label="bar" />
  17.             </treerow>
  18.             <treechildren>
  19.                 <treeitem container="true">
  20.                     <treerow>
  21.                         <treecell label="foo1" />
  22.                         <treecell label="bar1" />
  23.                     </treerow>
  24.                     <treechildren>
  25.                         <treeitem>
  26.                             <treerow>
  27.                                 <treecell label="foo3" />
  28.                                 <treecell label="bar3" />
  29.                             </treerow>
  30.                         </treeitem>
  31.                     </treechildren>
  32.                 </treeitem>
  33.                 <treeitem>
  34.                     <treerow>
  35.                         <treecell label="foo2" />
  36.                         <treecell label="bar2" />
  37.                     </treerow>
  38.                 </treeitem>
  39.             </treechildren>
  40.         </treeitem>
  41.     </treechildren>
  42. </tree>
  43.  
  44. </window>
  45.  
have a look here: http://www.xul.fr/tutorial/tree.html for more information.

now there are different possibilities to implement that either in a custom treeView or in a object/method that simply creates the shown node-structure based on the given data structure. normally you would create someting like (corresponding to the above example):

Expand|Select|Wrap|Line Numbers
  1. function MyTree() {
  2. }
  3.  
  4. MyTree.prototype.create = function(data, container) {
  5.     // implement tree-creation logic here
  6. }
  7.  
  8. // id of a XUL-container where the tree should be
  9. // inserted
  10. var cntId = 'myTreeContainer';
  11.  
  12. var data = [{
  13.     id1: 'foo', 
  14.     id2: 'bar', 
  15.     children: [{
  16.         id1: 'foo1', 
  17.         id2: 'bar1', 
  18.         children: [{
  19.             id1: 'foo3', 
  20.             id2: 'bar3', 
  21.         }]
  22.     }]
  23. },{
  24.     id1: 'foo2', 
  25.     id2: 'bar2', 
  26. }];
  27.  
  28. var myTree = new MyTree;
  29. myTree.create(data, cntId);
  30.  
Aug 20 '12 #4
mathswww
4 New Member
Thanks for your reply, I have one more question for the first example. Since I want to dynamically change the "childData" and "visibleData", I write two functions in the class of treeView:

Expand|Select|Wrap|Line Numbers
  1. var treeView = {
  2. ...
  3.    childData : null,
  4.    visibleData : null,
  5.    setchildData: function(childData)  {this.childData=childData;},
  6.   setvisibleData: function(visibleData) {this.visibleData=visibleData;},
  7. ...
  8. }
  9.  
And then I use the two functions to set the values.
However, the tree structure is invisible.
So what is the problem?
Aug 24 '12 #5
mathswww
4 New Member
Thanks for your reply, I have one more question for the first example. Since I want to dynamically change the "childData" and "visibleData", I write two functions in the class of treeView:

Expand|Select|Wrap|Line Numbers
  1. var treeView = {
  2. ...
  3.    childData : null,
  4.    visibleData : null,
  5.    setchildData: function(childData)  {this.childData=childData;},
  6.   setvisibleData: function(visibleData) {this.visibleData=visibleData;},
  7. ...
  8. }
  9.  
And then I use the two functions to set the values.
However, the tree structure is invisible.
So what is the problem?
Aug 24 '12 #6
gits
5,390 Recognized Expert Moderator Expert
in your treeView implement a refresh-method like this:

Expand|Select|Wrap|Line Numbers
  1. myRefresh: function() {
  2.     this.treeBox.rowCountChanged(0, this.visibleData.length);
  3. }
and the update-data method could look like this:

Expand|Select|Wrap|Line Numbers
  1. function setData() {
  2.   treeView.setchildData({
  3.     Solids: ["Silver", "Gold", "Lead"],
  4.     Liquids: ["Mercury"],
  5.     Gases: ["Helium", "Nitrogen"],
  6.     Images: ["ami-0000","ami-0002"],
  7.     Name: ["SCIEx"],
  8.     Gold: ["zhong","guo"]
  9.   });
  10.  
  11.   treeView.setvisibleData([
  12.     ["Solids", true, false],
  13.     ["Liquids", true, false],
  14.     ["Gases", true, false],
  15.     ["Images", true, false],
  16.     ["Name", true, false],
  17.     ["Gold", true, false],
  18.   ]);  
  19.  
  20.   treeView.myRefresh();
  21. }
Aug 24 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

53
5656
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
1
1676
by: John | last post by:
Hi, when I develop applications in Java I use Eclipse. A nice feature is the code assistant when coding, suggesting me the methods or variables for a special object. For web pages I use...
6
2661
by: rahul8143 | last post by:
hello, Is there any source code analysis tool avail for C programmers under Linux? That tool should go through all source code files and print functional dependencies. tool can run in any...
5
1402
by: Chris H | last post by:
Hello All, Hope all is having a cool holiday season... I am looking for a code validation tool for VB.NET. It should be able to point out variables that are not in use as well as ways to make...
16
1875
by: kazak | last post by:
Hello, I am looking for C code analysing tool, My problem is: To discover the portion of code that depends on(deals with) a number of specified structures and variables. Sample: void...
47
65253
by: SOLAV | last post by:
This is the only working way to completely hide your JavaScript code from the client just like PHP or ASP code. Here we'll need the help of PHP. Here is the code: index.php...
2
1178
by: vingomail | last post by:
let me know the best Javascript debugging software tool? help me guys...
3
1974
by: Alpha83 | last post by:
Hi, Is there a code measuring tool that tells you which is more efficient cost-wise. For example, if I were to compare the following two identical code blocks, how do I know, which is more...
2
1434
Frinavale
by: Frinavale | last post by:
I'm looking for a good code analyzing tool that can help me determine how long each method in a specified ASPX page is taking to execute. Specifically I need to find out why my page is taking so long...
0
7296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.