use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class SchemaVM method openSelectParentNodePopupForReparent.
private void openSelectParentNodePopupForReparent(final NodeDefinition selectedItem) {
UIOptions uiOptions = survey.getUIOptions();
final Set<UITab> assignableTabs = new HashSet<UITab>(uiOptions.getAssignableTabs(editedNodeParentEntity, selectedItem));
final EntityDefinition selectedItemParentDefn = selectedItem.getParentEntityDefinition();
UITab inheritedTab = uiOptions.getAssignedTab(selectedItemParentDefn);
assignableTabs.add(inheritedTab);
Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {
public boolean evaluate(SurveyObject item) {
if (item instanceof UITab) {
return true;
} else if (item instanceof NodeDefinition) {
if (item instanceof EntityDefinition) {
EntityDefinition entityItemDef = (EntityDefinition) item;
if (entityItemDef.isVirtual()) {
return false;
} else if (selectedItem instanceof EntityDefinition && entityItemDef.isDescendantOf((EntityDefinition) selectedItem)) {
return false;
} else {
return true;
}
} else {
return false;
}
} else {
return false;
}
}
};
Predicate<SurveyObject> disabledPredicate = new Predicate<SurveyObject>() {
@Override
public boolean evaluate(SurveyObject item) {
if (item instanceof UITab) {
return survey.isPublished() && !assignableTabs.contains(item);
} else if (item instanceof NodeDefinition) {
NodeDefinition itemNodeDef = (NodeDefinition) item;
if (itemNodeDef.equals(selectedItemParentDefn)) {
return false;
} else if (selectedItem instanceof EntityDefinition && itemNodeDef.isDescendantOf((EntityDefinition) selectedItem)) {
// is descendant of the selected item
return true;
} else if (!survey.isPublished() && itemNodeDef instanceof EntityDefinition && !itemNodeDef.equals(selectedItem)) {
// published
return false;
} else {
return true;
}
} else {
// do not allow selecting non-node definitions
return true;
}
}
};
String nodeName = editedNode instanceof NodeDefinition ? ((NodeDefinition) editedNode).getName() : "";
UITab assignedTab = survey.getUIOptions().getAssignedTab((NodeDefinition) editedNode);
String assignedTabLabel = assignedTab.getLabel(currentLanguageCode);
String title = Labels.getLabel("survey.schema.move_node_popup_title", new String[] { getNodeTypeHeaderLabel(), nodeName, assignedTabLabel });
// calculate parent item (tab or entity)
SchemaTreeNode treeNode = treeModel.getTreeNode(selectedItem);
TreeNode<SchemaNodeData> parentTreeNode = treeNode.getParent();
SurveyObject parentItem = parentTreeNode.getData().getSurveyObject();
final Window popup = SchemaTreePopUpVM.openPopup(title, selectedRootEntity, null, includedNodePredicate, false, true, disabledPredicate, null, parentItem, false);
popup.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {
public void onEvent(NodeSelectedEvent event) throws Exception {
SurveyObject selectedParent = event.getSelectedItem();
changeEditedNodeParent(selectedParent, false);
refreshNodeForm();
closePopUp(popup);
}
});
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class CollectEarthBalloonGenerator method createComponent.
private CEComponent createComponent(NodeDefinition def, int entityPosition) {
String label = def.getLabel(Type.INSTANCE, language);
if (label == null && !isDefaultLanguage()) {
label = def.getLabel(Type.INSTANCE);
}
if (label == null) {
label = def.getName();
}
boolean multiple = def.isMultiple();
UIOptions uiOptions = survey.getUIOptions();
boolean hideWhenNotRelevant = uiOptions.isHideWhenNotRelevant(def);
CEComponent comp;
if (def instanceof EntityDefinition) {
if (def.isMultiple() && ((EntityDefinition) def).isEnumerable()) {
comp = createEnumeratedEntityComponent((EntityDefinition) def);
} else {
String tooltip = def.getDescription(language);
CEFieldSet fieldSet = new CEFieldSet(def.getName(), label, tooltip);
for (NodeDefinition child : ((EntityDefinition) def).getChildDefinitions()) {
if (!uiOptions.isHidden(child)) {
fieldSet.addChild(createComponent(child));
}
}
comp = fieldSet;
}
} else {
AttributeDefinition attrDef = (AttributeDefinition) def;
String htmlParameterName;
boolean insideEnumeratedEntity = def.getParentEntityDefinition().isEnumerable();
if (insideEnumeratedEntity) {
htmlParameterName = getEnumeratedEntityComponentHtmlParameterName(def.getParentEntityDefinition(), entityPosition, def);
} else {
htmlParameterName = getHtmlParameterName(def);
}
String tooltip = attrDef.getDescription(language);
CEFieldType type = getFieldType(def);
boolean key = def instanceof KeyAttributeDefinition ? ((KeyAttributeDefinition) def).isKey() : false;
if (insideEnumeratedEntity && key) {
comp = new CEEnumeratingCodeField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
} else if (def instanceof CodeAttributeDefinition) {
CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) def;
CodeList list = codeAttrDef.getList();
Integer listLevelIndex = codeAttrDef.getListLevelIndex();
Map<Integer, List<CodeListItem>> codeItemsByParentCodeItemId = getCodeListItemsByParentId(list, listLevelIndex);
CodeAttributeDefinition parentCodeAttributeDef = codeAttrDef.getParentCodeAttributeDefinition();
String parentName = parentCodeAttributeDef == null ? null : getHtmlParameterName(parentCodeAttributeDef);
comp = new CECodeField(htmlParameterName, def.getName(), label, tooltip, type, multiple, key, codeItemsByParentCodeItemId, parentName);
} else {
comp = new CEField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
}
CollectAnnotations annotations = survey.getAnnotations();
if (attrDef.isCalculated() || (annotations.isFromCollectEarthCSV(attrDef) && annotations.isShowReadOnlyFieldInCollectEarth(attrDef))) {
((CEField) comp).setReadOnly(true);
}
}
comp.hideWhenNotRelevant = hideWhenNotRelevant;
componentByName.put(comp.getName(), comp);
return comp;
}
use of org.openforis.idm.metamodel.NodeDefinition 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;
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class EditableListOfNodesVM method getChildDefinitionsInTab.
public List<NodeDefinition> getChildDefinitionsInTab(EntityDefinition entityDefn) {
UIOptions uiOpts = getUIOptions();
List<NodeDefinition> childDefinitions = entityDefn.getChildDefinitions();
List<NodeDefinition> result = new ArrayList<NodeDefinition>();
ModelVersion formVersion = getLayoutFormVersion();
for (NodeDefinition nodeDefn : childDefinitions) {
if (formVersion == null || formVersion.isApplicable(nodeDefn)) {
UITab nodeTab = uiOpts.getAssignedTab(nodeDefn);
if (nodeTab == tab) {
result.add(nodeDefn);
}
}
}
return result;
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class EditableListOfNodesVM method getChildDefinitions.
public List<NodeDefinition> getChildDefinitions(EntityDefinition entityDefn) {
List<NodeDefinition> result = new ArrayList<NodeDefinition>();
List<NodeDefinition> childDefinitions = entityDefn.getChildDefinitions();
ModelVersion formVersion = getLayoutFormVersion();
for (NodeDefinition nodeDefn : childDefinitions) {
if (formVersion == null || formVersion.isApplicable(nodeDefn)) {
result.add(nodeDefn);
}
}
return childDefinitions;
}
Aggregations