Ejemplo n.º 1
0
        public void ProcessAddEntitiesToDiagram()
        {
            var diagramID = new ProjectTreeHelper().GetFirstAncestorID <DiagramDTO>();

            if (diagramID == Guid.Empty)
            {
                throw new InvalidOperationException("No diagram selected.");
            }

            var view = new EntitiesListView();

            view.DataSource = new EntitiesNotOnDiagramListDataSource();
            var popup = new PopupWindow();

            popup.Title = "Add Entity To Diagram";
            popup.ViewPanel.Children.Add(view);

            if (popup.ShowDialog() == true)
            {
                var selectedItems = view.SelectedItems;
                if (selectedItems != null)
                {
                    foreach (var item in selectedItems)
                    {
                        new ObjectDataSource().SaveObject(
                            new DiagramEntityDTO()
                        {
                            DiagramID = diagramID,
                            EntityID  = item.PersistentObject.ID
                        });
                    }
                }
            }

            ServiceLocator serviceLocator = ServiceLocator.GetActive();

            serviceLocator.BasicController.ProcessProjectTreeRefresh();
        }
        public DataBrowserControl(IEntityController controller)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("IEntityController<T> cannot be null");
            }
            this.Controller = controller;

            //Fill the properties with "fresh" data
            Items = controller.GetDataSource();

            //Listen when the data changes so that we can update the properties holding the data
            controller.Changed += Controller_Changed;

            InitializeComponent();

            //Setting the background is required => when using DataBrowserControl as a popup
            //and it flows out of the window its background shouldn't be transparent
            dockPanel.Background = App.Current.MainWindow.Background;

            #region Mapping with column names
            foreach (KeyValuePair <string, string> item in controller.Mapping)
            {
                GridViewColumn column = new GridViewColumn
                {
                    Header = item.Key,
                    DisplayMemberBinding = new Binding(item.Value)
                    {
                        StringFormat     = item.Value.Contains("PRICE") ? "C" : "",
                        ConverterCulture = Thread.CurrentThread.CurrentCulture
                    }
                };
                gridView.Columns.Add(column);
            }
            #endregion

            //Create binding to the current controller
            Binding controllerBinding = new Binding()
            {
                Source = this,
                Path   = new PropertyPath("Controller"),
                Mode   = BindingMode.OneWay
            };

            //Create binding to the selected item (reversed binding used for the sake of simplicity)
            Binding selecteditemBinding = new Binding()
            {
                Source = this.Controller,
                Path   = new PropertyPath("SelectedItem"),
                Mode   = BindingMode.OneWayToSource
            };
            EntitiesListView.SetBinding(ListView.SelectedItemProperty, selecteditemBinding);

            #region Context menu
            Style style = new Style(typeof(ListViewItem));

            ContextMenu contextMenu = new ContextMenu();

            MenuItem newMenuItem = new MenuItem()
            {
                Command = InvoiceManagerCommands.New,
                Icon    = new Image()
                {
                    Source = new BitmapImage(new Uri("/Resources/new.png", UriKind.Relative)),
                    Width  = 20,
                    Height = 20
                }
            };
            newMenuItem.SetBinding(MenuItem.CommandParameterProperty, controllerBinding);
            contextMenu.Items.Add(newMenuItem);

            MenuItem editMenuItem = new MenuItem()
            {
                Command = InvoiceManagerCommands.Edit,
                Icon    = new Image()
                {
                    Source = new BitmapImage(new Uri("/Resources/Edit.png", UriKind.Relative)),
                    Width  = 20,
                    Height = 20
                }
            };
            editMenuItem.SetBinding(MenuItem.CommandParameterProperty, controllerBinding);
            contextMenu.Items.Add(editMenuItem);

            MenuItem deleteMenuItem = new MenuItem()
            {
                Command = InvoiceManagerCommands.Delete,
                Icon    = new Image()
                {
                    Source = new BitmapImage(new Uri("/Resources/Delete.png", UriKind.Relative)),
                    Width  = 20,
                    Height = 20
                }
            };
            deleteMenuItem.SetBinding(MenuItem.CommandParameterProperty, controllerBinding);
            contextMenu.Items.Add(deleteMenuItem);

            style.Setters.Add(new Setter(ListViewItem.ContextMenuProperty, contextMenu));
            Resources.Add(typeof(ListViewItem), style);
            #endregion
        }