Пример #1
0
 protected virtual void OnGetChildResourcesCompleted(GetChildResourcesCompletedEventArgs args)
 {
     if (GetChildResourcesCompleted != null)
     {
         GetChildResourcesCompleted(this, args);
     }
 }
 protected virtual void OnGetChildResourcesCompleted(GetChildResourcesCompletedEventArgs args)
 {
     if (GetChildResourcesCompleted != null)
         GetChildResourcesCompleted(this, args);
 }
        void resource_GetChildResourcesCompleted(object sender, GetChildResourcesCompletedEventArgs e)
        {
            TreeViewItem tvi = null;
            string childName = "";

            object[] userState = e.UserState as object[];

            IDataSourceWithResources dataSource = userState[1] as IDataSourceWithResources;
            if (dataSource == null)
                return;

            // If the element at [0] is a tree view item, then this is a standard expand action on a parent node and
            // the logic flow is as it was before: remove current contents, add from array
            tvi = userState[0] as TreeViewItem;
            if (tvi != null)
            {
                tvi.Items.Clear();
            }
            else
            {
                // If the item we are adding to is the root (TreeView) then there are no children, but we are instead using the
                // progress indicator and must clear this here.
                showHideProgressIndicator(true);
                enableDisableUrlEntryUI(false);

                // Fabricate parent node and include connection, etc. so that when this node is expanded or child nodes are
                // referenced, the infrastructure will be in place to make existing logic work to obtain child information
                Resource parentResource = userState[2] as Resource;
                tvi = new TreeViewItem
                {
                    HeaderTemplate = LayoutRoot != null ? LayoutRoot.Resources["ResourceNodeDataTemplate"] as DataTemplate : null,
                    Header = parentResource,
                    DataContext = parentResource,
                    IsExpanded = true,
                    IsSelected = true,
                    Style = LayoutRoot != null ? LayoutRoot.Resources["TreeViewItemStyle"] as Style : null,
                };
                Connection connection = userState[3] as Connection;
                tvi.SetValue(TreeViewItemExtensions.ConnectionProperty, connection);
                treeResources.Items.Add(tvi);

                // If the parent item "tag" is assigned a value, store it for comparison against all child elements so that
                // the proper child element can be automatically selected. This is used when the URL contains the child
                // element of a map service, gp service, feature service, etc.
                if (parentResource.Tag != null)
                {
                    childName = parentResource.Tag as string;
                }
            }

            if (e.ChildResources == null)
                return;

            foreach (Resource childResource in e.ChildResources)
            {
                TreeViewItem treeViewItem = new TreeViewItem
                {
                    HeaderTemplate = LayoutRoot != null ? LayoutRoot.Resources["ResourceNodeDataTemplate"] as DataTemplate : null,
                    Header = childResource,
                    DataContext = childResource,
                    IsExpanded = false,
                    Style = LayoutRoot != null ? LayoutRoot.Resources["TreeViewItemStyle"] as Style : null,
                };
                if (childResource.ResourceType == ResourceType.Layer || childResource.ResourceType == ResourceType.EditableLayer)
                {
                    treeViewItem.SetValue(ToolTipService.ToolTipProperty, childResource.ResourceType == ResourceType.Layer ? Strings.MapLayer : Strings.FeatureLayer);
                }
                if (!string.IsNullOrWhiteSpace(childResource.DisplayName))
                {
                    string parentAutomationId = tvi.GetValue(System.Windows.Automation.AutomationProperties.AutomationIdProperty) as string;
                    if (parentAutomationId == null)
                        parentAutomationId = string.Empty;
                    treeViewItem.SetValue(System.Windows.Automation.AutomationProperties.AutomationIdProperty, parentAutomationId + childResource.DisplayName + childResource.ResourceType);
                }

                bool hasChildResource = dataSource.SupportsChildResources(childResource, filter);
                if (hasChildResource)
                {
                    treeViewItem.Items.Add(createRetrievingNode());
                    treeViewItem.Expanded += new RoutedEventHandler(resourceNode_Expanded);
                }

                // If a child Id was successfully extracted from the parent resource, this means there should be a child
                // resource with the same id and we need to select this as the initial URL indicated the desire to use
                // this child resource.
                if (!String.IsNullOrEmpty(childName))
                {
                    if (childResource.ResourceType == ResourceType.GPTool || childResource.ResourceType == ResourceType.DatabaseTable)
                    {
                        if (String.Compare(childName, childResource.DisplayName) == 0)
                            treeViewItem.IsSelected = true;
                    }
                    else if (childResource.ResourceType == ResourceType.Layer)
                    {
                        if (childResource.Tag != null)
                        {
                            int nodeId = (int)childResource.Tag;
                            string nodeName = String.Format("{0}", nodeId);
                            if (String.Compare(childName, nodeName) == 0)
                                treeViewItem.IsSelected = true;
                        }
                    }
                }

                tvi.Items.Add(treeViewItem);
            }

            if (tvi.Items.Count == 0)
            {
                TreeViewItem treeViewItem = CreateTreeNodeWhenNoItems();
                tvi.Items.Add(treeViewItem);
            }

            OnGetChildResourcesCompleted(e);
        }