Наследование: MonoBehaviour
    public static void Run(TreeElement node, ILexer lexer, ITokenOffsetProvider offsetProvider, bool trimTokens, SeldomInterruptChecker interruptChecker)
    {
      Assertion.Assert(node.parent == null, "node.parent == null");

      var root = node as CompositeElement;
      if (root == null)
      {
        return;
      }

      var inserter = new PsiMissingTokensInserter(lexer, offsetProvider, interruptChecker);
      lexer.Start();

      if (trimTokens)
      {
        using (var container = new DummyContainer(root))
        {
          inserter.Run(container);
        }
      }
      else
      {
        var terminator = new EofToken(lexer.Buffer);
        root.AppendNewChild(terminator);
        inserter.Run(root);
        root.DeleteChildRange(terminator, terminator);
      }
    }
Пример #2
0
        public override short GetChildRole(TreeElement child)
        {
            if (child is ReferenceName)
                return 0x27;

            return base.GetChildRole(child);
        }
Пример #3
0
        public void Write(TextWriter writer, IEnumerable<Stack> stacks)
        {
            var root = new TreeElement();

            var filtered = stacks
                .OrderByDescending(s => s.Count);

            foreach (var stack in filtered) {
                AddStacks(root, stack, 0);
            }

            var total = root.Total;
            var normMax = (double)(int.MaxValue / 2);
            var scaleFactor = Math.Min(normMax / total, 1);

            var lowerBound = total * 0.0001;

            RescaleAndTrim(root, scaleFactor, lowerBound);

            using (var jWriter = new JsonTextWriter(writer)) {
                jWriter.Formatting = Formatting.None;
                //jWriter.Formatting = Formatting.Indented;
                WriteTree(root, jWriter);
            }
        }
Пример #4
0
        public void ArrayTest()
        {
            var array = new TreeElement<int, string>(new TreeElement<int, string>("A"), new TreeElement<int, string>("B"));

            var arrayChangedHistory = array.ArrayChanged.SubscribeHistory();
            var grandChildrenChangedHistory = array.GrandChildrenChanged.SubscribeHistory();

            array.Type.Is(ElementType.Array);
            AssertEx.Catch<InvalidOperationException>(() => array.LeafValue.ToString());
            AssertEx.Catch<InvalidOperationException>(() => array.NodeChildren.ToString());
            AssertEx.Catch<InvalidOperationException>(() => array.NodeChildrenChanged.ToString());

            array.Array[0].LeafValue.Is("A");
            array.Array[1].LeafValue.Is("B");
            array.Array.Count.Is(2);

            arrayChangedHistory.Count().Is(0);
            grandChildrenChangedHistory.Count().Is(0);

            array.Array.Add(new TreeElement<int, string>("C"));
            array.Array.Clear();

            arrayChangedHistory.Values.Select(x => x.Action).IsSequenceEqual(NotifyCollectionChangedAction.Add, NotifyCollectionChangedAction.Reset);
            grandChildrenChangedHistory.Values.Select(x => x.Value.Action).IsSequenceEqual(NotifyCollectionChangedAction.Add, NotifyCollectionChangedAction.Reset);
        }
Пример #5
0
        public override short GetChildRole(TreeElement child)
        {
            if (child is IColumnElement && ((XmlTag)child).TagName == "column")
                    return Column_ROLE_ID;
                else

            return base.GetChildRole(child);
        }
Пример #6
0
        public override short GetChildRole(TreeElement child)
        {
            if (child is IParamElement && ((XmlTag)child).TagName == "param")
                    return Param_ROLE_ID;
                else

            return base.GetChildRole(child);
        }
Пример #7
0
 public override short GetChildRole(TreeElement child)
 {
     if (child.type == L4NElementType.REFERENCE_NAME)
     {
         return REFERENCE_NAME_ROLE;
     }
     return 0;
 }
 public override short GetChildRole(TreeElement child)
 {
     if (child is IIdMappingElement && ((XmlTag)child).TagName == "id")
         return ID_MAPPING_ELEMENT_ROLE;
     else if (child is IPropertyMappingElement && ((XmlTag)child).TagName == "property")
         return PROPTIY_ELEMENT_ROLE;
     else
         return base.GetChildRole(child);
 }
Пример #9
0
        public FileTree(Screen screen, Rectangle bound, Sprite background, string root, string extensionFilter = "")
            : base(screen)
        {
            Bound = bound;
            Background = background;
            elements = new Dictionary<TextBlock, TreeElement>();
            font = screen.Manager.Game.Content.Load<SpriteFont>("Fonts/Hud");

            Root = new TreeElement() { Path = root, isDirectory = true };
            AddToTreeAllChilds(Root, extensionFilter);
        }
Пример #10
0
        public void LeafTest()
        {
            var leaf = new TreeElement<int, string>("1");

            AssertEx.Catch<InvalidOperationException>(() => leaf.Array.ToString());
            AssertEx.Catch<InvalidOperationException>(() => leaf.ArrayChanged.Subscribe());
            AssertEx.Catch<InvalidOperationException>(() => leaf.NodeChildren.ToString());
            AssertEx.Catch<InvalidOperationException>(() => leaf.NodeChildrenChanged.Subscribe());
            leaf.GrandChildrenChanged.Subscribe(); // throws no exception
            leaf.LeafValue.Is("1");
            leaf.Type.Is(ElementType.Leaf);
        }
        public override short GetChildRole(TreeElement child)
        {
            if (child is IKeyPropertyElement && ((XmlTag)child).TagName == "key-property")
                    return KeyPropertys_ROLE_ID;
                else

                if (child is IKeyManyToOneElement && ((XmlTag)child).TagName == "key-many-to-one")
                    return KeyManyToOnes_ROLE_ID;
                else

            return base.GetChildRole(child);
        }
Пример #12
0
        public override short GetChildRole(TreeElement child)
        {
            if (child is IReturnDiscriminatorElement && ((XmlTag)child).TagName == "return-discriminator")
                    return ReturnDiscriminator_ROLE_ID;
                else

                if (child is IReturnPropertyElement && ((XmlTag)child).TagName == "return-property")
                    return ReturnProperty_ROLE_ID;
                else

            return base.GetChildRole(child);
        }
Пример #13
0
        public void EqualsAndHashCodeTest()
        {
            var te_a1 = new TreeElement<string, string>("a");
            var te_a2 = new TreeElement<string, string>("a");
            var te_b = new TreeElement<string, string>("b");
            var te_node = new TreeElement<string, string>();

            te_a1.Is(te_a1);
            te_a1.GetHashCode().Is(te_a1.GetHashCode());
            te_a1.Is(te_a2);
            te_a1.GetHashCode().Is(te_a2.GetHashCode());
            te_a1.IsNot(te_b);
            te_a1.IsNot(te_node);
        }
