Add TC to test InsertBefore operation of GenList with full style
[platform/core/csapi/elm-sharp.git] / ElmSharp.Test / TC / GenListTest10.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 System.Collections.Generic;
19 using ElmSharp;
20
21 namespace ElmSharp.Test
22 {
23     class GenListTest10 : TestCaseBase
24     {
25         public override string TestName => "GenListTest10";
26         public override string TestDescription => "To test InsertBefore operation of GenList with full style";
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             {
34                 AlignmentX = -1,
35                 AlignmentY = -1,
36                 WeightX = 1,
37                 WeightY = 1,
38             };
39             box.Show();
40             conformant.SetContent(box);
41
42             GenList list = new GenList(window)
43             {
44                 Homogeneous = false,
45                 AlignmentX = -1,
46                 AlignmentY = -1,
47                 WeightX = 1,
48                 WeightY = 1
49             };
50
51             GenItemClass defaultClass = new GenItemClass("full")
52             {
53                 GetContentHandler = (obj, part) =>
54                 {
55                     Console.WriteLine("{0} part create requested", part);
56                     var btn = new Button(window)
57                     {
58                         Text = obj.ToString(),
59                         AlignmentX = -1,
60                         WeightX = 1,
61                     };
62                     return btn;
63                 }
64             };
65
66             GenItemClass headerClass = new GenItemClass("full")
67             {
68                 GetContentHandler = (obj, part) =>
69                 {
70                     Console.WriteLine("{0} part create requested", part);
71                     var btn = new Button(window)
72                     {
73                         Text = obj.ToString(),
74                         AlignmentX = -1,
75                         WeightX = 1,
76                     };
77                     btn.Show();
78
79                     var label = new Label(window)
80                     {
81                         Text = "GenItem with full style"
82                     };
83                     label.Show();
84
85                     Box hBox = new Box(window)
86                     {
87                         AlignmentX = -1,
88                         AlignmentY = -1,
89                         WeightX = 1,
90                         WeightY = 1,
91                     };
92                     hBox.Show();
93                     hBox.PackEnd(btn);
94                     hBox.PackEnd(label);
95                     return hBox;
96                 }
97
98             };
99
100             List<GenListItem> itemList = new List<GenListItem>();
101             GenListItem firstItem = null;
102
103             for (int i = 0; i < 5; i++)
104             {
105                 GenListItem now = list.Append(defaultClass, string.Format("{0} Item", i));
106                 itemList.Add(now);
107
108                 if (firstItem == null)
109                 {
110                     firstItem = now;
111                 }
112             }
113             list.Show();
114             list.ItemSelected += List_ItemSelected;
115             box.PackEnd(list);
116
117             Button first = new Button(window)
118             {
119                 Text = "First",
120                 AlignmentX = -1,
121                 WeightX = 1,
122             };
123             Button last = new Button(window)
124             {
125                 Text = "last",
126                 AlignmentX = -1,
127                 WeightX = 1,
128             };
129
130             first.Clicked += (s, e) =>
131             {
132                 firstItem = list.InsertBefore(headerClass, "Header", firstItem);
133             };
134             last.Clicked += (s, e) =>
135             {
136                 list.Append(headerClass, "Footer");
137             };
138
139             first.Show();
140             last.Show();
141             box.PackEnd(first);
142             box.PackEnd(last);
143         }
144
145         private void List_ItemSelected(object sender, GenListItemEventArgs e)
146         {
147             Console.WriteLine("{0} Item was selected", (string)(e.Item.Data));
148         }
149     }
150 }