<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/wb/ (C) Ken Webb Thu Jul 12 2012 08:19:31 GMT-0400 (EDT)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: Workbook Scripts
Description:
Url: http://www.primordion.com/Xholon/wb/xholon
InternalName:
YoutubeId:
Keywords:
My Notes
--------
This workbook contains jQuery/JavaScript scripts that can be used with any Xholon Workbook, and with any other Xholon webEdition project.
It also contains equivalent scripts for use with the Java-based Xholon jvmEdition.
How to use a webEdition script ::
Run the workbook.
Copy the contents of a webEdition script, without the intitial and final Abehavior lines.
Paste the contents into the textarea of the workbook.
Click the Submit button.
The results will be written to the same textarea.
How to use a jvmEdition script ::
Run a jvmEdition app.
Copy the contents of a jvmEdition script, without the intitial and final Abehavior lines.
Open a Xholon Console on the root node of the app, or on any child or other descendant node.
Select Mode > JavaScript
Paste the contents of the script into the Xholon Console.
Click Submit.
The results will be written to stdout (operating system terminal, Java JNLP console, Eclipse console, etc.)
]]></Notes>
<script implName="lang:python:inline:"><![CDATA[
]]></script>
<script implName="lang:javascript:inline:"><![CDATA[
]]></script>
<_-.XholonClass>
<!-- types of domain objects -->
<ScriptSystem/>
<TestOne/>
<TestTwo/>
<TestThree/>
<!-- quantities -->
<Height superClass="Length"/>
</_-.XholonClass>
<xholonClassDetails>
</xholonClassDetails>
<ScriptSystem>
<!-- example for testing -->
<TestOne>
<TestTwo/>
<TestTwo roleName="hello"/>
<TestTwo>123.4</TestTwo>
<TestTwo>567.8 m/s^2</TestTwo>
<TestTwo>this is a string</TestTwo>
<TestTwo roleName="world">567.8 m/s^2</TestTwo>
</TestOne>
</ScriptSystem>
<Blockbehavior implName="lang:python:inline:"><![CDATA[
]]></Blockbehavior>
<Abehavior implName="lang:javascript:inline:"><![CDATA[
// Show the contents of the entire CSH tree (jvmEdition)
var contextNode = contextNodeKey;
var app = applicationKey;
print("\n\ntimestep: " + app.getTimeStep());
function show(node, indent) {
// name
var className = node.getXhcName();
var nodeName = node.getName();
// roleName
var roleName = node.getRoleName();
if (roleName) {roleName = roleName + " ";}
else {roleName = "";}
// val
var val = node.getVal();
if (val != undefined) {val = " " + val;}
else {val = "";}
// val_string
var val_string = node.getVal_String();
if (val_string != undefined) {val_string = " " + val_string;}
else {val_string = "";}
// unit
var unit = node.getUnits();
if (unit != undefined) {unit = " " + unit;}
else {unit = "";}
print("\n" + indent + roleName + nodeName + val + unit + val_string);
node = node.getFirstChild();
indent = indent + " ";
while (node) {
show(node, indent);
node = node.getNextSibling();
}
}
show(contextNode, "");
]]></Abehavior>
<Abehavior implName="lang:webEditionjs:inline:"><![CDATA[
// Show the contents of the entire CSH tree (webEdition)
var contextNode = ".CompositeStructureHierarchy"; // CSH node
var spaces = " ";
print("\n\ntimestep: " + app.application("getTimeStep"));
$(contextNode).find("*").each( function() {
var node = $(this);
// name
var className = node.getXhcName();
var nodeName = node.getName();
// roleName
var roleName = node.attr("roleName");
if (roleName) {roleName = roleName + " ";}
else {roleName = "";}
// val
var val = node.attr("val");
if (val != undefined) {val = " " + val;}
else {val = "";}
// val_string
var val_string = node.attr("val_string");
if (val_string != undefined) {val_string = " " + val_string;}
else {val_string = "";}
// unit
var unit = node.attr("unit");
if (unit != undefined) {unit = " " + unit;}
else {unit = "";}
// indent
var depth = node.parentsUntil(contextNode).length;
var indent = spaces.substring(0, depth);
// don't show behavior nodes
if (className.indexOf("behavior") == -1) {
print("\n" + indent + roleName + nodeName + val + unit + val_string);
}
});
]]></Abehavior>
<Abehavior implName="lang:webEditionjs:inline:"><![CDATA[
// verify that each node in the CSH is an instance of a node in the IH (webEdition)
print("\nMissing classes (if any)");
var ih = [];
$(".InheritanceHierarchy").find("*[id]").each( function() {
ih.push($(this).attr("id"));
});
ih.sort();
var csh = [];
$(".CompositeStructureHierarchy").find("*").each( function() {
csh.push($(this).getXhcName());
});
csh = $.unique(csh);
for (var i = 0; i < csh.length; i++) {
if ($.inArray(csh[i], ih) == -1) {
print("\n<" + csh[i] + "/>");
}
}
]]></Abehavior>
<Abehavior implName="lang:webEditionjs:inline:"><![CDATA[
// Write the contents of the CSH tree in CSV or TSV format for import into a spreadsheet (webEdition)
var contextNode = ".CompositeStructureHierarchy"; // CSH node
//var sep = ","; // can paste CSV to OpenOffice/LibreOffice Calc and Excel?
var sep = "\t"; // can paste TSV to Google Docs spreadsheets
var seps = "";
for (var i = 0; i < 20; i++) {
seps += sep;
}
print("\n\ntimestep: " + app.application("getTimeStep"));
$(contextNode).find("*").each( function() {
var node = $(this);
// name
var className = node.getXhcName();
var nodeName = node.getName();
// roleName
var roleName = node.attr("roleName");
if (roleName) {roleName = roleName + " ";}
else {roleName = "";}
// val
var val = node.attr("val");
if (val != undefined) {val = sep + val;}
else {val = "";}
// val_string
var val_string = node.attr("val_string");
if (val_string != undefined) {val_string = sep + val_string;}
else {val_string = "";}
// unit
var unit = node.attr("unit");
if (unit != undefined) {unit = sep + unit;}
else {unit = "";}
// indent
var depth = node.parentsUntil(contextNode).length;
var indent = seps.substring(0, depth);
// don't show behavior nodes
if (className.indexOf("behavior") == -1) {
print("\n" + indent + roleName + className + val + unit + val_string);
}
});
]]></Abehavior>
<Abehavior implName="lang:webEditionjs:inline:"><![CDATA[
// Write the contents of the CSH tree in D3 Pack Layout (including Bubble Chart) JSON format (webEdition)
// validate the resulting JSON at: http://jsonlint.com/
var contextNode = ".CompositeStructureHierarchy"; // CSH node
var sep = " "; // separator between parts of the JSON name
var seps = "";
for (var i = 0; i < 20; i++) {
seps += sep;
}
$(contextNode).find("*").each( function() {
var node = $(this);
var isLeafNode = node.children().length == 0 ? true : false;
var hasNextSibling = node.next().length == 1 ? true : false;
// name
var className = node.getXhcName();
var nodeName = node.getName();
// roleName
var roleName = node.attr("roleName");
if (roleName) {roleName = roleName + " ";}
else {roleName = "";}
// val
var val = node.attr("val");
if (className.indexOf("behavior") != -1) {
// don't show behavior nodes
val = "0";
}
else if (val == undefined) {
val = "1";
}
else {
if (val == "0") {
val = "1";
}
}
// indent
var depth = node.parentsUntil(contextNode).length;
var indent = seps.substring(0, depth);
if (isLeafNode) {
print("\n" + indent + '{"name": "' + roleName + className + '", "size": ' + val + '}');
if (hasNextSibling) {
print(',');
}
else {
var parent = node.parent();
while ((parent.length > 0) && ("." + parent.getXhcName() != contextNode)) {
print("\n]\n}");
if (parent.next().length == 1) {
print(',');
break;
}
parent = parent.parent();
}
}
}
else {
print("\n" + indent + '{\n"name": "' + roleName + className + '",');
print("\n" + indent + '"children": [');
}
});
]]></Abehavior>
<Blockbehavior implName="lang:bsh:inline:"><![CDATA[
]]></Blockbehavior>
<Blockbehavior implName="lang:jruby:inline:"><![CDATA[
]]></Blockbehavior>
<Blockbehavior implName="lang:groovy:inline:"><![CDATA[
]]></Blockbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Scripts</title>
<rect id="ScriptSystem" fill="#98FB98" height="50" width="50" x="25" y="0"/>
</g>
</svg>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>