Ejemplo n.º 1
0
        static JsonTreeViewItem addToJsonTree(JsonTreeViewItem parent_tvi, JToken jtok)
        {
            if (jtok is JObject)
            {
                JObject jobj = jtok as JObject;
                if (jobj.Parent == null)
                {
                    return(parent_tvi);
                }
                if (jobj.Parent != null && jobj.Parent is JArray)
                {
                    JsonTreeViewItem child_tvi = new JsonTreeViewItem();
                    parent_tvi.AddItem(child_tvi);
                    KeyTextBox tb_key = new KeyTextBox((jobj.Parent as JArray).IndexOf(jobj).ToString(), false);
                    child_tvi.Header.AddItem(tb_key);
                    child_tvi.type = JsonType.JObject;
                    parent_tvi     = child_tvi;
                }

                KeyTextBox tb_type = new KeyTextBox("object", false);
                parent_tvi.Header.AddItem(tb_type);
                parent_tvi.type = JsonType.JObject;
                return(parent_tvi);
            }
            else if (jtok is JProperty)
            {
                JProperty        jprop     = jtok as JProperty;
                JsonTreeViewItem child_tvi = new JsonTreeViewItem();
                parent_tvi.AddItem(child_tvi);

                KeyTextBox tb_key = new KeyTextBox(jprop.Name);
                child_tvi.Header.AddItem(tb_key);

                return(child_tvi);
            }
            else if (jtok is JValue)
            {
                JValue jval = jtok as JValue;

                string       data     = jval.ToString();
                ValueTextBox tb_value = new ValueTextBox(data);
                parent_tvi.Header.AddItem(tb_value);

                parent_tvi.Header.addButtn.Visibility = Visibility.Hidden;
                //parent_tvi.Items.Clear();
                return(parent_tvi);
            }
            else if (jtok is JArray)
            {
                KeyTextBox tb_type = new KeyTextBox("array", false);
                parent_tvi.Header.AddItem(tb_type);
                parent_tvi.type = JsonType.JArray;
                return(parent_tvi);
            }
            else
            {
                Console.WriteLine("[error] undefined type = " + jtok.GetType());
                return(parent_tvi);
            }
        }
Ejemplo n.º 2
0
        // Json 버튼은 JsonTreeViewItem.Header.children 에 존재
        protected override void OnClick()
        {
            base.OnClick();
            JsonTreeViewItemHeader jtvih = this.Parent as JsonTreeViewItemHeader;

            if (jtvih == null)
            {
                return;
            }
            JsonTreeViewItem jtvi = jtvih.Parent as JsonTreeViewItem;

            if (jtvi == null)
            {
                return;
            }

            if (jtvi.type == JsonTreeViewItem.JsonType.JArray)
            {
                JsonTreeViewItem child_tvi = new JsonTreeViewItem();
                KeyTextBox       tb_key    = new KeyTextBox(jtvi.getCountChildProperty().ToString(), false);
                child_tvi.Header.AddItem(tb_key);
                KeyTextBox tb_type = new KeyTextBox("object", false);
                child_tvi.Header.AddItem(tb_type);
                child_tvi.type = JsonTreeViewItem.JsonType.JObject;

                jtvi.AddItem(child_tvi);
            }
            else
            {
                // window_addJson showdialog()
                Window_AddJsonItem popup = new Window_AddJsonItem();
                Point pt = this.PointToScreen(new Point(0, 0));
                popup.Left = pt.X;
                popup.Top  = pt.Y;

                // cancel return
                if (popup.ShowDialog() != true)
                {
                    return;
                }

                JsonTreeViewItem.convertToTreeView_recursive(jtvi, new JProperty(popup.key, popup.value));
            }

            //JToken tmp = jtvi.Parent;
            //// tmp == root 일때
            //if(tmp is JObject)
            //	;
            //else
            //{
            //	JProperty jprop = tmp as JProperty;
            //	tmp = jprop.Value;
            //}
            //JToken add_jtok = null;
            //if(tmp is JArray)
            //{
            //	JArray jarr = tmp as JArray;
            //	// add Jtok_root
            //	add_jtok = new JObject();
            //	jarr.Add(add_jtok);
            //}
            //else if(tmp is JObject)
            //{
            //	JObject jobj = tmp as JObject;
            //	// window_addJson showdialog()
            //	popup_AddJsonItem popup = new popup_AddJsonItem();
            //	Point pt = sender.PointToScreen(new Point(0, 0));
            //	popup.Left = pt.X;
            //	popup.Top = pt.Y;

            //	// cancel return
            //	if(popup.ShowDialog() != true)
            //		return;

            //	foreach(JProperty v in jobj.Properties())
            //	{
            //		// 키 중복
            //		if(v.Name == popup.key)
            //			return;
            //	}

            //	// ok return & add Jtok_root
            //	add_jtok = new JProperty(popup.key, popup.value);
            //	jobj.Add(add_jtok);

            //}

            //// add to jtree_root
            //if(add_jtok != null)
            //	makeTree(this, add_jtok);
            ////tvi.Add(sender as JsonButton, convertToTreeView_recursive);
            ////FileContoller.write(JSonInfo.current.filename, JSonInfo.current.jtok_root.ToString());
        }
