/// <summary> /// Prepares field with all needed information including UI representation. /// </summary> /// <param name="properties">information about a field, needed for e.g setting id of field</param> /// <param name="road">if not empty, field belongs to some inner class. This fact must be set into fields id.</param> /// <param name="skin">defines the look of field</param> /// <returns>prepared field with all needed information</returns> public AFField prepareField(AFFieldInfo properties, StringBuilder road, Skin skin) { AFField field = new AFField(properties); field.setId(road.ToString() + properties.getId()); //LABEL TextBlock label = buildLabel(properties, skin); field.setLabel(label); //ERROR TEXT TextBlock errorView = buildErrorView(skin); field.setErrorView(errorView); //Input view FrameworkElement widget = null; AbstractWidgetBuilder widgetBuilder = WidgetBuilderFactory.getInstance().getFieldBuilder(field, skin); if (widgetBuilder != null && (widget = widgetBuilder.buildFieldView()) != null) { field.setWidgetBuilder(widgetBuilder); field.setFieldView(widget); } //put it all together //when field is not visible don't even add it to form; FrameworkElement completeView = buildCompleteView(field, skin); if (!properties.isVisible()) { completeView.Visibility = Visibility.Collapsed; } field.setCompleteView(completeView); return field; }
public void addFieldInfo(AFFieldInfo afField) { if (fieldInfos == null) { fieldInfos = new List<AFFieldInfo>(); } fieldInfos.Add(afField); }
/// <summary> /// Parses information about one field in component. /// Exception thrown if there war error during parsing field info. /// </summary> /// <param name="field">field information wrapped in JSONObject</param> /// <returns>field info wrapped in AFFieldInfo object</returns> private AFFieldInfo parseFieldInfo(JsonObject field) { Debug.WriteLine("PARSING FIELD " + Utils.TryToGetValueFromJson(field[Constants.ID])); AFFieldInfo fieldInfo = new AFFieldInfo(); try { fieldInfo.setWidgetType(Utils.ValueOf<SupportedWidgets>(typeof(SupportedWidgets), (String) Utils.TryToGetValueFromJson(field[Constants.WIDGET_TYPE]))); } catch (Exception e) { Debug.WriteLine(e.Message); } fieldInfo.setId((String) Utils.TryToGetValueFromJson(field[Constants.ID])); fieldInfo.setLabelText((String) Utils.TryToGetValueFromJson(field[Constants.LABEL])); fieldInfo.setIsClass((Boolean) Utils.TryToGetValueFromJson(field[Constants.CLASS_TYPE])); fieldInfo.setVisible((Boolean) Utils.TryToGetValueFromJson(field[Constants.VISIBLE])); fieldInfo.setReadOnly((Boolean) Utils.TryToGetValueFromJson(field[Constants.READ_ONLY])); //field layout fieldInfo.setLayout(createLayoutProperties((JsonObject) Utils.TryToGetValueFromJson(field[Constants.LAYOUT]))); //rules) JsonArray rules = (JsonArray) Utils.TryToGetValueFromJson(field[Constants.RULES]); if (rules != null) { for (int i = 0; i < rules.Count; i++) { fieldInfo.addRule(createRule((JsonObject) Utils.TryToGetValueFromJson(rules[i]))); } } //add number rule - it is not among others in json try { if (fieldInfo.getWidgetType().Equals(SupportedWidgets.NUMBERFIELD) || fieldInfo.getWidgetType().Equals(SupportedWidgets.NUMBERDOUBLEFIELD)) { AFValidationRule numberRule = new AFValidationRule(); numberRule.setValidationType(SupportedValidations.NUMBER); numberRule.setValue(""); fieldInfo.addRule(numberRule); } } catch (Exception e) { Debug.WriteLine(e.Message); } //options JsonArray options = (JsonArray) Utils.TryToGetValueFromJson(field[Constants.OPTIONS]); if (options != null) { for (int i = 0; i < options.Count; i++) { fieldInfo.addOption(createOption((JsonObject) Utils.TryToGetValueFromJson(options[i]))); } } return fieldInfo; }
public AFField(AFFieldInfo fieldInfo) { this.fieldInfo = fieldInfo; }
/// <summary> /// Builds element for label. /// </summary> /// <param name="properties">information about label</param> /// <param name="skin">defines the look of label</param> /// <returns>label element</returns> private TextBlock buildLabel(AFFieldInfo properties, Skin skin) { TextBlock label = new TextBlock(); if (!String.IsNullOrEmpty(properties.getLabelText())) { String labelText = Localization.translate(properties.getLabelText()); //set label position label.Foreground = new SolidColorBrush(skin.getLabelColor()); label.FontFamily = skin.getLabelFont(); label.FontSize = skin.getLabelFontSize(); label.Text = labelText; label.TextWrapping = TextWrapping.Wrap; return label; } return null; }