001package gwt.material.design.addins.client.subheader; 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.Element; 025import com.google.gwt.user.client.DOM; 026import com.google.gwt.user.client.ui.Widget; 027import gwt.material.design.addins.client.subheader.constants.SubHeaderType; 028import gwt.material.design.client.base.HasType; 029import gwt.material.design.client.base.MaterialWidget; 030import gwt.material.design.client.base.mixin.CssTypeMixin; 031 032//@formatter:off 033 034/** 035 * SubHeader Container will wrap your subheader items. 036 * There are two types of SubHeader Container <br/> 037 * 1. PINNED<br/> 038 * 2. STATIC 039 * 040 * <h3>XML Namespace Declaration</h3> 041 * <pre> 042 * {@code 043 * xmlns:ma='urn:import:gwt.material.design.addins.client' 044 * } 045 * </pre> 046 * 047 * <h3>UiBinder Usage:</h3> 048 * <pre> 049 * {@code 050 * <ma:subheader.MaterialSubHeaderContainer height="400px" type="PINNED"> 051 * <ma:subheader.MaterialSubHeader text="Subheader" textColor="pink" /> 052 * </ma:subheader.MaterialSubHeaderContainer> 053 * } 054 * </pre> 055 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#subheaders">Material Subheader</a> 056 * @author kevzlou7979 057 */ 058//@formatter:on 059public class MaterialSubHeaderContainer extends MaterialWidget implements HasType<SubHeaderType>{ 060 061 static { 062 MaterialSubHeader.loadResources(); 063 } 064 065 private final CssTypeMixin<SubHeaderType, MaterialSubHeaderContainer> typeMixin = new CssTypeMixin<>(this); 066 067 public MaterialSubHeaderContainer() { 068 super(Document.get().createDivElement(), "container1"); 069 } 070 071 @Override 072 protected void onLoad() { 073 super.onLoad(); 074 if(getType() == SubHeaderType.PINNED) { 075 String uniqueName = DOM.createUniqueId(); 076 for (Widget w : getChildren()) { 077 if (w instanceof MaterialSubHeader) { 078 w.addStyleName(uniqueName); 079 } 080 } 081 initSubheaders("." + uniqueName, getElement()); 082 } 083 } 084 085 protected native void initSubheaders(String subheader, Element container) /*-{ 086 $wnd.jQuery(document).ready(function() { 087 $wnd.initSubheader(subheader, container); 088 }); 089 }-*/; 090 091 @Override 092 public void setType(SubHeaderType type) { 093 typeMixin.setType(type); 094 } 095 096 @Override 097 public SubHeaderType getType() { 098 return typeMixin.getType(); 099 } 100}