gwt-material
gwt-material copied to clipboard
MaterialIcon and IconType usage/purpose inconsistency.
I am creating a button like follow:
final List<MaterialAnchorButton> buttons = new LinkedList<>();
final MaterialIcon icon = new MaterialIcon();
icon.setIconType(IconType.HOME);
final MaterialAnchorButton addb = new MaterialAnchorButton(ButtonType.FLOATING, "D1", icon);
addb.setBackgroundColor("red");
buttons.add(addb);
and then I am adding it to MaterialFABList
like follow
@UiField
MaterialAnchorButton mainButton;
@UiField
MaterialFABList additionalButtons;
for (final MaterialAnchorButton b : buttons) {
if (b.equals(buttons.get(0))) {
mainButton.setIconType(b.getIcon().getIconType());
mainButton.setBackgroundColor(b.getBackgroundColor());
mainButton.setText(b.getText());
} else {
b.setSize(ButtonSize.MEDIUM);
b.setWaves(WavesType.LIGHT);
b.setType(ButtonType.FLOATING);
b.setIconType(b.getIcon().getIconType());
b.setBackgroundColor("blue");
additionalButtons.add(b);
}
}
To have programatically set buttons on fab. Problem is in those 2 lines:
mainButton.setIconType(b.getIcon().getIconType());
b.setIconType(b.getIcon().getIconType());
those 2 lines shouldn't be needed, cause Icon have been already set in first code snippet above.
When I delete them the result is:
but the result should be:
For sure there is some inconsistency in code/return types of getters I think.
I've noticed that AbstractIconButton
has parameter icon private MaterialIcon icon = new MaterialIcon();
and also implements interfejs HasIcon
:
public abstract class AbstractIconButton extends AbstractButton implements HasIcon {
which has methods:
/**
* Get the icon widget.
*/
MaterialIcon getIcon();
/**
* Set Material Design icon.
* {@link https://www.google.com/design/icons/}
*/
void setIconType(IconType iconType);
In MaterialAnchorButton
class we have setter for IconType
, but no for MaterialIcon
, and
In MaterialAnchorButton
class we have getter for MaterialIcon
, but no for IconType
In MaterialAnchorButton
class we have constructor with MaterialIcon
, but no for IconType
.
Which cause that we have 2 separate Icon reference, which cause inconsistency in when and which one use. It have to be simplified.
MaterialIcon i = new MaterialIcon();
i.setIconType(IconType.AC_UNIT);
MaterialAnchorButton a = new MaterialAnchorButton("TEST",i);
a.getIcon().getIconType(); // will return IconType.AC_UNIT
a.setIconType(IconType.ACCESS_ALARM);
In this code I've set 2 different icon types for one button.
We have to use only one parameter, IconType
enum, or whole MaterialIcon
object, and it should be done for whole gwt-materials.
I think the simplest will be use only of enum IconType
and widget should internally create MaterialIcon
. MaterialIcon
should be completely hidden for end user.
End user should only use IconType
, IconPosition
, IconColor
etc. I think.
Giving access to the actual MaterialIcon is important to retain. There should also be methods for icon position and color available if I remember correctly.
It is hard to speculate, cause this issue affect a lot of widgets. But it have to be standardized across whole sources.