Skip to content

Commit ffd2681

Browse files
authored
Merge pull request #855 from GwtMaterialDesign/bd_statustext
Rework the status text design
2 parents cf9bedf + 43187b7 commit ffd2681

File tree

15 files changed

+344
-135
lines changed

15 files changed

+344
-135
lines changed

gwt-material/src/main/java/gwt/material/design/client/base/AbstractValueWidget.java

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import gwt.material.design.client.base.error.ErrorHandlerType;
3232
import gwt.material.design.client.base.error.HasErrorHandler;
3333
import gwt.material.design.client.base.mixin.ErrorHandlerMixin;
34-
import gwt.material.design.client.base.mixin.ErrorMixin;
34+
import gwt.material.design.client.base.mixin.StatusTextMixin;
3535
import gwt.material.design.client.base.mixin.ValidatorMixin;
3636
import gwt.material.design.client.base.validator.BlankValidator;
3737
import gwt.material.design.client.base.validator.HasValidators;
@@ -42,13 +42,13 @@
4242

4343
//TODO: HasRawValue
4444
public abstract class AbstractValueWidget<V> extends MaterialWidget implements HasValue<V>, LeafValueEditor<V>,
45-
HasEditorErrors<V>, HasErrorHandler, HasError, HasValidators<V> {
45+
HasEditorErrors<V>, HasErrorHandler, HasStatusText, HasValidators<V> {
4646

4747
private boolean allowBlank = true;
4848
private boolean autoValidate;
4949
private BlankValidator<V> blankValidator;
5050
private ValidatorMixin<AbstractValueWidget<V>, V> validatorMixin;
51-
private ErrorMixin<AbstractValueWidget, ?> errorMixin;
51+
private StatusTextMixin<AbstractValueWidget, ?> statusTextMixin;
5252
private ErrorHandlerMixin<V> errorHandlerMixin;
5353

5454
public AbstractValueWidget(Element element) {
@@ -85,23 +85,53 @@ public void setValue(V value, boolean fireEvents, boolean reload) {
8585
//setSanitizer();
8686

8787
@Override
88-
public void setError(String error) {
89-
getErrorMixin().setError(error);
88+
public void setErrorText(String errorText) {
89+
getStatusTextMixin().setErrorText(errorText);
9090
}
9191

9292
@Override
93-
public void setSuccess(String success) {
94-
getErrorMixin().setSuccess(success);
93+
public void setSuccessText(String successText) {
94+
getStatusTextMixin().setSuccessText(successText);
9595
}
9696

9797
@Override
9898
public void setHelperText(String helperText) {
99-
getErrorMixin().setHelperText(helperText);
99+
getStatusTextMixin().setHelperText(helperText);
100100
}
101101

102102
@Override
103-
public void clearErrorOrSuccess() {
104-
getErrorMixin().clearErrorOrSuccess();
103+
public void clearErrorText() {
104+
getStatusTextMixin().clearErrorText();
105+
}
106+
107+
@Override
108+
public void clearHelperText() {
109+
getStatusTextMixin().clearHelperText();
110+
}
111+
112+
@Override
113+
public void clearSuccessText() {
114+
getStatusTextMixin().clearSuccessText();
115+
}
116+
117+
@Override
118+
public void clearStatusText() {
119+
getStatusTextMixin().clearStatusText();
120+
}
121+
122+
@Override
123+
public boolean isErrorTextVisible() {
124+
return getStatusTextMixin().isErrorTextVisible();
125+
}
126+
127+
@Override
128+
public boolean isHelperTextVisible() {
129+
return getStatusTextMixin().isHelperTextVisible();
130+
}
131+
132+
@Override
133+
public boolean isSuccessTextVisible() {
134+
return getStatusTextMixin().isSuccessTextVisible();
105135
}
106136

107137
@Override
@@ -249,11 +279,11 @@ protected ValidatorMixin<AbstractValueWidget<V>, V> getValidatorMixin() {
249279
return validatorMixin;
250280
}
251281

252-
protected ErrorMixin<AbstractValueWidget, ?> getErrorMixin() {
253-
if (errorMixin == null) {
254-
errorMixin = new ErrorMixin<>(this);
282+
protected StatusTextMixin<AbstractValueWidget, ?> getStatusTextMixin() {
283+
if (statusTextMixin == null) {
284+
statusTextMixin = new StatusTextMixin<>(this);
255285
}
256-
return errorMixin;
286+
return statusTextMixin;
257287
}
258288

259289
protected ErrorHandlerMixin<V> getErrorHandlerMixin() {

gwt-material/src/main/java/gwt/material/design/client/base/HasError.java renamed to gwt-material/src/main/java/gwt/material/design/client/base/HasErrorText.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,23 @@
1919
*/
2020
package gwt.material.design.client.base;
2121

22-
public interface HasError {
22+
public interface HasErrorText {
2323

2424
/**
2525
* Errors occur when an app fails to complete what is expected, such as:
2626
* - The app does not understand user input
2727
* - The system or app fails
2828
* - A user intends to run incompatible operations concurrently
2929
*/
30-
void setError(String error);
30+
void setErrorText(String errorText);
3131

3232
/**
33-
* Set the success message marking a widget as success.
33+
* Is the error text applied and visible.
3434
*/
35-
void setSuccess(String success);
35+
boolean isErrorTextVisible();
3636

3737
/**
38-
* Apply a widgets help text.
38+
* Clear the error states.
3939
*/
40-
void setHelperText(String helperText);
41-
42-
/**
43-
* Clear the error or success states.
44-
*/
45-
void clearErrorOrSuccess();
40+
void clearErrorText();
4641
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* #%L
3+
* GwtMaterial
4+
* %%
5+
* Copyright (C) 2015 - 2018 GwtMaterialDesign
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package gwt.material.design.client.base;
21+
22+
public interface HasHelperText {
23+
24+
/**
25+
* Apply a widgets help text.
26+
*/
27+
void setHelperText(String helperText);
28+
29+
/**
30+
* Is the helper text applied and visible.
31+
*/
32+
boolean isHelperTextVisible();
33+
34+
/**
35+
* Clear the helper states.
36+
*/
37+
void clearHelperText();
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* #%L
3+
* GwtMaterial
4+
* %%
5+
* Copyright (C) 2015 - 2018 GwtMaterialDesign
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package gwt.material.design.client.base;
21+
22+
public interface HasStatusText extends HasHelperText, HasErrorText, HasSuccessText {
23+
24+
void clearStatusText();
25+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* #%L
3+
* GwtMaterial
4+
* %%
5+
* Copyright (C) 2015 - 2018 GwtMaterialDesign
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package gwt.material.design.client.base;
21+
22+
public interface HasSuccessText {
23+
24+
/**
25+
* Set the success message marking a widget as success.
26+
*/
27+
void setSuccessText(String successText);
28+
29+
/**
30+
* Is the success text applied and visible.
31+
*/
32+
boolean isSuccessTextVisible();
33+
34+
/**
35+
* Clear the success text states.
36+
*/
37+
void clearSuccessText();
38+
}

gwt-material/src/main/java/gwt/material/design/client/base/error/DefaultErrorHandler.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import com.google.gwt.editor.client.EditorError;
2323
import com.google.gwt.user.client.ui.HasWidgets;
2424
import com.google.gwt.user.client.ui.Widget;
25-
import gwt.material.design.client.base.HasError;
25+
import gwt.material.design.client.base.HasErrorText;
26+
import gwt.material.design.client.base.HasStatusText;
2627
import gwt.material.design.client.ui.MaterialHelpBlock;
2728

2829
import java.util.List;
@@ -74,8 +75,8 @@ public void cleanup() {
7475

7576
@Override
7677
public void clearErrors() {
77-
if (inputWidget instanceof HasError) {
78-
((HasError) inputWidget).clearErrorOrSuccess();
78+
if (inputWidget instanceof HasStatusText) {
79+
((HasStatusText) inputWidget).clearStatusText();
7980
}
8081
if (helpBlock != null) {
8182
helpBlock.removeStyleName("field-error-label");
@@ -139,8 +140,8 @@ public void showErrors(List<EditorError> errors) {
139140
}
140141
}
141142

142-
if (inputWidget instanceof HasError) {
143-
((HasError) inputWidget).setError(errorMsg);
143+
if (inputWidget instanceof HasErrorText) {
144+
((HasErrorText) inputWidget).setErrorText(errorMsg);
144145
}
145146

146147
if (helpBlock != null) {

0 commit comments

Comments
 (0)