[NUI] Add Component Application (#1148)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / NUIComponentApplication.cs
1 /*
2  * Copyright (c) 2019 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 System.ComponentModel;
20 using Tizen.Applications;
21 using Tizen.Applications.ComponentBased;
22 using Tizen.Applications.ComponentBased.Common;
23 using Tizen.NUI.BaseComponents;
24
25 namespace Tizen.NUI
26 {
27
28     /// <summary>
29     /// The class for supporting multi-components application model.
30     /// </summary>
31     [EditorBrowsable(EditorBrowsableState.Never)]
32     public class NUIComponentApplication : CoreApplication
33     {
34         private Dictionary<Type, ComponentStateManger> _componentFactories = new Dictionary<Type, ComponentStateManger>();
35
36         /// <summary>
37         /// Initializes the ComponentApplication class.
38         /// </summary>
39         /// <param name="typeInfo">The component type information.
40         /// The key should be a class type of FrameComponent or SubComponent subclass.
41         /// The value should be a component id which is declared in tizen-manifest.xml.
42         /// </param>
43         [EditorBrowsable(EditorBrowsableState.Never)]
44         public NUIComponentApplication(IDictionary<Type, string> typeInfo) : base(new NUIComponentCoreBackend())
45         {
46             foreach (var component in typeInfo)
47             {
48                 RegisterComponent(component.Key, component.Value);
49             }
50             (Backend as NUIComponentCoreBackend).ComponentFactories = _componentFactories;
51         }
52
53         /// <summary>
54         /// Registers a component.
55         /// </summary>
56         /// <param name="compType">Class type</param>
57         /// <param name="compId">Component ID</param>
58         /// <exception cref="ArgumentException">Thrown when component type is already added or not sub-class of FrameComponent or ServiceComponent</exception>
59         [EditorBrowsable(EditorBrowsableState.Never)]
60         public void RegisterComponent(Type compType, string compId)
61         {
62             if (_componentFactories.ContainsKey(compType))
63             {
64                 throw new ArgumentException("Already exist type");
65             }
66
67             if (typeof(FrameComponent).IsAssignableFrom(compType))
68             {
69                 _componentFactories.Add(compType, new FrameComponentStateManager(compType, compId, null));
70             }
71             else if (typeof(ServiceComponent).IsAssignableFrom(compType))
72             {
73                 _componentFactories.Add(compType, new ServiceComponentStateManager(compType, compId, null));
74             }
75             else
76             {
77                 throw new ArgumentException("compType must be sub type of FrameComponent or ServiceComponent", "compType");
78             }
79         }
80
81
82         /// <summary>
83         /// Runs the application's main loop.
84         /// </summary>
85         /// <param name="args">Arguments from commandline.</param>
86         /// <exception cref="InvalidOperationException">Thrown when component type is already added to the component.</exception>
87         [EditorBrowsable(EditorBrowsableState.Never)]
88         public override void Run(string[] args)
89         {
90             //Register Callback.
91             base.Run(args);
92         }
93
94         /// <summary>
95         /// Exits the main loop of the application.
96         /// </summary>
97         [EditorBrowsable(EditorBrowsableState.Never)]
98         public override void Exit()
99         {
100             base.Exit();
101         }
102
103         /// <summary>
104         /// This method will be called before running main-loop
105         /// </summary>
106         [EditorBrowsable(EditorBrowsableState.Never)]
107         protected override void OnCreate()
108         {
109             base.OnCreate();
110         }
111
112         /// <summary>
113         /// This method will be called after exiting main-loop
114         /// </summary>
115         [EditorBrowsable(EditorBrowsableState.Never)]
116         protected override void OnTerminate()
117         {
118             base.OnTerminate();
119         }
120     }
121 }
122