Beispiel #1
0
        private void DisplayItem(int i)
        {
            itemContentPanel.ClearGrid();
            MList ml = data[shownList];

            if (ml.Count == 0 || i == -1)
            {
                itemContentPanel.Visibility = Visibility.Collapsed;
                noItemsLabel.Visibility     = Visibility.Visible;
                noItemsLabel.Content        = i == -1 ? "No Item Selected" : "No Items!";
            }
            else
            {
                itemContentPanel.Visibility = Visibility.Visible;
                noItemsLabel.Visibility     = Visibility.Collapsed;
                MItem item = ml[i];
                Utils.SetupContentGrid(itemContentPanel, ml.Template.Values.Select(fti => fti.Space));
                //TODO
                foreach (string fieldName in ml.Template.Keys)
                {
                    MField            lif = item[fieldName];
                    FrameworkElement  fe  = null;
                    FieldTemplateItem fti = ml.Template[fieldName];
                    if (lif.FieldType.Equals(FieldType.IMAGE))
                    {
                        fe = new CImage();
                        (fe as CImage).Source = (lif as ImageField).ToVisibleValue(fti.Metadata)
                                                as System.Windows.Media.Imaging.BitmapImage;
                    }
                    //else if (lif is EnumField) {
                    //	fe = new Label();
                    //	(fe as Label).Content = (lif as EnumField).GetSelectedValue(fti.Metadata as EnumMetadata);
                    //}
                    else
                    {
                        fe = new Label();
                        (fe as Label).Content = lif.Value == null ? "" : lif.ToVisibleValue(fti.Metadata).ToString();
                    }
                    Grid.SetColumn(fe, fti.X);
                    Grid.SetRow(fe, fti.Y);
                    Grid.SetColumnSpan(fe, fti.Width);
                    Grid.SetRowSpan(fe, fti.Height);
                    itemContentPanel.Children.Add(fe);
                }
            }
        }
        private Grid CreateImageUI(string fieldName, FrameworkElement mainUI, MItem item)
        {
            Button browse = new Button();

            browse.Content = "Browse...";
            browse.Click  += BrowseButton_Click;
            browse.Name    = fieldName + "_bb";
            Button clear = new Button();

            clear.Content = "Clear";
            clear.Name    = fieldName + "_clr";
            clear.Click  += ClearButton_Click;
            Label file = new Label();

            file.Content = item != null ? "<Cached file>" : "<No file>";
            register.Add(fieldName + "_lab", file);

            Grid g = new Grid();

            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.RowDefinitions.Add(new RowDefinition());
            g.RowDefinitions.Add(new RowDefinition());
            file.SetValue(Grid.ColumnProperty, 0);
            file.SetValue(Grid.RowProperty, 0);
            browse.SetValue(Grid.ColumnProperty, 1);
            browse.SetValue(Grid.RowProperty, 0);
            clear.SetValue(Grid.ColumnProperty, 0);
            clear.SetValue(Grid.RowProperty, 1);
            mainUI.SetValue(Grid.ColumnProperty, 1);
            mainUI.SetValue(Grid.RowProperty, 1);
            g.Children.Add(browse);
            g.Children.Add(clear);
            g.Children.Add(file);
            g.Children.Add(mainUI);
            return(g);
        }
        //FIXME REFACTOR HERE
        private FrameworkElement WrapUpElement(string fieldName, FieldType fieldType, FrameworkElement mainUI, MItem item)
        {
            switch (fieldType)
            {
            case FieldType.BASIC:
            case FieldType.DATE:
            case FieldType.NUMBER:
            case FieldType.DECIMAL:
            case FieldType.ENUM:
                DockPanel dp = new DockPanel();
                Label     l  = new Label();
                l.Content = fieldName + ": ";
                dp.Children.Add(l);
                DockPanel.SetDock(l, Dock.Left);
                dp.Children.Add(mainUI);
                DockPanel.SetDock(mainUI, Dock.Right);
                return(dp);

            case FieldType.IMAGE:
                return(CreateImageUI(fieldName, mainUI, item));

            default: throw new NotImplementedException();
            }
        }
 /// <summary>
 /// Creates and adds ui elements for each field in a <seealso cref="List{FieldTemplateItem}"/>
 /// (with possible starting values if a <seealso cref="MItem"/> is given).
 /// </summary>
 /// <param name="template">a list of template items to use to create ui elements</param>
 /// <param name="item">a possibly null value that will be used to fill in ui
 /// elements with previous values</param>
 private void CreateUIElements(Dictionary <string, FieldTemplateItem> template, MItem item)
 {
     foreach (string fieldName in template.Keys)
     {
         FieldTemplateItem fti = template[fieldName];
         //create the main ui element for each template item
         //i.e. the ui element that holds the content of each field
         FrameworkElement uiField = CreateMainUIElement(fti.Type, fti.Metadata);
         //add this ui element to the register for access later, appending the suffix "_ui"
         //to differentiate it as the main ui element
         register.Add(fieldName + UI_ELEMENT_SUFFIX, uiField);
         //if using values from before
         if (item != null)
         {
             //fill in the ui element with the field's value
             FillValueIn(uiField, item[fieldName]);
         }
         //wrap up the element for presentation and add it to the content panel
         contentPanel.Children.Add(WrapUpElement(fieldName, fti.Type, uiField, item));
     }
 }
