use of org.openforis.idm.metamodel.Schema in project collect by openforis.
the class MetaModelExpressionTest method testParentExpression.
@Test
public void testParentExpression() {
Schema schema = survey.getSchema();
EntityDefinition clusterDefn = schema.getRootEntityDefinition("cluster");
EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
NodeDefinition plotNoDefn = plotDefn.getChildDefinition("no");
SchemaPathExpression expression = new SchemaPathExpression("parent()");
NodeDefinition resultDefn = expression.evaluate(plotDefn, plotNoDefn);
Assert.assertEquals(clusterDefn, resultDefn);
}
use of org.openforis.idm.metamodel.Schema in project collect by openforis.
the class SchemaVM method performRemoveNode.
protected void performRemoveNode(NodeDefinition nodeDefn) {
EntityDefinition parentDefn = (EntityDefinition) nodeDefn.getParentDefinition();
if (parentDefn == null) {
// root entity
UIOptions uiOpts = survey.getUIOptions();
UITabSet tabSet = uiOpts.getAssignedRootTabSet((EntityDefinition) nodeDefn);
uiOpts.removeTabSet(tabSet);
Schema schema = nodeDefn.getSchema();
String nodeName = nodeDefn.getName();
schema.removeRootEntityDefinition(nodeName);
selectedRootEntity = null;
rootTabSet = null;
notifyChange("selectedRootEntity", "rootEntities");
refreshTreeModel();
} else {
if (treeModel != null) {
treeModel.removeSelectedNode();
notifyChange("treeModel");
}
parentDefn.removeChildDefinition(nodeDefn);
}
survey.refreshSurveyDependencies();
resetEditingStatus();
dispatchCurrentFormValidatedCommand(true);
dispatchSurveyChangedCommand();
}
use of org.openforis.idm.metamodel.Schema in project collect by openforis.
the class SchemaVM method changeEditedNodeParentEntity.
private void changeEditedNodeParentEntity(EntityDefinition newParentEntity) {
// update parent entity
NodeDefinition node = (NodeDefinition) editedNode;
Schema schema = survey.getSchema();
schema.changeParentEntity(node, newParentEntity);
// update tab
UIOptions uiOptions = survey.getUIOptions();
uiOptions.removeTabAssociation(node);
if (node instanceof AttributeDefinition) {
survey.getAnnotations().setMeasurementAttribute((AttributeDefinition) node, false);
}
// update ui
refreshTreeModel();
editedNodeParentEntity = newParentEntity;
selectTreeNode(editedNode);
treeModel.showSelectedNode();
notifyChange("selectedTreeNode", "editedNode");
}
use of org.openforis.idm.metamodel.Schema in project collect by openforis.
the class SurveyBaseVM method getRootEntities.
public List<EntityDefinition> getRootEntities() {
CollectSurvey survey = getSurvey();
if (survey == null) {
// TODO session expired...?
return Collections.emptyList();
} else {
Schema schema = survey.getSchema();
List<EntityDefinition> result = schema.getRootEntityDefinitions();
return result;
}
}
use of org.openforis.idm.metamodel.Schema in project collect by openforis.
the class UnitsVM method getReferences.
protected List<NodeDefinition> getReferences(Unit item) {
List<NodeDefinition> references = new ArrayList<NodeDefinition>();
Schema schema = survey.getSchema();
List<EntityDefinition> rootEntities = schema.getRootEntityDefinitions();
Stack<NodeDefinition> stack = new Stack<NodeDefinition>();
stack.addAll(rootEntities);
while (!stack.isEmpty()) {
NodeDefinition defn = stack.pop();
if (defn instanceof EntityDefinition) {
stack.addAll(((EntityDefinition) defn).getChildDefinitions());
} else if (defn instanceof NumericAttributeDefinition) {
List<Unit> units = ((NumericAttributeDefinition) defn).getUnits();
if (units.contains(item)) {
references.add(defn);
}
}
}
return references;
}
Aggregations