001    package org.gwtbootstrap3.extras.select.client.ui;
002    
003    /*
004     * #%L
005     * GwtBootstrap3
006     * %%
007     * Copyright (C) 2013 - 2014 GwtBootstrap3
008     * %%
009     * Licensed under the Apache License, Version 2.0 (the "License");
010     * you may not use this file except in compliance with the License.
011     * You may obtain a copy of the License at
012     * 
013     *      http://www.apache.org/licenses/LICENSE-2.0
014     * 
015     * Unless required by applicable law or agreed to in writing, software
016     * distributed under the License is distributed on an "AS IS" BASIS,
017     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018     * See the License for the specific language governing permissions and
019     * limitations under the License.
020     * #L%
021     */
022    
023    import com.google.gwt.dom.client.Document;
024    import org.gwtbootstrap3.client.ui.base.AbstractTextWidget;
025    import org.gwtbootstrap3.client.ui.base.mixin.AttributeMixin;
026    import org.gwtbootstrap3.client.ui.constants.IconType;
027    
028    import static org.gwtbootstrap3.extras.select.client.constants.DataAttributes.*;
029    
030    /**
031     * @author godi
032     */
033    public class Option extends AbstractTextWidget {
034        private final AttributeMixin<Option> attributeMixin = new AttributeMixin<Option>(this);
035    
036        public Option() {
037            super(Document.get().createOptionElement());
038        }
039    
040        public void setName(final String name) {
041            attributeMixin.setAttribute(NAME, name);
042        }
043    
044        public String getName() {
045            return attributeMixin.getAttribute(NAME);
046        }
047    
048        public void setValue(final String value) {
049            attributeMixin.setAttribute(VALUE, value);
050        }
051    
052        public String getValue() {
053            return attributeMixin.getAttribute(VALUE);
054        }
055    
056        public void setSubtext(final String subtext) {
057            attributeMixin.setAttribute(DATA_SUBTEXT, subtext);
058        }
059    
060        public String getSubtext() {
061            return attributeMixin.getAttribute(DATA_SUBTEXT);
062        }
063    
064        public void clearSubtext() {
065            attributeMixin.removeAttribute(DATA_SUBTEXT);
066        }
067    
068        public void setShowDivider(final boolean showDivider) {
069            if (showDivider) {
070                attributeMixin.setAttribute(DATA_DIVIDER, Boolean.toString(true));
071            } else {
072                attributeMixin.removeAttribute(DATA_DIVIDER);
073            }
074        }
075    
076        public boolean getShowDivider() {
077            return attributeMixin.getAttribute(DATA_DIVIDER) != null;
078        }
079    
080        public void setEnabled(final boolean enabled) {
081            if (enabled) {
082                attributeMixin.removeAttribute(DISABLED);
083            } else {
084                attributeMixin.setAttribute(DISABLED, DISABLED);
085            }
086        }
087    
088        public boolean isEnabled() {
089            return attributeMixin.getAttribute(DISABLED) == null;
090        }
091    
092        public void setIcon(final IconType iconType) {
093            attributeMixin.setAttribute(DATA_ICON, iconType.getCssName());
094        }
095    
096        public IconType getIcon() {
097            return IconType.fromStyleName(attributeMixin.getAttribute(DATA_ICON));
098        }
099        
100        public void setHidden(final boolean hidden) {
101            if (hidden) {
102                attributeMixin.setAttribute(DATA_HIDDEN, Boolean.toString(true));
103            } else {
104                attributeMixin.removeAttribute(DATA_HIDDEN);
105            }
106        }
107        
108        public boolean isHidden() {
109            return attributeMixin.getAttribute(DATA_HIDDEN) != null;
110        }
111    }