private void SelectObjectProperty(object sender, ObjectProperty valueProperty) { var propertiesForm = new PropertiesForm(); propertiesForm.ParentProperty = PropertiesView.FocusedColumn.FieldName; propertiesForm.SetPropertyEditors(_repository.Editors); propertiesForm.SetSimpleProperties(valueProperty.SimpleProperties); propertiesForm.SetCollectionProperties(valueProperty.CollectionProperties); propertiesForm.SetValidationRules(valueProperty.ValidationRules); if (propertiesForm.ShowDialog() == DialogResult.OK) { //долбаный грид заворачивает объект в строку при создании DataRow dynamic instance = PropertiesView.GetFocusedValue().ToString().ToDynamic(); DesignerExtensions.SetSimplePropertiesToInstance(valueProperty.SimpleProperties, instance); DesignerExtensions.SetCollectionPropertiesToInstance(valueProperty.CollectionProperties, instance); ((ButtonEdit)sender).EditValue = instance.ToString(); ((ButtonEdit)sender).Refresh(); } else { propertiesForm.RevertChanges(); } }
private void CustomizeColumns(CollectionProperty collectionProperty) { PropertiesView.Columns.Clear(); foreach (var property in collectionProperty.Properties) { var column = new GridColumn(); column.FieldName = property.Key; var objectProperty = property.Value as ObjectProperty; if (objectProperty != null) { column.ColumnEdit = DesignerExtensions.CreateRepositoryItem(repositoryItemButtonEdit_ButtonClick); } else { var innerCollectionProperty = property.Value as CollectionProperty; if (innerCollectionProperty != null) { column.ColumnEdit = DesignerExtensions.CreateRepositoryItem(repositoryItemButtonEdit_ButtonClick); } else { column.ColumnEdit = _repository.GetRepositoryItem(property.Key, property.Value) ?? (!string.IsNullOrEmpty(PropertyName) ? _repository.GetRepositoryItem(PropertyName + "." + property.Key, property.Value) : null); } } column.Visible = true; PropertiesView.Columns.Add(column); } }
private void repositoryItemButtonEdit_ButtonClick(object sender, ButtonPressedEventArgs e) { if (e.Button.Kind == ButtonPredefines.Delete) { ((BaseEdit)sender).EditValue = new DynamicWrapper().ToString(); } else if (e.Button.Kind == ButtonPredefines.Glyph) { var value = ((BaseEdit)sender).EditValue; var form = new ValueEdit(); form.Value = value != null?value.ToString() : string.Empty; form.ShowDialog(); } else if (e.Button.Kind == ButtonPredefines.Ellipsis) { var instance = _dataSource.ToArray()[PropertiesView.FocusedRowHandle]; CollectionProperty property = _rows[instance]; //если разбираем свойство являющееся объектом var valueProperty = property.Properties[PropertiesView.FocusedColumn.FieldName] as ObjectProperty; dynamic propertyValue = null; try { propertyValue = DynamicWrapperExtensions.ToDynamic( (string) ObjectHelper.GetProperty(instance, PropertiesView.FocusedColumn.FieldName).ToString()); DesignerExtensions.SetSimplePropertiesFromInstance(valueProperty.SimpleProperties, propertyValue); DesignerExtensions.SetCollectionPropertiesFromInstance(valueProperty.CollectionProperties, propertyValue); } catch (Exception) { propertyValue = DynamicWrapperExtensions.ToDynamicList( (string) ObjectHelper.GetProperty(instance, PropertiesView.FocusedColumn.FieldName).ToString()); } if (valueProperty != null) { SelectObjectProperty(sender, valueProperty); } var collectionProperty = property.Properties[PropertiesView.FocusedColumn.FieldName] as CollectionProperty; if (collectionProperty != null) { SelectCollectionProperty(sender, collectionProperty); } } }
private void repositoryItemButtonEdit_ButtonClick(object sender, ButtonPressedEventArgs e) { if (e.Button.Kind == ButtonPredefines.Delete) { ((BaseEdit)sender).EditValue = new DynamicWrapper(); } else if (e.Button.Kind == ButtonPredefines.Glyph && e.Button.Tag == null) { var value = ((BaseEdit)sender).EditValue; var form = new ValueEdit(); form.ReadOnly = true; form.Value = value != null?value.ToString() : string.Empty; form.ShowDialog(); } else if (e.Button.Kind == ButtonPredefines.Ellipsis) { var properties = (ObjectProperty)((RepositoryItemButtonEdit)((ButtonEdit)sender).Tag).Tag; var propertiesForm = new PropertiesForm(); DesignerExtensions.SetSimplePropertiesFromInstance(properties.SimpleProperties, properties.Value); DesignerExtensions.SetCollectionPropertiesFromInstance(properties.CollectionProperties, properties.Value); propertiesForm.ParentProperty = SimplePropertiesGrid.FocusedRow.Name; propertiesForm.SetValidationRules(properties.ValidationRules); propertiesForm.SetPropertyEditors(_repository.Editors); propertiesForm.SetSimpleProperties(properties.SimpleProperties); propertiesForm.SetCollectionProperties(properties.CollectionProperties); if (propertiesForm.ShowDialog() == DialogResult.OK) { dynamic instance = ((ButtonEdit)sender).EditValue; DesignerExtensions.SetSimplePropertiesToInstance(properties.SimpleProperties, instance); DesignerExtensions.SetCollectionPropertiesToInstance(properties.CollectionProperties, instance); ((ButtonEdit)sender).Refresh(); } else { propertiesForm.RevertChanges(); } } }
public void SetSimpleProperties(Dictionary <string, IControlProperty> properties) { _simpleProperties = properties; _snapshotSimpleProperties.Clear(); SimplePropertiesGrid.Rows.Clear(); SimplePropertiesGrid.RowHeaderWidth = 300; SimplePropertiesGrid.RecordWidth = 350; foreach (var property in properties) { var editorRow = new EditorRow(); editorRow.Properties.Caption = property.Key; editorRow.Name = property.Key; var propertyObjectValue = property.Value as ObjectProperty; if (propertyObjectValue != null) { editorRow.Properties.RowEdit = DesignerExtensions.CreateRepositoryItem(repositoryItemButtonEdit_ButtonClick); editorRow.Properties.RowEdit.Tag = propertyObjectValue; editorRow.Properties.Value = propertyObjectValue.Value; _snapshotSimpleProperties.Add(property.Key, propertyObjectValue.Value); } else { editorRow.Properties.RowEdit = _repository.GetRepositoryItem(property.Key, property.Value) ?? (!string.IsNullOrEmpty(ParentProperty) ? _repository.GetRepositoryItem( ParentProperty + "." + property.Key, property.Value) : null); editorRow.Properties.Value = property.Value.Value; _snapshotSimpleProperties.Add(property.Key, property.Value.Value); } SimplePropertiesGrid.Rows.Add(editorRow); } }