#nullable enable using System.Collections.Generic; using System.Linq; namespace UVC.UIToolkit { /// /// 다중 선택 드롭다운 속성 데이터 클래스입니다. /// UI는 UTKMultiSelectDropdownPropertyItemView에서 담당합니다. /// public class UTKMultiSelectDropdownPropertyItem : UTKPropertyItemBase> { #region Fields private List _choices; #endregion #region Properties /// 속성 타입 public override UTKPropertyType PropertyType => UTKPropertyType.MultiSelectDropdownList; /// 선택 가능한 항목 목록 public List Choices { get => _choices; set => _choices = value ?? new List(); } /// 선택된 인덱스 목록 public List SelectedIndices { get { if (Value == null || Value.Count == 0) return new List(); return Value .Select(v => _choices.IndexOf(v)) .Where(i => i >= 0) .OrderBy(i => i) .ToList(); } } #endregion #region Constructor /// /// 다중 선택 드롭다운 속성을 생성합니다. /// /// 고유 ID /// 표시 이름 /// 선택 항목 목록 /// 초기 선택 값 목록 /// 읽기 전용 여부 /// 라벨 표시 여부 public UTKMultiSelectDropdownPropertyItem( string id, string name, List choices, List? initialValues = null, bool isReadOnly = false, bool showLabel = true) : base(id, name, initialValues ?? new List()) { _choices = choices ?? new List(); // initialValues가 유효한지 확인하고 필터링 if (initialValues != null && initialValues.Count > 0) { var validValues = initialValues.Where(v => _choices.Contains(v)).ToList(); _value = validValues; } _isReadOnly = isReadOnly; _showLabel = showLabel; } /// /// 다중 선택 드롭다운 속성을 생성합니다 (인덱스 기반). /// /// 고유 ID /// 표시 이름 /// 선택 항목 목록 /// 초기 선택 인덱스 목록 /// 읽기 전용 여부 /// 라벨 표시 여부 public UTKMultiSelectDropdownPropertyItem( string id, string name, IEnumerable choices, IEnumerable? selectedIndices = null, bool isReadOnly = false, bool showLabel = true) : base(id, name, new List()) { _choices = choices?.ToList() ?? new List(); if (selectedIndices != null) { var validValues = selectedIndices .Where(i => i >= 0 && i < _choices.Count) .Select(i => _choices[i]) .ToList(); _value = validValues; } _isReadOnly = isReadOnly; _showLabel = showLabel; } #endregion #region Public Methods /// 선택 항목 추가 public void AddChoice(string choice) { if (!_choices.Contains(choice)) { _choices.Add(choice); } } /// 선택 항목 제거 public bool RemoveChoice(string choice) { bool removed = _choices.Remove(choice); if (removed && Value != null && Value.Contains(choice)) { // 값 목록에서도 제거 var newValue = Value.Where(v => v != choice).ToList(); Value = newValue; } return removed; } /// 인덱스로 선택 설정 public void SetSelectedIndices(List indices) { var validValues = indices .Where(i => i >= 0 && i < _choices.Count) .Select(i => _choices[i]) .Distinct() .ToList(); Value = validValues; } /// 값으로 선택 설정 public void SetSelectedValues(List values) { var validValues = values .Where(v => _choices.Contains(v)) .Distinct() .ToList(); Value = validValues; } /// 모든 항목 선택 public void SelectAll() { Value = new List(_choices); } /// 모든 선택 해제 public void ClearSelection() { Value = new List(); } #endregion } }