Example #1
0
        public static string ModelPropertyList(object obj, string lineDelimeter, string[] includes, string[] excludes)
        {
            Type t     = obj.GetType();
            var  props = t.GetProperties();
            var  sb    = new StringBuilder();

            foreach (var p in props)
            {
                if (excludes != null && Array.Exists(excludes, element => element == p.Name))
                {
                    continue;
                }
                if (includes != null && !Array.Exists(includes, element => element == p.Name))
                {
                    continue;
                }
                JIgnore ignoreAttr = AttrHelper.GetAttribute <JIgnore>(t, p.Name);
                if (ignoreAttr != null)
                {
                    continue;
                }
                string desc = GetPropertyJDescriptionOrName(p);
                object v    = Dm.Instance.GetCustomPropertyValue(obj, p.Name, true, -1, -1);
                if (v != null)
                {
                    sb.Append(desc + ": " + v);
                    if (lineDelimeter != null)
                    {
                        sb.Append(lineDelimeter);
                    }
                    sb.AppendLine();
                }
            }
            return(sb.ToString());
        }
        private void ListView_FormatCell(object sender, FormatCellEventArgs e)
        {
            object item = e.Model;

            if (item != null)
            {
                PropertyInfo p = item.GetType().GetProperty("IsArchived");
                if (p != null && p.PropertyType == typeof(bool) && (bool)(p.GetValue(item)) == true)
                {
                    e.SubItem.ForeColor = Color.Gray;
                }
                else
                {
                    if (e.Column.AspectName == null)
                    {
                        return;
                    }
                    Type         pType       = AttrHelper.GetPropertyType(SourceObjectType, e.Column.AspectName);
                    PropertyInfo propInfo    = SourceObjectType.GetProperty(e.Column.AspectName);
                    JExpired     expiredProp = AttrHelper.GetAttribute <JExpired>(propInfo);
                    if (expiredProp != null)
                    {
                        object propValue = null;
                        if (expiredProp.ExpiredProperty != null)
                        {
                            PropertyInfo propInfo1 = SourceObjectType.GetProperty(expiredProp.ExpiredProperty);
                            if (propInfo1 != null)
                            {
                                propValue = AttrHelper.GetPropertyValue(e.Model, propInfo1);
                            }
                        }
                        else
                        {
                            propValue = AttrHelper.GetPropertyValue(e.Model, propInfo);
                        }
                        if (propValue != null)
                        {
                            ModelHelper.ExpiredToColor(propValue.ToString(), e.SubItem.ForeColor);
                        }
                    }
                    else
                    {
                        JDictProp dictProp = AttrHelper.GetAttribute <JDictProp>(propInfo);
                        if (dictProp != null &&
                            (dictProp.DictPropertyStyle == DisplyPropertyStyle.ColoredTextOnly || dictProp.DictPropertyStyle == DisplyPropertyStyle.ColoredTextAndImage))
                        {
                            object propValue = AttrHelper.GetPropertyValue(e.Model, propInfo);
                            if (propValue != null)
                            {
                                JDictItem ditem = Dm.Instance.GetDictText(dictProp.Id, propValue.ToString());
                                if (ditem != null && ditem.TextColor != null && ditem.TextColor != Color.Black)
                                {
                                    e.SubItem.ForeColor = ditem.TextColor;
                                }
                            }
                        }
                    }
                }
            }
        }
