/
KtunaxaEntryPoint.java
246 lines (214 loc) · 9.93 KB
/
KtunaxaEntryPoint.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
* Ktunaxa Referral Management System.
*
* Copyright (C) see version control system
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ktunaxa.referral.client;
import java.util.LinkedHashMap;
import org.geomajas.gwt.client.action.ToolCreator;
import org.geomajas.gwt.client.action.ToolbarBaseAction;
import org.geomajas.gwt.client.action.toolbar.ToolbarRegistry;
import org.geomajas.gwt.client.command.AbstractCommandCallback;
import org.geomajas.gwt.client.command.GwtCommand;
import org.geomajas.gwt.client.command.GwtCommandDispatcher;
import org.geomajas.gwt.client.command.event.TokenChangedEvent;
import org.geomajas.gwt.client.command.event.TokenChangedHandler;
import org.geomajas.gwt.client.map.event.MapModelChangedEvent;
import org.geomajas.gwt.client.map.event.MapModelChangedHandler;
import org.geomajas.gwt.client.map.layer.VectorLayer;
import org.geomajas.gwt.client.service.ClientConfigurationLoader;
import org.geomajas.gwt.client.service.ClientConfigurationService;
import org.geomajas.gwt.client.service.ClientConfigurationSetter;
import org.geomajas.gwt.client.util.WidgetLayout;
import org.geomajas.gwt.client.widget.MapWidget;
import org.geomajas.gwt.client.widget.attribute.AssociationItem;
import org.geomajas.gwt.client.widget.attribute.AttributeFormFieldRegistry;
import org.geomajas.gwt.client.widget.attribute.DataSourceFieldFactory;
import org.geomajas.gwt.client.widget.attribute.FormItemFactory;
import org.geomajas.plugin.printing.client.util.PrintingLayout;
import org.geomajas.plugin.staticsecurity.client.StaticSecurityTokenRequestHandler;
import org.geomajas.plugin.staticsecurity.client.util.SsecLayout;
import org.geomajas.widget.searchandfilter.client.util.GsfLayout;
import org.ktunaxa.referral.client.action.WmsFeatureInfoModalAction;
import org.ktunaxa.referral.client.action.ZoomCurrentReferralModalAction;
import org.ktunaxa.referral.client.action.ZoomKtunaxaTerritoryModalAction;
import org.ktunaxa.referral.client.gui.DocumentItem;
import org.ktunaxa.referral.client.gui.MapLayout;
import org.ktunaxa.referral.client.layer.ReferenceLayer;
import org.ktunaxa.referral.client.referral.MakeReferralCurrentModalAction;
import org.ktunaxa.referral.client.security.UserContext;
import org.ktunaxa.referral.client.widget.CommunicationHandler;
import org.ktunaxa.referral.server.command.dto.GetReferralMapRequest;
import org.ktunaxa.referral.server.command.dto.GetReferralMapResponse;
import org.ktunaxa.referral.server.service.KtunaxaConstant;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.TextAreaItem;
/**
* Entry point and main class for GWT application. This class defines the layout and functionality of this application.
*
* @author Pieter De Graef
*/
public class KtunaxaEntryPoint implements EntryPoint {
public static final String TOOL_ZOOM_KTUNAXA_TERRITORY = "ZoomKtunaxaTerritory";
public static final String TOOL_ZOOM_CURRENT_REFERRAL = "ZoomCurrentReferral";
public static final String TOOL_SELECT_REFERRAL = "SelectReferralMode";
public static final String TOOL_FEATURE_INFO = "GetFeatureInfoMode";
private GetReferralMapResponse appInfo;
public void onModuleLoad() {
// force a fixed height to feature attribute windows, preventing them to become too big (and add scroll bars)
WidgetLayout.featureAttributeWindowHeight =
Integer.toString(Window.getClientHeight() - WidgetLayout.windowOffset * 4);
WidgetLayout.featureAttributeWindowWidth = "470";
GsfLayout.geometricSearchPanelTabWidth = "100%";
PrintingLayout.templateIncludeLegend = false;
SsecLayout.tokenRequestWindowLogo = "[ISOMORPHIC]/images/logoKtunaxaReferrals.png";
SsecLayout.tokenRequestWindowLogoWidth = "300";
SsecLayout.tokenRequestWindowLogoHeight = "120";
SsecLayout.tokenRequestWindowWidth = "400";
SsecLayout.tokenRequestWindowHeight = "240";
ToolbarRegistry.put(TOOL_ZOOM_KTUNAXA_TERRITORY, new ToolCreator() {
public ToolbarBaseAction createTool(MapWidget mapWidget) {
return new ZoomKtunaxaTerritoryModalAction(mapWidget);
}
});
ToolbarRegistry.put(TOOL_ZOOM_CURRENT_REFERRAL, new ToolCreator() {
public ToolbarBaseAction createTool(MapWidget mapWidget) {
return new ZoomCurrentReferralModalAction(mapWidget);
}
});
ToolbarRegistry.put(TOOL_SELECT_REFERRAL, new ToolCreator() {
public ToolbarBaseAction createTool(MapWidget mapWidget) {
return new MakeReferralCurrentModalAction(mapWidget);
}
});
ToolbarRegistry.put(TOOL_FEATURE_INFO, new ToolCreator() {
public ToolbarBaseAction createTool(MapWidget mapWidget) {
return new WmsFeatureInfoModalAction(mapWidget);
}
});
AttributeFormFieldRegistry.registerCustomFormItem("topMiddleBottom", new DataSourceFieldFactory() {
public DataSourceField create() {
return new DataSourceIntegerField();
}
}, new FormItemFactory() {
public FormItem create() {
ComboBoxItem formItem = new ComboBoxItem();
LinkedHashMap<String, String> values = new LinkedHashMap<String, String>();
values.put("1", "top");
values.put("2", "middle");
values.put("3", "bottom");
formItem.setValueMap(values);
formItem.setValue(2);
return formItem;
}
}, null
);
// TYPE: MANY_TO_ONE
AttributeFormFieldRegistry.registerCustomFormItem("many-to-one-sorted", new DataSourceFieldFactory() {
public DataSourceField create() {
// Don't use a DataSourceEnumField, as it doesn't work together with the SelectItem's OptionDataSource.
return new DataSourceTextField();
}
}, new FormItemFactory() {
public FormItem create() {
SortedManyToOneItem manyToOneItem = new SortedManyToOneItem();
manyToOneItem.getItem().setAttribute(AssociationItem.ASSOCIATION_ITEM_ATTRIBUTE_KEY, manyToOneItem);
return manyToOneItem.getItem();
}
}, null);
GwtCommandDispatcher.getInstance().setTokenRequestHandler(new StaticSecurityTokenRequestHandler());
GwtCommandDispatcher.getInstance().addTokenChangedHandler(new TokenChangedHandler() {
public void onTokenChanged(TokenChangedEvent event) {
UserContext.getInstance().set(event.getUserDetail().getUserId(), event.getUserDetail().getUserName());
}
});
ClientConfigurationService.setConfigurationLoader(new ClientConfigurationLoader() {
public void loadClientApplicationInfo(final String applicationId, final ClientConfigurationSetter setter) {
GwtCommand commandRequest = new GwtCommand(GetReferralMapRequest.COMMAND);
commandRequest.setCommandRequest(new GetReferralMapRequest(applicationId));
CommunicationHandler.get().execute(commandRequest,
new AbstractCommandCallback<GetReferralMapResponse>() {
public void execute(GetReferralMapResponse response) {
UserContext.getInstance().setBpmRoles(response.getBpmRoles());
UserContext.getInstance().setAdmin(response.isAdmin());
appInfo = response;
setter.set(applicationId, response.getApplication());
}
}, "Loading RMS...");
}
});
// Register custom text area item
registerTextAreaFormItem();
// Register custom item for uploading documents
registerDocumentIdFormItem();
// Determine the layout:
String createReferralParam = Window.Location.getParameter(KtunaxaConstant.CREATE_REFERRAL_URL_PARAMETER);
MapLayout mapLayout = MapLayout.getInstance();
mapLayout.getMap().getMapModel().runWhenInitialized(new Runnable() {
public void run() {
// Initializes the referral state: map navigation + title.
MapLayout mapLayout = MapLayout.getInstance();
mapLayout.setReferralAndTask(appInfo.getReferral(), appInfo.getTask());
// Initializes the layer tree.
// VectorLayer base = (VectorLayer) mapLayout.getMap().getMapModel()
// .getLayer(KtunaxaConstant.LAYER_REFERENCE_BASE_ID);
// VectorLayer value = (VectorLayer) mapLayout.getMap().getMapModel()
// .getLayer(KtunaxaConstant.LAYER_REFERENCE_VALUE_ID);
// ReferenceLayer baseLayer =
// new ReferenceLayer(base, appInfo.getLayers(), appInfo.getLayerTypes(), true);
// ReferenceLayer valueLayer = new ReferenceLayer(value, appInfo.getLayers(),
// appInfo.getLayerTypes(), false);
// mapLayout.getLayerPanel().setBaseLayer(baseLayer);
// mapLayout.getLayerPanel().setValueLayer(valueLayer);
}
});
// set default state
mapLayout.draw();
if (null != createReferralParam) {
mapLayout.createReferral();
}
}
private void registerTextAreaFormItem() {
// Register a custom form item for text area's:
AttributeFormFieldRegistry.registerCustomFormItem("textArea", new DataSourceFieldFactory() {
public DataSourceField create() {
return new DataSourceTextField();
}
}, new FormItemFactory() {
public FormItem create() {
return new TextAreaItem();
}
}, null);
}
private void registerDocumentIdFormItem() {
// Register a custom form item for text area's:
AttributeFormFieldRegistry.registerCustomFormItem("DOCUMENT_ID_TYPE", new DataSourceFieldFactory() {
public DataSourceField create() {
return new DataSourceTextField();
}
}, new FormItemFactory() {
public FormItem create() {
return new DocumentItem();
}
}, null);
}
}