-
Notifications
You must be signed in to change notification settings - Fork 477
/
AddSdkProfileViewImpl.java
executable file
·390 lines (330 loc) · 13.2 KB
/
AddSdkProfileViewImpl.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/*
* Copyright 2014-2016 CyberVision, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kaaproject.kaa.server.admin.client.mvp.view.sdk;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.text.shared.Renderer;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ValueListBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import org.kaaproject.avro.ui.gwt.client.widget.SizedTextBox;
import org.kaaproject.kaa.common.dto.VersionDto;
import org.kaaproject.kaa.common.dto.event.AefMapInfoDto;
import org.kaaproject.kaa.common.dto.user.UserVerifierDto;
import org.kaaproject.kaa.server.admin.client.mvp.view.AddSdkProfileView;
import org.kaaproject.kaa.server.admin.client.mvp.view.base.BaseDetailsViewImpl;
import org.kaaproject.kaa.server.admin.client.mvp.view.widget.KaaAdminSizedTextBox;
import org.kaaproject.kaa.server.admin.client.mvp.view.widget.MultiAefMapListBox;
import org.kaaproject.kaa.server.admin.client.mvp.view.widget.MultiValueListBox;
import org.kaaproject.kaa.server.admin.client.mvp.view.widget.VersionListBox;
import org.kaaproject.kaa.server.admin.client.util.Utils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AddSdkProfileViewImpl
extends BaseDetailsViewImpl
implements AddSdkProfileView, ValueChangeHandler<VersionDto> {
private static final String REQUIRED = Utils.avroUiStyle.requiredField();
private static final int SDK_NAME_TEXT_SIZE_BOX = 255;
private SizedTextBox name;
private VersionListBox configurationSchemaVersion;
private VersionListBox profileSchemaVersion;
private VersionListBox notificationSchemaVersion;
private VersionListBox logSchemaVersion;
private List<AefMapInfoDto> aefMaps;
private AefMapInfoDtoComparator aefMapComparator = new AefMapInfoDtoComparator();
private MultiAefMapListBox availableAefMaps;
private MultiAefMapListBox selectedAefMaps;
private Button addAefMapButton;
private Button removeAefMapButton;
private ValueListBox<UserVerifierDto> defaultUserVerifier;
public AddSdkProfileViewImpl() {
super(true);
}
@Override
protected void initDetailsTable() {
detailsTable.getColumnFormatter().setWidth(0, "250px");
detailsTable.getColumnFormatter().setWidth(1, "500px");
Widget label = new Label(Utils.constants.name());
label.addStyleName(REQUIRED);
name = new KaaAdminSizedTextBox(SDK_NAME_TEXT_SIZE_BOX);
name.addInputHandler(this);
detailsTable.setWidget(0, 0, label);
detailsTable.setWidget(0, 1, name);
label = new Label(Utils.constants.configurationSchemaVersion());
label.addStyleName(REQUIRED);
configurationSchemaVersion = new VersionListBox();
configurationSchemaVersion.setWidth("80px");
configurationSchemaVersion.addValueChangeHandler(this);
detailsTable.setWidget(1, 0, label);
detailsTable.setWidget(1, 1, configurationSchemaVersion);
label = new Label(Utils.constants.profileSchemaVersion());
label.addStyleName(REQUIRED);
profileSchemaVersion = new VersionListBox();
profileSchemaVersion.setWidth("80px");
profileSchemaVersion.addValueChangeHandler(this);
detailsTable.setWidget(2, 0, label);
detailsTable.setWidget(2, 1, profileSchemaVersion);
label = new Label(Utils.constants.notificationSchemaVersion());
label.addStyleName(REQUIRED);
notificationSchemaVersion = new VersionListBox();
notificationSchemaVersion.setWidth("80px");
notificationSchemaVersion.addValueChangeHandler(this);
detailsTable.setWidget(3, 0, label);
detailsTable.setWidget(3, 1, notificationSchemaVersion);
label = new Label(Utils.constants.logSchemaVersion());
label.addStyleName(REQUIRED);
logSchemaVersion = new VersionListBox();
logSchemaVersion.setWidth("80px");
logSchemaVersion.addValueChangeHandler(this);
detailsTable.setWidget(4, 0, label);
detailsTable.setWidget(4, 1, logSchemaVersion);
FlexTable ecfsTable = new FlexTable();
ecfsTable.setCellSpacing(6);
availableAefMaps = new MultiAefMapListBox();
selectedAefMaps = new MultiAefMapListBox();
addAefMapButton = new Button(Utils.constants.add());
removeAefMapButton = new Button(Utils.constants.remove());
VerticalPanel availableEcfsPanel = new VerticalPanel();
availableEcfsPanel.setSpacing(6);
Label availableLabel = new Label(Utils.constants.available());
availableEcfsPanel.add(availableLabel);
availableEcfsPanel.add(availableAefMaps);
VerticalPanel ecfButtonsPanel = new VerticalPanel();
ecfButtonsPanel.setSpacing(6);
ecfButtonsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
ecfButtonsPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
ecfButtonsPanel.add(addAefMapButton);
ecfButtonsPanel.add(removeAefMapButton);
VerticalPanel selectedEcfsPanel = new VerticalPanel();
selectedEcfsPanel.setSpacing(6);
Label selectedLabel = new Label(Utils.constants.selected());
selectedEcfsPanel.add(selectedLabel);
selectedEcfsPanel.add(selectedAefMaps);
ecfsTable.setWidget(0, 0, availableEcfsPanel);
ecfsTable.setWidget(0, 1, ecfButtonsPanel);
ecfsTable.setWidget(0, 2, selectedEcfsPanel);
ecfsTable.getFlexCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_MIDDLE);
DisclosurePanel ecfsDisclosure = new DisclosurePanel(Utils.constants.ecfs());
ecfsDisclosure.setAnimationEnabled(true);
ecfsDisclosure.setContent(ecfsTable);
addAefMapButton.addStyleName(Utils.kaaAdminStyle.bAppButtonSmall());
removeAefMapButton.addStyleName(Utils.kaaAdminStyle.bAppButtonSmall());
addAefMapButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
addAefMap();
}
});
removeAefMapButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
removeAefMap();
}
});
availableAefMaps.setSize("250px", "100px");
selectedAefMaps.setSize("250px", "100px");
availableAefMaps.addValueChangeHandler(new ValueChangeHandler<List<AefMapInfoDto>>() {
@Override
public void onValueChange(ValueChangeEvent<List<AefMapInfoDto>> event) {
updateAefMapButtons();
}
});
selectedAefMaps.addValueChangeHandler(new ValueChangeHandler<List<AefMapInfoDto>>() {
@Override
public void onValueChange(ValueChangeEvent<List<AefMapInfoDto>> event) {
updateAefMapButtons();
}
});
detailsTable.setWidget(5, 0, ecfsDisclosure);
detailsTable.getFlexCellFormatter().setColSpan(5, 0, 2);
label = new Label(Utils.constants.defaultUserVerifier());
Renderer<UserVerifierDto> userVerifierRenderer = new Renderer<UserVerifierDto>() {
@Override
public String render(UserVerifierDto object) {
if (object != null) {
return object.getName();
} else {
return "";
}
}
@Override
public void render(UserVerifierDto object, Appendable appendable) throws IOException {
appendable.append(render(object));
}
};
defaultUserVerifier = new ValueListBox<>(userVerifierRenderer);
defaultUserVerifier.addValueChangeHandler(new ValueChangeHandler<UserVerifierDto>() {
@Override
public void onValueChange(ValueChangeEvent<UserVerifierDto> event) {
fireChanged();
}
});
detailsTable.setWidget(6, 0, label);
detailsTable.setWidget(6, 1, defaultUserVerifier);
}
@Override
public void onValueChange(ValueChangeEvent<VersionDto> event) {
fireChanged();
}
@Override
protected String getCreateTitle() {
return Utils.constants.addSdkProfile();
}
@Override
protected String getViewTitle() {
return Utils.constants.sdkProfiles();
}
@Override
protected String getSubTitle() {
return Utils.constants.sdkProfileDetails();
}
@Override
public HasValue<String> getName() {
return name;
}
@Override
public ValueListBox<VersionDto> getConfigurationSchemaVersion() {
return configurationSchemaVersion;
}
@Override
public ValueListBox<VersionDto> getProfileSchemaVersion() {
return profileSchemaVersion;
}
@Override
public ValueListBox<VersionDto> getNotificationSchemaVersion() {
return notificationSchemaVersion;
}
@Override
public ValueListBox<VersionDto> getLogSchemaVersion() {
return logSchemaVersion;
}
@Override
public MultiValueListBox<AefMapInfoDto> getSelectedAefMaps() {
return selectedAefMaps;
}
@Override
public ValueListBox<UserVerifierDto> getDefaultUserVerifier() {
return defaultUserVerifier;
}
@Override
public void setAefMaps(List<AefMapInfoDto> aefMaps) {
this.aefMaps = aefMaps;
Collections.sort(this.aefMaps, aefMapComparator);
availableAefMaps.setAcceptableValues(aefMaps);
}
@Override
protected void resetImpl() {
name.setValue("");
configurationSchemaVersion.reset();
profileSchemaVersion.reset();
notificationSchemaVersion.reset();
logSchemaVersion.reset();
availableAefMaps.reset();
selectedAefMaps.reset();
addAefMapButton.setEnabled(false);
removeAefMapButton.setEnabled(false);
defaultUserVerifier.setValue(null);
defaultUserVerifier.setAcceptableValues(Collections.<UserVerifierDto>emptyList());
}
@Override
protected boolean validate() {
boolean result = configurationSchemaVersion.getValue() != null;
result &= profileSchemaVersion.getValue() != null;
result &= notificationSchemaVersion.getValue() != null;
result &= logSchemaVersion.getValue() != null;
result &= name.getValue().length() > 0;
return result;
}
private void addAefMap() {
List<AefMapInfoDto> selected = availableAefMaps.getValue();
availableAefMaps.setValue(null, true);
Map<String, AefMapInfoDto> idMap = new HashMap<String, AefMapInfoDto>();
for (AefMapInfoDto aefMap : selected) {
AefMapInfoDto previous = idMap.get(aefMap.getEcfId());
if (previous == null || aefMap.getVersion() > previous.getVersion()) {
idMap.put(aefMap.getEcfId(), aefMap);
}
}
List<AefMapInfoDto> totalSelected = new ArrayList<>();
totalSelected.addAll(idMap.values());
totalSelected.addAll(selectedAefMaps.getValues());
updateAefMapLists(totalSelected);
}
private void removeAefMap() {
List<AefMapInfoDto> selected = selectedAefMaps.getValue();
selectedAefMaps.setValue(null, true);
List<AefMapInfoDto> totalSelected = new ArrayList<>();
for (AefMapInfoDto aefMap : selectedAefMaps.getValues()) {
if (!selected.contains(aefMap)) {
totalSelected.add(aefMap);
}
}
updateAefMapLists(totalSelected);
}
private void updateAefMapLists(List<AefMapInfoDto> totalSelected) {
List<AefMapInfoDto> available = new ArrayList<>();
Map<String, AefMapInfoDto> idMap = new HashMap<String, AefMapInfoDto>();
for (AefMapInfoDto aefMap : totalSelected) {
idMap.put(aefMap.getEcfId(), aefMap);
}
for (AefMapInfoDto aefMap : aefMaps) {
if (!idMap.containsKey(aefMap.getEcfId())) {
available.add(aefMap);
}
}
Collections.sort(available, aefMapComparator);
Collections.sort(totalSelected, aefMapComparator);
availableAefMaps.setAcceptableValues(available);
selectedAefMaps.setAcceptableValues(totalSelected);
}
private void updateAefMapButtons() {
boolean availableSelected = availableAefMaps.getValue() != null
&& !availableAefMaps.getValue().isEmpty();
boolean selectedSelected = selectedAefMaps.getValue() != null
&& !selectedAefMaps.getValue().isEmpty();
addAefMapButton.setEnabled(availableSelected);
removeAefMapButton.setEnabled(selectedSelected);
}
@Override
protected void updateSaveButton(boolean enabled, boolean invalid) {
getSaveButtonWidget().setText(Utils.constants.add());
getSaveButtonWidget().setEnabled(enabled);
}
class AefMapInfoDtoComparator implements Comparator<AefMapInfoDto> {
@Override
public int compare(AefMapInfoDto o1, AefMapInfoDto o2) {
int result = o1.getEcfName().compareTo(o2.getEcfName());
if (result == 0) {
result = o1.getVersion() - o2.getVersion();
}
return result;
}
}
}