Exemplo n.º 1
0
        protected virtual void OnTupleValueChangedFromInput(TTupleViewsHolder tupleVH, TupleValueViewsHolder tupleValueVH, object newValue)
        {
            int    columnIndex = tupleValueVH.ItemIndex;
            var    column      = Columns.GetColumnState(columnIndex);
            var    tuple       = Tuples.GetTuple(tupleVH.ItemIndex);
            object valueToSet  = null;
            string asStr;
            bool   setValue      = false;
            bool   forceUpdateVH = false;

            switch (column.Info.ValueType)
            {
            case TableValueType.RAW:
                valueToSet = newValue;
                setValue   = true;
                break;

            case TableValueType.STRING:
                asStr = newValue as string;
                if (asStr == null)
                {
                    return;
                }

                forceUpdateVH = true;

                valueToSet = asStr;
                setValue   = true;
                break;

            case TableValueType.INT:
                asStr = newValue as string;
                if (asStr == null)
                {
                    return;
                }

                forceUpdateVH = true;

                int asInt;
                if (!int.TryParse(asStr, out asInt) /*invalid*/)
                {
                    // Resetting the original value
                    break;
                }

                // Commented code kept to aknowledge this case. Same may happen to long, float, double
                //if (asInt.ToString() != asStr /*valid, but resolved to a different value (for example, -0123 is valid, but resolves to -123)*/)
                //{
                //	// Changing the vh value to the new resolved number, but also allowing setValue=true below,
                //	// beacause the model also needs to be updated with the new resolved value, which is different
                //	forceUpdateVH = true;
                //}

                valueToSet = asInt;
                setValue   = true;
                break;

            case TableValueType.LONG_INT:
                asStr = newValue as string;
                if (asStr == null)
                {
                    return;
                }

                forceUpdateVH = true;

                long asLong;
                if (!long.TryParse(asStr, out asLong) /*invalid*/)
                {
                    // Resetting the original value
                    break;
                }

                //if (asLong.ToString() != asStr /*valid, but resolved to a different value (for example, -0123 is valid, but resolves to -123)*/)
                //{
                //	// Changing the vh value to the new resolved number, but also allowing setValue=true below,
                //	// beacause the model also needs to be updated with the new resolved value, which is different
                //	forceUpdateVH = true;
                //}

                valueToSet = asLong;
                setValue   = true;
                break;

            case TableValueType.FLOAT:
                asStr = newValue as string;
                if (asStr == null)
                {
                    return;
                }

                forceUpdateVH = true;

                float asFloat;
                if (!float.TryParse(asStr, out asFloat) /*invalid*/)
                {
                    // Resetting the original value
                    break;
                }

                valueToSet = asFloat;
                setValue   = true;
                break;

            case TableValueType.DOUBLE:
                asStr = newValue as string;
                if (asStr == null)
                {
                    return;
                }

                forceUpdateVH = true;

                double asDouble;
                if (!double.TryParse(asStr, out asDouble) /*invalid*/)
                {
                    // Resetting the original value
                    break;
                }

                valueToSet = asDouble;
                setValue   = true;
                break;

            // Enums are set via dropdown and expected to always be valid (or null)
            case TableValueType.ENUMERATION:
                forceUpdateVH = true;
                valueToSet    = newValue;
                setValue      = true;

                break;

            case TableValueType.BOOL:
                if (newValue != null && !(newValue is bool))
                {
                    return;
                }

                forceUpdateVH = true;
                valueToSet    = newValue;
                setValue      = true;
                break;

            // Textures aren't handled (can't change)
            //case TableValueType.TEXTURE:
            //	break;

            default:
                return;
            }

            if (setValue)
            {
                SetTupleValueAndResetColumnSortingIfNeeded(tuple, columnIndex, valueToSet);
            }
            if (forceUpdateVH)
            {
                tupleVH.Adapter.ForceUpdateValueViewsHolder(tupleValueVH);
            }
        }
Exemplo n.º 2
0
        protected virtual void OnHeaderColumnClicked(THeaderTupleViewsHolder headerTupleVH, TupleValueViewsHolder columnValueVH)
        {
            int columnIndex = columnValueVH.ItemIndex;

            if (Options != null && Options.IsClearing)
            {
                if (!Tuples.ColumnClearingSupported)
                {
                    return;
                }

                // The tuple provider may have its own way of clearing the entire column, which could be more optimized
                Tuples.SetAllValuesOnColumn(columnIndex, null);
                for (int i = 0; i < _VisibleItemsCount; i++)
                {
                    var tupleVH = GetItemViewsHolder(i);
                    tupleVH.Adapter.ForceUpdateValueViewsHolderIfVisible(columnIndex);
                }

                SetColumnSorting(columnIndex, TableValueSortType.NONE);
                return;
            }

            if (!Tuples.ColumnSortingSupported)
            {
                return;
            }

            var columnState = Columns.GetColumnState(columnIndex);

            // If current is raw or descending, set to ascending. Otherwise, to descending
            TableValueSortType nextSorting;

            if (columnState.CurrentSortingType == TableValueSortType.ASCENDING)
            {
                nextSorting = TableValueSortType.DESCENDING;
            }
            else
            {
                nextSorting = TableValueSortType.ASCENDING;
            }

            bool done = Tuples.ChangeColumnSortType(columnIndex, columnState.Info.ValueType, columnState.CurrentSortingType, nextSorting);

            if (!done)
            {
                return;
            }

            // Update: this is already done as a result or Refresh
            //// Change all other columns' stored sorting type to NONE
            //for (int i = 0; i < _Columns.ColumnsCount; i++)
            //{
            //	if (i == columnIndex)
            //		continue;

            //	SetColumnSorting(i, TableValueSortType.NONE);
            //}

            Refresh();

            // Setting column sorting after Refresh, because it's reset in ChangeItemsCount by design
            SetColumnSorting(columnIndex, nextSorting);
        }
