private static async Task <FieldView> CreateChildEntryView(
            ListFieldView self, JObject root, JsonSchemaToView viewGenerator, JToken modelEntry, string fieldName)
        {
            JsonSchema newEntryVm = GetMatchingSchema(modelEntry, self.field.items);
            GameObject childView  = await AddChildEntryView(self, viewGenerator, fieldName, newEntryVm);

            await childView.LinkToJsonModel(root, viewGenerator);

            return(childView.GetComponentInChildren <FieldView>());
        }
        private static IEnumerable <ListEntryView> GetSelectedViews(ListFieldView self)
        {
            var entries        = self.gameObject.GetComponentsInChildren <ListEntryView>(includeInactive: false);
            var checkedEntries = entries.Filter(x => x.checkmark.isOn);

            if (checkedEntries.IsNullOrEmpty())
            {
                Toast.Show("No entries selected");
            }
            return(checkedEntries);
        }
        public static async Task LoadModelList(this ListFieldView self, JObject root, JsonSchemaToView viewGenerator)
        {
            JArray modelArray = self.GetFieldJModel(root) as JArray;

            AssertV2.IsNotNull(modelArray, "modelArray");
            var map = new Dictionary <FieldView, JToken>();

            for (int i = 0; i < modelArray.Count; i++)
            {
                var    fieldName = "" + i;
                JToken entry     = modelArray[i];
                var    fv        = await CreateChildEntryView(self, root, viewGenerator, entry, fieldName);

                map.Add(fv, entry);
            }
            SetupButtons(self, root, viewGenerator, modelArray, map);
        }
        private static async Task <GameObject> AddChildEntryView(
            ListFieldView self, JsonSchemaToView viewGenerator, string fieldName, JsonSchema entryVm)
        {
            var parentView = self.mainLink.gameObject;

            if (CanBeShownInListViewEntry(entryVm.GetJTokenType()))
            {
                GameObject childGo = await viewGenerator.AddChild(parentView, await viewGenerator.NewListViewEntry());

                await viewGenerator.InitChild(childGo, fieldName, entryVm);

                return(childGo);
            }
            else
            {
                return(await viewGenerator.AddViewForJsonSchemaField(parentView, entryVm, fieldName));
            }
        }
 private static void SetupButtons(ListFieldView listView, JObject root, JsonSchemaToView viewGenerator, JArray modelArray, Dictionary <FieldView, JToken> map)
 {
     listView.add.SetOnClickAction(async delegate {
         JToken entry = listView.field.items.First().NewDefaultJInstance();
         modelArray.Add(entry);
         var fieldName = "" + (modelArray.Count - 1);
         var fv        = await CreateChildEntryView(listView, root, viewGenerator, entry, fieldName);
         map.Add(fv, entry);
     });
     listView.up.SetOnClickAction(delegate {
         foreach (var v in GetSelectedViews(listView))
         {
             var selectedData = map[v];
             var index        = modelArray.IndexOf(selectedData);
             if (index > 0)
             {
                 modelArray.RemoveAt(index);
                 modelArray.Insert(index - 1, selectedData);
                 v.transform.SetSiblingIndex(v.transform.GetSiblingIndex() - 1);
             }
         }
     });
     listView.down.SetOnClickAction(delegate {
         foreach (var v in GetSelectedViews(listView).Reverse())
         {
             var selectedData = map[v];
             var index        = modelArray.IndexOf(selectedData);
             if (index < modelArray.Count - 1)
             {
                 modelArray.RemoveAt(index);
                 modelArray.Insert(index + 1, selectedData);
                 v.transform.SetSiblingIndex(v.transform.GetSiblingIndex() + 1);
             }
         }
     });
     listView.delete.SetOnClickAction(delegate {
         foreach (var v in GetSelectedViews(listView))
         {
             var selectedData = map[v];
             modelArray.Remove(selectedData);
             v.gameObject.Destroy();
         }
     });
 }