Пример #14
0
        private void AddStacks(TreeElement root, Stack stack, int depth)
        {
            root.Total += stack.Count;

            var limit = stack.Stacks.Length;
            //var limit = Math.Min(stack.Stacks.Length, 4);
            if (depth < limit) {
                var frame = stack.Stacks[depth];
                if (!root.Children.ContainsKey(frame)) {
                    root.Children.Add(frame, new TreeElement());
                }

                AddStacks(root.Children[frame], stack, depth + 1);
            }
        }
        public override short GetChildRole(TreeElement child)
        {
            if (child is ICreateElement && ((XmlTag)child).TagName == "create")
                    return Create_ROLE_ID;
                else

                if (child is IDropElement && ((XmlTag)child).TagName == "drop")
                    return Drop_ROLE_ID;
                else

                if (child is IDialectScopeElement && ((XmlTag)child).TagName == "dialect-scope")
                    return DialectScope_ROLE_ID;
                else

            return base.GetChildRole(child);
        }
        public override short GetChildRole(TreeElement child)
        {
            if (child is IParentElement && ((XmlTag)child).TagName == "parent")
                    return Parent_ROLE_ID;
                else

                if (child is IPropertyElement && ((XmlTag)child).TagName == "property")
                    return Properties_ROLE_ID;
                else

                if (child is IManyToOneElement && ((XmlTag)child).TagName == "many-to-one")
                    return ManyToOnes_ROLE_ID;
                else

                if (child is INestedCompositeElementElement && ((XmlTag)child).TagName == "nested-composite-element")
                    return NestedCompositeElements_ROLE_ID;
                else

            return base.GetChildRole(child);
        }
    protected override void ProcessLeafElement(TreeElement element)
    {
      int leafOffset = GetLeafOffset(element).Offset;

      // Check if some tokens are missed before this leaf
      if (myLexer.TokenType != null && myLexer.TokenStart < leafOffset)
      {
        // Find out the right place to insert tokens to
        TreeElement anchor = element;
        CompositeElement parent = anchor.parent;
        while (anchor == parent.firstChild && parent.parent != null)
        {
          anchor = parent;
          parent = parent.parent;
        }

        // proceed with inserting tokens
        while (myLexer.TokenType != null && myLexer.TokenStart < leafOffset)
        {
          LeafElementBase token = CreateMissingToken();

          parent.AddChildBefore(token, anchor);

          myLexer.Advance();
        }
      }

      // skip all tokens which lie inside given leaf element
      int leafEndOffset = leafOffset + element.GetTextLength();
      if ((element is IClosedChameleonBody) && (myLexer is CachingLexer))
      {
        ((CachingLexer)myLexer).FindTokenAt(leafEndOffset);
      }
      else
      {
        while (myLexer.TokenType != null && myLexer.TokenStart < leafEndOffset)
        {
          myLexer.Advance();
        }
      }
    }
Пример #18
0
 /// <summary>
 /// добавление элемента в дерево
 /// </summary>
 /// <param name="value"></param>
 public void Add(int value)
 {
     if (head == null)
     {
         head = new TreeElement(value);
     }
     else
     {
         TreeElement tmpHead = head;
         while (true)
         {
             if (tmpHead.GetValue() == value)
                 return;
             if (tmpHead.GetValue() > value)
             {
                 if (tmpHead.GetLeft() == null)
                 {
                     tmpHead.SetLeft(new TreeElement(value));
                     return;
                 }
                 else
                 {
                     tmpHead = tmpHead.GetLeft();
                 }
             }
             if (tmpHead.GetValue() < value)
             {
                 if (tmpHead.GetRight() == null)
                 {
                     tmpHead.SetRight(new TreeElement(value));
                     return;
                 }
                 else
                 {
                     tmpHead = tmpHead.GetRight();
                 }
             }
         }
     }
 }
Пример #19
0
        public void AddItem(string item, object context, string tooltip)
        {
            // Parse the string
            string[] tokens = item.Split(new char[] { '/' });

            int NumTokens = tokens.Length;

            // If the tokens
            TreeElement currItem = null;

            for (int i = 0; i < NumTokens; i++)
            {
                TreeElement element = null;

                if (i == 0)
                {
                    element = FindItem(mTree, tokens[i], false);
                }
                else
                {
                    element = FindItem(currItem.mList, tokens[i], false);
                }

                if (element != null)
                {
                    currItem = element;
                    continue;
                }

                if (i < NumTokens - 1 && NumTokens > 1)
                {
                    currItem = AddHeader(currItem, tokens[i], tooltip);
                }
                else
                {
                    currItem = AddItem(currItem, tokens[i], context, tooltip);
                }
            }
        }
Пример #20
0
        public static IReferenceName GetScalarTypename(this IDeclaration fieldDeclaration)
        {
            CompositeElement compositeElement = (CompositeElement)fieldDeclaration;

            if (!(compositeElement.parent is IMultipleFieldDeclaration) || compositeElement.parent.GetChildRole((TreeElement)compositeElement) != (short)104)
            {
                return((IReferenceName)null);
            }
            CompositeElement parent        = compositeElement.parent;
            IReferenceName   referenceName = (IReferenceName)null;
            CompositeElement childByRole1  = (CompositeElement)parent.FindChildByRole((short)19);

            if (childByRole1 != null)
            {
                TreeElement childByRole2 = childByRole1.FindChildByRole((short)19);
                if (childByRole2 != null)
                {
                    referenceName = (IReferenceName)childByRole2;
                }
            }
            return(referenceName);
        }
        public static ReSharper.NTriples.Tree.IStatement GetByFactsElement(ReSharper.NTriples.Tree.IFacts param)
        {
            if (param == null)
            {
                return(null);
            }
            TreeElement current = (TreeElement)param;

            if (current.parent is ReSharper.NTriples.Impl.Tree.Statement)
            {
                if (current.parent.GetChildRole(current) != ReSharper.NTriples.Impl.Tree.Statement.FACTS)
                {
                    return(null);
                }
                current = current.parent;
            }
            else
            {
                return(null);
            }
            return((ReSharper.NTriples.Tree.IStatement)current);
        }
        public static ReSharper.NTriples.Tree.IStatement GetByKeywordStatement(ReSharper.NTriples.Tree.IKeywordStatement param)
        {
            if (param == null)
            {
                return(null);
            }
            TreeElement current = (TreeElement)param;

            if (current.parent is ReSharper.NTriples.Impl.Tree.Statement)
            {
                if (current.parent.GetChildRole(current) != ReSharper.NTriples.Impl.Tree.Statement.KEYWORD_STATEMENT)
                {
                    return(null);
                }
                current = current.parent;
            }
            else
            {
                return(null);
            }
            return((ReSharper.NTriples.Tree.IStatement)current);
        }
