001 /*
002 * Copyright 2012 GWT-Bootstrap
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package com.github.gwtbootstrap.client.ui.base;
017
018 import com.github.gwtbootstrap.client.ui.constants.Device;
019 import com.google.gwt.user.client.DOM;
020 import com.google.gwt.user.client.ui.ComplexPanel;
021 import com.google.gwt.user.client.ui.HasWidgets;
022 import com.google.gwt.user.client.ui.Widget;
023
024 /**
025 * A widget that can have several child widgets.
026 * <p>
027 * Base of a lot of other components :)
028 *
029 * @since 2.0.4.0
030 *
031 * @author Carlos Alexandro Becker
032 */
033 public class ComplexWidget extends ComplexPanel implements HasWidgets,
034 HasStyle, IsResponsive {
035
036 /**
037 * Creates a new widget that is based on the provided html tag.
038 *
039 * @param tag
040 * the html tag used for this widget
041 */
042 public ComplexWidget(String tag) {
043 setElement(DOM.createElement(tag));
044 }
045
046 /**
047 * {@inheritDoc}
048 */
049 @Override
050 public void add(Widget w) {
051 add(w, getElement());
052
053 // // logical add
054 // getChildren().add(w);
055 //
056 // // physical add
057 // getElement().appendChild(w.getElement());
058
059 }
060
061 /**
062 * Inserts another widget into this one.
063 *
064 * @param w
065 * the widget to be inserted
066 * @param beforeIndex
067 * the index of the position before which it should be set
068 */
069 public void insert(Widget w, int beforeIndex) {
070 insert(w, getElement(), beforeIndex, true);
071 }
072
073 /**
074 * {@inheritDoc}
075 */
076 public void setStyle(Style style) {
077 StyleHelper.setStyle(this, style);
078 }
079
080 /**
081 * {@inheritDoc}
082 */
083 public void addStyle(Style style) {
084 StyleHelper.addStyle(this, style);
085 }
086
087 /**
088 * {@inheritDoc}
089 */
090 public void removeStyle(Style style) {
091 StyleHelper.removeStyle(this, style);
092 }
093
094 /**
095 * {@inheritDoc}
096 */
097 public void setShowOn(Device device) {
098 ResponsiveHelper.setShowOn(this, device);
099 }
100
101 /**
102 * {@inheritDoc}
103 */
104 public void setHideOn(Device device) {
105 ResponsiveHelper.setHideOn(this, device);
106 }
107 }