Exemplo n.º 1
0
        private void ExecutedRemoveBlueprint(object sender, RoutedEventArgs e)
        {
            // Check if an item is selected.
            BlueprintViewModel selectedItem = this.SelectedItem;

            if (selectedItem == null)
            {
                return;
            }

            // Select other blueprint.
            var node = (TreeViewItem)this.TvTree.ItemContainerGenerator.ContainerFromIndex(0);

            node.IsSelected = true;

            // Delete current selected blueprint.
            try
            {
                ((BlueprintManagerViewModel)this.DataContext).RemoveBlueprint(selectedItem.BlueprintId);
            }
            catch (InvalidOperationException exception)
            {
                EditorDialog.Error("Unable to delete blueprint", exception.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Adds inspectors for the components of the specified blueprint and its parents.
        /// </summary>
        /// <param name="viewModel">Blueprint to add component inspectors for.</param>
        /// <param name="panel">Panel to add inspectors to.</param>
        /// <param name="getPropertyValue">Callback to get current value for a property.</param>
        /// <param name="onValueChanged">Callback to invoke when a property value changed.</param>
        public void AddComponentInspectorsRecursively(
            BlueprintViewModel viewModel,
            Panel panel,
            GetPropertyValueDelegate getPropertyValue,
            InspectorControlValueChangedDelegate onValueChanged)
        {
            // Add inspectors for parent blueprints.
            if (viewModel.Parent != null)
            {
                this.AddComponentInspectorsRecursively(viewModel.Parent, panel, getPropertyValue, onValueChanged);
            }

            // Add inspectors for specified blueprint.
            foreach (var componentType in viewModel.AddedComponents)
            {
                // Get attributes.
                InspectorType componentInfo = InspectorComponentTable.Instance.GetInspectorType(componentType);
                if (componentInfo == null)
                {
                    continue;
                }

                this.AddInspectorControls(componentInfo, panel, getPropertyValue, onValueChanged);
            }
        }
        /// <summary>
        ///   Adds inspectors for the components of the specified blueprint and its parents.
        /// </summary>
        /// <param name="viewModel">Blueprint to add component inspectors for.</param>
        /// <param name="panel">Panel to add inspectors to.</param>
        /// <param name="getPropertyValue">Callback to get current value for a property.</param>
        /// <param name="onValueChanged">Callback to invoke when a property value changed.</param>
        public void AddComponentInspectorsRecursively(
            BlueprintViewModel viewModel,
            Panel panel,
            GetPropertyValueDelegate getPropertyValue,
            InspectorControlValueChangedDelegate onValueChanged)
        {
            // Add inspectors for parent blueprints.
            if (viewModel.Parent != null)
            {
                this.AddComponentInspectorsRecursively(viewModel.Parent, panel, getPropertyValue, onValueChanged);
            }

            // Add inspectors for specified blueprint.
            foreach (var componentType in viewModel.AddedComponents)
            {
                // Get attributes.
                InspectorType componentInfo = InspectorComponentTable.Instance.GetInspectorType(componentType);
                if (componentInfo == null)
                {
                    continue;
                }

                this.AddInspectorControls(componentInfo, panel, getPropertyValue, onValueChanged);
            }
        }
Exemplo n.º 4
0
        private void TvTree_OnDrop(object sender, DragEventArgs e)
        {
            TreeViewItem dropTarget = (TreeViewItem)sender;

            if (dropTarget == null || !this.dragging)
            {
                return;
            }

            // Check if any data is present.
            if (!e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                return;
            }

            string             dragSourceBlueprintId = (string)e.Data.GetData(DataFormats.StringFormat);
            BlueprintViewModel dropTargetBlueprint   = (BlueprintViewModel)dropTarget.Header;

            // Prevent dragging and dropping on self.
            if (dragSourceBlueprintId.Equals(dropTargetBlueprint.BlueprintId))
            {
                return;
            }

            // Reparent blueprint.
            BlueprintManagerViewModel viewModel = this.DataContext as BlueprintManagerViewModel;

            if (viewModel != null)
            {
                viewModel.ReparentBlueprint(dragSourceBlueprintId, dropTargetBlueprint.BlueprintId);
            }

            // Stop dragging to prevent raising the drop event on parent items.
            this.dragging = false;
        }
        private void OnSelectedBlueprintChanged(BlueprintViewModel newBlueprint, BlueprintViewModel oldBlueprint)
        {
            var handler = this.SelectedBlueprintChaged;

            if (handler != null)
            {
                handler(newBlueprint, oldBlueprint);
            }
        }
        private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.ignoreSelectionChange)
            {
                return;
            }

            BlueprintViewModel newSelectedBlueprint = (BlueprintViewModel)this.ComboBox.SelectedItem;

            this.SelectedBlueprint   = newSelectedBlueprint;
            this.SelectedBlueprintId = newSelectedBlueprint != null ? newSelectedBlueprint.BlueprintId : null;
        }
Exemplo n.º 7
0
        private void TvTree_OnMouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                return;
            }

            TreeViewItem       dragSource         = (TreeViewItem)sender;
            BlueprintViewModel blueprintViewModel = (BlueprintViewModel)dragSource.Header;

            // Start dragging.
            this.dragging = true;

            DragDrop.DoDragDrop(dragSource, blueprintViewModel.BlueprintId, DragDropEffects.Move);
        }
        private void UpdateInspectors()
        {
            // Clear inspectors.
            this.AttributesPanel.Children.Clear();

            BlueprintViewModel viewModel = (BlueprintViewModel)this.DataContext;

            if (viewModel == null || viewModel.AddedComponents == null)
            {
                return;
            }

            // Add inspectors for blueprint components.
            this.inspectorFactory.AddComponentInspectorsRecursively(
                viewModel, this.AttributesPanel, this.GetCurrentAttributeValue, this.OnPropertyControlValueChanged);
        }
        private void ExecutedAddComponent(object sender, ExecutedRoutedEventArgs e)
        {
            // Get selected component type of available component types.
            Type componentType = (Type)this.LbComponentsAvailable.SelectedItem;

            if (componentType == null)
            {
                MessageBox.Show("No component type selected.");
                return;
            }

            BlueprintViewModel viewModel = (BlueprintViewModel)this.DataContext;

            viewModel.AddComponent(componentType);

            // Select component type.
            this.LbComponentsAdded.SelectedItem = componentType;
        }
        private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            BlueprintViewModel oldViewModel = (BlueprintViewModel)e.OldValue;

            if (oldViewModel != null)
            {
                oldViewModel.AddedComponents.CollectionChanged -= this.OnBlueprintComponentsChanged;
            }

            BlueprintViewModel newViewModel = (BlueprintViewModel)e.NewValue;

            if (newViewModel != null)
            {
                newViewModel.AddedComponents.CollectionChanged += this.OnBlueprintComponentsChanged;
            }

            this.UpdateInspectors();

            this.OnSelectedBlueprintChanged(newViewModel, oldViewModel);
        }
        private void OnBlueprintChanged(BlueprintViewModel newBlueprint)
        {
            if (Equals(this.selectedBlueprint, newBlueprint))
            {
                return;
            }

            this.selectedBlueprint = newBlueprint;

            // Update attribute table.
            this.UpdateAttributeTable();

            // Set value.
            EntityConfiguration entityConfiguration = (EntityConfiguration)this.Value ?? new EntityConfiguration();
            entityConfiguration.BlueprintId = newBlueprint != null ? newBlueprint.BlueprintId : string.Empty;

            this.Value = entityConfiguration;

            this.OnValueChanged();
        }