Пример #23
0
    public void MoveElements(TreeElement parentElement, int insertionIndex, List <TreeElement> elements)
    {
        if (insertionIndex < 0)
        {
            throw new ArgumentException("Invalid input: insertionIndex is -1, client needs to decide what index elements should be reparented at");
        }

        // Invalid reparenting input
        if (parentElement == null)
        {
            return;
        }

        // We are moving items so we adjust the insertion index to accomodate that any items above the insertion index is removed before inserting
        if (insertionIndex > 0)
        {
            insertionIndex -= parentElement.children.GetRange(0, insertionIndex).Count(elements.Contains);
        }

        // Remove draggedItems from their parents
        foreach (var draggedItem in elements)
        {
            draggedItem.parent.children.Remove(draggedItem);    // remove from old parent
            draggedItem.parent = parentElement;                 // set new parent
        }

        if (parentElement.children == null)
        {
            parentElement.children = new List <TreeElement>();
        }

        // Insert dragged items under new parent
        parentElement.children.InsertRange(insertionIndex, elements);

        TreeElementUtility.UpdateDepthValues(root);
        TreeElementUtility.TreeToList(m_Root, m_Data);

        Changed();
    }
Пример #24
0
        private void RescaleAndTrim(TreeElement root, double scaleFactor, double lowerBound)
        {
            root.Total = (long)(root.Total * scaleFactor);

            if (root.Total == 0) {
                Console.WriteLine("Zero encountered.");
                root.Total = 1;
            }

            var toRemove = root.Children
                .Where(c => c.Value.Total < lowerBound)
                .Select(c => c.Key)
                .ToArray();

            foreach (var remove in toRemove) {
                root.Children.Remove(remove);
            }

            foreach (var child in root.Children) {
                RescaleAndTrim(child.Value, scaleFactor, lowerBound);
            }
        }
Пример #25
0
        /*
         * (non-Javadoc)
         * @see org.javarosa.core.model.utils.ITreeVisitor#visit(org.javarosa.core.model.DataModelTree)
         */
        public void visit(FormInstance tree)
        {
            theXmlDoc = new XmlDocument();
            //TreeElement root = tree.getRoot();

            TreeElement root = tree.resolveReference(rootRef);

            //For some reason resolveReference won't ever return the root, so we'll
            //catch that case and just start at the root.
            if (root == null)
            {
                root = tree.getRoot();
            }

            for (int i = 0; i < root.getNumChildren(); i++)
            {
                TreeElement childAt = root.getChildAt(i);
            }

            if (root != null)
            {
                theXmlDoc.AppendChild(serializeNode(root));
            }

            XmlElement top = (XmlElement)theXmlDoc.FirstChild;

            String[] prefixes = tree.getNamespacePrefixes();
            for (int i = 0; i < prefixes.Length; ++i)
            {
                top.Prefix = prefixes[i];
            }
            if (tree.schema != null)
            {
                //top.setNamespace(tree.schema);
                top.SetAttribute(top.Name, tree.schema, top.Value);
                top.Prefix = tree.schema;
            }
        }
        public static TreeElement GetHierarchy(this IEnumerable <string> paths, string userId)
        {
            var root = new TreeElement()
            {
                Name     = userId,
                Children = new List <TreeElement>()
            };

            foreach (var path in paths)
            {
                var splitBetweenBaseAndDirectory = path.IndexOf(userId, StringComparison.Ordinal) + userId.Length;
                var pathWithoutUser = path.Remove(0, splitBetweenBaseAndDirectory).TrimStart('/');

                if (!string.IsNullOrWhiteSpace(pathWithoutUser))
                {
                    var parts            = pathWithoutUser.Split('/');
                    var baseAbsolutePath = path.Substring(0, splitBetweenBaseAndDirectory);
                    root.BuildTree(parts, baseAbsolutePath);
                }
            }

            return(root);
        }
Пример #27
0
        private static TreeElement BuildTree(this TreeElement root, List <TreeElement> elements)
        {
            if (elements.Count == 0)
            {
                return(root);
            }

            var children = root.FetchChildren(elements).ToList();

            root.Children.AddRange(children);
            root.RemoveChildren(elements);

            for (int i = 0; i < children.Count; i++)
            {
                children[i] = children[i].BuildTree(elements);
                if (elements.Count == 0)
                {
                    break;
                }
            }

            return(root);
        }
Пример #28
0
    IList <int> GetParentsBelowStackBased(TreeElement searchFromThis)
    {
        Stack <TreeElement> stack = new Stack <TreeElement>();

        stack.Push(searchFromThis);

        var parentsBelow = new List <int>();

        while (stack.Count > 0)
        {
            TreeElement current = stack.Pop();
            if (current.hasChildren)
            {
                parentsBelow.Add(current.id);
                foreach (var T in current.children)
                {
                    stack.Push(T);
                }
            }
        }

        return(parentsBelow);
    }
        /// <summary>
        /// The get tree node from configuration element.
        /// </summary>
        /// <param name="tree">
        /// The tree.
        /// </param>
        /// <param name="queryStrings">
        /// The query strings.
        /// </param>
        /// <param name="parentTree">
        /// The parent tree.
        /// </param>
        /// <returns>
        /// The <see cref="TreeNode"/>.
        /// </returns>
        private TreeNode GetTreeNodeFromConfigurationElement(TreeElement tree, FormDataCollection queryStrings, TreeElement parentTree = null)
        {
            var hasSubs = tree.SubTree != null && tree.SubTree.GetTrees().Any();

            if (tree.Id == "reports" && hasSubs == false)
            {
                hasSubs = ReportApiControllerResolver.Current.ResolvedTypes.Any();
            }
            if (_collectiontrees.Contains(tree.Id))
            {
                hasSubs = this.GetCollectionProviderInfo(tree.Id).ManagedCollections.Any() ||
                          tree.SelfManagedEntityCollectionProviderCollections.EntityCollectionProviders().Any();
            }

            return(CreateTreeNode(
                       tree.Id,
                       parentTree == null ? string.Empty : parentTree.Id,
                       queryStrings,
                       this.LocalizeTitle(tree),
                       tree.Icon,
                       hasSubs,
                       tree.RoutePath));
        }
Пример #30
0
        private void performAction(TreeElement node, int action)
        {
            switch (action)
            {
            case ACTION_NULL: break;

            case ACTION_SHOW: node.setRelevant(true); break;

            case ACTION_HIDE: node.setRelevant(false); break;

            case ACTION_ENABLE: node.setEnabled(true); break;

            case ACTION_DISABLE: node.setEnabled(false); break;

            case ACTION_LOCK: /* not supported */; break;

            case ACTION_UNLOCK: /* not supported */; break;

            case ACTION_REQUIRE: node.setRequired(true); break;

            case ACTION_DONT_REQUIRE: node.setRequired(false); break;
            }
        }
