Merge "[Telephony] Sample App implementation."
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / GenListTest7.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using ElmSharp;
19 using System.Collections.Generic;
20
21 namespace ElmSharp.Test
22 {
23     class GenListTest7 : TestCaseBase
24     {
25         public override string TestName => "GenListTest7";
26         public override string TestDescription => "To test basic operation of GenList";
27
28         public override void Run(Window window)
29         {
30             Conformant conformant = new Conformant(window);
31             conformant.Show();
32             Box box = new Box(window);
33             conformant.SetContent(box);
34             box.Show();
35
36             GenList list = new GenList(window)
37             {
38                 Homogeneous = true,
39                 AlignmentX = -1,
40                 AlignmentY = -1,
41                 WeightX = 1,
42                 WeightY = 1
43             };
44
45             Button button = new Button(window)
46             {
47                 Text = "Remove",
48                 AlignmentX = -1,
49                 AlignmentY = -1,
50             };
51
52             GenItemClass defaultClass = new GenItemClass("default")
53             {
54                 GetTextHandler = (obj, part) =>
55                 {
56                     return string.Format("{0} - {1}",(string)obj, part);
57                 }
58             };
59
60             GenListItem[] itemArr = new GenListItem[9];
61             for (int i = 0; i < 9; i++)
62             {
63                 itemArr[i] = list.Append(defaultClass, string.Format("{0} Item", i));
64             }
65
66             int idx = 0;
67             button.Clicked += (s, e) =>
68             {
69                 if (idx < 9) {
70                     Console.WriteLine("GenListItem deleted");
71                     itemArr[idx++].Delete();
72                 }
73             };
74             button.Show();
75
76             list.Show();
77             list.ItemSelected += List_ItemSelected;
78             list.ItemRealized += List_ItemRealized;
79             list.ItemUnrealized += List_ItemUnrealized;
80
81             box.PackEnd(list);
82             box.PackEnd(button);
83         }
84
85         private void List_ItemSelected(object sender, GenListItemEventArgs e)
86         {
87             Console.WriteLine("{0} Item was selected", (string)(e.Item.Data));
88         }
89         private void List_ItemRealized(object sender, GenListItemEventArgs e)
90         {
91             Console.WriteLine("{0} Item was realized", (string)(e.Item.Data));
92         }
93         private void List_ItemUnrealized(object sender, GenListItemEventArgs e)
94         {
95             Console.WriteLine("{0} Item was unrealized", (string)(e.Item.Data));
96         }
97     }
98 }