001package com.github.gwtbootstrap.client.ui; 002 003import com.github.gwtbootstrap.client.ui.base.DivWidget; 004import com.github.gwtbootstrap.client.ui.base.HasIcon; 005import com.github.gwtbootstrap.client.ui.base.HasVisibility; 006import com.github.gwtbootstrap.client.ui.base.HasVisibleHandlers; 007import com.github.gwtbootstrap.client.ui.base.IconAnchor; 008import com.github.gwtbootstrap.client.ui.constants.Constants; 009import com.github.gwtbootstrap.client.ui.constants.IconSize; 010import com.github.gwtbootstrap.client.ui.constants.IconType; 011import com.github.gwtbootstrap.client.ui.event.HiddenHandler; 012import com.github.gwtbootstrap.client.ui.event.HideHandler; 013import com.github.gwtbootstrap.client.ui.event.ShowHandler; 014import com.github.gwtbootstrap.client.ui.event.ShownHandler; 015import com.google.gwt.event.shared.HandlerRegistration; 016import com.google.gwt.uibinder.client.UiChild; 017import com.google.gwt.user.client.ui.Widget; 018 019/** 020 * Collapsible Widget like accordion. 021 * <p> 022 * Please see {@link Accordion} 023 * </p> 024 * @since 2.1.1.0 025 * @author ohashi keisuke 026 * @see Accordion 027 * @see Collapse 028 * @see CollapseTrigger 029 * @see <a href="http://twitter.github.com/bootstrap/javascript.html#collapse">Twitter Bootstrap document</a> 030 * 031 */ 032public class AccordionGroup extends DivWidget implements HasIcon,HasVisibility, HasVisibleHandlers { 033 034 private DivWidget innerBody = new DivWidget(Constants.ACCORDION_INNER); 035 036 private IconAnchor trigger = new IconAnchor(); 037 038 private Collapse collapse; 039 040 private CollapseTrigger collapseTrigger; 041 042 private boolean defaultOpen; 043 044 public AccordionGroup() { 045 super(Constants.ACCORDION_GROUP); 046 047 DivWidget body = new DivWidget(Constants.ACCORDION_BODY); 048 049 body.add(innerBody); 050 051 collapse = new Collapse(); 052 053 collapse.setWidget(body); 054 055 collapse.setExistTrigger(true); 056 057 trigger.addStyleName(Constants.ACCORDION_TOGGLE); 058 059 collapseTrigger = new CollapseTrigger("#" + collapse.getId()); 060 061 collapseTrigger.setWidget(trigger); 062 063 DivWidget heading = new DivWidget(Constants.ACCORDION_HEADING); 064 065 heading.add(collapseTrigger); 066 067 super.add(heading); 068 069 super.add(collapse.asWidget()); 070 } 071 072 /** 073 * {@inheritDoc} 074 */ 075 @Override 076 public void setIcon(IconType type) { 077 trigger.setIcon(type); 078 } 079 080 /** 081 * {@inheritDoc} 082 */ 083 @Override 084 public void setIconSize(IconSize size) { 085 trigger.setIconSize(size); 086 } 087 088 public void setParent(String parent) { 089 collapseTrigger.setParent(parent); 090 } 091 092 /** 093 * {@inheritDoc} 094 */ 095 @Override 096 public HandlerRegistration addHideHandler(HideHandler handler) { 097 return collapse.addHideHandler(handler); 098 } 099 100 /** 101 * {@inheritDoc} 102 */ 103 @Override 104 public HandlerRegistration addHiddenHandler(HiddenHandler handler) { 105 return collapse.addHiddenHandler(handler); 106 } 107 108 /** 109 * {@inheritDoc} 110 */ 111 @Override 112 public HandlerRegistration addShowHandler(ShowHandler handler) { 113 return collapse.addShowHandler(handler); 114 } 115 116 /** 117 * {@inheritDoc} 118 */ 119 @Override 120 public HandlerRegistration addShownHandler(ShownHandler handler) { 121 return collapse.addShownHandler(handler); 122 } 123 124 /** 125 * {@inheritDoc} 126 */ 127 @Override 128 public void show() { 129 collapse.show(); 130 } 131 132 /** 133 * {@inheritDoc} 134 */ 135 @Override 136 public void hide() { 137 collapse.hide(); 138 } 139 140 /** 141 * {@inheritDoc} 142 */ 143 @Override 144 public void toggle() { 145 collapse.toggle(); 146 } 147 148 /** 149 * {@inheritDoc} 150 */ 151 @Override 152 public void add(Widget w) { 153 innerBody.add(w); 154 } 155 156 /** 157 * {@inheritDoc} 158 */ 159 @Override 160 public void clear() { 161 innerBody.clear(); 162 } 163 164 /** 165 * {@inheritDoc} 166 */ 167 @Override 168 public boolean remove(Widget w) { 169 return innerBody.remove(w); 170 } 171 172 /** 173 * Add a widget to trigger anchor 174 * @param w added widget 175 */ 176 @UiChild(limit=1,tagname="customTrigger") 177 public void addCustomTrigger(Widget w) { 178 trigger.insert(w, 0); 179 } 180 181 /** 182 * is opened on attached. 183 * @return defaultOpen true:open false:close 184 */ 185 public boolean isDefaultOpen() { 186 return defaultOpen; 187 } 188 189 /** 190 * Set is opened on attached. 191 * @param defaultOpen true:open false:close 192 */ 193 public void setDefaultOpen(boolean defaultOpen) { 194 this.defaultOpen = defaultOpen; 195 196 if(!isAttached()) { 197 collapse.getWidget().setStyleName("in", defaultOpen); 198 } 199 200 } 201 202 public void setHeading(String heading) { 203 trigger.setText(heading); 204 } 205 206 /** 207 * {@inheritDoc} 208 */ 209 @Override 210 public void setCustomIconStyle(String customIconStyle) { 211 trigger.setCustomIconStyle(customIconStyle); 212 } 213 214}