Exemplo n.º 3
0
        //void OnTupleValueChangedFromInput(TTupleViewsHolder tupleVH, TupleValueViewsHolder tupleValueVH, object newValue)
        //{
        //	var columnIndex = tupleValueVH.ItemIndex;
        //	var tupleModel = _TupleProvider.GetTuple(tupleVH.ItemIndex);
        //	SetTupleValueAndResetColumnSortingIfNeeded(tupleModel, columnIndex, newValue);
        //	tupleVH.Adapter.ForceUpdateValueViewsHolder(tupleValueVH);
        //}

        protected virtual void OnTupleValueClicked(TTupleViewsHolder tupleVH, TupleValueViewsHolder tupleValueVH)
        {
            var columnIndex = tupleValueVH.ItemIndex;
            var column      = Columns.GetColumnState(columnIndex);

            if (!column.CurrentlyReadOnly)
            {
                if (Options != null && Options.IsClearing)
                {
                    ClearValue(tupleVH.ItemIndex, columnIndex);
                    return;
                }

                bool   multiLineTextInput   = false;
                bool   showInputText        = false;
                string defaultValueAsString = "";
                switch (column.Info.ValueType)
                {
                case TableValueType.STRING:
                    multiLineTextInput = true;
                    showInputText      = true;
                    break;

                case TableValueType.BOOL:
                    if (Tuples.GetTuple(tupleVH.ItemIndex).GetValue(columnIndex) == null)
                    {
                        OnTupleValueChangedFromInput(tupleVH, tupleValueVH, false);
                    }
                    return;

                case TableValueType.INT:
                case TableValueType.LONG_INT:
                case TableValueType.FLOAT:
                case TableValueType.DOUBLE:
                    defaultValueAsString = "0";
                    showInputText        = true;
                    break;

                case TableValueType.ENUMERATION:
                    var dropdown = GetOrInstantiateFloatingDropdown();
                    if (dropdown)
                    {
                        // Make sure the panel won't be displaced from the value box
                        StopMovementOfAllVisibleTupleVHs();
                        StopMovement();

                        int invalidValue = int.MinValue;
                        dropdown.InitWithEnum(column.Info.EnumValueType);
                        dropdown.ShowFloating(
                            tupleValueVH.root,
                            selectedValue =>
                        {
                            int selectionInt = (int)selectedValue;
                            if (selectionInt == invalidValue)
                            {
                                return;
                            }

                            //var tupleModel = _TupleProvider.GetTuple(tupleVH.ItemIndex);
                            //SetTupleValueAndResetColumnSortingIfNeeded(tupleModel, columnIndex, selectedValue);
                            //tupleVH.Adapter.ForceUpdateValueViewsHolder(tupleValueVH);
                            OnTupleValueChangedFromInput(tupleVH, tupleValueVH, selectedValue);
                        },
                            invalidValue
                            );
                    }
                    return;
                }
                if (showInputText)
                {
                    var input = GetOrInstantiateTextInputController();
                    if (input)
                    {
                        // Make sure the panel won't be displaced from the value box
                        StopMovementOfAllVisibleTupleVHs();
                        StopMovement();

                        // Initial value same as the current one, which is expected to be the exact one from the model
                        var    curValue               = Tuples.GetTuple(tupleVH.ItemIndex).GetValue(columnIndex);
                        bool   curValueNull           = curValue == null;
                        var    textComponentOnValueVH = tupleValueVH.TextComponent;
                        string initialText            = curValueNull ? defaultValueAsString : textComponentOnValueVH.text;

                        float prevAlpha        = textComponentOnValueVH.SetAlpha(0f);
                        bool  supportsRichText = textComponentOnValueVH.supportRichText;
                        textComponentOnValueVH.supportRichText = false;                         // override any current color, otherwise alpha doesn't have any effect
                        input.fontSize = textComponentOnValueVH.fontSize;
                        input.ShowFloating(
                            textComponentOnValueVH.RT,
                            initialText,
                            multiLineTextInput,
                            text =>
                        {
                            textComponentOnValueVH.SetAlpha(prevAlpha);
                            // Update: actually, this is not needed, as we'll have a valid value anyway
                            //tupleValueVH.TextComponent.supportRichText = supportsRichText;
                            OnTupleValueChangedFromInput(tupleVH, tupleValueVH, text);
                        },
                            () =>
                        {
                            textComponentOnValueVH.SetAlpha(prevAlpha);
                        }
                            );
                    }

                    return;
                }
            }
            tupleValueVH.ProcessUnhandledClick();
        }