Ejemplo n.º 1
0
        /// <summary>
        /// Counts the number of all collection items of node output and if specified
        /// it generates appropriate view model for compact preview bubble
        /// </summary>
        /// <param name="mirrorData">Data which represents the value of node output</param>
        /// <param name="generateViewModel">Flag to not create unused view models</param>
        /// <returns><cref name="CompactBubbleViewModel"/> instance
        /// if <paramref name="generateViewModel"/> is specified. Otherwise, null</returns>
        private static CompactBubbleViewModel ProcessThing(MirrorData mirrorData, bool generateViewModel)
        {
            if (mirrorData == null)
            {
                return(generateViewModel ? new CompactBubbleViewModel(Resources.NullString, 0) : null);
            }

            if (mirrorData.IsCollection)
            {
                var list = mirrorData.GetElements();

                foreach (var item in list)
                {
                    ProcessThing(item, false);
                }

                return(generateViewModel
                    ? new CompactBubbleViewModel(true)
                {
                    NodeLabel = list.Any() ? WatchViewModel.LIST : WatchViewModel.EMPTY_LIST
                }
                    : null);
            }

            items++;

            if (!generateViewModel)
            {
                return(null);
            }

            var viewModel = new CompactBubbleViewModel(false);

            if (mirrorData.Data == null && !mirrorData.IsNull && mirrorData.Class != null)
            {
                viewModel.NodeLabel = mirrorData.Class.ClassName;
            }
            else if (mirrorData.Data is Enum)
            {
                viewModel.NodeLabel = ((Enum)mirrorData.Data).GetDescription();
            }
            else
            {
                // Cut StringData so that only the type name remains
                // for example, "Point (Z = 0.000, Y = 0.000, Z = 0.000)" -> "Point"
                viewModel.NodeLabel = string.IsNullOrEmpty(mirrorData.StringData)
                    ? string.Empty
                    : mirrorData.StringData.Split('(')[0];
            }

            return(viewModel);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Obtain the condensed preview values for this control.  Must not be called from
        /// Scheduler thread or this could cause a live-lock.
        /// </summary>
        /// <param name="refreshDisplay">The action to refresh the UI</param>
        private void RefreshCondensedDisplay(Action refreshDisplay)
        {
            // The preview control will not have its content refreshed unless
            // the content is null. In order to perform real refresh, new data
            // source needs to be rebound to the preview control by calling
            // BindToDataSource method.
            //
            if (cachedSmallContent != null)
            {
                // If there are cached contents, simply update the UI and return
                if (refreshDisplay != null)
                {
                    refreshDisplay();
                }
                return;
            }

            CompactBubbleViewModel newContent = null;

            RunOnSchedulerSync(
                () =>
            {
                var mirrorData = nodeViewModel.NodeModel.CachedValue;
                newContent     = CompactBubbleHandler.Process(mirrorData);
            },
                (m) =>
            {
                cachedSmallContent           = newContent;
                var smallContentView         = smallContentGrid.Children[0] as PreviewCompactView;
                smallContentView.DataContext = cachedSmallContent;

                if (refreshDisplay != null)
                {
                    refreshDisplay();
                }
            }
                );
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Bind a mirror data to the preview control for display, this call
        /// unbinds the internal data structure from the view that it was
        /// originally bound to and resets the data structure. If this call is
        /// made while the preview control is in condensed or expanded state,
        /// the display will immediately be refreshed. Since this method deals
        /// with UI elements internally, it must be called from the UI thread.
        /// </summary>
        internal void BindToDataSource()
        {
            // First detach the bound data from its view.
            ResetContentViews();

            // Reset expanded content.
            cachedLargeContent = null;
            // Reset condensed content.
            cachedSmallContent = null;

            // If at the time of data binding the preview control is within the
            // following states, then its contents need to be updated immediately.
            if (IsCondensed)
            {
                RefreshCondensedDisplay(null);
            }
            else if (IsExpanded)
            {
                RefreshExpandedDisplay(RefreshExpandedDisplayAction);
            }

            IsDataBound = true;
        }