Example #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);
                }
            }
        }
Example #2
0
 //methods
 /// <summary>
 /// Adds a new <seealso cref="FieldTemplateItem"/> to the list's template,
 /// and adds a new field based off of the <seealso cref="FieldTemplateItem"/>
 /// to each item already in the list.
 /// </summary>
 /// <param name="fieldName">the name of the new field</param>
 /// <param name="fti">the template item to add</param>
 internal void AddToTemplate(string fieldName, FieldTemplateItem fti)
 {
     //can't add new field with same name
     if (template.ContainsKey(fieldName))
     {
         throw new NotSupportedException("There exists a field with name " + fieldName + " already.");
     }
     else
     {
         //add the new template for the field
         template.Add(fieldName, fti);
         //add the field to each item already in the list
         foreach (MItem mi in items)
         {
             mi.AddField(fieldName, fti);
         }
     }
 }
Example #3
0
        private void FillItem(SyncItem si, Dictionary <string, FieldTemplateItem> template, XmlNode animeNode)
        {
            //Console.WriteLine("anime node id: " + si.Id);
            HtmlDocument htmlDoc = new HtmlDocument();

            System.Diagnostics.Stopwatch s = System.Diagnostics.Stopwatch.StartNew();
            string htmlStr = webClient.DownloadString("http://myanimelist.net/anime/" + si.Id + "/");

            htmlDoc.LoadHtml(htmlStr);
            foreach (string fieldName in template.Keys)
            {
                FieldTemplateItem fti = template[fieldName];
                if (fti is SyncTemplateItem)
                {
                    SyncTemplateItem sti = fti as SyncTemplateItem;
                    si[fieldName].Value = sti.ParamList[0].Equals("XML") ?
                                          FindDataFromXML(sti, animeNode.FindChild(sti.Id)) : FindDataFromHTML(htmlDoc, sti);
                }
            }
            //Console.WriteLine("time: " + s.ElapsedMilliseconds);
        }
 /// <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));
     }
 }
Example #5
0
 private void SaveReadable()
 {
     //TODO
     using (TextWriter tw = new StreamWriter(C.READABLE_BACKUP_FILE)) {
         foreach (MList ml in lists)
         {
             tw.WriteLine(ml.Name);
             tw.WriteLine("=================");
             foreach (MItem mi in ml)
             {
                 tw.WriteLine("Item:");
                 foreach (string fieldName in ml.Template.Keys)
                 {
                     MField            lif = mi[fieldName];
                     FieldTemplateItem fti = ml.Template[fieldName];
                     tw.Write("\t" + fieldName + ": ");
                     tw.Write(lif.ToReadable(fti.Metadata));
                 }
             }
         }
     }
 }
Example #6
0
        private DataGridTemplateColumn DefineColumn(string fieldName, FieldTemplateItem fti)
        {
            //CImage img = new CImage();
            //img.BeginInit();
            //img.Source = (lif as ImageField).GetBitmap();
            //img.EndInit();
            //fe = img;
            DataGridTemplateColumn dgc = new DataGridTemplateColumn();
            Binding bind = new Binding();

            bind.Mode = BindingMode.OneWay;
            bind.ConverterParameter = new ConverterData()
            {
                Name = fieldName, Template = fti
            };
            Type uiType = typeof(TextBlock);

            switch (fti.Type)
            {
            case FieldType.DATE:
            case FieldType.BASIC:
                bind.Converter = new ListItemToValueConverter();
                break;

            case FieldType.ENUM:
                bind.Converter = new ListItemToEnumConverter();
                break;

            case FieldType.IMAGE:
                uiType         = typeof(CImage);
                bind.Converter = new ListItemToImageConverter();
                break;

            case FieldType.NUMBER:
                bind.Converter = new ListItemToNumberConverter();
                break;

            case FieldType.DECIMAL:
                bind.Converter = new ListItemToDecimalConverter();
                break;

            default:
                throw new NotImplementedException();
            }
            FrameworkElementFactory fef = new FrameworkElementFactory(uiType);

            if (uiType.Name.Equals("TextBlock"))
            {
                fef.SetBinding(TextBlock.TextProperty, bind);
            }
            else if (uiType.Name.Equals("Image"))
            {
                //TODO
                fef.SetBinding(CImage.SourceProperty, bind);
                fef.SetValue(CImage.MaxHeightProperty, (fti.Metadata as ImageMetadata).MaxHeight);
            }
            else
            {
                throw new NotImplementedException();
            }
            DataTemplate dataTemp = new DataTemplate();

            dataTemp.VisualTree = fef;
            dataTemp.DataType   = typeof(DataGridTemplateColumn);
            dgc.CellTemplate    = dataTemp;
            dgc.Header          = fieldName;
            dgc.CanUserSort     = true;
            dgc.SortMemberPath  = fieldName;

            return(dgc);
        }
Example #7
0
 /// <summary>
 /// Adds a field to this item based on a template
 /// </summary>
 /// <param name="fieldName">The field name to use</param>
 /// <param name="fti">the template to use to construct the item</param>
 internal void AddField(string fieldName, FieldTemplateItem fti)
 {
     //create and add a field based on the type of item
     fields.Add(fieldName, CreateField(fti.Type));
 }