use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class SchemaVM method getIcon.
public static String getIcon(SchemaNodeData data) {
SurveyObject surveyObject = data.getSurveyObject();
boolean key = surveyObject instanceof KeyAttributeDefinition && ((KeyAttributeDefinition) surveyObject).isKey();
boolean calculated = surveyObject instanceof AttributeDefinition && ((AttributeDefinition) surveyObject).isCalculated();
return getIcon(data, key, calculated);
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class SchemaVM method removeNodeDefinition.
protected void removeNodeDefinition(final NodeDefinition nodeDefn) {
String confirmMessageKey;
Object[] extraMessageArgs = null;
if (nodeDefn instanceof EntityDefinition && !((EntityDefinition) nodeDefn).getChildDefinitions().isEmpty()) {
confirmMessageKey = CONFIRM_REMOVE_NON_EMPTY_ENTITY_MESSAGE_KEY;
} else if (nodeDefn.hasDependencies()) {
confirmMessageKey = CONFIRM_REMOVE_NODE_WITH_DEPENDENCIES_MESSAGE_KEY;
} else if (nodeDefn instanceof AttributeDefinition && !((AttributeDefinition) nodeDefn).getReferencingAttributes().isEmpty()) {
confirmMessageKey = CONFIRM_REMOVE_REFERENCED_ATTRIBUTE_MESSAGE_KEY;
List<String> referencedAttrNames = org.openforis.commons.collection.CollectionUtils.project(((AttributeDefinition) nodeDefn).getReferencingAttributes(), "name");
extraMessageArgs = new String[] { StringUtils.join(referencedAttrNames, ", ") };
} else {
confirmMessageKey = CONFIRM_REMOVE_NODE_MESSAGE_KEY;
}
NodeType type = NodeType.valueOf(nodeDefn);
String typeLabel = type.getLabel().toLowerCase(Locale.ENGLISH);
boolean isRootEntity = nodeDefn.getParentDefinition() == null;
if (isRootEntity) {
typeLabel = Labels.getLabel("survey.schema.root_entity");
}
Object[] messageArgs = new String[] { typeLabel, nodeDefn.getName() };
if (extraMessageArgs != null) {
messageArgs = ArrayUtils.addAll(messageArgs, extraMessageArgs);
}
Object[] titleArgs = new String[] { typeLabel };
MessageUtil.showConfirm(new MessageUtil.ConfirmHandler() {
@Override
public void onOk() {
performRemoveNode(nodeDefn);
}
}, confirmMessageKey, messageArgs, CONFIRM_REMOVE_NODE_TITLE_KEY, titleArgs, "global.remove_item", "global.cancel");
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class SchemaVM method getIcon.
public static String getIcon(SchemaNodeData data, boolean key, boolean calculated) {
SurveyObject surveyObject = data.getSurveyObject();
String imagesRootPath = NODE_TYPES_IMAGES_PATH;
if (surveyObject instanceof UITab) {
return imagesRootPath + "tab-small.png";
} else if (surveyObject instanceof EntityDefinition) {
return getEntityIcon((EntityDefinition) surveyObject);
} else if (key) {
return imagesRootPath + "key-small.png";
} else if (calculated) {
return imagesRootPath + "calculated-small.png";
} else {
AttributeType attributeType = AttributeType.valueOf((AttributeDefinition) surveyObject);
return getAttributeIcon(attributeType.name());
}
}
use of org.openforis.idm.metamodel.AttributeDefinition 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);
}
});
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class NodeDefinitionFormValidator method validateMaxCount.
protected void validateMaxCount(ValidationContext ctx) {
Boolean multiple = (Boolean) getValue(ctx, MULTIPLE_FIELD);
if (multiple != null && multiple.booleanValue()) {
NodeDefinition editedNode = getEditedNode(ctx);
boolean result = true;
if (editedNode instanceof AttributeDefinition) {
result = validateRequired(ctx, MAX_COUNT_EXPRESSION_FIELD);
}
if (result) {
Object maxCountVal = getValue(ctx, MAX_COUNT_EXPRESSION_FIELD);
if (maxCountVal != null && isNumber(maxCountVal)) {
String minCountVal = getValue(ctx, MIN_COUNT_EXPRESSION_FIELD);
if (StringUtils.isBlank(minCountVal) || isNumber(minCountVal) && Double.parseDouble(minCountVal.toString()) < MAX_COUNT_MIN_VALUE) {
validateGreaterThan(ctx, MAX_COUNT_EXPRESSION_FIELD, MAX_COUNT_MIN_VALUE, false);
} else if (isNumber(minCountVal)) {
String minCountLabel = Labels.getLabel(LabelKeys.NODE_MIN_COUNT);
validateGreaterThan(ctx, MAX_COUNT_EXPRESSION_FIELD, MIN_COUNT_EXPRESSION_FIELD, minCountLabel, false);
}
}
}
}
}
Aggregations