001package gwt.material.design.client.ui; 002 003/* 004 * #%L 005 * GwtMaterial 006 * %% 007 * Copyright (C) 2015 GwtMaterialDesign 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 023import com.google.gwt.dom.client.Document; 024import com.google.gwt.dom.client.Style; 025import com.google.gwt.event.dom.client.*; 026import com.google.gwt.event.shared.HandlerRegistration; 027import com.google.gwt.user.client.ui.Widget; 028import gwt.material.design.client.base.MaterialWidget; 029import gwt.material.design.client.ui.html.ListItem; 030import gwt.material.design.client.ui.html.UnorderedList; 031 032//@formatter:off 033 034/** 035 * CollapsibleItem element to define the header 036 * @author kevzlou7979 037 * @author Ben Dol 038 * @see <a href="http://gwt-material-demo.herokuapp.com/#collapsibles">Material Collapsibles</a> 039 */ 040//@formatter:on 041public class MaterialCollapsibleHeader extends MaterialWidget implements HasAllMouseHandlers, HasClickHandlers { 042 043 /** Creates empty collapsible header. 044 */ 045 public MaterialCollapsibleHeader() { 046 super(Document.get().createDivElement(), "collapsible-header"); 047 } 048 049 /** Adds other components as header. 050 */ 051 public MaterialCollapsibleHeader(final Widget... widgets) { 052 this(); 053 for(Widget w : widgets) { 054 add(w); 055 } 056 } 057 058 @Override 059 public void add(Widget child) { 060 if(child instanceof UnorderedList) { 061 for(Widget w : (UnorderedList) child) { 062 if(w instanceof ListItem) { 063 w.getElement().getStyle().setDisplay(Style.Display.BLOCK); 064 } 065 } 066 } else if(child instanceof ListItem) { 067 child.getElement().getStyle().setDisplay(Style.Display.BLOCK); 068 } 069 super.add(child); 070 } 071 072 @Override 073 public HandlerRegistration addClickHandler(final ClickHandler handler) { 074 return addDomHandler(new ClickHandler() { 075 @Override 076 public void onClick(ClickEvent event) { 077 if(isEnabled()){ 078 handler.onClick(event); 079 } 080 } 081 }, ClickEvent.getType()); 082 } 083 084 @Override 085 public HandlerRegistration addMouseDownHandler(final MouseDownHandler handler) { 086 return addDomHandler(new MouseDownHandler() { 087 @Override 088 public void onMouseDown(MouseDownEvent event) { 089 if(isEnabled()){ 090 handler.onMouseDown(event); 091 } 092 } 093 }, MouseDownEvent.getType()); 094 } 095 096 @Override 097 public HandlerRegistration addMouseMoveHandler(final MouseMoveHandler handler) { 098 return addDomHandler(new MouseMoveHandler() { 099 @Override 100 public void onMouseMove(MouseMoveEvent event) { 101 if(isEnabled()){ 102 handler.onMouseMove(event); 103 } 104 } 105 }, MouseMoveEvent.getType()); 106 } 107 108 @Override 109 public HandlerRegistration addMouseOutHandler(final MouseOutHandler handler) { 110 return addDomHandler(new MouseOutHandler() { 111 @Override 112 public void onMouseOut(MouseOutEvent event) { 113 if(isEnabled()){ 114 handler.onMouseOut(event); 115 } 116 } 117 }, MouseOutEvent.getType()); 118 } 119 120 @Override 121 public HandlerRegistration addMouseOverHandler(final MouseOverHandler handler) { 122 return addDomHandler(new MouseOverHandler() { 123 @Override 124 public void onMouseOver(MouseOverEvent event) { 125 if(isEnabled()){ 126 handler.onMouseOver(event); 127 } 128 } 129 }, MouseOverEvent.getType()); 130 } 131 132 @Override 133 public HandlerRegistration addMouseUpHandler(final MouseUpHandler handler) { 134 return addDomHandler(new MouseUpHandler() { 135 @Override 136 public void onMouseUp(MouseUpEvent event) { 137 if(isEnabled()){ 138 handler.onMouseUp(event); 139 } 140 } 141 }, MouseUpEvent.getType()); 142 } 143 144 @Override 145 public HandlerRegistration addMouseWheelHandler(final MouseWheelHandler handler) { 146 return addDomHandler(new MouseWheelHandler() { 147 @Override 148 public void onMouseWheel(MouseWheelEvent event) { 149 if(isEnabled()){ 150 handler.onMouseWheel(event); 151 } 152 } 153 }, MouseWheelEvent.getType()); 154 } 155}