-
Notifications
You must be signed in to change notification settings - Fork 477
/
ConfigFormStructView.java
executable file
·118 lines (99 loc) · 3.96 KB
/
ConfigFormStructView.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
/*
* 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.struct;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import org.kaaproject.avro.ui.shared.RecordField;
import org.kaaproject.kaa.common.dto.UpdateStatus;
import org.kaaproject.kaa.server.admin.client.mvp.view.widget.RecordPanel;
import org.kaaproject.kaa.server.admin.client.util.HasErrorMessage;
import org.kaaproject.kaa.server.admin.client.util.Utils;
import org.kaaproject.kaa.server.admin.shared.config.ConfigurationRecordFormDto;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.HasValue;
public class ConfigFormStructView extends BaseStructView<ConfigurationRecordFormDto, RecordField> {
private Button downloadConfigurationButton;
public ConfigFormStructView(HasErrorMessage hasErrorMessage) {
super(hasErrorMessage);
}
@Override
protected HasValue<RecordField> createBody(HasErrorMessage hasErrorMessage) {
RecordPanel field = new RecordPanel(Utils.constants.configurationBody(), hasErrorMessage, false, false);
field.getRecordWidget().setForceNavigation(true);
field.setPreferredHeightPx(200);
return field;
}
@Override
protected boolean hasLabel() {
return false;
}
@Override
protected void setBodyReadOnly(boolean readOnly) {
((RecordPanel)body).setReadOnly(readOnly);
}
@Override
protected void setBodyValue(ConfigurationRecordFormDto struct) {
body.setValue(struct.getConfigurationRecord());
}
@Override
protected HandlerRegistration addBodyChangeHandler() {
return body.addValueChangeHandler(new ValueChangeHandler<RecordField>() {
@Override
public void onValueChange(ValueChangeEvent<RecordField> event) {
fireChanged();
}
});
}
@Override
protected void init() {
super.init();
downloadConfigurationButton = new Button(Utils.constants.downloadConfiguration());
buttonsPanel.add(downloadConfigurationButton);
downloadConfigurationButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
String url = Window.Location.getHref();
Window.open("/kaaAdmin/servlet/kaaConfigurationDownloadServlet?schemaId=" + Utils.getSchemaIdFromUrl(url) +
"&endGroupId=" + Utils.getEndpointGroupIdFromUrl(url),
"_blank", "status=0,toolbar=0,menubar=0,location=0");
}
});
}
@Override
public void reset() {
super.reset();
downloadConfigurationButton.setVisible(false);
}
@Override
public void setData(ConfigurationRecordFormDto struct) {
super.setData(struct);
if (struct.getStatus()==UpdateStatus.ACTIVE) {
downloadConfigurationButton.setVisible(true);
}
}
@Override
protected boolean validateBody() {
return ((RecordPanel)body).validate();
}
@Override
protected void onShown() {
((RecordPanel)body).getRecordWidget().onShown();
}
}