Skip to content

Commit 6aca198

Browse files
committed
#4179 Add text input control to dashboards
1 parent b742316 commit 6aca198

File tree

14 files changed

+648
-5
lines changed

14 files changed

+648
-5
lines changed

Diff for: stroom-app/src/main/resources/ui/css/dashboard.css

+1
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@
642642
background-color: #1f77b4;
643643
}
644644

645+
.TextInputView,
645646
.KeyValueInputView {
646647
padding: 0 0.4rem 0.4rem 0.4rem;
647648
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright 2017 Crown Copyright
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+
package stroom.dashboard.client.input;
18+
19+
import stroom.dashboard.client.input.BasicTextInputSettingsPresenter.BasicTextInputSettingsView;
20+
import stroom.dashboard.client.main.BasicSettingsTabPresenter;
21+
import stroom.dashboard.client.main.BasicSettingsView;
22+
import stroom.dashboard.shared.ComponentConfig;
23+
import stroom.dashboard.shared.TextInputComponentSettings;
24+
25+
import com.google.gwt.user.client.ui.Focus;
26+
import com.google.inject.Inject;
27+
import com.google.web.bindery.event.shared.EventBus;
28+
29+
import java.util.Objects;
30+
31+
public class BasicTextInputSettingsPresenter
32+
extends BasicSettingsTabPresenter<BasicTextInputSettingsView>
33+
implements Focus {
34+
35+
@Inject
36+
public BasicTextInputSettingsPresenter(final EventBus eventBus,
37+
final BasicTextInputSettingsView view) {
38+
super(eventBus, view);
39+
}
40+
41+
@Override
42+
public void focus() {
43+
getView().focus();
44+
}
45+
46+
@Override
47+
public void read(final ComponentConfig componentConfig) {
48+
super.read(componentConfig);
49+
50+
final TextInputComponentSettings settings = (TextInputComponentSettings) componentConfig.getSettings();
51+
if (settings != null) {
52+
getView().setKey(settings.getKey());
53+
}
54+
}
55+
56+
@Override
57+
public ComponentConfig write(final ComponentConfig componentConfig) {
58+
ComponentConfig result = super.write(componentConfig);
59+
final TextInputComponentSettings oldSettings = (TextInputComponentSettings) result.getSettings();
60+
final TextInputComponentSettings newSettings = writeSettings(oldSettings);
61+
return result.copy().settings(newSettings).build();
62+
}
63+
64+
private TextInputComponentSettings writeSettings(final TextInputComponentSettings settings) {
65+
return settings
66+
.copy()
67+
.key(getView().getKey())
68+
.build();
69+
}
70+
71+
@Override
72+
public boolean isDirty(final ComponentConfig componentConfig) {
73+
if (super.isDirty(componentConfig)) {
74+
return true;
75+
}
76+
77+
final TextInputComponentSettings oldSettings = (TextInputComponentSettings) componentConfig.getSettings();
78+
final TextInputComponentSettings newSettings = writeSettings(oldSettings);
79+
80+
final boolean equal = Objects.equals(oldSettings.getKey(), newSettings.getKey());
81+
82+
return !equal;
83+
}
84+
85+
public interface BasicTextInputSettingsView extends BasicSettingsView {
86+
87+
String getKey();
88+
89+
void setKey(String key);
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2016 Crown Copyright
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+
package stroom.dashboard.client.input;
18+
19+
import stroom.dashboard.client.input.BasicTextInputSettingsPresenter.BasicTextInputSettingsView;
20+
21+
import com.google.gwt.uibinder.client.UiBinder;
22+
import com.google.gwt.uibinder.client.UiField;
23+
import com.google.gwt.user.client.ui.Label;
24+
import com.google.gwt.user.client.ui.RequiresResize;
25+
import com.google.gwt.user.client.ui.TextBox;
26+
import com.google.gwt.user.client.ui.Widget;
27+
import com.google.inject.Inject;
28+
import com.gwtplatform.mvp.client.ViewImpl;
29+
30+
public class BasicTextInputSettingsViewImpl extends ViewImpl implements BasicTextInputSettingsView {
31+
32+
private final Widget widget;
33+
@UiField
34+
Label id;
35+
@UiField
36+
TextBox name;
37+
@UiField
38+
TextBox key;
39+
40+
@Inject
41+
public BasicTextInputSettingsViewImpl(final Binder binder) {
42+
widget = binder.createAndBindUi(this);
43+
}
44+
45+
@Override
46+
public Widget asWidget() {
47+
return widget;
48+
}
49+
50+
@Override
51+
public void focus() {
52+
name.setFocus(true);
53+
}
54+
55+
@Override
56+
public void setId(final String id) {
57+
this.id.setText(id);
58+
}
59+
60+
@Override
61+
public String getName() {
62+
return name.getText();
63+
}
64+
65+
@Override
66+
public void setName(final String name) {
67+
this.name.setText(name);
68+
}
69+
70+
@Override
71+
public String getKey() {
72+
return key.getValue();
73+
}
74+
75+
@Override
76+
public void setKey(final String key) {
77+
this.key.setValue(key);
78+
}
79+
80+
public void onResize() {
81+
((RequiresResize) widget).onResize();
82+
}
83+
84+
public interface Binder extends UiBinder<Widget, BasicTextInputSettingsViewImpl> {
85+
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2016 Crown Copyright
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+
package stroom.dashboard.client.input;
18+
19+
import stroom.dashboard.client.main.ComponentRegistry;
20+
21+
import com.google.inject.Inject;
22+
import com.google.inject.Provider;
23+
import com.google.web.bindery.event.shared.EventBus;
24+
25+
public class TextInputPlugin {
26+
27+
@Inject
28+
public TextInputPlugin(final EventBus eventBus,
29+
final ComponentRegistry componentRegistry,
30+
final Provider<TextInputPresenter> provider) {
31+
componentRegistry.register(TextInputPresenter.TYPE, provider);
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright 2017 Crown Copyright
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+
package stroom.dashboard.client.input;
18+
19+
import stroom.dashboard.client.main.AbstractComponentPresenter;
20+
import stroom.dashboard.client.main.ComponentChangeEvent;
21+
import stroom.dashboard.client.main.ComponentRegistry.ComponentType;
22+
import stroom.dashboard.client.main.ComponentRegistry.ComponentUse;
23+
import stroom.dashboard.client.input.TextInputPresenter.TextInputView;
24+
import stroom.dashboard.client.main.HasParams;
25+
import stroom.dashboard.shared.ComponentConfig;
26+
import stroom.dashboard.shared.ComponentSettings;
27+
import stroom.dashboard.shared.TextInputComponentSettings;
28+
import stroom.query.api.v2.Param;
29+
30+
import com.google.inject.Inject;
31+
import com.google.inject.Provider;
32+
import com.google.web.bindery.event.shared.EventBus;
33+
import com.gwtplatform.mvp.client.HasUiHandlers;
34+
import com.gwtplatform.mvp.client.View;
35+
36+
import java.util.ArrayList;
37+
import java.util.List;
38+
39+
public class TextInputPresenter
40+
extends AbstractComponentPresenter<TextInputView>
41+
implements TextInputUiHandlers, HasParams {
42+
43+
public static final ComponentType TYPE =
44+
new ComponentType(1,
45+
"text-input",
46+
"Text Input",
47+
ComponentUse.INPUT);
48+
49+
@Inject
50+
public TextInputPresenter(final EventBus eventBus,
51+
final TextInputView view,
52+
final Provider<TextInputSettingsPresenter> settingsPresenterProvider) {
53+
super(eventBus, view, settingsPresenterProvider);
54+
view.setUiHandlers(this);
55+
}
56+
57+
@Override
58+
public void onValueChanged(final String value) {
59+
setSettings(getTextInputSettings().copy().value(value).build());
60+
ComponentChangeEvent.fire(this, this);
61+
setDirty(true);
62+
}
63+
64+
@Override
65+
public List<Param> getParams() {
66+
final List<Param> list = new ArrayList<>();
67+
final String key = getTextInputSettings().getKey();
68+
final String value = getView().getValue();
69+
if (key != null && key.trim().length() > 0 && value != null && value.trim().length() > 0) {
70+
final Param param = new Param(key.trim(), value.trim());
71+
list.add(param);
72+
}
73+
return list;
74+
}
75+
76+
@Override
77+
public void read(final ComponentConfig componentConfig) {
78+
super.read(componentConfig);
79+
80+
ComponentSettings settings = componentConfig.getSettings();
81+
if (!(settings instanceof TextInputComponentSettings)) {
82+
setSettings(createSettings());
83+
}
84+
85+
update(getTextInputSettings());
86+
}
87+
88+
private void update(final TextInputComponentSettings settings) {
89+
getView().setValue(settings.getValue());
90+
}
91+
92+
private TextInputComponentSettings getTextInputSettings() {
93+
return (TextInputComponentSettings) getSettings();
94+
}
95+
96+
private TextInputComponentSettings createSettings() {
97+
return TextInputComponentSettings.builder().build();
98+
}
99+
100+
101+
@Override
102+
public void link() {
103+
}
104+
105+
@Override
106+
public void changeSettings() {
107+
super.changeSettings();
108+
update(getTextInputSettings());
109+
}
110+
111+
@Override
112+
public ComponentType getType() {
113+
return TYPE;
114+
}
115+
116+
public interface TextInputView extends View, HasUiHandlers<TextInputUiHandlers> {
117+
118+
void setValue(String value);
119+
120+
String getValue();
121+
}
122+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2016 Crown Copyright
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+
package stroom.dashboard.client.input;
18+
19+
import stroom.dashboard.client.main.SettingsPresenter;
20+
import stroom.widget.tab.client.presenter.LinkTabsLayoutView;
21+
22+
import com.google.inject.Inject;
23+
import com.google.web.bindery.event.shared.EventBus;
24+
25+
public class TextInputSettingsPresenter extends SettingsPresenter {
26+
27+
@Inject
28+
public TextInputSettingsPresenter(final EventBus eventBus, final LinkTabsLayoutView view,
29+
final BasicTextInputSettingsPresenter basicSettingsPresenter) {
30+
super(eventBus, view);
31+
getView().asWidget().addStyleName("settingsPresenter");
32+
33+
addTab("Basic", basicSettingsPresenter);
34+
}
35+
}

0 commit comments

Comments
 (0)