Ejemplo n.º 1
0
        /// <summary>
        /// Creates and adds the required GUI elements
        /// </summary>
        private void CreateGUI()
        {
            // Create the add button
            AddButton = ControlsFactory.CreateStandardAddCircularButton();

            AddButton.Command = new RelayCommand(async() =>
            {
                // Disable the button
                AddButton.IsEnabled = false;

                // Create a steps presenter
                var stepsPresenter = new StepsPresenter()
                {
                    AllowArbitraryNavigation = false
                };

                // Create a columns container
                var propertiesContainer = new UniformGridCollapsibleVerticalMenuCategorizingItemsControl <PropertyInfo, InformationalButton>()
                {
                    Columns            = 3,
                    CategoryNameGetter = (prop) => prop.DeclaringType.Name.Split("-").Last()
                };

                propertiesContainer.Linker = (prop) => new InformationalButton()
                {
                    MinWidth = 0,
                    Text     = prop.Name,
                    Command  = new RelayCommand(() =>
                    {
                        foreach (var element in propertiesContainer.Elements)
                        {
                            element.Selected = false;
                        }

                        propertiesContainer.GetElement(prop).Selected = true;
                    })
                };

                // Add the tables
                propertiesContainer.SetItemsSource(QueryMap.DataModelTypes.SelectMany(x => x.GetProperties().Where(y => !DataPresenter.Items.Any(z => z.PropertyInfo == y))).OrderBy(x => x.Name));

                // Add it to the steps presenter
                stepsPresenter.Add("Property", propertiesContainer, (element) => element.Elements.Any(x => x.Selected));

                // Create the form
                var form = new DataForm <PropertyMap>()
                {
                    Mapper = CeidDiplomatikiDataModelHelpers.PropertyMapMapper.Value
                }
                .ShowInput(x => x.Name, settings => settings.IsRequired = true)
                .ShowInput(x => x.Description)
                .ShowStringColorInput(x => x.Color)
                .ShowSelectMultipleOptionsInput(x => x.Attributes, (form, propertyInfo) => new DropDownMenuOptionsFormInput <ColumnAttribute>(form, propertyInfo, ColumnAttributes.Data.Value, x => x.Name), null, settings => settings.IsRequired = true)
                .ShowNumericInput(x => x.Order)
                .ShowInput(x => x.DefaultValue)
                .ShowInput(x => x.IsEditable)
                .ShowInput(x => x.IsRequired)
                .ShowInput(x => x.IsPreview);

                // Add it to the steps presenter
                stepsPresenter.Add("Info", form, (element) => element.Validate());

                // Show a dialog
                var dialogResult = await DialogHelpers.ShowStepsDialogAsync(this, "Property map creation", null, stepsPresenter, IconPaths.TableColumnPath);

                // If we didn't get positive feedback...
                if (!dialogResult.Feedback)
                {
                    // Re enable the button
                    AddButton.IsEnabled = true;

                    // Return
                    return;
                }

                // Get the selected property
                var property = propertiesContainer.Get(propertiesContainer.Elements.First(x => x.Selected));

                // Create the model
                var model = new PropertyMap(QueryMap, property.DeclaringType, property, QueryMap.GetColumnOrNull(property));

                // Set it to the form
                form.Model = model;

                // Update its values
                form.UpdateModelValues();

                // Get the manager
                var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager;

                // Register the model
                QueryMap.Add(model);

                // Save the changes
                var result = await manager.SaveChangesAsync();

                // If there was an error...
                if (!result.Successful)
                {
                    // Show the error
                    await result.ShowDialogAsync(this);

                    // Re enable the button
                    AddButton.IsEnabled = true;

                    // Return
                    return;
                }

                // Add it to the presenter
                DataPresenter.Add(model);

                // Re enable the button
                AddButton.IsEnabled = true;
            });

            // Add it to the content grid
            ContentGrid.Children.Add(AddButton);
        }