Ejemplo n.º 3
0
        public void PublicDrop(DragEventArgs e)
        {
            base.OnDrop(e);

            // bubble (자식부터 부모요소로 이벤트 전달 방식) 이므로 처음 수행할때 (제일 자식에서 이벤트를 받았을 때), 이벤트 수행처리.
            e.Handled = true;

            // If the DataObject contains string data, extract it.
            if (e.Data.GetDataPresent("Object"))
            {
                Object data_obj = (Object)e.Data.GetData("Object");

                JsonTreeViewItem tvi_src = data_obj as JsonTreeViewItem;
                if (tvi_src == null)
                {
                    return;
                }

                // dst 의 조상중에 src 가 있나 체크 & dst == src 인지 체크
                JsonTreeViewItem tmp_parent = this;
                while (tmp_parent != null)
                {
                    if (tmp_parent == tvi_src)
                    {
                        return;
                    }

                    tmp_parent = tmp_parent.Parent as JsonTreeViewItem;
                }

                JsonTreeViewItem tvi_parent     = this.Parent as JsonTreeViewItem;
                JsonTreeViewItem tvi_src_parent = tvi_src.Parent as JsonTreeViewItem;
                if (tvi_parent == null || tvi_src_parent == null)
                {
                    return;
                }

                // JArray 타입과 다른타입과는 드래그앤드롭 불가. (src==JArray && dst==JArray) 이거나 (src != JArray && dst==JArray) 일떄 수행
                if ((tvi_parent.type == JsonType.JArray && tvi_src_parent.type != JsonType.JArray) ||
                    (tvi_parent.type != JsonType.JArray && tvi_src_parent.type == JsonType.JArray))
                {
                    return;
                }

                // 중복 체크
                if (tvi_parent.type != JsonType.JArray && tvi_src_parent.type != JsonType.JArray &&
                    tvi_parent != tvi_src_parent &&
                    tvi_parent.checkDuplication(tvi_src) < 0)
                {
                    return;
                }

                // remove
                bool ischecked_more_button = false;
                if (tvi_parent.button_more != null)
                {
                    ischecked_more_button = tvi_parent.button_more.IsChecked.Value;
                }

                int idx_insert = tvi_parent.Items.IndexOf(this);
                tvi_src.Remove();

                // insert
                tvi_parent.AddItem(tvi_src, idx_insert);
                if (tvi_parent.button_more != null)
                {
                    tvi_parent.button_more.IsChecked = ischecked_more_button;
                }
            }
        }
Ejemplo n.º 4
0
        static JsonTreeViewItem addToJsonTree(JsonTreeViewItem parent_tvi, JToken jtok)
        {
            if (jtok is JObject)
            {
                JObject jobj = jtok as JObject;
                if (jobj.Parent == null)
                {
                    return(parent_tvi);
                }
                if (jobj.Parent != null && jobj.Parent is JArray)
                {
                    JsonTreeViewItem child_tvi = new JsonTreeViewItem();
                    parent_tvi.AddItem(child_tvi);
                    KeyTextBox tb_key = new KeyTextBox((jobj.Parent as JArray).IndexOf(jobj).ToString(), false);
                    child_tvi.Header.AddItem(tb_key);
                    child_tvi.value_token_type = JTokenType.Object;
                    parent_tvi = child_tvi;
                }

                //KeyTextBox tb_type = new KeyTextBox("object", false);
                //parent_tvi.Header.AddItem(tb_type);
                //parent_tvi.value_token_type = JTokenType.Object;
                //return parent_tvi;
                ValuePanel panel_value = new ValuePanel(JTokenType.Object, "object");
                parent_tvi.Header.AddItem(panel_value);
                parent_tvi.value_token_type = JTokenType.Object;
                return(parent_tvi);
            }
            else if (jtok is JProperty)
            {
                JProperty        jprop     = jtok as JProperty;
                JsonTreeViewItem child_tvi = new JsonTreeViewItem();
                parent_tvi.AddItem(child_tvi);

                KeyTextBox tb_key = new KeyTextBox(jprop.Name);
                child_tvi.Header.AddItem(tb_key);

                return(child_tvi);
            }
            else if (jtok is JValue)
            {
                JValue     jval        = jtok as JValue;
                ValuePanel panel_value = new ValuePanel(jval.Type, jval.Value);
                parent_tvi.Header.AddItem(panel_value);
                parent_tvi.value_token_type = jval.Type;

                parent_tvi.Header.addButtn.Visibility = Visibility.Hidden;
                //parent_tvi.Items.Clear();
                return(parent_tvi);
            }
            else if (jtok is JArray)
            {
                //KeyTextBox tb_type = new KeyTextBox("array", false);
                //parent_tvi.Header.AddItem(tb_type);
                //parent_tvi.value_token_type = JTokenType.Array;
                //return parent_tvi;
                ValuePanel panel_value = new ValuePanel(JTokenType.Array, "array");
                parent_tvi.Header.AddItem(panel_value);
                parent_tvi.value_token_type = JTokenType.Array;
                return(parent_tvi);
            }
            else
            {
                Log.Print("[error] undefined type = " + jtok.GetType());
                return(parent_tvi);
            }
        }