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" - var treeView = {
-
-
childData : {
-
Solids: ["Silver", "Gold", "Lead"],
-
Liquids: ["Mercury"],
-
Gases: ["Helium", "Nitrogen"],
-
Images: ["ami-0000","ami-0002"],
-
Name: ["SCIEx"],
-
Gold: ["zhong","guo"]
-
},
-
-
visibleData : [
-
["Solids", true, false],
-
["Liquids", true, false],
-
["Gases", true, false],
-
["Images", true, false],
-
["Name", true, false],
-
["Gold", true, false],
-
],
-
-
treeBox: null,
-
selection: null,
-
-
get rowCount() { return this.visibleData.length; },
-
setTree: function(treeBox) { this.treeBox = treeBox; },
-
getCellText: function(idx, column) { return this.visibleData[idx][0]; },
-
isContainer: function(idx) { return this.visibleData[idx][1]; },
-
isContainerOpen: function(idx) { return this.visibleData[idx][2]; },
-
isContainerEmpty: function(idx) { return false; },
-
isSeparator: function(idx) { return false; },
-
isSorted: function() { return false; },
-
isEditable: function(idx, column) { return false; },
-
-
getParentIndex: function(idx) {
-
if (this.isContainer(idx)) return -1;
-
for (var t = idx - 1; t >= 0 ; t--) {
-
if (this.isContainer(t)) return t;
-
}
-
},
-
getLevel: function(idx) {
-
if (this.isContainer(idx)) return 0;
-
return 1;
-
},
-
hasNextSibling: function(idx, after) {
-
var thisLevel = this.getLevel(idx);
-
for (var t = after + 1; t < this.visibleData.length; t++) {
-
var nextLevel = this.getLevel(t);
-
if (nextLevel == thisLevel) return true;
-
if (nextLevel < thisLevel) break;
-
}
-
return false;
-
},
-
toggleOpenState: function(idx) {
-
var item = this.visibleData[idx];
-
if (!item[1]) return;
-
-
if (item[2]) {
-
item[2] = false;
-
-
var thisLevel = this.getLevel(idx);
-
var deletecount = 0;
-
for (var t = idx + 1; t < this.visibleData.length; t++) {
-
if (this.getLevel(t) > thisLevel) deletecount++;
-
else break;
-
}
-
if (deletecount) {
-
this.visibleData.splice(idx + 1, deletecount);
-
this.treeBox.rowCountChanged(idx + 1, -deletecount);
-
}
-
}
-
else {
-
item[2] = true;
-
-
var label = this.visibleData[idx][0];
-
var toinsert = this.childData[label];
-
for (var i = 0; i < toinsert.length; i++) {
-
this.visibleData.splice(idx + i + 1, 0, [toinsert[i], false]);
-
}
-
this.treeBox.rowCountChanged(idx + 1, toinsert.length);
-
}
-
this.treeBox.invalidateRow(idx);
-
},
-
getImageSrc: function(idx, column) {},
-
getProgressMode : function(idx,column) {},
-
getCellValue: function(idx, column) {},
-
cycleHeader: function(col, elem) {},
-
selectionChanged: function() {},
-
cycleCell: function(idx, column) {},
-
performAction: function(action) {},
-
performActionOnCell: function(action, index, column) {},
-
getRowProperties: function(idx, prop) {},
-
getCellProperties: function(idx, column, prop) {},
-
getColumnProperties: function(column, element, prop) {},
-
};
-
-
function tree() {
-
document.getElementById("elementList").view = treeView;
-
}
2) Then I want to invoke the function "tree()" in the "image.xul" file, where should I put the code? - <overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-
<script type="application/x-javascript" src="imagestree.js" />
-
<tabpanel id="images_tab" flex="1">
-
<vbox flex="1">
-
<hbox flex="2">
-
<groupbox flex="3" orient="vertical">
-
<caption label="schemes;" />
-
<tree id="elementList" flex="1">
-
<treecols>
-
<treecol id="element" label="Element" primary="true" flex="1"/>
-
</treecols>
-
<treechildren/>
-
</tree>
-
</groupbox>
3) For example, I add the code with the "onfocus" event: - <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?
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: - <?xml version="1.0" encoding="ISO-8859-1"?>
-
<!DOCTYPE window []>
-
<?xml-stylesheet href="chrome://global/skin/" style="text/css"?>
-
-
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="tree();">
-
<script type="application/x-javascript" src="imagestree.js" />
-
-
<groupbox flex="3" orient="vertical">
-
<caption label="schemes;" />
-
<tree id="elementList" flex="1">
-
<treecols>
-
<treecol id="element" label="Element" primary="true" flex="1"/>
-
</treecols>
-
<treechildren/>
-
</tree>
-
</groupbox>
-
</window>
-
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: - function tree() {
-
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
document.getElementById("elementList").view = treeView;
-
}
-
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.
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: - <?xml version="1.0" encoding="ISO-8859-1"?>
-
<!DOCTYPE window []>
-
<?xml-stylesheet href="chrome://global/skin/" style="text/css"?>
-
-
<window id="sixt" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="">
-
-
<tree flex="1">
-
<treecols>
-
<treecol label="col 1" flex="1" primary="true"/>
-
<treecol label="col 2" flex="2"/>
-
</treecols>
-
<treechildren>
-
<treeitem container="true">
-
<treerow>
-
<treecell label="foo" />
-
<treecell label="bar" />
-
</treerow>
-
<treechildren>
-
<treeitem container="true">
-
<treerow>
-
<treecell label="foo1" />
-
<treecell label="bar1" />
-
</treerow>
-
<treechildren>
-
<treeitem>
-
<treerow>
-
<treecell label="foo3" />
-
<treecell label="bar3" />
-
</treerow>
-
</treeitem>
-
</treechildren>
-
</treeitem>
-
<treeitem>
-
<treerow>
-
<treecell label="foo2" />
-
<treecell label="bar2" />
-
</treerow>
-
</treeitem>
-
</treechildren>
-
</treeitem>
-
</treechildren>
-
</tree>
-
-
</window>
-
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): - function MyTree() {
-
}
-
-
MyTree.prototype.create = function(data, container) {
-
// implement tree-creation logic here
-
}
-
-
// id of a XUL-container where the tree should be
-
// inserted
-
var cntId = 'myTreeContainer';
-
-
var data = [{
-
id1: 'foo',
-
id2: 'bar',
-
children: [{
-
id1: 'foo1',
-
id2: 'bar1',
-
children: [{
-
id1: 'foo3',
-
id2: 'bar3',
-
}]
-
}]
-
},{
-
id1: 'foo2',
-
id2: 'bar2',
-
}];
-
-
var myTree = new MyTree;
-
myTree.create(data, cntId);
-
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: -
var treeView = {
-
...
-
childData : null,
-
visibleData : null,
-
setchildData: function(childData) {this.childData=childData;},
-
setvisibleData: function(visibleData) {this.visibleData=visibleData;},
-
...
-
}
-
And then I use the two functions to set the values.
However, the tree structure is invisible.
So what is the problem?
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: -
var treeView = {
-
...
-
childData : null,
-
visibleData : null,
-
setchildData: function(childData) {this.childData=childData;},
-
setvisibleData: function(visibleData) {this.visibleData=visibleData;},
-
...
-
}
-
And then I use the two functions to set the values.
However, the tree structure is invisible.
So what is the problem?
gits 5,390
Recognized Expert Moderator Expert
in your treeView implement a refresh-method like this: - myRefresh: function() {
-
this.treeBox.rowCountChanged(0, this.visibleData.length);
-
}
and the update-data method could look like this: - function setData() {
-
treeView.setchildData({
-
Solids: ["Silver", "Gold", "Lead"],
-
Liquids: ["Mercury"],
-
Gases: ["Helium", "Nitrogen"],
-
Images: ["ami-0000","ami-0002"],
-
Name: ["SCIEx"],
-
Gold: ["zhong","guo"]
-
});
-
-
treeView.setvisibleData([
-
["Solids", true, false],
-
["Liquids", true, false],
-
["Gases", true, false],
-
["Images", true, false],
-
["Name", true, false],
-
["Gold", true, false],
-
]);
-
-
treeView.myRefresh();
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
by: vingomail |
last post by:
let me know the best Javascript debugging software tool? help me guys...
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |