1 | /** |
2 | * Copyright 2005-2011 Steve McDuff d-duff@users.sourceforge.net |
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 | package org.deduced.viewer.web.client; |
17 | |
18 | import org.deduced.viewer.web.shared.DynamicUserInterfaceService; |
19 | import org.deduced.viewer.web.shared.DynamicUserInterfaceServiceAsync; |
20 | import org.deduced.viewer.web.shared.ModelRegistry; |
21 | import org.deduced.viewer.web.shared.RootWidgetControl; |
22 | import org.deduced.viewer.web.shared.Utilities; |
23 | import org.deduced.viewer.web.shared.WidgetModel; |
24 | |
25 | import com.google.gwt.core.client.EntryPoint; |
26 | import com.google.gwt.core.client.GWT; |
27 | import com.google.gwt.user.client.ui.RootPanel; |
28 | import com.google.gwt.user.client.ui.Widget; |
29 | |
30 | /** |
31 | * Entry point classes define <code>onModuleLoad()</code>. Starts the deduced |
32 | * web viewer application. |
33 | * |
34 | * @author Steve McDuff |
35 | */ |
36 | public class DeducedWebViewer implements EntryPoint, RootWidgetControl |
37 | { |
38 | |
39 | /** |
40 | * model registry used to create all the GWT components we need. |
41 | */ |
42 | private ModelRegistry registry; |
43 | |
44 | /** |
45 | * root widget |
46 | */ |
47 | private WidgetModel rootWidget; |
48 | |
49 | /** |
50 | * root panel |
51 | */ |
52 | private RootPanel rootPanel; |
53 | |
54 | /** |
55 | * Deduced_Web_Viewer constructor |
56 | */ |
57 | public DeducedWebViewer() |
58 | { |
59 | registry = createModelRegistry(); |
60 | registry.setRootWidgetControl(this); |
61 | DynamicUserInterfaceServiceAsync setDynamicViewService = |
62 | createServerInterface(); |
63 | registry.setUserInterfaceService(setDynamicViewService); |
64 | } |
65 | |
66 | /** |
67 | * create ModelRegistry |
68 | * |
69 | * @return the model registry |
70 | */ |
71 | public ModelRegistry createModelRegistry() |
72 | { |
73 | return new ModelRegistry(); |
74 | } |
75 | |
76 | /** |
77 | * create Server Interface |
78 | * |
79 | * @return the server interface |
80 | */ |
81 | public DynamicUserInterfaceServiceAsync createServerInterface() |
82 | { |
83 | DynamicUserInterfaceServiceAsync setDynamicViewService = |
84 | GWT.create(DynamicUserInterfaceService.class); |
85 | return setDynamicViewService; |
86 | } |
87 | |
88 | /** |
89 | * This is the entry point method. |
90 | */ |
91 | @Override |
92 | public void onModuleLoad() |
93 | { |
94 | registry.getInitialUserInterface(); |
95 | } |
96 | |
97 | /** |
98 | * get the model Registry |
99 | * |
100 | * @return the model registry |
101 | */ |
102 | public ModelRegistry getRegistry() |
103 | { |
104 | return registry; |
105 | } |
106 | |
107 | /** |
108 | * set Root Panel |
109 | * |
110 | * @param rootModel the root widget model to use |
111 | */ |
112 | @Override |
113 | public void setRootWidget( |
114 | WidgetModel rootModel) |
115 | { |
116 | rootWidget = rootModel; |
117 | if (rootPanel == null) |
118 | { |
119 | rootPanel = RootPanel.get("dynamicView"); |
120 | } |
121 | Widget setRootWidget = null; |
122 | if (rootModel != null) |
123 | { |
124 | setRootWidget = rootModel.getWidget(); |
125 | } |
126 | |
127 | if (setRootWidget == null) |
128 | { |
129 | if (rootPanel != null) |
130 | { |
131 | rootPanel.clear(); |
132 | } |
133 | } |
134 | else |
135 | { |
136 | Widget currentParent = setRootWidget.getParent(); |
137 | if (currentParent != rootPanel) |
138 | { |
139 | Utilities.addWidgetToPanel(setRootWidget, rootPanel); |
140 | } |
141 | } |
142 | } |
143 | |
144 | /** |
145 | * get Root Widget |
146 | * |
147 | * @return the root widget |
148 | */ |
149 | public WidgetModel getRootWidget() |
150 | { |
151 | return rootWidget; |
152 | } |
153 | |
154 | } |