001/*
002 * #%L
003 * GwtMaterial
004 * %%
005 * Copyright (C) 2015 - 2017 GwtMaterialDesign
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 * 
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 * 
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package gwt.material.design.addins.client.emptystate;
021
022import com.google.gwt.dom.client.Document;
023import com.google.gwt.dom.client.Style.Unit;
024import gwt.material.design.addins.client.MaterialAddins;
025import gwt.material.design.addins.client.base.constants.AddinsCssName;
026import gwt.material.design.client.MaterialDesignBase;
027import gwt.material.design.client.base.HasIcon;
028import gwt.material.design.client.base.HasTitle;
029import gwt.material.design.client.base.MaterialWidget;
030import gwt.material.design.client.constants.*;
031import gwt.material.design.client.ui.MaterialIcon;
032import gwt.material.design.client.ui.MaterialLoader;
033import gwt.material.design.client.ui.MaterialTitle;
034import gwt.material.design.client.ui.html.Div;
035
036//@formatter:off
037
038/**
039 * <p>Material Empty State is a component that will have to display once content is empty.
040 * <h3>UiBinder Usage:</h3>
041 * <p>
042 * <pre>
043 * {@code
044 * <m:MaterialEmptyState iconType="POLYMER" title="No Inbox" description="You dont have new message" backgroundColor="BLUE"/>
045 * }
046 * </pre>
047 * </p>
048 *
049 * @author kevzlou7979
050 * @author Ben Dol
051 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#empty-state">Material Empty State</a>
052 * @see <a href="https://material.io/guidelines/patterns/empty-states.html">Material Design Specification</a>
053 */
054//@formatter:on
055public class MaterialEmptyState extends MaterialWidget implements HasIcon, HasTitle {
056
057    static {
058        if (MaterialAddins.isDebug()) {
059            MaterialDesignBase.injectCss(MaterialEmptyStateDebugClientBundle.INSTANCE.emptyStateDebugCss());
060        } else {
061            MaterialDesignBase.injectCss(MaterialEmptyStateClientBundle.INSTANCE.emptyStateCss());
062        }
063    }
064
065    private boolean loading;
066    private MaterialIcon icon = new MaterialIcon();
067    private MaterialTitle title = new MaterialTitle();
068    private Div container = new Div();
069
070    public MaterialEmptyState() {
071        super(Document.get().createDivElement(), CssName.VALIGN_WRAPPER, AddinsCssName.EMPTY_STATE);
072    }
073
074    public MaterialEmptyState(Color bgColor, Color textColor, IconType iconType, String title, String description) {
075        this();
076        setBackgroundColor(bgColor);
077        setTextColor(textColor);
078        setIconType(iconType);
079        setTitle(title);
080        setDescription(description);
081    }
082
083    @Override
084    protected void onLoad() {
085        super.onLoad();
086
087        setTextAlign(TextAlign.CENTER);
088        add(container);
089        container.setWidth("100%");
090        container.setStyleName(CssName.VALIGN + " " + CssName.CENTER);
091        container.add(title);
092        icon.setIconSize(IconSize.LARGE);
093        title.insert(icon, 0);
094    }
095
096    @Override
097    public void setDescription(String description) {
098        title.setDescription(description);
099    }
100
101    @Override
102    public void setTitle(String titleText) {
103        title.setTitle(titleText);
104    }
105
106    @Override
107    public MaterialIcon getIcon() {
108        return icon;
109    }
110
111    @Override
112    public void setIconType(IconType iconType) {
113        icon.setIconType(iconType);
114    }
115
116    @Override
117    public void setIconPosition(IconPosition position) {
118        icon.setIconPosition(position);
119    }
120
121    @Override
122    public void setIconSize(IconSize size) {
123        icon.setIconSize(size);
124    }
125
126    @Override
127    public void setIconFontSize(double size, Unit unit) {
128        icon.setIconFontSize(size, unit);
129    }
130
131    @Override
132    public void setIconColor(Color iconColor) {
133        icon.setIconColor(iconColor);
134    }
135
136    @Override
137    public Color getIconColor() {
138        return icon.getIconColor();
139    }
140
141    @Override
142    public void setIconPrefix(boolean prefix) {
143        icon.setIconPrefix(prefix);
144    }
145
146    @Override
147    public boolean isIconPrefix() {
148        return icon.isIconPrefix();
149    }
150
151    public Div getContainer() {
152        return container;
153    }
154
155    public boolean isLoading() {
156        return loading;
157    }
158
159    public void setLoading(boolean loading) {
160        this.loading = loading;
161        MaterialLoader.loading(loading, icon);
162    }
163}