@@ -41,21 +41,26 @@ interface MaterialTabsUiBinder extends UiBinder<Widget, MaterialTabs> {
4141 @ UiField
4242 UnorderedList tabPanel ;
4343
44- private String name ;
4544
4645 private String color = "" ;
4746 private String textColor = "" ;
4847 private String indicatorColor = "" ;
4948 private String waves = "" ;
49+ private int tabIndex = 1 ;
5050
51+ /**
52+ * The tabs structure consists of an unordered list of tabs that have hashes corresponding to tab ids. Then when you click on each tab, only the container with the corresponding tab id will become visible.
53+ */
5154 public MaterialTabs () {
5255 initWidget (uiBinder .createAndBindUi (this ));
5356 }
54-
57+
5558 @ Override
5659 protected void onAttach () {
60+ // TODO Auto-generated method stub
5761 super .onAttach ();
58- name = String .valueOf (hashCode ());
62+ tabPanel .getElement ().setId (String .valueOf (System .currentTimeMillis ()));
63+ String name = String .valueOf (hashCode ());
5964 int col = 12 / tabPanel .getWidgetCount ();
6065 int index = tabPanel .getWidgetCount ();
6166 for (Widget w : tabPanel ) {
@@ -74,14 +79,25 @@ protected void onAttach() {
7479 w .getElement ().setAttribute ("id" , name + indexC );
7580 indexC --;
7681 }
77- initTabs ();
82+ initTabs (tabPanel . getElement (). getId () );
7883 changeIndicator (indicatorColor );
84+
85+ String id = contentPanel .getWidget (tabIndex ).getElement ().getId ();
86+ selectTab (id , tabPanel .getElement ().getId ());
7987 }
8088
89+ /**
90+ * Line Indicator on Tab Navigation
91+ * @param color
92+ */
8193 public native void changeIndicator (String color )/*-{
8294 $wnd.jQuery( ".indicator" ).css( "background-color", color );
8395 }-*/ ;
8496
97+ /**
98+ * Adding each tab nav , must add also the Content if you add a tab nav item
99+ * @param item
100+ */
85101 @ UiChild (tagname = "tab" )
86102 public void addTab (final Widget item ) {
87103 CustomAnchor a = new CustomAnchor ();
@@ -90,48 +106,110 @@ public void addTab(final Widget item) {
90106 tabPanel .add (li );
91107 }
92108
109+ /**
110+ * Adding each tab content on the navigation
111+ * @param item
112+ */
93113 @ UiChild (tagname = "content" )
94114 public void addContent (final Widget item ) {
95115 item .addStyleName ("col s12" );
96116 contentPanel .add (item );
97117 }
98118
99- public static native void initTabs ()/*-{
119+ /**
120+ * Initialize the Material Tab
121+ */
122+ public static native void initTabs (String ulId )/*-{
100123 $wnd.jQuery(document).ready(function() {
101- $wnd.jQuery('ul.tabs' ).tabs();
124+ $wnd.jQuery('ul#' + ulId ).tabs();
102125 });
103126 }-*/ ;
104-
127+
128+
129+ /**
130+ * Selecting the tab with id on the content
131+ * @param id
132+ */
133+ private native void selectTab (String id , String ulId )/*-{
134+ $wnd.jQuery(document).ready(function(){
135+ $wnd.jQuery('ul#' + ulId).tabs('select_tab', id);
136+ });
137+ }-*/ ;
138+
139+ /**
140+ * Get the color of the tab
141+ */
105142 public String getColor () {
106143 return color ;
107144 }
108145
146+ /**
147+ * Setting the color of the tab
148+ */
109149 public void setColor (String color ) {
110150 this .color = color ;
111151 }
112152
153+ /**
154+ * Get the text color of the tab
155+ */
113156 public String getTextColor () {
114157 return textColor ;
115158 }
116159
160+ /**
161+ * Set the text color of the tab
162+ */
117163 public void setTextColor (String textColor ) {
118164 this .textColor = textColor ;
119165 }
120166
167+ /**
168+ * Get the indicator underlined color
169+ * @return
170+ */
121171 public String getIndicatorColor () {
122172 return indicatorColor ;
123173 }
124174
175+ /**
176+ * Set the indicator underlined color
177+ * @param indicatorColor
178+ */
125179 public void setIndicatorColor (String indicatorColor ) {
126180 this .indicatorColor = indicatorColor ;
127181 }
128182
183+ /**
184+ * Get the waves effect of the tab
185+ */
129186 public String getWaves () {
130187 return waves ;
131188 }
132189
190+ /**
191+ * Set the waves effect of the tab
192+ */
133193 public void setWaves (String waves ) {
134194 this .waves = waves ;
135195 }
196+
197+
198+ /**
199+ * @return the tabIndex
200+ */
201+ public int getTabIndex () {
202+ return tabIndex ;
203+ }
204+
205+
206+ /**
207+ * @param You can automatically set the tab index by passing the desired tab index number, starts from 1.
208+ */
209+ public void setTabIndex (int tabIndex ) {
210+ this .tabIndex = tabIndex ;
211+ }
212+
213+
136214
137215}
0 commit comments