Example #3
0
 static protected bool IsForeignKey(PropertyInfo p)
 {
     if (AttrHelper.GetAttribute <JManyToOne>(p) != null ||
         AttrHelper.GetAttribute <JOneToOne>(p) != null)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #4
0
 static protected bool IsNecessary(PropertyInfo p)
 {
     if (AttrHelper.GetAttribute <JManyToOne>(p) != null ||
         AttrHelper.GetAttribute <JOneToOne>(p) != null ||
         AttrHelper.GetAttribute <JPrimaryKey>(p) != null)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #5
0
        static public bool IsTextColoredFieldPresent(Type t)
        {
            var pl = AttrHelper.GetPropertiesWithAttribute <JDictProp>(t);

            foreach (var p in pl)
            {
                JDictProp d = AttrHelper.GetAttribute <JDictProp>(p);
                if (d.DictPropertyStyle == DisplyPropertyStyle.ColoredTextOnly || d.DictPropertyStyle == DisplyPropertyStyle.ColoredTextAndImage)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #6
0
 static protected bool IsIgnore(PropertyInfo p)
 {
     if (AttrHelper.GetAttribute <JIgnore>(p) != null ||
         AttrHelper.GetAttribute <JsonIgnoreAttribute>(p) != null ||
         AttrHelper.GetAttribute <JManyToMany>(p) != null ||
         AttrHelper.GetAttribute <JOneToMany>(p) != null
         )
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #7
0
        override protected void MakeListColumns()
        {
            JModelOVLGenerator.Instance = new JModelOVLGenerator();
            JModelOVLGenerator.GenerateColumns(this.listView, SourceObjectType, true);
            foreach (var column in this.listView.AllColumns)
            {
                JHeaderImage headerImageAttr = AttrHelper.GetAttribute <JHeaderImage>(SourceObjectType, column.AspectName);
                PropertyInfo propInfo        = AttrHelper.GetProperty(SourceObjectType, column.AspectName);
                Type         pType           = propInfo.PropertyType;
                if (pType == typeof(bool))
                {
                    column.CheckBoxes     = true;
                    column.HeaderCheckBox = true;// -not SubItemChecking, but only HeaderCheckBoxChanging
                }
                if (AttrHelper.GetAttribute <JUrl>(propInfo) != null)
                {
                    column.Hyperlink = true;
                }
                column.Text = ModelHelper.GetPropertyJDescriptionOrName(propInfo);
                if (headerImageAttr != null && headerImageAttr.HeaderImageName != null)
                {
                    this.CreateColumHeaderImage(column, headerImageAttr.HeaderImageName);
                    column.ShowTextInHeader = false;
                }
                if (AttrHelper.GetAttribute <JReadOnly>(SourceObjectType, column.AspectName) != null)
                {
                    column.IsEditable = false;
                }
                if (AppManager.Instance.IsCustomEditProperty(SourceObjectType, column.AspectName))
                {
                    column.AspectGetter = delegate(Object rowObject)
                    {
                        try
                        {
                            if (AppManager.Instance.IsOnlyImageColumnProperty(SourceObjectType, column.AspectName))
                            {
                                return(null);
                            }
                            else
                            {
                                return(Dm.Instance.GetCustomPropertyValue(rowObject, column.AspectName, true,
                                                                          AppManager.Instance.ListCellTruncatedMaxItemCount, AppManager.Instance.ListCellTruncatedMaxLength));
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.LogError(ex);
                            return(ex.ToString());
                        }
                    };
                    CreateImageGetterDelegate(column, SourceObjectType);
                }
            }
            if (ModelHelper.IsIsArchiveFieldPresent(SourceObjectType))
            {
                isActiveCheckBox.Text               = FrwCRUDRes.Active;
                isActiveCheckBox.Checked            = true;
                isActiveCheckBox.CheckStateChanged += (s, ex) => { listView.UpdateColumnFiltering(); };
                AddToolStripItem(new ToolStripControlHost(isActiveCheckBox));

                listView.AdditionalFilter = new ModelFilter(delegate(object x)
                {
                    return(isActiveCheckBox.Checked ? !ModelHelper.GetIsArchiveValue(x) : true);
                });
            }
        }
Example #8
0
        override public void ProcessView()
        {
            if (SourceObjectType != null)
            {
                string descr = ModelHelper.GetEntityJDescriptionOrName(SourceObjectType);
                SetNewCaption(descr + " " + FrwCRUDRes.SimplePropertyWindow_Props);
            }
            if (tempSourceObject != null)
            {
                if (tempSourceObject.GetType().Equals(SourceObjectType) == false)
                {
                    throw new ArgumentException("SourceObject not of SourceObjectType");
                }

                bag1                  = new PropertyBag();
                bag1.GetValue        += new PropertySpecEventHandler(this.bag1_GetValue);
                bag1.SetValue        += new PropertySpecEventHandler(this.bag1_SetValue);
                bag1.ValueModified   += Bag1_ValueModified;
                bag1.SourceObject     = tempSourceObject;
                bag1.SourceObjectType = SourceObjectType;

                PropertyInfo[] propsList = AttrHelper.GetBasePropertiesFirst(tempSourceObject.GetType());
                PropertyInfo   pName     = AttrHelper.GetProperty <JNameProperty>(tempSourceObject.GetType());
                if (pName != null)
                {
                    propsList = propsList.OrderBy(x => x != pName).ToArray();
                }

                PropertySpec props = null;
                foreach (PropertyInfo p in propsList)
                {
                    if (AttrHelper.IsGenericListTypeOf(p.PropertyType, typeof(IField)))
                    {
                        IList itemDatas = (IList)p.GetValue(tempSourceObject);
                        if (itemDatas != null)
                        {
                            foreach (var it in itemDatas)
                            {
                                IField itemdata = (IField)it;
                                string group    = null;

                                props = new PropertySpec(ITEM_ATTRIBUTE_PREFIX + itemdata.FieldSysname, typeof(string), group,
                                                         itemdata.Name);
                                props.PropTag = itemdata;
                                if (viewMode == ViewMode.View || viewMode == ViewMode.ViewContent)
                                {
                                    props.Attributes = new Attribute[] { new ReadOnlyAttribute(true) };
                                }
                                bag1.Properties.Add(props);
                            }
                        }
                    }
                    else
                    {
                        JReadOnly readOnlyAttr = AttrHelper.GetAttribute <JReadOnly>(SourceObjectType, p.Name);
                        JIgnore   ignoreAttr   = AttrHelper.GetAttribute <JIgnore>(SourceObjectType, p.Name);

                        if (ignoreAttr != null)
                        {
                            continue;
                        }

                        string desc         = ModelHelper.GetPropertyJDescriptionOrName(p);
                        bool   isCustomEdit = false;
                        if (AppManager.Instance.IsCustomEditProperty(SourceObjectType, p.Name))
                        {
                            isCustomEdit = true;
                        }
                        Type pType = null;
                        if (isCustomEdit)
                        {
                            pType = typeof(string);              //disabled comboboxes for list type fields
                        }
                        else
                        {
                            pType = p.PropertyType;
                        }
                        props         = new PropertySpec(desc, pType, null, desc);
                        props.PropTag = p.Name;
                        if (readOnlyAttr != null || viewMode == ViewMode.View || viewMode == ViewMode.ViewContent)
                        {
                            props.Attributes = new Attribute[] { new ReadOnlyAttribute(true) };
                        }
                        if (isCustomEdit)
                        {
                            //not only for edit
                            props.EditorTypeName = typeof(CustomPropertyEditor).ToString();
                        }

                        bag1.Properties.Add(props);
                    }

                    this.propertyGrid1.SelectedObjects = new object[] { bag1 };
                }
            }
            else
            {
                this.propertyGrid1.SelectedObjects = null;
            }
        }
Example #9
0
        public SimpleTreeListWindow()
        {
            InitializeComponent();
            treeControl.LabelEdit = true;
            //treeControl.ChangeNodeImageOnExpand = true;
            treeControl.AllowDrop        = true;
            treeControl.ShowNodeToolTips = true;

            treeControl.OnTreeNodeSelectEvent += TreeControl_OnTreeNodeSelectEvent;

            this.treeControl.CanExpandGetter += delegate(TreeNode parentNode)
            {
                if (parentNode == null)
                {
                    return(true);
                }
                object x = parentNode.Tag;
                if (x == null)
                {
                    return(false);
                }
                if (x is string)
                {
                    return(true);            //folder
                }
                Type type = x.GetType();
                if (x is RootGroupTreeFolder)
                {
                    Type etype = (x as RootGroupTreeFolder).EntityType;
                    if (ModelHelper.IsSingleHierEntity(etype))
                    {
                        return(Dm.Instance.FindRootList(etype).Count > 0);
                    }
                    else
                    {
                        return(Dm.Instance.FindAll(etype).Count > 0);
                    }
                }
                else if (x is BranchGroupTreeFolder)
                {
                    BranchGroupTreeFolder bf = (x as BranchGroupTreeFolder);
                    if (AttrHelper.GetAttribute <JManyToMany>(bf.RefEntityInfo.foreinProperty) != null)
                    {
                        return(Dm.Instance.ResolveManyToManyRelation(bf.ParentObject, bf.RefEntityInfo.RefEntity).Count > 0);
                    }
                    else if (AttrHelper.GetAttribute <JManyToOne>(bf.RefEntityInfo.foreinProperty) != null)
                    {
                        return(Dm.Instance.ResolveOneToManyRelation(bf.ParentObject, bf.RefEntityInfo.RefEntity,
                                                                    bf.RefEntityInfo.foreinProperty.Name).Count > 0);
                    }
                    else if (AttrHelper.GetAttribute <JOneToOne>(bf.RefEntityInfo.foreinProperty) != null)
                    {
                        return(Dm.Instance.ResolveOneToOneRelation(bf.ParentObject, bf.RefEntityInfo.RefEntity,
                                                                   bf.RefEntityInfo.foreinProperty.Name) != null);
                    }
                }
                else
                {
                    JEntity entityAttr = x.GetType().GetCustomAttribute <JEntity>();
                    if (entityAttr != null)
                    {
                        if (showGroupsFolder)
                        {
                            List <RefEntityInfo> rels = Dm.Instance.GetAllReferencedToEntity(x, false);
                            return(rels.Count(s => (s.foreinProperty != null)) > 0);

                            /*
                             * foreach (var rt in rels)
                             * {
                             *  HashSet<object> refs = rt.Records;
                             *  if (refs.Count > 0)
                             *  {
                             *      return true;
                             *  }
                             * }
                             */
                        }
                        else
                        {
                            //find all ManyToOne relations rels to this entity type
                            List <RefEntityInfo> rels = Dm.Instance.GetAllReferencedToEntity(x);
                            foreach (var rt in rels)
                            {
                                HashSet <object> refs = rt.Records;
                                if (refs.Count > 0)
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
                return(false);
            };
            treeControl.ChildrenGetter += delegate(TreeNode parentNode)
            {
                IList lo = new List <object>();
                if (parentNode == null)
                {
                    //root
                    foreach (var e in rootEntites)
                    {
                        RootGroupTreeFolder ef = new RootGroupTreeFolder();
                        ef.EntityType = e;
                        lo.Add(ef);
                    }
                }
                else
                {
                    object x = parentNode.Tag;
                    if (x == null)
                    {
                        return(new List <object>());
                    }
                    if (x is RootGroupTreeFolder)
                    {
                        Type type = (x as RootGroupTreeFolder).EntityType;
                        if (ModelHelper.IsSingleHierEntity(type))
                        {
                            return(Dm.Instance.FindRootList(type));
                        }
                        else
                        {
                            return(Dm.Instance.FindAll(type));
                        }
                    }
                    else if (x is BranchGroupTreeFolder)
                    {
                        BranchGroupTreeFolder bf = (x as BranchGroupTreeFolder);
                        if (AttrHelper.GetAttribute <JManyToMany>(bf.RefEntityInfo.foreinProperty) != null)
                        {
                            return(Dm.Instance.ResolveManyToManyRelation(bf.ParentObject, bf.RefEntityInfo.RefEntity));
                        }
                        else if (AttrHelper.GetAttribute <JManyToOne>(bf.RefEntityInfo.foreinProperty) != null)
                        {
                            return(Dm.Instance.ResolveOneToManyRelation(bf.ParentObject, bf.RefEntityInfo.RefEntity,
                                                                        bf.RefEntityInfo.foreinProperty.Name));
                        }
                        else if (AttrHelper.GetAttribute <JOneToOne>(bf.RefEntityInfo.foreinProperty) != null)
                        {
                            lo.Add(Dm.Instance.ResolveOneToOneRelation(bf.ParentObject, bf.RefEntityInfo.RefEntity,
                                                                       bf.RefEntityInfo.foreinProperty.Name));
                        }
                    }
                    else
                    {
                        bool    isSingleHierEntity = ModelHelper.IsSingleHierEntity(x.GetType());
                        JEntity entityAttr         = x.GetType().GetCustomAttribute <JEntity>();
                        if (entityAttr != null)
                        {
                            if (showGroupsFolder)
                            {
                                //List<RefEntityInfo> rels = Dm.Instance.GetAllReferencedToEntity(x, false);
                                List <RefEntityInfo> rels = Dm.Instance.GetAllReferencedToEntity(x);
                                foreach (var rt in rels)
                                {
                                    if (rt.foreinProperty != null)
                                    {
                                        if (rt.IsSelfRelation() && isSingleHierEntity)
                                        {
                                            //IList lll = Dm.Instance.ResolveOneToManyRelation(x, rt.RefEntity,
                                            //   rt.foreinProperty.Name);
                                            //foreach (var l1 in lll)
                                            //  lo.Add(l1);
                                            foreach (var l1 in rt.Records)
                                            {
                                                lo.Add(l1);
                                            }
                                        }
                                        else
                                        {
                                            if (rt.Records.Count > 0)
                                            {
                                                BranchGroupTreeFolder bf = new BranchGroupTreeFolder();
                                                bf.ParentObject  = x;
                                                bf.RefEntityInfo = rt;
                                                lo.Add(bf);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                List <RefEntityInfo> rels = Dm.Instance.GetAllReferencedToEntity(x);

                                foreach (var rt in rels)
                                {
                                    HashSet <object> refs = rt.Records;
                                    if (refs.Count > 0)
                                    {
                                        foreach (var l in refs)
                                        {
                                            lo.Add(l);
                                        }
                                    }
                                }
                            }
                        }
                        return(lo);
                    }
                }
                return(lo);
            };
            treeControl.AfterEditTreeNodeLabel += delegate(object model, string labelText)
            {
                if (model == null)
                {
                    return(false);
                }
                Type    t          = model.GetType();
                JEntity entityAttr = t.GetCustomAttribute <JEntity>();
                if (entityAttr != null)
                {
                    PropertyInfo pName = AttrHelper.GetProperty <JNameProperty>(t);
                    if (pName != null)
                    {
                        object oldValue = pName.GetValue(model);
                        try
                        {
                            pName.SetValue(model, labelText);//force exception if no set method
                            Dm.Instance.SaveObject(model);
                            return(true);
                        }
                        catch (JValidationException ex)
                        {
                            AppManager.ShowValidationErrorMessage(ex.ValidationResult);
                            pName.SetValue(model, oldValue);
                        }
                    }
                }
                return(false);
            };
        }
Example #10
0
 protected static bool IsMarkedNotNull(PropertyInfo p)
 {
     return(AttrHelper.GetAttribute <JRequired>(p) != null);
 }
Example #11
0
 protected static bool IsAutoInc(PropertyInfo p)
 {
     return(AttrHelper.GetAttribute <JAutoIncrement>(p) != null);
 }
Example #12
0
 protected static bool IsPK(PropertyInfo p)
 {
     return(AttrHelper.GetAttribute <JPrimaryKey>(p) != null);
 }
 private void ListView_CellEditStarting(object sender, CellEditEventArgs e)
 {
     try
     {
         OLVColumn column    = e.Column;
         object    rowObject = e.RowObject;
         //object value = e.Value;
         JReadOnly readOnlyAttr = AttrHelper.GetAttribute <JReadOnly>(SourceObjectType, column.AspectName);
         if (readOnlyAttr != null)
         {
             DialogResult res = MessageBox.Show(null, FrwCRUDRes.This_field_is_readonly,
                                                FrwCRUDRes.WARNING, MessageBoxButtons.OK, MessageBoxIcon.Warning);
             e.Cancel = true;
             return;
         }
         if (AppManager.Instance.IsCustomEditProperty(SourceObjectType, column.AspectName))
         {
             /* This code was needed to provide a call for heavy dialogue (HTML editing) from a list cell. So far, we manage without him.
              *  if (AttrHelper.GetAttribute<JText>(SourceObjectType, column.AspectName) != null)
              *  {
              *      // it is necessary to use a complex scheme, otherwise it cycles through the MouseUp event
              *      Button b = new Button();
              *      b.Image = Properties.Resources.book_open;
              *      b.Bounds = e.CellBounds;
              *      b.Font = ((ObjectListView)sender).Font;
              *      b.Click += (s1, e1) =>
              *      {
              *          bool complated = false;
              *          e.NewValue = AppManager.Instance.ProcessEditCustomPropertyValueAndSave(rowObject, column.AspectName, out complated, this);
              *          if (complated)
              *          {
              *              RefreshObject(rowObject);
              *              b.Text = e.NewValue as string;
              *          }
              *          else
              *          {
              *              RefreshObject(rowObject);
              *              //it is necessary to use even if not complated
              *              b.Text = e.NewValue as string;
              *          }
              *          b.Dispose();
              *      };
              *      e.Control = b;
              *      e.Cancel = false;
              *  }
              *  else
              *  {*/
             bool complated = false;
             e.NewValue = AppManager.Instance.ProcessEditCustomPropertyValueAndSave(rowObject, column.AspectName, out complated, this);
             if (complated)
             {
                 RefreshObject(rowObject);
             }
             e.Cancel = true;
             //}
         }
         else
         {
             e.Cancel = false;
         }
     }
     catch (Exception ex)
     {
         Log.ShowError(ex);
         e.Cancel = true;
     }
 }
        // create a typical handler for the image
        protected bool CreateImageGetterDelegate(OLVColumn column, Type sourceObjectType)
        {
            Type pType = AttrHelper.GetPropertyType(sourceObjectType, column.AspectName);
            // the code for the case of the dictionary is implemented
            JImageName imageNameAttr = AttrHelper.GetAttribute <JImageName>(SourceObjectType, column.AspectName);
            JImageRef  imageRefAttr  = AttrHelper.GetAttribute <JImageRef>(SourceObjectType, column.AspectName);
            JDictProp  dictAttr      = AttrHelper.GetAttribute <JDictProp>(SourceObjectType, column.AspectName);

            if (dictAttr != null && dictAttr.DictPropertyStyle != DisplyPropertyStyle.TextOnly &&
                dictAttr.AllowMultiValues == false) //todo
            {
                column.ImageGetter = delegate(object x)
                {
                    if (dictAttr.AllowMultiValues)
                    {
                        return(null);
                    }
                    object value = AttrHelper.GetPropertyValue(x, column.AspectName);
                    if (value == null)
                    {
                        return(null);
                    }
                    JDictItem item = Dm.Instance.GetDictText(dictAttr.Id, value.ToString());
                    if (item == null)
                    {
                        return(null);
                    }
                    Image smallImage = AddImageToImageList(this.listView, item.Image, null);
                    if (smallImage != null && item.Image == null)
                    {
                        item.Image = smallImage;
                    }
                    return(smallImage);
                };
                return(true);
            }
            else if (imageNameAttr != null && imageNameAttr.DictPropertyStyle != DisplyPropertyStyle.TextOnly)
            {
                column.ImageGetter = delegate(object x)
                {
                    object value = AttrHelper.GetPropertyValue(x, column.AspectName);
                    if (value == null)
                    {
                        return(null);
                    }
                    Image smallImage = AddImageToImageList(this.listView, null, value.ToString());
                    //if (smallImage != null && item.Image == null) item.Image = smallImage;
                    return(smallImage);
                };
                return(true);
            }
            else if (imageRefAttr != null && imageRefAttr.DictPropertyStyle != DisplyPropertyStyle.TextOnly)
            {
                column.ImageGetter = delegate(object x)
                {
                    object value = AttrHelper.GetPropertyValue(x, column.AspectName);
                    if (value == null)
                    {
                        return(null);
                    }
                    PropertyInfo propInfo      = x.GetType().GetProperty(column.AspectName);
                    PropertyInfo imagePropInfo = AttrHelper.GetPropertiesWithAttribute <JImageName>(propInfo.PropertyType).FirstOrDefault <PropertyInfo>();
                    if (imagePropInfo == null)
                    {
                        return(null);
                    }
                    value = imagePropInfo.GetValue(value);
                    if (value == null)
                    {
                        return(null);
                    }

                    AttrHelper.GetProperty <JImageName>(propInfo.PropertyType);
                    Image smallImage = AddImageToImageList(this.listView, null, value.ToString());
                    //if (smallImage != null && item.Image == null) item.Image = smallImage;
                    return(smallImage);
                };
                return(true);
            }
            else if (pType == typeof(JAttachment) || AttrHelper.IsGenericListTypeOf(pType, typeof(JAttachment)) ||
                     AttrHelper.GetAttribute <JText>(sourceObjectType, column.AspectName) != null)
            {
                column.ImageGetter = delegate(object x)
                {
                    object v = AttrHelper.GetPropertyValue(x, column.AspectName);
                    if (v != null)
                    {
                        Image smallImage = null;
                        if (AttrHelper.GetAttribute <JText>(sourceObjectType, column.AspectName) != null)
                        {
                            if (string.IsNullOrEmpty(v as string) == false)
                            {
                                smallImage = (Image)Properties.Resources.book_open;
                            }
                        }
                        else if (pType == typeof(JAttachment) || AttrHelper.IsGenericListTypeOf(pType, typeof(JAttachment)))
                        {
                            smallImage = (Image)Properties.Resources.attachment;
                        }
                        return(smallImage);
                    }
                    else
                    {
                        return(null);
                    }
                };
                return(true);
            }
            return(false);
        }
        public SimpleTreeListWindow()
        {
            InitializeComponent();
            treeControl.LabelEdit = true;
            //treeControl.ChangeNodeImageOnExpand = true;
            treeControl.AllowDrop        = true;
            treeControl.ShowNodeToolTips = true;

            treeControl.OnTreeNodeSelectEvent += TreeControl_OnTreeNodeSelectEvent;

            this.treeControl.CanExpandGetter += delegate(TreeNode currentNode)
            {
                if (currentNode == null)
                {
                    return(true);
                }
                //currentNode may be not object node (may by branch node), so find real object node to view object
                TreeNode currentObjectNode = (currentNode.Tag is BranchGroupTreeFolder) ? currentNode.Parent : currentNode;
                TreeNode parentObjectNode  = (currentObjectNode != null && currentObjectNode.Parent != null)
                    ? ((currentObjectNode.Parent.Tag is BranchGroupTreeFolder) ? currentObjectNode.Parent.Parent : currentObjectNode.Parent) : null;

                object curentObject = (currentNode.Tag is TreeObjectWrap) ? (currentNode.Tag as TreeObjectWrap).Tag : currentNode.Tag;
                object parentObject = (parentObjectNode != null) ? ((parentObjectNode.Tag is TreeObjectWrap)? (parentObjectNode.Tag as TreeObjectWrap).Tag : parentObjectNode.Tag) : null;

                RefEntityInfo currentNodeRel = (currentObjectNode != null && currentObjectNode.Tag is TreeObjectWrap) ? (currentObjectNode.Tag as TreeObjectWrap).Rel : null;
                RefEntityInfo parentNodeRel  = (parentObjectNode != null && parentObjectNode.Tag is TreeObjectWrap) ? (parentObjectNode.Tag as TreeObjectWrap).Rel : null;

                if (curentObject == null)
                {
                    return(false);
                }
                if (curentObject is string)
                {
                    return(true);                       //folder
                }
                Type type = curentObject.GetType();
                if (curentObject is RootGroupTreeFolder)
                {
                    Type etype = (curentObject as RootGroupTreeFolder).EntityType;
                    if (ModelHelper.IsSingleHierEntity(etype))
                    {
                        return(Dm.Instance.FindRootList(etype).Count > 0);
                    }
                    else
                    {
                        return(Dm.Instance.FindAll(etype).Count > 0);
                    }
                }
                else if (curentObject is BranchGroupTreeFolder)
                {
                    BranchGroupTreeFolder bf = (curentObject as BranchGroupTreeFolder);
                    if (bf.RefEntityInfo.PropertyInForeign != null)
                    {
                        if (AttrHelper.GetAttribute <JManyToMany>(bf.RefEntityInfo.PropertyInForeign) != null)
                        {
                            return(Dm.Instance.ResolveManyToManyRelation(bf.ParentObject, bf.RefEntityInfo.ForeignEntity).Count > 0);
                        }
                        else if (AttrHelper.GetAttribute <JManyToOne>(bf.RefEntityInfo.PropertyInForeign) != null)
                        {
                            return(Dm.Instance.ResolveOneToManyRelation(bf.ParentObject, bf.RefEntityInfo.ForeignEntity,
                                                                        bf.RefEntityInfo.PropertyInForeign.Name).Count > 0);
                        }
                        else if (AttrHelper.GetAttribute <JOneToOne>(bf.RefEntityInfo.PropertyInForeign) != null)
                        {
                            return(Dm.Instance.ResolveOneToOneRelationReverse(bf.ParentObject, bf.RefEntityInfo.ForeignEntity,
                                                                              bf.RefEntityInfo.PropertyInForeign.Name) != null);
                        }
                    }
                    else if (bf.RefEntityInfo.PropertyInSource != null)
                    {
                        if (AttrHelper.GetAttribute <JManyToOne>(bf.RefEntityInfo.PropertyInSource) != null || AttrHelper.GetAttribute <JOneToOne>(bf.RefEntityInfo.PropertyInSource) != null)
                        {
                            object o = AttrHelper.GetPropertyValue(bf.ParentObject, bf.RefEntityInfo.PropertyInSource);
                            return(o != null);
                        }
                    }
                }
                else
                {
                    JEntity entityAttr = curentObject.GetType().GetCustomAttribute <JEntity>();
                    if (entityAttr != null)
                    {
                        //if (showGroupsFolder)
                        //{
                        //   List<RefEntityInfo> rels = Dm.Instance.GetAllReferencedToEntity(parentObject, false);
                        //   return rels.Count(s => (s.RefFromProperty != null || s.RefToProperty != null)) > 0;
                        //}
                        //else
                        //{
                        //find all ManyToOne relations rels to this entity type
                        List <RefEntityInfo> rels = Dm.Instance.GetAllReferencedToEntity(curentObject);
                        foreach (var rt in rels)
                        {
                            HashSet <object> refs = rt.Records;
                            if (refs.Count > 0)
                            {
                                return(true);
                            }
                        }
                        //}
                    }
                }
                return(false);
            };
            treeControl.ChildrenGetter += delegate(TreeNode currentNode)
            {
                IList lo = new List <object>();
                if (currentNode == null)
                {
                    //root
                    foreach (var e in rootEntites)
                    {
                        RootGroupTreeFolder ef = new RootGroupTreeFolder();
                        ef.EntityType = e;
                        lo.Add(ef);
                    }
                }
                else
                {
                    TreeNode currentObjectNode = (currentNode.Tag is BranchGroupTreeFolder) ? currentNode.Parent : currentNode;
                    TreeNode parentObjectNode  = (currentObjectNode != null && currentObjectNode.Parent != null)
                        ? ((currentObjectNode.Parent.Tag is BranchGroupTreeFolder) ? currentObjectNode.Parent.Parent : currentObjectNode.Parent) : null;

                    object currentObject = (currentNode.Tag is TreeObjectWrap) ? (currentNode.Tag as TreeObjectWrap).Tag : currentNode.Tag;
                    object parentObject  = (parentObjectNode != null) ? ((parentObjectNode.Tag is TreeObjectWrap) ? (parentObjectNode.Tag as TreeObjectWrap).Tag : parentObjectNode.Tag) : null;

                    RefEntityInfo currentNodeRel = (currentObjectNode != null && currentObjectNode.Tag is TreeObjectWrap) ?  (currentObjectNode.Tag as TreeObjectWrap).Rel : null;
                    RefEntityInfo parentNodeRel  = (parentObjectNode != null && parentObjectNode.Tag is TreeObjectWrap) ? (parentObjectNode.Tag as TreeObjectWrap).Rel : null;

                    if (currentObject == null)
                    {
                        return(new List <object>());
                    }
                    if (currentObject is RootGroupTreeFolder)
                    {
                        Type type = (currentObject as RootGroupTreeFolder).EntityType;
                        if (ModelHelper.IsSingleHierEntity(type))
                        {
                            return(WrapList(Dm.Instance.FindRootList(type), null));
                        }
                        else
                        {
                            return(WrapList(Dm.Instance.FindAll(type), null));
                        }
                    }
                    else if (currentObject is BranchGroupTreeFolder)
                    {
                        BranchGroupTreeFolder bf = (currentObject as BranchGroupTreeFolder);

                        if (savedTreeState.IsRelationVisible(bf.RefEntityInfo.SourceEntity, bf.RefEntityInfo.Name))
                        {
                            if (bf.RefEntityInfo.PropertyInForeign != null)
                            {
                                if (AttrHelper.GetAttribute <JManyToMany>(bf.RefEntityInfo.PropertyInForeign) != null)
                                {
                                    return(WrapList(Dm.Instance.ResolveManyToManyRelation(bf.ParentObject, bf.RefEntityInfo.ForeignEntity), bf.RefEntityInfo));
                                }
                                else if (AttrHelper.GetAttribute <JManyToOne>(bf.RefEntityInfo.PropertyInForeign) != null)
                                {
                                    return(WrapList(Dm.Instance.ResolveOneToManyRelation(bf.ParentObject, bf.RefEntityInfo.ForeignEntity,
                                                                                         bf.RefEntityInfo.PropertyInForeign.Name), bf.RefEntityInfo));
                                }
                                else if (AttrHelper.GetAttribute <JOneToOne>(bf.RefEntityInfo.PropertyInForeign) != null)
                                {
                                    lo.Add(new TreeObjectWrap()
                                    {
                                        Tag = Dm.Instance.ResolveOneToOneRelationReverse(bf.ParentObject, bf.RefEntityInfo.ForeignEntity,
                                                                                         bf.RefEntityInfo.PropertyInForeign.Name),
                                        Rel = bf.RefEntityInfo
                                    });
                                }
                            }
                            else if (bf.RefEntityInfo.PropertyInSource != null)
                            {
                                if (AttrHelper.GetAttribute <JManyToOne>(bf.RefEntityInfo.PropertyInSource) != null || AttrHelper.GetAttribute <JOneToOne>(bf.RefEntityInfo.PropertyInSource) != null)
                                {
                                    object o = AttrHelper.GetPropertyValue(bf.ParentObject, bf.RefEntityInfo.PropertyInSource);

                                    if (o != null)
                                    {
                                        if (parentObject != null && parentObject.Equals(o) &&
                                            currentNodeRel != null && currentNodeRel.PropertyInForeign != null && bf.RefEntityInfo.PropertyInSource != null &&
                                            currentNodeRel.PropertyInForeign == bf.RefEntityInfo.PropertyInSource)
                                        {
                                        }
                                        else
                                        {
                                            lo.Add(new TreeObjectWrap()
                                            {
                                                Tag = o, Rel = bf.RefEntityInfo
                                            });
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        bool    isSingleHierEntity = ModelHelper.IsSingleHierEntity(currentObject.GetType());
                        JEntity entityAttr         = currentObject.GetType().GetCustomAttribute <JEntity>();
                        if (entityAttr != null)
                        {
                            List <RefEntityInfo> rels = Dm.Instance.GetAllReferencedToEntity(currentObject);
                            foreach (var rt in rels)
                            {
                                if (savedTreeState.IsRelationVisible(rt.SourceEntity, rt.Name))
                                {
                                    bool isSelfRelation = rt.IsSelfRelation();
                                    if ((notShowGroupsFolderTypes.Contains(rt.ForeignEntity) == false && rt.PropertyInForeign != null) && !(isSelfRelation && isSingleHierEntity))
                                    {
                                        if (rt.Records.Count > 0)
                                        {
                                            BranchGroupTreeFolder bf = new BranchGroupTreeFolder();
                                            bf.ParentObject  = currentObject;
                                            bf.RefEntityInfo = rt;
                                            lo.Add(bf);
                                        }
                                    }
                                    else
                                    {
                                        foreach (var l in rt.Records)
                                        {
                                            if (!(parentObject != null && parentObject.Equals(l) &&
                                                  currentNodeRel != null && currentNodeRel.PropertyInForeign != null && rt.PropertyInSource != null &&
                                                  currentNodeRel.PropertyInForeign == rt.PropertyInSource))
                                            {
                                                lo.Add(new TreeObjectWrap()
                                                {
                                                    Tag = l, Rel = rt
                                                });
                                            }
                                        }
                                    }
                                }
                            }//foreach (var rt in rels)
                        }
                        return(lo);
                    }
                }
                return(lo);
            };
            treeControl.AfterEditTreeNodeLabel += delegate(object model, string labelText)
            {
                if (model == null)
                {
                    return(false);
                }
                Type    t          = model.GetType();
                JEntity entityAttr = t.GetCustomAttribute <JEntity>();
                if (entityAttr != null)
                {
                    PropertyInfo pName = AttrHelper.GetProperty <JNameProperty>(t);
                    if (pName != null)
                    {
                        object oldValue = pName.GetValue(model);
                        try
                        {
                            pName.SetValue(model, labelText);//force exception if no set method
                            Dm.Instance.SaveObject(model);
                            return(true);
                        }
                        catch (JValidationException ex)
                        {
                            AppManager.ShowValidationErrorMessage(ex.ValidationResult);
                            pName.SetValue(model, oldValue);
                        }
                    }
                }
                return(false);
            };
        }