Beispiel #5
0
        internal static ListData LoadTestLists()
        {
            ListData data = new ListData();

            MList list1 = new MList("group a");

            list1.AddToTemplate("notes", FieldType.BASIC, null);
            list1.AddToTemplate("date", FieldType.DATE, null);
            list1.AddToTemplate("dec", FieldType.DECIMAL, new DecimalMetadata(2, 3.14f, 10.26f));
            list1.AddToTemplate("num", FieldType.NUMBER, new NumberMetadata(0, 10));
            MItem li1a = list1.Add();

            li1a["notes"].Value = "There are many things here";
            li1a["date"].Value  = new XDate(DateTime.Today);
            li1a["dec"].Value   = 50f;
            li1a["num"].Value   = 6;
            MItem li2a = list1.Add();

            li2a["notes"].Value = "more notes";
            li2a["date"].Value  = new XDate(DateTime.Today);
            li2a["dec"].Value   = 40f;
            li2a["num"].Value   = 5;
            data.AddList(list1);

            MList list2 = new MList("group b");

            list2.AddToTemplate("notes", FieldType.BASIC, null);
            list2.AddToTemplate("date", FieldType.DATE, null);
            list2.AddToTemplate("img", FieldType.IMAGE, new ImageMetadata(50.0));
            MItem li1b = list2.Add();

            li1b["notes"].Value = "More notes";
            li1b["date"].Value  = new XDate(DateTime.Today);
            li1b["img"].Value   = new XImage("http://images2.fanpop.com/images/photos/8300000/Rin-Kagamine-Vocaloid-Wallpaper-vocaloids-8316875-1024-768.jpg", true);
            MItem li2b = list2.Add();

            li2b["notes"].Value = "More notes";
            li2b["date"].Value  = new XDate(DateTime.Today);
            li2b["img"].Value   = new XImage(@"F:\Documents\Visual Studio 2015\Projects\ListApp\a.jpg", false);
            data.AddList(list2);

            SyncList            list4 = new SyncList("AnimeSchema (Sync)", SyncList.SchemaType.ANIME_LIST, new string[] { "progressivespoon" });
            List <SchemaOption> opts  = list4.Schema.GenerateOptions();

            foreach (SchemaOption so in opts)
            {
                list4.AddToTemplate(so);
            }
            list4.AddToTemplate("random tag", FieldType.ENUM, new EnumMetadata("one", "two", "three"));

            data.AddList(list4);

            //PrintLists();

            /* TEST FOR LOTS OF COLUMNS
             * list1.AddToTemplate("status", FieldType.ENUM, new EnumMetadata("completed", "started", "on hold"));
             * list1.AddToTemplate("a", FieldType.BASIC, null);
             * list1.AddToTemplate("b", FieldType.BASIC, null);
             * list1.AddToTemplate("f", FieldType.BASIC, null);
             * list1.AddToTemplate("q", FieldType.IMAGE, new ImageMetadata(10.0));
             * list1.AddToTemplate("z", FieldType.DATE, null);
             * list1.AddToTemplate("adfsd", FieldType.DATE, null);
             * list1.AddToTemplate("ccccc", FieldType.DATE, null);
             * list1.AddToTemplate("a333", FieldType.DATE, null);
             * list1.AddToTemplate("a2334", FieldType.DATE, null);
             * list1.AddToTemplate("a3aaaa4", FieldType.DATE, null);
             * list1.AddToTemplate("a32aaaaaaaaa4", FieldType.DATE, null);
             * list1.AddToTemplate("a445fd", FieldType.DATE, null);
             * list1.AddToTemplate("zxd", FieldType.DATE, null);
             * list1.AddToTemplate("a32ddd", FieldType.DATE, null);
             * list1.AddToTemplate("hytrd", FieldType.DATE, null);
             * list1.AddToTemplate("a44ree", FieldType.DATE, null);
             * list1.AddToTemplate("aaaaaaaa", FieldType.DATE, null);
             * list1.SetMetadata("status", new EnumMetadata("a", "b", "c", "d"));
             * li1a["status"].Value = 1;
             */
            //list2.ReorderTemplate(2, 0);
            //list2.ResolveFieldFields();
            //li2a.SetFieldData("status", 1);

            return(data);
        }