Пример #31
0
        public TreeElement AddItem(TreeElement parent, string label, object context, string tooltip)
        {
            // Parse the list and check for duplicates!
            TreeElement pItem = new TreeElement();

            pItem.Label    = label;
            pItem.Tooltip  = tooltip;
            pItem.IsHeader = false;
            pItem.IsOpen   = true;
            pItem.context  = context;
            pItem.color    = defaultColor;

            if (parent != null)
            {
                parent.mList.Add(pItem);
            }
            else
            {
                mTree.Add(pItem);
            }

            return(pItem);
        }
Пример #32
0
        public TreeElement ParseNTriplesFile(bool isFileReal, bool restoreWhitespaces = false)
        {
            TreeElement file = base.parseNTriplesFile();

            if (restoreWhitespaces)
            {
                this.InsertMissingTokens(file, false, myTokenIntern);
            }

            var psiFile = file as NTriplesFile;

            if (psiFile != null)
            {
                psiFile.SetSourceFile(this.SourceFile);
                psiFile.CreatePrefixesSymbolTable();
                if (this.SourceFile != null)
                {
                    psiFile.CreateUriIdentifiersSymbolTable();
                }
            }

            return(psiFile);
        }
Пример #33
0
    public static void TestTreeModelCanRemoveElements()
    {
        var root = new TreeElement {
            name = "Root", depth = -1
        };
        var listOfElements = new List <TreeElement>();

        listOfElements.Add(root);

        var model = new TreeModel <TreeElement>(listOfElements);

        model.AddElement(new TreeElement {
            name = "Element"
        }, root, 0);
        model.AddElement(new TreeElement {
            name = "Element " + root.children.Count
        }, root, 0);
        model.AddElement(new TreeElement {
            name = "Element " + root.children.Count
        }, root, 0);
        model.AddElement(new TreeElement {
            name = "Sub Element"
        }, root.children[1], 0);

        model.RemoveElements(new[] { root.children[1].children[0], root.children[1] });

        // Assert order is correct
        string[] namesInCorrectOrder = { "Root", "Element 2", "Element" };
        Assert.AreEqual(namesInCorrectOrder.Length, listOfElements.Count, "Result count does not match");
        for (int i = 0; i < namesInCorrectOrder.Length; ++i)
        {
            Assert.AreEqual(namesInCorrectOrder[i], listOfElements[i].name);
        }

        // Assert depths are valid
        TreeElementUtility.ValidateDepthValues(listOfElements);
    }
Пример #34
0
        private void AddToTreeAllChilds(TreeElement parent, string extensionFilter)
        {
            string root = parent.Path;

            foreach (string dir in Directory.GetDirectories(root))
            {
                TreeElement child = new TreeElement()
                {
                    Path = dir, isDirectory = true, Parent = parent
                };
                elements.Add(new TextBlock(Screen, nextPos, dir.Split('\\').Last())
                {
                    Parent = this
                }, child);
                nextPos.X += 20;
                nextPos.Y += 30;
                AddToTreeAllChilds(child, extensionFilter);
                parent.Childs.Add(child);
            }
            foreach (string file in Directory.GetFiles(root))
            {
                if (file.EndsWith(extensionFilter))
                {
                    TreeElement child = new TreeElement()
                    {
                        Path = file, isDirectory = false, Parent = parent
                    };
                    parent.Childs.Add(child);
                    elements.Add(new TextBlock(Screen, nextPos, file.Split('\\').Last())
                    {
                        Parent = this
                    }, child);
                    nextPos.Y += 30;
                }
            }
            nextPos.X -= 20;
        }
Пример #35
0
        private void DoRemove(AssetInfo[] assetInfo)
        {
            for (int i = 0; i < assetInfo.Length; ++i)
            {
                if (assetInfo[i].Folder != null)
                {
                    assetInfo[i].Folder.Assets.Remove(assetInfo[i]);
                    assetInfo[i].Folder = null;
                }
            }

            TreeElement parent = assetInfo[0].parent;
            int         index  = parent.children.IndexOf(assetInfo[0]);

            TreeView.treeModel.RemoveElements(assetInfo.Select(a => a.id).ToArray());

            if (index >= parent.children.Count)
            {
                index = parent.children.Count - 1;
            }

            if (index >= 0)
            {
                TreeView.SetSelection(new int[] { parent.children[index].id }, TreeViewSelectionOptions.FireSelectionChanged);
            }
            else
            {
                if (parent != null)
                {
                    TreeView.SetSelection(new int[] { parent.id }, TreeViewSelectionOptions.FireSelectionChanged);
                }
                else
                {
                    TreeView.SetSelection(new int[0], TreeViewSelectionOptions.FireSelectionChanged);
                }
            }
        }
Пример #36
0
    public void AddElement(T element, TreeElement parent, int insertPosition)
    {
        if (element == null)
        {
            throw new ArgumentNullException("element", "element is null");
        }
        if (parent == null)
        {
            throw new ArgumentNullException("parent", "parent is null");
        }

        if (parent.children == null)
        {
            parent.children = new List <TreeElement> ();
        }

        parent.children.Insert(insertPosition, element);
        element.parent = parent;

        TreeElementUtility.UpdateDepthValues(parent);
        TreeElementUtility.TreeToList(m_Root, m_Data);

        Changed();
    }
Пример #37
0
        /// <summary>
        /// The get tree node from configuration element.
        /// </summary>
        /// <param name="tree">
        /// The tree.
        /// </param>
        /// <param name="queryStrings">
        /// The query strings.
        /// </param>
        /// <param name="parentTree">
        /// The parent tree.
        /// </param>
        /// <returns>
        /// The <see cref="TreeNode"/>.
        /// </returns>
        private TreeNode GetTreeNodeFromConfigurationElement(TreeElement tree, FormDataCollection queryStrings, TreeElement parentTree = null)
        {
            var hasSubs = tree.SubTree != null && tree.SubTree.GetTrees().Any();

            if (_collectiontrees.Contains(tree.Id))
            {
                hasSubs = this.GetCollectionProviderInfo(tree.Id).ManagedCollections.Any() ||
                          tree.SelfManagedEntityCollectionProviderCollections.EntityCollectionProviders().Any();
            }

            if (_attributetrees.Contains(tree.Id))
            {
                hasSubs = GetAttributeDefinedTrees(queryStrings).Any();
            }

            return(CreateTreeNode(
                       tree.Id,
                       parentTree == null ? string.Empty : parentTree.Id,
                       queryStrings,
                       this.LocalizeTitle(tree),
                       tree.Icon,
                       hasSubs,
                       tree.RoutePath));
        }
