我有一位来自Isomorphic的顾问开始开发webapp,并提供基础。对应用程序导航至关重要的treegrid具有按需加载的节点。我需要弄清楚如何更改它以从一开始就加载所有孩子。
这是ds.xml代码:
<DataSource serverType="sql" dbName="CSODatabaseCities"
ID="Sensor"
schema="dynamic"
tableName="sensor_data">
<fields>
<field name="nodeId" type="int" />
<field name="nodeName" type="text" />
<field name="number" type="int" />
<field name="title" type="text" />
<field name="multiplier" type="float" />
<field name="offset" type="float" />
<field name="latitude" type="float"/>
<field name="longitude" type="float"/>
<field name="controlUrl" type="text" />
<field name="structureType" type="text" />
<field name="sensorType" type="text" >
<valueMap>
<value ID="d">Depth</value>
<value ID="q">Flow</value>
<value ID="rg">Rain Gauge</value>
<value ID="t">Temperature</value>
<value ID="v">Velocity</value>
</valueMap>
</field>
<field name="criticalLow" type="float" />
<field name="criticalHigh" type="float" />
<field name="units" type="text" />
<field name="latestValue" type="float" title="Reading" format="#.###"/>
<field name="lastCollected" type="datetime" />
<field name="percentUtilization" type="float" format="##.##'%'" title="Utilization" />
<field name="percentUtilizationImageUrl" type="image">
<customSelectExpression>
CASE
WHEN percentUtilization < 0
THEN CONCAT('structure/', structureType, '_0.bmp')
WHEN percentUtilization > 100
THEN CONCAT('structure/', structureType, '_100.bmp')
WHEN structureType = 'raingauge' AND percentUtilization BETWEEN 0 AND 10
THEN CONCAT('structure/', structureType, '_10.bmp')
ELSE
CONCAT('structure/', structureType, '_', ROUND(percentUtilization, -1),'.bmp')
END
</customSelectExpression>
</field>
<field name="parentId" type="text" title="Group" />
<field name="sensorId" type="text" customSelectExpression="CONCAT('c',nodeId, '_', number)" />
<field name="isFolder" hidden="true" canFilter="false" customSelectExpression="false" />
</fields>
<operationBinding operationType="fetch" operationId="fetchByParentGroup">
<script language="groovy"><![CDATA[
if (criteria.get('parentId', '/') == '/') {
dsRequest.setOperationId('fetchSensorGroups');
} else {
dsRequest.setOperationId(null);
}
return dsRequest.execute();
]]></script>
</operationBinding>
<operationBinding operationType="fetch" operationId="fetchSensorGroups" >
<selectClause>'/' AS parentId, TRIM(descr) AS sensorId, TRIM(descr) AS title, true AS isFolder, COUNT(*) AS sensorCount</selectClause>
<tableClause>${rawValue.schema}.inodes</tableClause>
<whereClause>
sensType1 != 'No Sensor'
OR sensType2 != 'No Sensor'
OR sensType3 != 'No Sensor'
OR sensType4 != 'No Sensor'
</whereClause>
<groupClause>descr</groupClause>
</operationBinding>
<operationBinding operationType="fetch" qualifyColumnNames="false">
<tableClause>
(
SELECT TRIM(i.descr) AS parentId, i.id AS nodeId, i.name AS nodeName,
1 AS number, i.sensType1 AS title, i.a1 AS multiplier, i.b1 AS offset,
i.lat AS latitude, i.lon AS longitude, i.controlURL as controlUrl,
s.structure_type_s1 AS structureType, s.sensor_type_s1 AS sensorType,
s.critical_low_s1 AS criticalLow, s.critical_high_s1 AS criticalHigh,
s.sensor1_units AS units, lv.sens1 AS latestValue, lv.time AS lastCollected,
(lv.sens1 / s.critical_high_s1) * 100 AS percentUtilization
FROM #schema.inodes i
INNER JOIN #schema.inodes_structure_data s
ON i.id = s.id
LEFT JOIN #schema.inodes_latest_values lv
ON i.id = lv.node_id
WHERE i.sensType1 != 'No Sensor'
UNION
SELECT TRIM(i.descr) AS nodeGroup, i.id AS nodeId, i.name AS nodeName,
2 AS sensorNumber, i.sensType2 AS title, i.a2 AS multiplier, i.b2 AS offset,
i.lat AS latitude, i.lon AS longitude, i.controlURL as controlUrl,
s.structure_type_s2 AS structureType, s.sensor_type_s2 AS sensorType,
s.critical_low_s2 AS criticalLow, s.critical_high_s2 AS criticalHigh,
s.sensor2_units AS units, lv.sens2 AS latestValue, lv.time AS lastCollected,
(lv.sens2 / s.critical_high_s2) * 100
FROM #schema.inodes i
INNER JOIN #schema.inodes_structure_data s
ON i.id = s.id
LEFT JOIN #schema.inodes_latest_values lv
ON i.id = lv.node_id
WHERE i.sensType2 != 'No Sensor'
UNION
SELECT TRIM(i.descr) AS nodeGroup, i.id AS nodeId, i.name AS nodeName,
3 AS sensorNumber, i.sensType3 AS title, i.a3 AS multiplier, i.b3 AS offset,
i.lat AS latitude, i.lon AS longitude, i.controlURL as controlUrl,
s.structure_type_s3 AS structureType, s.sensor_type_s3 AS sensorType,
s.critical_low_s3 AS criticalLow, s.critical_high_s3 AS criticalHigh,
s.sensor3_units AS units, lv.sens3 AS latestValue, lv.time AS lastCollected,
(lv.sens3 / s.critical_high_s3) * 100
FROM #schema.inodes i
INNER JOIN #schema.inodes_structure_data s
ON i.id = s.id
LEFT JOIN #schema.inodes_latest_values lv
ON i.id = lv.node_id
WHERE i.sensType3 != 'No Sensor'
UNION
SELECT TRIM(i.descr) AS nodeGroup, i.id AS nodeId, i.name AS nodeName,
4 AS sensorNumber, i.sensType4 AS title, i.a4 AS multiplier, i.b4 AS offset,
i.lat AS latitude, i.lon AS longitude, i.controlURL as controlUrl,
s.structure_type_s4 AS structureType, s.sensor_type_s4 AS sensorType,
s.critical_low_s4 AS criticalLow, s.critical_high_s4 AS criticalHigh,
s.sensor4_units AS units, lv.sens4 AS latestValue, lv.time AS lastCollected,
(lv.sens4 / s.critical_high_s4) * 100
FROM #schema.inodes i
INNER JOIN #schema.inodes_structure_data s
ON i.id = s.id
LEFT JOIN #schema.inodes_latest_values lv
ON i.id = lv.node_id
WHERE i.sensType4 != 'No Sensor'
) sensor_data
</tableClause>
</operationBinding>
<operationBinding operationType="add" requires="false" />
<operationBinding operationType="remove" requires="false" />
<operationBinding operationType="update" requires="false" />
</DataSource>
以下是与设置treegrid相关的代码:
Tree tree = new Tree();
tree.setModelType(TreeModelType.PARENT);
tree.setRootValue("/");
tree.setIdField("sensorId");
treeGrid.setFetchOperation("fetchByParentGroup");
//treeGrid.setLoadDataOnDemand(false);
treeGrid.setDataProperties(tree);
treeGrid.setSort(new SortSpecifier("title", SortDirection.ASCENDING));
treeGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
treeGrid.setShowPartialSelection(true);
treeGrid.setCascadeSelection(true);
treeGrid.setNodeIcon("[SKINIMG]SchemaViewer/simpleType.png");
treeGrid.setFolderIcon("[SKINIMG]SchemaViewer/complexType.gif");
treeGrid.setShowOpenIcons(false);
treeGrid.setShowDropIcons(false);
treeGrid.setClosedIconSuffix("");
/*
* Load selected children on demand and update listPane with currently
* selected items
*/
treeGrid.addSelectionUpdatedHandler(new SelectionUpdatedHandler() {
@Override
public void onSelectionUpdated(SelectionUpdatedEvent event) {
final TreeNode updated = treeGrid.getRecord(treeGrid.getEventRow());
final TreeNode[] children = treeGrid.getTree().getChildren(updated);
if (updated.getAttributeAsBoolean("isFolder") && children.length == 0) {
treeGrid.getData().loadChildren(updated, new DSCallback() {
@Override
public void execute(DSResponse dsResponse, Object data,
DSRequest dsRequest) {
treeGrid.selectRecords(dsResponse.getData());
}
});
} else {
RecordList selected = new RecordList(treeGrid.getSelectedRecords());
listGrid.setData(selected.findAll(new AdvancedCriteria("isFolder",
OperatorId.NOT_EQUAL, true)));
}
listGrid.selectRecord(0);
}
});
我一直在努力解决这个问题,但我不能为我的生活找出如何保持相同的外观(分组)并从一开始就加载所有传感器。
这是当前外观的图像,并且在父项展开之前不会获取传感器。
非常感谢任何关于这个主题的灯光。
答案 0 :(得分:1)
setLoadDataOnDemand
方法是从一开始就加载所有孩子的好方法:
treeGrid.setLoadDataOnDemand(Boolean.FALSE);