use of org.openforis.collect.metamodel.ui.UIOptions 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.collect.metamodel.ui.UIOptions 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.collect.metamodel.ui.UIOptions in project collect by openforis.
the class SchemaVM method createRootEntityDefinition.
protected EntityDefinition createRootEntityDefinition() {
EntityDefinition rootEntity = createEntityDefinition();
rootEntity.setName(SurveyController.DEFAULT_ROOT_ENTITY_NAME);
survey.getSchema().addRootEntityDefinition(rootEntity);
UIOptions uiOptions = survey.getUIOptions();
rootTabSet = uiOptions.createRootTabSet((EntityDefinition) rootEntity);
UITab mainTab = uiOptions.getMainTab(rootTabSet);
mainTab.setLabel(currentLanguageCode, SurveyController.DEFAULT_MAIN_TAB_LABEL);
notifyChange("rootEntities");
return rootEntity;
}
use of org.openforis.collect.metamodel.ui.UIOptions in project collect by openforis.
the class SchemaVM method checkCanAddChildTab.
private boolean checkCanAddChildTab() {
if (TreeViewType.DATA.name().equalsIgnoreCase(selectedTreeViewType)) {
MessageUtil.showWarning("survey.schema.unsupported_operation_in_data_view");
return false;
} else {
SurveyObject selectedSurveyObject = selectedTreeNode.getSurveyObject();
if (selectedSurveyObject instanceof UITab) {
UITab parentTab = getSelectedNodeParentTab();
UIOptions uiOptions = survey.getUIOptions();
if (parentTab != null && uiOptions.isAssociatedWithMultipleEntityForm(parentTab)) {
MessageUtil.showWarning("survey.schema.cannot_add_nested_tab.form_entity_assosicated");
return false;
}
}
return true;
}
}
use of org.openforis.collect.metamodel.ui.UIOptions 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;
}
Aggregations