Пример #38
0
 /**
  * For the current index: Checks whether the index represents a node which
  * should exist given a non-interactive repeat, along with a count for that
  * repeat which is beneath the dynamic level specified.
  *
  * If this index does represent such a node, the new model for the repeat is
  * created behind the scenes and the index for the initial question is
  * returned.
  *
  * Note: This method will not prevent the addition of new repeat elements in
  * the interface, it will merely use the xforms repeat hint to create new
  * nodes that are assumed to exist
  *
  * @param The index to be evaluated as to whether the underlying model is
  *        hinted to exist
  */
 private void createModelIfNecessary(FormIndex index)
 {
     if (index.isInForm())
     {
         IFormElement e = getForm().getChild(index);
         if (e is GroupDef)
         {
             GroupDef g = (GroupDef)e;
             if (g.Repeat && g.CountReference != null)
             {
                 IAnswerData count = getForm().Instance.getDataValue(g.CountReference);
                 if (count != null)
                 {
                     long          fullcount = ((int)count.Value);
                     TreeReference ref_      = getForm().getChildInstanceRef(index);
                     TreeElement   element   = getForm().Instance.resolveReference(ref_);
                     if (element == null)
                     {
                         if (index.getInstanceIndex() < fullcount)
                         {
                             try
                             {
                                 getForm().createNewRepeat(index);
                             }
                             catch (InvalidReferenceException ire)
                             {
                                 Console.WriteLine(ire.StackTrace);
                                 throw new SystemException("Invalid Reference while creting new repeat!" + ire.Message);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #39
0
 private void AddToTreeAllChilds(TreeElement parent, string extensionFilter)
 {
     string root = parent.Path;
     foreach (string dir in Directory.GetDirectories(root))
     {
         TreeElement child = new TreeElement() { Path = dir, isDirectory = true, Parent = parent };
         elements.Add(new TextBlock(Screen, nextPos, dir.Split('\\').Last()) { Parent = this }, child);
         nextPos.X += 20;
         nextPos.Y += 30;
         AddToTreeAllChilds(child, extensionFilter);
         parent.Childs.Add(child);
     }
     foreach (string file in Directory.GetFiles(root))
     {
         if (file.EndsWith(extensionFilter))
         {
             TreeElement child = new TreeElement() { Path = file, isDirectory = false, Parent = parent };
             parent.Childs.Add(child);
             elements.Add(new TextBlock(Screen, nextPos, file.Split('\\').Last()) { Parent = this }, child);
             nextPos.Y += 30;
         }
     }
     nextPos.X -= 20;
 }
        public static void BuildTree(this TreeElement treeElement, IEnumerable <string> remainingElements, string baseAbsolutePath)
        {
            var elements = remainingElements as IList <string> ?? remainingElements.ToList();

            if (elements.Any())
            {
                var name  = elements.First();
                var child = treeElement.Children.SingleOrDefault(c => c.Name == name);

                if (child == null)
                {
                    child = new TreeElement()
                    {
                        Name         = name,
                        Children     = new List <TreeElement>(),
                        AbsolutePath = baseAbsolutePath + "/" + name,
                    };

                    treeElement.Children.Add(child);
                }

                BuildTree(child, elements.Skip(1), child.AbsolutePath);
            }
        }
Пример #41
0
        public TreeElement FindItem(string item)
        {
            // Parse the string
            string[] tokens = item.Split(new char[] { '/' });

            int NumTokens = tokens.Length;

            // Find root element
            // If the tokens
            TreeElement currItem = FindItem(mTree, tokens[0], false);

            for (int i = 1; i < NumTokens; i++)
            {
                currItem = FindItem(currItem.mList, tokens[i], true);

                if (currItem == null)
                {
                    UnityEngine.Debug.Log("HierarchyTree:FindItem - Unable to find " + item);
                    break;
                }
            }

            return(currItem);
        }
        public static void Run(
            TreeElement node,
            ILexer lexer,
            ITokenOffsetProvider offsetProvider,
            bool trimTokens,
            SeldomInterruptChecker interruptChecker,
            ITokenIntern intern)
        {
            Assertion.Assert(node.parent == null, "node.parent == null");

            var root = node as CompositeElement;

            if (root == null)
            {
                return;
            }

            var inserter = new NTriplesMissingTokensInserter(lexer, offsetProvider, interruptChecker, intern);

            lexer.Start();

            if (trimTokens)
            {
                using (var container = new DummyContainer(root))
                {
                    inserter.Run(container);
                }
            }
            else
            {
                var terminator = new EofToken(lexer.Buffer);
                root.AppendNewChild(terminator);
                inserter.Run(root);
                root.DeleteChildRange(terminator, terminator);
            }
        }
Пример #43
0
 private ReferenceName CreateMemeberIdentifier(TreeElement firstIdentifier, IQualifier qualifier)
 {
     return new FilteredReferenceName(firstIdentifier, qualifier, new FiltersArray(new ISymbolFilter[] { PropertyOrFiledFilter.INSTANCE, PublicOrProtectedFilter.INSTANCE }));
 }
Пример #44
0
        /**
         * recursively read in a node of the instance, by filling out the template instance
         * @param e
         * @param ref
         * @param in
         * @param pf
         * @throws IOException
         * @throws DeserializationException
         */
        private void readTreeElement(TreeElement e, BinaryReader in_, PrototypeFactory pf)
        {
            TreeElement templ   = instance.getTemplatePath(e.getRef());
            Boolean     isGroup = !templ.isLeaf();

            if (isGroup)
            {
                ArrayList childTypes = new ArrayList();
                for (int i = 0; i < templ.getNumChildren(); i++)
                {
                    String childName = templ.getChildAt(i).getName();
                    if (!childTypes.Contains(childName))
                    {
                        childTypes.Add(childName);
                    }
                }

                for (int i = 0; i < childTypes.Count; i++)
                {
                    String childName = (String)childTypes[i];

                    TreeReference childTemplRef = e.getRef().extendRef(childName, 0);
                    TreeElement   childTempl    = instance.getTemplatePath(childTemplRef);

                    Boolean repeatable = childTempl.repeatable;
                    int     n          = ExtUtil.readInt(in_);

                    Boolean relevant = (n > 0);
                    if (!repeatable && n > 1)
                    {
                        throw new DeserializationException("Detected repeated instances of a non-repeatable node");
                    }

                    if (repeatable)
                    {
                        int mult = e.getChildMultiplicity(childName);
                        for (int j = mult - 1; j >= 0; j--)
                        {
                            e.removeChild(childName, j);
                        }

                        for (int j = 0; j < n; j++)
                        {
                            TreeReference dstRef = e.getRef().extendRef(childName, j);
                            try
                            {
                                instance.copyNode(childTempl, dstRef);
                            }
                            catch (InvalidReferenceException ire)
                            {
                                //If there is an invalid reference, this is a malformed instance,
                                //so we'll throw a Deserialization exception.
                                TreeReference r = ire.InvalidReference;
                                if (r == null)
                                {
                                    throw new DeserializationException("Null Reference while attempting to deserialize! " + ire.Message);
                                }
                                else
                                {
                                    throw new DeserializationException("Invalid Reference while attemtping to deserialize! Reference: " + r.toString(true) + " | " + ire.Message);
                                }
                            }

                            TreeElement child = e.getChild(childName, j);
                            child.setRelevant(true);
                            readTreeElement(child, in_, pf);
                        }
                    }
                    else
                    {
                        TreeElement child = e.getChild(childName, 0);
                        child.setRelevant(relevant);
                        if (relevant)
                        {
                            readTreeElement(child, in_, pf);
                        }
                    }
                }
            }
            else
            {
                e.setValue((IAnswerData)ExtUtil.read(in_, new ExtWrapAnswerData(e.dataType)));
            }
        }
Пример #45
0
        public override short GetChildRole(TreeElement child)
        {
            if (child is IMetaElement && ((XmlTag)child).TagName == "meta")
                    return Meta_ROLE_ID;
                else

                if (child is IJcsCacheElement && ((XmlTag)child).TagName == "jcs-cache")
                    return JcsCache_ROLE_ID;
                else

                if (child is ICacheElement && ((XmlTag)child).TagName == "cache")
                    return Cache_ROLE_ID;
                else

                if (child is IKeyElement && ((XmlTag)child).TagName == "key")
                    return Key_ROLE_ID;
                else

                if (child is IElementElement && ((XmlTag)child).TagName == "element")
                    return Element_ROLE_ID;
                else

                if (child is IOneToManyElement && ((XmlTag)child).TagName == "one-to-many")
                    return OneToMany_ROLE_ID;
                else

                if (child is IManyToManyElement && ((XmlTag)child).TagName == "many-to-many")
                    return ManyToMany_ROLE_ID;
                else

                if (child is ICompositeElementElement && ((XmlTag)child).TagName == "composite-element")
                    return CompositeElement_ROLE_ID;
                else

                if (child is IManyToAnyElement && ((XmlTag)child).TagName == "many-to-any")
                    return ManyToAny_ROLE_ID;
                else

                if (child is IFilterElement && ((XmlTag)child).TagName == "filter")
                    return Filter_ROLE_ID;
                else

                if (child is ILoaderElement && ((XmlTag)child).TagName == "loader")
                    return Loader_ROLE_ID;
                else

                if (child is ISqlInsertElement && ((XmlTag)child).TagName == "sql-insert")
                    return SqlInsert_ROLE_ID;
                else

                if (child is ISqlUpdateElement && ((XmlTag)child).TagName == "sql-update")
                    return SqlUpdate_ROLE_ID;
                else

                if (child is ISqlDeleteElement && ((XmlTag)child).TagName == "sql-delete")
                    return SqlDelete_ROLE_ID;
                else

                if (child is ISqlDeleteAllElement && ((XmlTag)child).TagName == "sql-delete-all")
                    return SqlDeleteAll_ROLE_ID;
                else

            return base.GetChildRole(child);
        }
Пример #46
0
        private IList <AssetInfo> GetData()
        {
            if (m_folders != null)
            {
                List <AssetInfo> result = new List <AssetInfo>();

                AssetInfo root = new AssetInfo
                {
                    id        = 0,
                    name      = "Root",
                    IsEnabled = false,
                    depth     = -1,
                };

                result.Add(root);
                foreach (AssetInfo assetInfo in m_folders.Where(folder => folder.Assets != null).SelectMany(folder => folder.Assets))
                {
                    assetInfo.parent = root;
                    result.Add(assetInfo);

                    if (assetInfo.PrefabParts != null)
                    {
                        Dictionary <int, AssetInfo> assets = new Dictionary <int, AssetInfo>();
                        assets.Add(-1, assetInfo);

                        for (int i = 0; i < assetInfo.PrefabParts.Count; ++i)
                        {
                            PrefabPartInfo prefabPart = assetInfo.PrefabParts[i];
                            string         name;
                            if (prefabPart.Object == null)
                            {
                                name = "<Null>";
                            }
                            else
                            {
                                if (prefabPart.Object is Component)
                                {
                                    name = prefabPart.Object.GetType().Name;
                                }
                                else
                                {
                                    name = prefabPart.Object.name;
                                }
                            }

                            AssetInfo prefabPartAssetInfo = new AssetInfo(name, assetInfo.depth + prefabPart.Depth + 1, prefabPart.PersistentID);
                            prefabPartAssetInfo.Object = prefabPart.Object;

                            assets.Add(prefabPartAssetInfo.id, prefabPartAssetInfo);

                            if (assets.ContainsKey(prefabPart.ParentPersistentID))
                            {
                                TreeElement parent = assets[prefabPart.ParentPersistentID];
                                prefabPartAssetInfo.parent = parent;
                                result.Add(prefabPartAssetInfo);
                            }
                        }
                    }
                }
                return(result);
            }

            return(new List <AssetInfo>
            {
                new AssetInfo
                {
                    id = 0,
                    name = "Root",
                    IsEnabled = false,
                    depth = -1,
                }
            });
        }
Пример #47
0
        private bool CreateAsset(UnityObject obj, AssetInfo parentAssetInfo, int insertIndex = -1, AssetFolderInfo folder = null)
        {
            if (obj is GameObject)
            {
                GameObject go = (GameObject)obj;

                int identity = m_asset.AssetLibrary.Identity + 1;
                List <PrefabPartInfo> prefabParts = new List <PrefabPartInfo>();
                CreatePefabParts(go, ref identity, prefabParts);
                if (identity >= AssetLibraryInfo.MAX_ASSETS)
                {
                    return(false);
                }

                AssetInfo assetInfo = CreateAsset(obj.name, parentAssetInfo, insertIndex, folder);
                assetInfo.Object = obj;
                AddAssetToFolder(assetInfo, folder);

                assetInfo.PrefabParts         = prefabParts;
                m_asset.AssetLibrary.Identity = identity;

                if (folder != null)
                {
                    if (IsFolderSelected(folder))
                    {
                        if (assetInfo.PrefabParts != null)
                        {
                            Dictionary <int, AssetInfo> assets = new Dictionary <int, AssetInfo>();
                            assets.Add(-1, assetInfo);

                            for (int i = 0; i < assetInfo.PrefabParts.Count; ++i)
                            {
                                PrefabPartInfo prefabPart = assetInfo.PrefabParts[i];
                                string         name;
                                if (prefabPart.Object == null)
                                {
                                    name = "<Null>";
                                }
                                else
                                {
                                    if (prefabPart.Object is Component)
                                    {
                                        name = prefabPart.Object.GetType().Name;
                                    }
                                    else
                                    {
                                        name = prefabPart.Object.name;
                                    }
                                }

                                AssetInfo prefabPartAssetInfo = new AssetInfo(name, assetInfo.depth + prefabPart.Depth, prefabPart.PersistentID);
                                prefabPartAssetInfo.Object = prefabPart.Object;

                                assets.Add(prefabPartAssetInfo.id, prefabPartAssetInfo);

                                TreeElement parent = assets[prefabPart.ParentPersistentID];
                                TreeView.treeModel.AddElement(prefabPartAssetInfo, parent, parent.children != null ? parent.children.Count : 0);
                            }
                        }
                    }
                }
            }
            else
            {
                AssetInfo assetInfo = CreateAsset(obj.name, parentAssetInfo, insertIndex, folder);
                assetInfo.Object = obj;
                AddAssetToFolder(assetInfo, folder);
            }
            return(true);
        }
Пример #48
0
 public static string Printable(this TreeElement tree, bool dense = false) =>
 tree is Error error ? error.Message
Пример #49
0
        /// <summary>
        /// The localize title.
        /// </summary>
        /// <param name="tree">
        /// The tree.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private string LocalizeTitle(TreeElement tree)
        {
            var name = tree.LocalizeName.IsNullOrWhiteSpace() ? tree.Id : tree.LocalizeName;

            var localized = _textService.Localize(string.Format("{0}/{1}", tree.LocalizeArea, name), _culture);

            return localized.IsNullOrWhiteSpace() ? tree.Title : localized;
        }
Пример #50
0
        /// <summary>
        /// Gets tree nodes for self managed collection providers.
        /// </summary>
        /// <param name="currentTree">
        /// The current tree.
        /// </param>
        /// <param name="info">
        /// The info.
        /// </param>
        /// <param name="splitId">
        /// The split id.
        /// </param>
        /// <param name="collectionId">
        /// The collection id.
        /// </param>
        /// <param name="parentRouteId">
        /// The parent route id.
        /// </param>
        /// <param name="queryStrings">
        /// The query strings.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{TreeNode}"/>.
        /// </returns>
        private IEnumerable<TreeNode> GetTreeNodesForSelfManagedProviders(
            TreeElement currentTree,
            CollectionProviderInfo info,
            SplitRoutePath splitId,
            string collectionId,
            string parentRouteId,
            FormDataCollection queryStrings)
        {
            var treeNodes = new List<TreeNode>();
            if (splitId.IsChildCollection) return treeNodes;

            // if there are no self managed providers - return
            if (currentTree.SelfManagedEntityCollectionProviderCollections == null
                ||
                !currentTree.SelfManagedEntityCollectionProviderCollections.EntityCollectionProviders().Any(x => x.Visible))
                return treeNodes;

            return this.GetTreeNodeForConfigurationEntityCollectionProviders(currentTree, collectionId, info, queryStrings, parentRouteId);
        }
Пример #51
0
        /// <summary>
        /// The get tree node from configuration element.
        /// </summary>
        /// <param name="tree">
        /// The tree.
        /// </param>
        /// <param name="queryStrings">
        /// The query strings.
        /// </param>
        /// <param name="parentTree">
        /// The parent tree.
        /// </param>
        /// <returns>
        /// The <see cref="TreeNode"/>.
        /// </returns>
        private TreeNode GetTreeNodeFromConfigurationElement(TreeElement tree, FormDataCollection queryStrings, TreeElement parentTree = null)
        {
            var hasSubs = tree.SubTree != null && tree.SubTree.GetTrees().Any();

            if (tree.Id == "reports" && hasSubs == false) hasSubs = ReportApiControllerResolver.Current.ResolvedTypes.Any();

            return CreateTreeNode(
                tree.Id,
                parentTree == null ? string.Empty : parentTree.Id,
                queryStrings,
                tree.Title,
                tree.Icon,
                hasSubs,
                tree.RoutePath);
        }
Пример #52
0
        private TreeElement ParseReferencedName(TreeElement id)
        {
            TreeElement result = id;
            TokenNodeType tokenType = lexer.TokenType;
            XmlToken xmlToken = id as XmlToken;
            if (xmlToken != null && xmlToken.type == L4NTokenNodeType.IDENTIFIER)
            {
                result = new ReferenceName(id);
                // TODO parse argument list
            }

            while (tokenType == CSharpTokenType.DOT)
            {
            //                if (LexerUtil.LookaheadToken(lexer, 1) != CSharpTokenType.IDENTIFIER)
            //                {
            //                    UnexpectedToken ex = new UnexpectedToken("Expected identifier");
            //                    ex.ParsingResult = result;
            //                    throw ex;
            //                }
                result = ParseReferenceNameInternal(result);
                tokenType = lexer.TokenType;
            }
            return result;
        }
Пример #53
0
        private TreeElement ParseReferenceNameInternal(TreeElement qualifier)
        {
            CompositeElement result = null;
            TreeElement tempParsingResult = null;
            try
            {
                result = CreateReferenceName();
                tempParsingResult = qualifier;
                result.AppendNewChild(tempParsingResult);
                TokenNodeType tokenType = lexer.TokenType;
                if (tokenType == CSharpTokenType.DOT)
                {
                    tokenType = lexer.TokenType;
                    if (tokenType == CSharpTokenType.DOT)
                    {
                        tempParsingResult =
                            new XmlToken(L4NTokenNodeType.DOT, lexer.Buffer, lexer.TokenStart, lexer.TokenEnd);
                        lexer.Advance();
                        result.AppendNewChild(tempParsingResult);
                    }
                    else
                    {
                        if (result.firstChild == null)
                        {
                            result = null;
                        }
                        throw new UnexpectedToken("Unexpected token");
                    }

                    tempParsingResult = this.ParseIdentifier();
                    result.AppendNewChild(tempParsingResult);
                }
            }
            catch (SyntaxError e)
            {
                if (((qualifier != null) && (qualifier.Parent == null)) && (qualifier != null))
                {
                    result.AppendNewChild(qualifier);
                }
                if ((e.ParsingResult != null) && (result != null))
                {
                    result.AppendNewChild(e.ParsingResult);
                }
                if (result != null)
                {
                    e.ParsingResult = result;
                }
                throw;
            }
            return result;
        }
Пример #54
0
 public virtual JetBrains.ReSharper.PsiPlugin.Tree.IRoleName SetRoleName(JetBrains.ReSharper.PsiPlugin.Tree.IRoleName param)
 {
     using (JetBrains.Application.WriteLockCookie.Create(this.IsPhysical()))
     {
         TreeElement current = null, next = GetNextFilteredChild(current), result = null;
         next = GetNextFilteredChild(current);
         if (next == null)
         {
             return((JetBrains.ReSharper.PsiPlugin.Tree.IRoleName)result);
         }
         else
         {
             if (next.NodeType == JetBrains.ReSharper.PsiPlugin.Tree.Impl.ElementType.PATH_NAME)
             {
                 current = next;
             }
             else
             {
                 return((JetBrains.ReSharper.PsiPlugin.Tree.IRoleName)result);
             }
         }
         next = GetNextFilteredChild(current);
         if (next == null)
         {
             result = current = (TreeElement)JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.AddChildAfter(this, current, TreeElementFactory.CreateErrorElement(string.Empty));
         }
         else
         {
             if (next.NodeType == JetBrains.ReSharper.PsiPlugin.Tree.Impl.TokenType.COLON)
             {
                 if (param != null)
                 {
                     current = next;
                 }
                 else
                 {
                     current = GetNextFilteredChild(next);
                     JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.DeleteChild(next);
                 }
             }
             else
             {
                 return((JetBrains.ReSharper.PsiPlugin.Tree.IRoleName)result);
             }
         }
         next = GetNextFilteredChild(current);
         if (next == null)
         {
             if (param == null)
             {
                 return(null);
             }
             result = current = (TreeElement)JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.AddChildAfter(this, current, (JetBrains.ReSharper.Psi.Tree.ITreeNode)param);
         }
         else
         {
             if (next.NodeType == JetBrains.ReSharper.PsiPlugin.Tree.Impl.ElementType.ROLE_NAME)
             {
                 if (param != null)
                 {
                     result = current = (TreeElement)JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.ReplaceChild(next, (JetBrains.ReSharper.Psi.Tree.ITreeNode)param);
                 }
                 else
                 {
                     current = GetNextFilteredChild(next);
                     JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.DeleteChild(next);
                 }
             }
             else
             {
                 if (param == null)
                 {
                     return(null);
                 }
                 result  = (TreeElement)JetBrains.ReSharper.Psi.ExtensionsAPI.Tree.ModificationUtil.AddChildBefore(next, (JetBrains.ReSharper.Psi.Tree.ITreeNode)param);
                 current = next;
             }
         }
         return((JetBrains.ReSharper.PsiPlugin.Tree.IRoleName)result);
     }
 }
Пример #55
0
 /// <summary>
 /// 要素を作成
 /// </summary>
 private TreeViewItem CreateTreeViewItem(TreeElement model)
 {
     return(new TreeViewItem {
         id = model.Id, displayName = "Label"
     });
 }
 public override short GetChildRole(TreeElement child)
 {
     return base.GetChildRole(child);
 }
Пример #57
0
 public ForElement(string var, List <TreeElement> startVar, List <TreeElement> toVar, TreeElement parent, List <TreeElement> block) : base(parent.File, parent.Position, parent.Line, parent.CharIndex)
 {
     Block      = block;
     VarName    = var;
     StartValue = startVar;
     ToValue    = toVar;
 }
Пример #58
0
        /// <summary>
        /// The get tree node from configuration element.
        /// </summary>
        /// <param name="tree">
        /// The tree.
        /// </param>
        /// <param name="collectionId">
        /// The root collection type (e.g. sales, product, customer)
        /// </param>
        /// <param name="info">
        /// The info.
        /// </param>
        /// <param name="queryStrings">
        /// The query strings.
        /// </param>
        /// <param name="parentRouteId">The parent route id</param>
        /// <returns>
        /// The <see cref="IEnumerable{TreeNode}"/>.
        /// </returns>
        private IEnumerable<TreeNode> GetTreeNodeForConfigurationEntityCollectionProviders(TreeElement tree, string collectionId, CollectionProviderInfo info, FormDataCollection queryStrings, string parentRouteId)
        {
            // get the self managed providers
            var grouping = new List<Tuple<EntityCollectionProviderElement, EntityCollectionProviderDisplay>>();
            foreach (var element in
                tree.SelfManagedEntityCollectionProviderCollections.EntityCollectionProviders().Where(x => x.Visible))
            {
                Guid elementKey;
                if (!Guid.TryParse(element.Key, out elementKey))
                {
                    continue;
                }

                var providerDisplay =
                    this._entityCollectionProviderResolver.GetProviderAttributes()
                        .First(x => x.Key == elementKey)
                        .ToEntityCollectionProviderDisplay();
                if (providerDisplay != null)
                {
                    grouping.Add(new Tuple<EntityCollectionProviderElement, EntityCollectionProviderDisplay>(element, providerDisplay));
                }
            }

            if (!grouping.Any()) return Enumerable.Empty<TreeNode>();

            var treeNodes = new List<TreeNode>();

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var g in grouping)
            {
                if (!g.Item2.ManagedCollections.Any()) continue;

                var element = g.Item1;
                var provider = g.Item2;
                var collection = g.Item2.ManagedCollections.First();

                treeNodes.Add(
                    this.CreateTreeNode(
                        MakeCollectionRoutePathId(collectionId, collection.Key.ToString()) + "_resolved",
                        parentRouteId,
                        queryStrings,
                        provider.LocalizedNameKey.IsNullOrWhiteSpace() ? provider.Name : this._textService.Localize(provider.LocalizedNameKey, this._culture),
                        element.Icon,
                        false,
                        string.Format("/merchello/merchello/{0}/{1}", info.ViewName, collection.Key)));
            }

            return treeNodes;
        }
        /// <summary>
        /// The get tree node from configuration element.
        /// </summary>
        /// <param name="tree">
        /// The tree.
        /// </param>
        /// <param name="queryStrings">
        /// The query strings.
        /// </param>
        /// <param name="parentTree">
        /// The parent tree.
        /// </param>
        /// <returns>
        /// The <see cref="TreeNode"/>.
        /// </returns>
        private TreeNode GetTreeNodeFromConfigurationElement(TreeElement tree, FormDataCollection queryStrings, TreeElement parentTree = null)
        {
            var hasSubs = tree.SubTree != null && tree.SubTree.GetTrees().Any();

            if (tree.Id == "reports" && hasSubs == false)
            {
                hasSubs = ReportApiControllerResolver.Current.ResolvedTypes.Any();
            }

            return(CreateTreeNode(
                       tree.Id,
                       parentTree == null ? string.Empty : parentTree.Id,
                       queryStrings,
                       tree.Title,
                       tree.Icon,
                       hasSubs,
                       tree.RoutePath));
        }
Пример #60
0
        /// <summary>
        /// The get tree node from configuration element.
        /// </summary>
        /// <param name="tree">
        /// The tree.
        /// </param>
        /// <param name="queryStrings">
        /// The query strings.
        /// </param>
        /// <param name="parentTree">
        /// The parent tree.
        /// </param>
        /// <returns>
        /// The <see cref="TreeNode"/>.
        /// </returns>
        private TreeNode GetTreeNodeFromConfigurationElement(TreeElement tree, FormDataCollection queryStrings, TreeElement parentTree = null)
        {
            var hasSubs = tree.SubTree != null && tree.SubTree.GetTrees().Any();

            if (tree.Id == "reports" && hasSubs == false) hasSubs = ReportApiControllerResolver.Current.ResolvedTypes.Any();
            if (_collectiontrees.Contains(tree.Id))
                hasSubs = this.GetCollectionProviderInfo(tree.Id).ManagedCollections.Any()
                          || tree.SelfManagedEntityCollectionProviderCollections.EntityCollectionProviders().Any();

            return CreateTreeNode(
                tree.Id,
                parentTree == null ? string.Empty : parentTree.Id,
                queryStrings,
                this.LocalizeTitle(tree),
                tree.Icon,
                hasSubs,
                tree.RoutePath);
        }