public void RenameNode()
        {
            try
            {
                if (this.CanRename)
                {
                    AbstractActionModelTreeNode selectedNode = base.SelectedNode;
                    RenameNodeComponent         component    = new RenameNodeComponent();
                    component.Name = selectedNode.Label;

                    ApplicationComponentExitCode result = ApplicationComponent.LaunchAsDialog(
                        this.Context.DesktopWindow,
                        new SimpleComponentContainer(component),
                        SR.TitleRename);

                    if (result == ApplicationComponentExitCode.Accepted)
                    {
                        selectedNode.Label = component.Name;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Report(ex, this.Context.DesktopWindow);
            }
        }
        internal IAction BuildAction()
        {
            IAction action = AbstractAction.Create(_action);

            Stack <PathSegment>         stack   = new Stack <PathSegment>();
            AbstractActionModelTreeNode current = this;

            do
            {
                stack.Push(current.PathSegment);
                current = current.Parent;
            } while (current != null);

            Path path = new Path(stack.Pop());             // the first path segment is the site, which is never processed through the resource resolver

            while (stack.Count > 0)
            {
                // for each subsequent segment, ensure the action's resolver will resolve the string in the expected way
                PathSegment pathSegment     = stack.Pop();
                string      localizedString = action.ResourceResolver.LocalizeString(pathSegment.ResourceKey);
                if (localizedString == pathSegment.LocalizedText)
                {
                    path = path.Append(pathSegment);
                }
                else
                {
                    path = path.Append(new PathSegment(pathSegment.LocalizedText, pathSegment.LocalizedText));
                }
            }

            action.Path = new ActionPath(path.ToString(), action.ResourceResolver);
            return(action);
        }
        internal override bool RequestValidation(AbstractActionModelTreeNode node, string propertyName, object value)
        {
            NodeValidationRequestedEventArgs e = new NodeValidationRequestedEventArgs(node, propertyName, value);

            EventsHelper.Fire(this.NodeValidationRequested, this, e);
            return(e.IsValid);
        }
 internal virtual void NotifyValidated(AbstractActionModelTreeNode node, string propertyName, object value)
 {
     if (!ReferenceEquals(this.Parent, null))
     {
         this.Parent.NotifyValidated(node, propertyName, value);
     }
 }
 public override DragDropKind CanAcceptDrop(object dropData, DragDropKind dragDropKind, DragDropPosition dragDropPosition)
 {
     if (dragDropPosition == DragDropPosition.Default)
     {
         if (dropData is AbstractActionModelTreeNode)
         {
             AbstractActionModelTreeNode droppedNode = (AbstractActionModelTreeNode)dropData;
             if (dragDropKind == DragDropKind.Move)
             {
                 // to drag-move, we can't be dragging onto ourself, onto our parent, or onto one of our descendants
                 if (!ReferenceEquals(this, droppedNode) &&
                     !ReferenceEquals(this, droppedNode.Parent) &&
                     !this.IsDescendantOf(droppedNode as AbstractActionModelTreeBranch))
                 {
                     return(dragDropKind);
                 }
             }
         }
     }
     else if (dragDropPosition == DragDropPosition.After)
     {
         // prevent dropping something after an expanded branch node with children,
         // because the user is physically dropping between the branch and its children
         // but the child logically appears as a sibling of the branch *after* both the branch and its children.
         if (this.Children.Count > 0 && this.IsExpanded)
         {
             return(DragDropKind.None);
         }
     }
     return(base.CanAcceptDrop(dropData, dragDropKind, dragDropPosition));
 }
Esempio n. 6
0
 public IEnumerable <NodePropertiesComponent> CreateComponents(AbstractActionModelTreeNode selectedNode)
 {
     if (selectedNode is AbstractActionModelTreeLeafClickAction)
     {
         yield return(new ClickActionKeystrokePropertyComponent((AbstractActionModelTreeLeafClickAction)selectedNode));
     }
 }
Esempio n. 7
0
        public virtual DragDropKind CanAcceptDrop(object dropData, DragDropKind dragDropKind, DragDropPosition dragDropPosition)
        {
            // drop target must have a parent, otherwise there is no concept of "sibling"
            if (dragDropPosition != DragDropPosition.Default && !ReferenceEquals(this.Parent, null))
            {
                if (dropData is AbstractActionModelTreeNode)
                {
                    AbstractActionModelTreeNode droppedNode = (AbstractActionModelTreeNode)dropData;
                    if (dragDropKind == DragDropKind.Move)
                    {
                        AbstractActionModelTreeNode sibling = null;
                        if (droppedNode.Parent != null)
                        {
                            int index = droppedNode.Parent.Children.IndexOf(droppedNode) + (dragDropPosition == DragDropPosition.After ? -1 : 1);
                            if (index >= 0 && index < droppedNode.Parent.Children.Count)
                            {
                                sibling = droppedNode.Parent.Children[index];
                            }
                        }

                        // to drag-move, we can't be dragging immediately before/after ourself, or onto one of our descendants
                        if (!ReferenceEquals(this, droppedNode) &&
                            !ReferenceEquals(this, sibling) &&
                            !this.IsDescendantOf(droppedNode as AbstractActionModelTreeBranch))
                        {
                            return(dragDropKind);
                        }
                    }
                }
            }
            return(DragDropKind.None);
        }
 public NodeValidationRequestedEventArgs(AbstractActionModelTreeNode node, string propertyName, object value)
 {
     this.Node         = node;
     this.PropertyName = propertyName;
     this.Value        = value;
     this.IsValid      = true;
 }
Esempio n. 9
0
		public NodeValidationRequestedEventArgs(AbstractActionModelTreeNode node, string propertyName, object value)
		{
			this.Node = node;
			this.PropertyName = propertyName;
			this.Value = value;
			this.IsValid = true;
		}
 internal virtual bool RequestValidation(AbstractActionModelTreeNode node, string propertyName, object value)
 {
     if (!ReferenceEquals(this.Parent, null))
     {
         return(this.Parent.RequestValidation(node, propertyName, value));
     }
     return(true);
 }
 protected virtual bool OnRequestNodePropertiesValidation(AbstractActionModelTreeNode node, string propertyName, object value)
 {
     if (_validationPolicy == null)
     {
         return(true);
     }
     return(_validationPolicy.Validate(node, propertyName, value));
 }
        private void SynchronizeParent(AbstractActionModelTreeNode node, ItemChangeType changeType)
        {
            switch (changeType)
            {
            case ItemChangeType.ItemAdded:
            case ItemChangeType.ItemInserted:
                // set the parent on the added node
                node.Parent = this;

                // sync the secondary list
                _syncList.Add(node);

                // force the node to expand
                this.IsExpanded = true;
                break;

            case ItemChangeType.ItemRemoved:
                // nullify the parent on the node if and only if it is us (just in case something silly happens and the parent is already updated)
                if (ReferenceEquals(this, node.Parent))
                {
                    node.Parent = null;
                }

                // sync the secondary list
                _syncList.Remove(node);
                break;

            case ItemChangeType.ItemChanged:
            // replacing an item in the list can cause ItemChanged, thus we need to resync the entire list to update the replaced item
            case ItemChangeType.Reset:
            default:
                // resync the parent nodes using the secondary list as a reference for what was in the tree before the change
                foreach (AbstractActionModelTreeNode child in _syncList)
                {
                    if (!_subtree.Items.Contains(child))
                    {
                        if (ReferenceEquals(this, node.Parent))
                        {
                            node.Parent = null;
                        }
                    }
                }
                foreach (AbstractActionModelTreeNode child in _subtree.Items)
                {
                    if (!_syncList.Contains(child))
                    {
                        child.Parent = this;
                    }
                }

                // update the secondary list
                _syncList.Clear();
                _syncList.AddRange(_subtree.Items);
                break;
            }
        }
 public bool Validate(AbstractActionModelTreeNode node, string propertyName, object value)
 {
     if (_propertyName != propertyName)
     {
         return(true);
     }
     if (!(node is T))
     {
         return(true);
     }
     return(_delegate.Invoke((T)node, value));
 }
 public bool Validate(AbstractActionModelTreeNode node, string propertyName, object value)
 {
     foreach (INodePropertiesValidationRule rule in _rules)
     {
         // if the node fails any single validation rule, it fails all
         if (!rule.Validate(node, propertyName, value))
         {
             return(false);
         }
     }
     return(true);
 }
 private void InsertNode(AbstractActionModelTreeNode node, AbstractActionModelTreeNode selectedNode, DragDropPosition position)
 {
     if (position == DragDropPosition.After && selectedNode.Parent != null)
     {
         selectedNode.Parent.Children.Insert(selectedNode.Parent.Children.IndexOf(selectedNode) + 1, node);
     }
     else if (position == DragDropPosition.Default && selectedNode is AbstractActionModelTreeBranch)
     {
         ((AbstractActionModelTreeBranch)selectedNode).Children.Add(node);
         selectedNode.IsExpanded = true;
     }
     else if (position == DragDropPosition.Before && selectedNode.Parent != null)
     {
         selectedNode.Parent.Children.Insert(selectedNode.Parent.Children.IndexOf(selectedNode), node);
     }
     else
     {
         base.Component.AbstractActionModelTreeRoot.Children.Add(node);
         base.Component.AbstractActionModelTreeRoot.IsExpanded = true;
     }
 }
        private void InsertNode(AbstractActionModelTreeNode node)
        {
            AbstractActionModelTreeNode selectedNode = base.SelectedNode;

            if (selectedNode is AbstractActionModelTreeBranch && !selectedNode.IsExpanded && selectedNode.Parent != null)
            {
                this.InsertNode(node, selectedNode, DragDropPosition.After);
            }
            else if (selectedNode is AbstractActionModelTreeBranch)
            {
                this.InsertNode(node, selectedNode, DragDropPosition.Default);
            }
            else if (selectedNode is AbstractActionModelTreeLeaf && selectedNode.Parent != null)
            {
                this.InsertNode(node, selectedNode, DragDropPosition.After);
            }
            else
            {
                this.InsertNode(node, base.Component.AbstractActionModelTreeRoot, DragDropPosition.After);
            }
        }
Esempio n. 17
0
        internal Path GetSeparatorPath()
        {
            Stack <PathSegment> stack = new Stack <PathSegment>();

            stack.Push(new PathSegment(Guid.NewGuid().ToString()));

            AbstractActionModelTreeNode current = this.Parent;

            while (current != null)
            {
                stack.Push(current.PathSegment);
                current = current.Parent;
            }

            Path path = new Path(stack.Pop());

            while (stack.Count > 0)
            {
                path = path.Append(stack.Pop());
            }
            return(path);
        }
        public void RemoveNode()
        {
            try
            {
                AbstractActionModelTreeNode selectedNode = base.SelectedNode;
                if (this.CanRemove && selectedNode.Parent != null)
                {
                    AbstractActionModelTreeBranch branch = selectedNode as AbstractActionModelTreeBranch;
                    if (branch != null && !branch.HasNoActions)
                    {
                        base.Context.DesktopWindow.ShowMessageBox(SR.MessageNodeNotEmpty, MessageBoxActions.Ok);
                        return;
                    }

                    selectedNode.Parent.Children.Remove(selectedNode);
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Report(ex, this.Context.DesktopWindow);
            }
        }
		internal override void NotifyValidated(AbstractActionModelTreeNode node, string propertyName, object value)
		{
			NodeValidatedEventArgs e = new NodeValidatedEventArgs(node, propertyName, value);
			EventsHelper.Fire(this.NodeValidated, this, e);
		}
		internal override bool RequestValidation(AbstractActionModelTreeNode node, string propertyName, object value)
		{
			NodeValidationRequestedEventArgs e = new NodeValidationRequestedEventArgs(node, propertyName, value);
			EventsHelper.Fire(this.NodeValidationRequested, this, e);
			return e.IsValid;
		}
 internal void NotifyChildChanged(AbstractActionModelTreeNode child)
 {
     _subtree.Items.NotifyItemUpdated(child);
 }
 /// <summary>
 /// Use only for performing initial population of the node.
 /// </summary>
 internal void AppendChild(AbstractActionModelTreeNode child)
 {
     _subtree.Items.Add(child);
 }
Esempio n. 23
0
 protected NodePropertiesComponent(AbstractActionModelTreeNode selectedNode)
 {
     Platform.CheckForNullReference(selectedNode, "selectedNode");
     _selectedNode = selectedNode;
 }
        internal override void NotifyValidated(AbstractActionModelTreeNode node, string propertyName, object value)
        {
            NodeValidatedEventArgs e = new NodeValidatedEventArgs(node, propertyName, value);

            EventsHelper.Fire(this.NodeValidated, this, e);
        }
 protected virtual void OnNodePropertiesValidated(AbstractActionModelTreeNode node, string propertyName, object value)
 {
 }
 protected virtual IEnumerable <NodePropertiesComponent> CreateNodePropertiesComponents(AbstractActionModelTreeNode node)
 {
     if (node != null)
     {
         foreach (object extension in new NodePropertiesComponentProviderExtensionPoint().CreateExtensions())
         {
             INodePropertiesComponentProvider provider = extension as INodePropertiesComponentProvider;
             if (provider != null)
             {
                 foreach (NodePropertiesComponent component in provider.CreateComponents(node))
                 {
                     yield return(component);
                 }
             }
         }
     }
 }