Exemplo n.º 12
0
        /// <summary>
        ///   Adds mapping controls for mapping CSV columns to blueprint attribute table keys for the specified parent blueprint.
        /// </summary>
        /// <param name="viewModel">Blueprint to add mapping controls for.</param>
        private void AddAttributeMappingsRecursively(BlueprintViewModel viewModel)
        {
            if (viewModel == null)
            {
                return;
            }

            // Add mapping controls for parent blueprints.
            if (viewModel.Parent != null)
            {
                this.AddAttributeMappingsRecursively(viewModel.Parent);
            }

            // Add mapping controls for specified blueprint.
            foreach (var componentType in viewModel.AddedComponents)
            {
                // Get attributes.
                var componentInfo = InspectorComponentTable.Instance.GetInspectorType(componentType);
                if (componentInfo == null)
                {
                    continue;
                }

                foreach (var inspectorProperty in componentInfo.Properties)
                {
                    // Create attribute mapping control.
                    PropertyValueMappingViewModel valueMapping = new PropertyValueMappingViewModel
                    {
                        MappingSource           = inspectorProperty.Name,
                        AvailableMappingTargets = new ObservableCollection <string>(this.CSVColumnHeaders),
                        InspectorProperty       = inspectorProperty
                    };

                    ValueMappingControl valueMappingControl = new ValueMappingControl(valueMapping);

                    // Add to panel.
                    this.valueMappings.Add(valueMapping);
                    this.SpAttributeMapping.Children.Add(valueMappingControl);
                }
            }
        }
Exemplo n.º 13
0
        private void OnBlueprintChanged(BlueprintViewModel newBlueprint)
        {
            if (Equals(this.selectedBlueprint, newBlueprint))
            {
                return;
            }

            this.selectedBlueprint = newBlueprint;

            // Update attribute table.
            this.UpdateAttributeTable();

            // Set value.
            EntityConfiguration entityConfiguration = (EntityConfiguration)this.Value ?? new EntityConfiguration();

            entityConfiguration.BlueprintId = newBlueprint != null ? newBlueprint.BlueprintId : string.Empty;

            this.Value = entityConfiguration;

            this.OnValueChanged();
        }
