use of org.openforis.collect.designer.util.Predicate in project collect by openforis.
the class CodeAttributeVM method openParentAttributeSelector.
@Command
public void openParentAttributeSelector(@ContextParam(ContextType.BINDER) final Binder binder) {
String title = Labels.getLabel("survey.schema.attribute.code.select_parent_for_node", new String[] { editedItem.getName() });
final Collection<CodeAttributeDefinition> assignableParentAttributes = editedItem.getAssignableParentCodeAttributeDefinitions();
if (assignableParentAttributes.isEmpty()) {
MessageUtil.showWarning("survey.schema.attribute.code.no_assignable_parent_available");
} else {
CodeAttributeDefinition parentCodeAttributeDefinition = ((CodeAttributeDefinitionFormObject) formObject).getParentCodeAttributeDefinition();
Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {
@Override
public boolean evaluate(SurveyObject item) {
return item instanceof UITab || item instanceof EntityDefinition || item instanceof CodeAttributeDefinition && assignableParentAttributes.contains(item);
}
};
Predicate<SurveyObject> disabledNodePredicate = new Predicate<SurveyObject>() {
@Override
public boolean evaluate(SurveyObject item) {
return !(item instanceof CodeAttributeDefinition);
}
};
final Window parentSelectorPopUp = SchemaTreePopUpVM.openPopup(title, editedItem.getRootEntity(), null, includedNodePredicate, false, false, disabledNodePredicate, null, parentCodeAttributeDefinition, true);
parentSelectorPopUp.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {
public void onEvent(NodeSelectedEvent event) throws Exception {
CodeAttributeDefinition parentAttrDefn = (CodeAttributeDefinition) event.getSelectedItem();
CodeAttributeDefinitionFormObject fo = (CodeAttributeDefinitionFormObject) formObject;
fo.setParentCodeAttributeDefinition(parentAttrDefn);
String hierarchicalLevel = getHierarchicalLevelName(parentAttrDefn);
fo.setHierarchicalLevel(hierarchicalLevel);
notifyChange("formObject");
dispatchApplyChangesCommand(binder);
notifyChange("dependentCodePaths");
closePopUp(parentSelectorPopUp);
}
});
}
}
use of org.openforis.collect.designer.util.Predicate 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.designer.util.Predicate in project collect by openforis.
the class SchemaAttributesImportVM method openParentEntitySelectionButton.
@Command
public void openParentEntitySelectionButton() {
Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {
public boolean evaluate(SurveyObject item) {
return item instanceof UITab || item instanceof EntityDefinition;
}
};
Predicate<SurveyObject> selectableNodePredicate = new Predicate<SurveyObject>() {
public boolean evaluate(SurveyObject item) {
return item instanceof EntityDefinition;
}
};
String title = Labels.getLabel("survey.schema.attributes_import.select_entity.popup.title");
// calculate parent item (tab or entity)
final Window popup = SchemaTreePopUpVM.openPopup(title, parentEntityDefinition.getRootEntity(), null, includedNodePredicate, true, true, null, selectableNodePredicate, parentEntityDefinition, false);
popup.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {
public void onEvent(NodeSelectedEvent event) throws Exception {
SurveyObject selectedParent = event.getSelectedItem();
parentEntityDefinition = (EntityDefinition) selectedParent;
notifyChange("parentEntityDefinitionPath");
closePopUp(popup);
}
});
}
use of org.openforis.collect.designer.util.Predicate in project collect by openforis.
the class SchemaVM method openSelectParentNodePopupForDuplicate.
private void openSelectParentNodePopupForDuplicate(final NodeDefinition node) {
Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {
@Override
public boolean evaluate(SurveyObject item) {
return item instanceof UITab || item instanceof EntityDefinition;
}
};
Predicate<SurveyObject> disabledPredicate = new Predicate<SurveyObject>() {
@Override
public boolean evaluate(SurveyObject item) {
return !(item instanceof UITab || item instanceof EntityDefinition);
}
};
String nodeName = node.getName();
UITab assignedTab = survey.getUIOptions().getAssignedTab((NodeDefinition) node);
String assignedTabLabel = assignedTab.getLabel(currentLanguageCode);
String title = Labels.getLabel("survey.schema.duplicate_node_popup_title", new String[] { getNodeTypeHeaderLabel(), nodeName, assignedTabLabel });
// calculate parent item (tab or entity)
SchemaTreeNode treeNode = treeModel.getTreeNode(node);
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();
duplicateEditedNodeInto(node, selectedParent);
closePopUp(popup);
}
});
}
use of org.openforis.collect.designer.util.Predicate in project collect by openforis.
the class AttributeVM method openReferencedAttributeSelector.
@Command
public void openReferencedAttributeSelector(@ContextParam(ContextType.BINDER) final Binder binder) {
ReferenceableKeyAttributeHelper referenceableKeyAttributeHelper = new ReferenceableKeyAttributeHelper(editedItem);
final Set<EntityDefinition> referenceableEntityDefinitions = referenceableKeyAttributeHelper.determineReferenceableEntities();
final Set<AttributeDefinition> selectableAttributes = referenceableKeyAttributeHelper.determineReferenceableAttributes();
if (selectableAttributes.isEmpty()) {
MessageUtil.showWarning("survey.schema.attribute.no_referenceable_attributes_available");
} else {
Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {
public boolean evaluate(SurveyObject item) {
EntityDefinition parentEntity;
if (item instanceof UITab) {
parentEntity = survey.getUIOptions().getParentEntityForAssignedNodes((UITab) item);
} else {
parentEntity = ((NodeDefinition) item).getParentEntityDefinition();
}
for (EntityDefinition entityDef : referenceableEntityDefinitions) {
if (parentEntity == entityDef || parentEntity.isAncestorOf(entityDef)) {
return true;
}
}
return false;
}
};
Predicate<SurveyObject> disabledNodePredicate = new Predicate<SurveyObject>() {
public boolean evaluate(SurveyObject item) {
return !selectableAttributes.contains(item);
}
};
String title = Labels.getLabel("survey.schema.attribute.select_attribute_referenced_by", new String[] { editedItem.getName() });
final Window parentSelectorPopUp = SchemaTreePopUpVM.openPopup(title, editedItem.getRootEntity(), null, includedNodePredicate, false, false, disabledNodePredicate, null, editedItem.getReferencedAttribute(), true);
parentSelectorPopUp.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {
public void onEvent(NodeSelectedEvent event) throws Exception {
AttributeDefinition referencedAttribute = (AttributeDefinition) event.getSelectedItem();
AttributeDefinitionFormObject<?> fo = (AttributeDefinitionFormObject<?>) formObject;
fo.setReferencedAttributePath(referencedAttribute == null ? null : referencedAttribute.getPath());
notifyChange("formObject");
dispatchApplyChangesCommand(binder);
closePopUp(parentSelectorPopUp);
}
});
}
}
Aggregations