001 package org.gwtbootstrap3.client.ui.base;
002
003 /*
004 * #%L
005 * GwtBootstrap3
006 * %%
007 * Copyright (C) 2013 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 org.gwtbootstrap3.client.ui.base.helper.StyleHelper;
024 import org.gwtbootstrap3.client.ui.base.mixin.ActiveMixin;
025 import org.gwtbootstrap3.client.ui.base.mixin.EnabledMixin;
026 import org.gwtbootstrap3.client.ui.base.mixin.IdMixin;
027 import org.gwtbootstrap3.client.ui.base.mixin.PullMixin;
028 import org.gwtbootstrap3.client.ui.constants.DeviceSize;
029 import org.gwtbootstrap3.client.ui.constants.Pull;
030 import org.gwtbootstrap3.client.ui.constants.Styles;
031
032 import com.google.gwt.dom.client.Document;
033 import com.google.gwt.user.client.ui.HasEnabled;
034
035 /**
036 * Base class for list items.
037 *
038 * @author Sven Jacobs
039 * @author Joshua Godi
040 * @see org.gwtbootstrap3.client.ui.ListItem
041 * @see org.gwtbootstrap3.client.ui.AnchorListItem
042 * @see org.gwtbootstrap3.client.ui.ListDropDown
043 */
044 public abstract class AbstractListItem extends ComplexWidget implements HasEnabled, HasPull, HasActive,
045 HasResponsiveness, HasId {
046
047 private final ActiveMixin<AbstractListItem> activeMixin = new ActiveMixin<AbstractListItem>(this);
048 private final PullMixin<AbstractListItem> pullMixin = new PullMixin<AbstractListItem>(this);
049 private final IdMixin<AbstractListItem> idMixin = new IdMixin<AbstractListItem>(this);
050 private final EnabledMixin<AbstractListItem> enabledMixin = new EnabledMixin<AbstractListItem>(this);
051
052 protected AbstractListItem() {
053 setElement(Document.get().createLIElement());
054 }
055
056 @Override
057 public void setEnabled(final boolean enabled) {
058 enabledMixin.setEnabled(enabled);
059 }
060
061 @Override
062 public boolean isEnabled() {
063 return !StyleHelper.containsStyle(getStyleName(), Styles.DISABLED);
064 }
065
066 @Override
067 public void setPull(final Pull pull) {
068 pullMixin.setPull(pull);
069 }
070
071 @Override
072 public Pull getPull() {
073 return pullMixin.getPull();
074 }
075
076 @Override
077 public void setActive(final boolean active) {
078 activeMixin.setActive(active);
079 }
080
081 @Override
082 public boolean isActive() {
083 return activeMixin.isActive();
084 }
085
086 @Override
087 public void setVisibleOn(final DeviceSize deviceSize) {
088 StyleHelper.setVisibleOn(this, deviceSize);
089 }
090
091 @Override
092 public void setHiddenOn(final DeviceSize deviceSize) {
093 StyleHelper.setHiddenOn(this, deviceSize);
094 }
095
096 @Override
097 public void setId(final String id) {
098 idMixin.setId(id);
099 }
100
101 @Override
102 public String getId() {
103 return idMixin.getId();
104 }
105 }