gpt4 book ai didi

java - SmartGWT TreeGrid 禁用延迟加载

转载 作者:行者123 更新时间:2023-12-01 11:24:45 26 4
gpt4 key购买 nike

我有一位来自 Isomorphic 的顾问开始开发一个网络应用程序,并提供一个基础。对于应用程序导航至关重要的树形网格具有按需加载的节点。我需要弄清楚如何更改它以从一开始就加载所有子项。

这是 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 &lt; 0
THEN CONCAT('structure/', structureType, '_0.bmp')
WHEN percentUtilization &gt; 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>

以下是与设置树形网格相关的代码:

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);
}
});

我已经尝试了几个小时来解决这个问题,但我一生都无法弄清楚如何保持相同的外观(分组)并从一开始就加载所有传感器。

这是当前外观的图像,在展开父级之前不会获取传感器。

enter image description here

任何对这个主题的启发将不胜感激。

最佳答案

setLoadDataOnDemand 方法是从一开始就加载所有子项的好方法:

treeGrid.setLoadDataOnDemand(Boolean.FALSE);

关于java - SmartGWT TreeGrid 禁用延迟加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30920647/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com