Exemplo n.º 14
0
 private void OnSelectedBlueprintChanged(BlueprintViewModel newBlueprint, BlueprintViewModel oldBlueprint)
 {
     this.Context.SelectedBlueprint = newBlueprint;
 }
        /// <summary>
        ///   Gets the current value of the specified property for the passed blueprint,
        ///   taking into account, in order: Blueprint attribute table, parents, default value.
        /// </summary>
        /// <param name="property">Property to get the current value of.</param>
        /// <returns>Current value of the specified property for the passed blueprint.</returns>
        private object GetCurrentAttributeValue(InspectorPropertyAttribute property, out bool inherited)
        {
            BlueprintViewModel viewModel = (BlueprintViewModel)this.DataContext;

            return(viewModel.GetCurrentAttributeValue(property.Name, out inherited));
        }
Exemplo n.º 16
0
 private void OnSelectedBlueprintChanged(BlueprintViewModel newBlueprint, BlueprintViewModel oldBlueprint)
 {
     this.Context.SelectedBlueprint = newBlueprint;
 }
        /// <summary>
        ///   Adds mapping controls for mapping CSV columns to blueprint attribute table keys for the specified parent blueprint.
        /// </summary>
        /// <param name="viewModel">Blueprint to add mapping controls for.</param>
        private void AddAttributeMappingsRecursively(BlueprintViewModel viewModel)
        {
            if (viewModel == null)
            {
                return;
            }

            // Add mapping controls for parent blueprints.
            if (viewModel.Parent != null)
            {
                this.AddAttributeMappingsRecursively(viewModel.Parent);
            }

            // Add mapping controls for specified blueprint.
            foreach (var componentType in viewModel.AddedComponents)
            {
                // Get attributes.
                var componentInfo = InspectorComponentTable.Instance.GetInspectorType(componentType);
                if (componentInfo == null)
                {
                    continue;
                }

                foreach (var inspectorProperty in componentInfo.Properties)
                {
                    // Create attribute mapping control.
                    PropertyValueMappingViewModel valueMapping = new PropertyValueMappingViewModel
                        {
                            MappingSource = inspectorProperty.Name,
                            AvailableMappingTargets = new ObservableCollection<string>(this.CSVColumnHeaders),
                            InspectorProperty = inspectorProperty
                        };

                    ValueMappingControl valueMappingControl = new ValueMappingControl(valueMapping);

                    // Add to panel.
                    this.valueMappings.Add(valueMapping);
                    this.SpAttributeMapping.Children.Add(valueMappingControl);
                }
            }
        }
        /// <summary>
        ///   Creates a new blueprint.
        /// </summary>
        /// <param name="blueprintId">Id for new blueprint.</param>
        /// <param name="original">Original blueprint to copy. Null if to create an empty blueprint.</param>
        /// <returns>New blueprint view model.</returns>
        public BlueprintViewModel CreateNewBlueprint(string blueprintId, BlueprintViewModel original = null)
        {
            if (this.CurrentBlueprintManager == null)
            {
                throw new InvalidOperationException("No blueprint file selected. Please select a blueprint file to add the new blueprint to!");
            }

            // Update blueprint view models.
            var newBlueprint = new BlueprintViewModel(
                blueprintId, original != null ? new Blueprint(original.Blueprint) : new Blueprint())
                {
                    AssemblyComponents = this.assemblyComponents
                };

            // Parent under same blueprint.
            if (original != null)
            {
                newBlueprint.Parent = original.Parent;
            }

            this.Blueprints.Add(newBlueprint);

            return newBlueprint;
        }
        public void ChangeBlueprintId(BlueprintViewModel blueprintViewModel, string newBlueprintId)
        {
            if (this.blueprintManager == null)
            {
                return;
            }

            var oldBlueprintId = blueprintViewModel.BlueprintId;
            this.blueprintManager.ChangeBlueprintId(oldBlueprintId, newBlueprintId);
            blueprintViewModel.BlueprintId = newBlueprintId;

            // Validate new blueprint id again as it may be valid/invalid now.
            this.OnPropertyChanged("NewBlueprintId");

            // Update parents.
            foreach (
                var viewModel in this.Blueprints.Where(viewModel => oldBlueprintId.Equals(viewModel.Blueprint.ParentId))
                )
            {
                viewModel.Blueprint.ParentId = newBlueprintId;
            }
        }
        private void OnPropertyControlValueChanged(InspectorPropertyAttribute inspectorProperty, object newValue)
        {
            BlueprintViewModel viewModel = (BlueprintViewModel)this.DataContext;

            viewModel.SetAttributeValue(inspectorProperty.Name, newValue);
        }
 private void OnSelectedBlueprintChanged(BlueprintViewModel newBlueprint, BlueprintViewModel oldBlueprint)
 {
     var handler = this.SelectedBlueprintChaged;
     if (handler != null)
     {
         handler(newBlueprint, oldBlueprint);
     }
 }