private FrameworkElement AddAction()
        {
            ActionType actionType = nodeSelectionManager.AppConfig.GetActionTypes().First();
            ActionConfiguration action = new ActionConfiguration(actionType.Name) {
                Configuration = new SerializableXDocument(new XDocument(new XElement(XName.Get("objectConfig"))))
            };
            node.Actions.Add(action);

            FrameworkElement actionRepresentation = CreateActionRepresentation(action);
            return actionRepresentation;
        }
        private FrameworkElement CreateActionRepresentation(ActionConfiguration action)
        {
            string[] actionTypeNames = nodeSelectionManager.AppConfig.GetActionTypes().Select(at => at.Name).ToArray();
            ComboBox uiActionType = new ComboBox {
                Tag = action,
                Margin = new Thickness(10, 3, 5, 3),
                IsEditable = false,
                HorizontalAlignment = HorizontalAlignment.Stretch
            };
            foreach (string actionTypeName in actionTypeNames) {
                uiActionType.Items.Add(new ComboBoxItem {
                    Tag = actionTypeName,
                    Content = actionTypeName.Substring(actionTypeName.LastIndexOf('.') + 1)
                });
            }
            uiActionType.SelectedIndex = actionTypeNames.ToList().IndexOf(action.ActionTypeName);
            uiActionType.SelectionChanged += delegate {
                string selectedActionTypeName = (string)(((ComboBoxItem)uiActionType.SelectedItem).Tag);
                action.ActionTypeName = selectedActionTypeName;
                SetActiveAction(uiActionType);
            };
            Grid.SetColumn(uiActionType, 1);

            var uiAction = new Grid {
                Tag = action,
                ColumnDefinitions = {
                    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) },
                    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }
                },
                Children = {
                    new Image {
                        Source = new BitmapImage(new Uri("pack://application:,,,/XRouter.Gui;component/Resources/Actions-tool-animator-icon.png")),
                        Height = 18,
                        Margin = new Thickness(8, 0, 0, 0)
                    },
                    uiActionType
                }
            };

            return uiAction;
        }
        private void SetActiveAction(FrameworkElement uiAction)
        {
            if (uiAction == null) {
                activeAction = null;
                uiActionConfigurationRegion.Visibility = Visibility.Collapsed;
                return;
            }

            activeAction = (ActionConfiguration)uiAction.Tag;
            uiActionConfigurationRegion.Visibility = Visibility.Visible;

            ActionType activeActionType = nodeSelectionManager.AppConfig.GetActionType(activeAction.ActionTypeName);
            activeConfigurationEditor = Configurator.CreateEditor(activeActionType.ConfigurationMetadata);
            activeConfigurationEditor.LoadConfiguration(activeAction.Configuration.XDocument);
            activeConfigurationEditor.ConfigurationChanged += delegate {
                activeAction.Configuration = new SerializableXDocument(activeConfigurationEditor.SaveConfiguration());
            };
            uiActionConfigurationContainer.Child = activeConfigurationEditor;
        }
        private ContextMenu CreateGraphCanvasContextMenu()
        {
            ContextMenu result = new ContextMenu();

            MenuItem menuItemAddActionNode = new MenuItem {
                Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/XRouter.Gui;component/Resources/Actions-tool-animator-icon.png")), Height = 20 },
                Header = new TextBlock { Text = "Action", FontSize = 14, FontWeight = FontWeights.Bold }
            };
            menuItemAddActionNode.Click += delegate {
                AddNode("Action", result, delegate {
                    ActionNodeConfiguration newActionNode = new ActionNodeConfiguration();
                    #region Add a default action
                    ActionType actionType = ConfigManager.Configuration.GetActionTypes().First();
                    ActionConfiguration action = new ActionConfiguration(actionType.Name) {
                        Configuration = new SerializableXDocument(new XDocument(new XElement(XName.Get("objectConfig"))))
                    };
                    newActionNode.Actions.Add(action);
                    #endregion
                    return newActionNode;
                });
            };

            MenuItem menuItemAddCbrNode = new MenuItem {
                Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/XRouter.Gui;component/Resources/nfs-unmount-icon.png")), Height = 20 },
                Header = new TextBlock { Text = "CBR", FontSize = 14, FontWeight = FontWeights.Bold }
            };
            menuItemAddCbrNode.Click += delegate {
                AddNode("CBR", result, delegate { return new CbrNodeConfiguration(); });
            };

            MenuItem menuItemAddTerminatorNode = new MenuItem {
                Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/XRouter.Gui;component/Resources/Button-exit-icon.png")), Height = 20 },
                Header = new TextBlock { Text = "Terminator", FontSize = 14, FontWeight = FontWeights.Bold }
            };
            menuItemAddTerminatorNode.Click += delegate {
                Point menuLocationOnCanvas = result.TranslatePoint(new Point(), graphCanvas.Canvas);
                AddNode("Terminator", result, delegate { return new TerminatorNodeConfiguration(); });
            };

            MenuItem menuItemAdd = new MenuItem {
                Header = new TextBlock { Text = "Add node...", FontSize = 14 }  
            };
            menuItemAdd.Items.Add(menuItemAddActionNode);
            menuItemAdd.Items.Add(menuItemAddCbrNode);
            menuItemAdd.Items.Add(menuItemAddTerminatorNode);

            result.Items.Add(menuItemAdd);
            return result;
        }