Coverage Report - org.kuali.student.common.ui.client.widgets.tabs.impl.KSTabPanelImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
KSTabPanelImpl
0%
0/90
0%
0/14
1.794
KSTabPanelImpl$Tab
0%
0/80
0%
0/34
1.794
KSTabPanelImpl$Tab$1
0%
0/3
N/A
1.794
KSTabPanelImpl$Tab$2
0%
0/6
0%
0/4
1.794
KSTabPanelImpl$Tab$3
0%
0/3
N/A
1.794
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.common.ui.client.widgets.tabs.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.HashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.kuali.student.common.ui.client.mvc.Callback;
 24  
 import org.kuali.student.common.ui.client.widgets.ClickablePanel;
 25  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 26  
 import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
 27  
 import org.kuali.student.common.ui.client.widgets.menus.KSListPanel;
 28  
 import org.kuali.student.common.ui.client.widgets.tabs.KSTabPanelAbstract;
 29  
 import org.kuali.student.common.ui.client.widgets.tabs.KSTabPanel.TabPanelStyle;
 30  
 import org.kuali.student.common.ui.client.widgets.tabs.KSTabPanel.TabPosition;
 31  
 
 32  
 import com.google.gwt.event.dom.client.ClickEvent;
 33  
 import com.google.gwt.event.dom.client.ClickHandler;
 34  
 import com.google.gwt.event.dom.client.MouseOutEvent;
 35  
 import com.google.gwt.event.dom.client.MouseOutHandler;
 36  
 import com.google.gwt.event.dom.client.MouseOverEvent;
 37  
 import com.google.gwt.event.dom.client.MouseOverHandler;
 38  
 import com.google.gwt.user.client.ui.ComplexPanel;
 39  
 import com.google.gwt.user.client.ui.Composite;
 40  
 import com.google.gwt.user.client.ui.FlowPanel;
 41  
 import com.google.gwt.user.client.ui.HorizontalPanel;
 42  
 import com.google.gwt.user.client.ui.Image;
 43  
 import com.google.gwt.user.client.ui.Label;
 44  
 import com.google.gwt.user.client.ui.SimplePanel;
 45  
 import com.google.gwt.user.client.ui.Widget;
 46  
 
 47  0
 public class KSTabPanelImpl extends KSTabPanelAbstract{
 48  
         
 49  0
         private VerticalFlowPanel container = new VerticalFlowPanel();
 50  0
         private FlowPanel tabRow = new FlowPanel();
 51  
         //private HorizontalPanel left = new HorizontalPanel();
 52  
         //private HorizontalPanel right = new HorizontalPanel();
 53  0
         private KSListPanel left = new KSListPanel();
 54  0
         private KSListPanel right = new KSListPanel();
 55  0
         private SimplePanel content = new SimplePanel();
 56  
         private Tab selectedTab;
 57  0
         private Map<String, Tab> tabMap = new HashMap<String, Tab>();
 58  
         
 59  
 
 60  
         
 61  
 /*        protected class TabPanel extends SimplePanel implements HasAllMouseHandlers{
 62  
 
 63  
                 @Override
 64  
                 public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
 65  
                         // TODO Auto-generated method stub
 66  
                         return null;
 67  
                 }
 68  
 
 69  
                 @Override
 70  
                 public HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
 71  
                         // TODO Auto-generated method stub
 72  
                         return null;
 73  
                 }
 74  
 
 75  
                 @Override
 76  
                 public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
 77  
                         // TODO Auto-generated method stub
 78  
                         return null;
 79  
                 }
 80  
 
 81  
                 @Override
 82  
                 public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
 83  
                         // TODO Auto-generated method stub
 84  
                         return null;
 85  
                 }
 86  
 
 87  
                 @Override
 88  
                 public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
 89  
                         // TODO Auto-generated method stub
 90  
                         return null;
 91  
                 }
 92  
 
 93  
                 @Override
 94  
                 public HandlerRegistration addMouseWheelHandler(
 95  
                                 MouseWheelHandler handler) {
 96  
                         // TODO Auto-generated method stub
 97  
                         return null;
 98  
                 }
 99  
 
 100  
                 
 101  
         }*/
 102  
         
 103  0
         protected class Tab extends Composite{
 104  0
                 private boolean selected = false;
 105  
                 private Widget tab;
 106  0
                 private ClickablePanel tabPanel = new ClickablePanel();
 107  
                 private Widget displayContent;
 108  0
                 private int labelIndex = -1;
 109  0
                 private String tabKey = "";
 110  0
                 private List<Callback<String>> callbacks = new ArrayList<Callback<String>>();
 111  
                 
 112  0
                 public Tab(String key, String label, Image image, Widget displayContent){
 113  0
                         tabKey = key;
 114  0
                         HorizontalPanel tabContent = new HorizontalPanel();
 115  0
                         tabContent.add(image);
 116  0
                         KSLabel labelWidget = new KSLabel(label);
 117  0
                         tabContent.add(labelWidget);
 118  0
                         labelIndex = tabContent.getWidgetIndex(labelWidget);
 119  0
                         init(tabContent, displayContent);
 120  
                         
 121  0
                 }
 122  
                 
 123  0
                 public Tab(String key, String label, Widget displayContent){
 124  0
                         tabKey = key;
 125  0
                         KSLabel labelWidget = new KSLabel(label);
 126  0
                         init(labelWidget, displayContent);
 127  0
                 }
 128  
                 
 129  0
                 public Tab(String key, Widget tab, Widget displayContent){
 130  0
                         tabKey = key;
 131  0
                         init(tab, displayContent);
 132  0
                 }
 133  
                 
 134  
                 public void addCallback(Callback<String> callback) {
 135  0
                         callbacks.add(callback);
 136  0
                 }
 137  
                 
 138  
                 public void emptyCallbacks(){
 139  0
                         callbacks = new ArrayList<Callback<String>>();
 140  0
                 }
 141  
 
 142  
                 public String getTabKey() {
 143  0
                         return tabKey;
 144  
                 }
 145  
 
 146  
                 public void init(Widget tab, Widget displayContent){
 147  0
                         this.tab = tab;
 148  0
                         this.tabPanel.setWidget(tab);
 149  0
                         tabPanel.addMouseOverHandler(new MouseOverHandler(){
 150  
 
 151  
                                 @Override
 152  
                                 public void onMouseOver(MouseOverEvent event) {
 153  0
                                         Tab.this.onMouseOver();
 154  
                                         
 155  0
                                 }
 156  
                         });
 157  0
                         tabPanel.addClickHandler(new ClickHandler(){
 158  
 
 159  
                                 @Override
 160  
                                 public void onClick(ClickEvent event) {
 161  0
                                         Tab.this.onSelect();
 162  0
                                         if(!callbacks.isEmpty()){
 163  0
                                                 for(Callback<String> callback: callbacks){
 164  0
                                                         callback.exec(tabKey);
 165  
                                                 }
 166  
                                         }
 167  0
                                 }
 168  
                         });
 169  0
                         tabPanel.addMouseOutHandler(new MouseOutHandler(){
 170  
 
 171  
                                 @Override
 172  
                                 public void onMouseOut(MouseOutEvent event) {
 173  0
                                         Tab.this.onMouseOut();
 174  
                                         
 175  0
                                 }
 176  
                         });
 177  0
                         tabPanel.addStyleName("KS-TabPanel-Tab");
 178  0
                         this.initWidget(tabPanel);
 179  0
                         this.displayContent = displayContent;
 180  0
                 }
 181  
                 
 182  
                 public void addTabStyleName(String style){
 183  0
                         tabPanel.addStyleName(style);
 184  0
                 }
 185  
                 
 186  
                 public void onSelect(){
 187  0
                         KSTabPanelImpl.this.deselectCurrentTab();
 188  0
                         KSTabPanelImpl.this.selectedTab = Tab.this;
 189  0
                         selected = true;
 190  0
                         this.onMouseOut();
 191  0
                         tabPanel.addStyleName("KS-TabPanel-Tab-Selected");
 192  0
                         if(tab instanceof Label || tab instanceof KSLabel){
 193  0
                                 tab.addStyleName("KS-TabPanel-Tab-Label-Selected");
 194  
                         }
 195  0
                         else if(tab instanceof ComplexPanel){
 196  0
                                 if(labelIndex != -1){
 197  0
                                         Widget w = ((ComplexPanel) tab).getWidget(labelIndex);
 198  0
                                         w.addStyleName("KS-TabPanel-Tab-Label-Selected");
 199  
                                 }
 200  
                         }
 201  0
                         KSTabPanelImpl.this.content.clear();
 202  0
                         KSTabPanelImpl.this.content.setWidget(displayContent);
 203  0
                 }
 204  
                 
 205  
                 public void onDeselect(){
 206  0
                         selected = false;
 207  0
                         tabPanel.removeStyleName("KS-TabPanel-Tab-Selected");
 208  0
                         if(tab instanceof Label || tab instanceof KSLabel){
 209  0
                                 tab.removeStyleName("KS-TabPanel-Tab-Label-Selected");
 210  
                         }
 211  0
                         else if(tab instanceof ComplexPanel){
 212  0
                                 if(labelIndex != -1){
 213  0
                                         Widget w = ((ComplexPanel) tab).getWidget(labelIndex);
 214  0
                                         w.removeStyleName("KS-TabPanel-Tab-Label-Selected");
 215  
                                 }
 216  
                         }
 217  0
                 }
 218  
                 
 219  
                 public void onMouseOver(){
 220  0
                         if(!selected){
 221  0
                                 tabPanel.addStyleName("KS-TabPanel-Tab-Hover");
 222  0
                                 if(tab instanceof Label || tab instanceof KSLabel){
 223  0
                                         tab.addStyleName("KS-TabPanel-Tab-Label-Hover");
 224  
                                 }
 225  0
                                 else if(tab instanceof ComplexPanel){
 226  0
                                         if(labelIndex != -1){
 227  0
                                                 Widget w = ((ComplexPanel) tab).getWidget(labelIndex);
 228  0
                                                 w.addStyleName("KS-TabPanel-Tab-Label-Hover");
 229  
                                         }
 230  
                                 }
 231  
                         }
 232  0
                 }
 233  
                 
 234  
                 public void onMouseOut(){
 235  0
                         tabPanel.removeStyleName("KS-TabPanel-Tab-Hover");
 236  0
                         if(tab instanceof Label || tab instanceof KSLabel){
 237  0
                                 tab.removeStyleName("KS-TabPanel-Tab-Label-Hover");
 238  
                         }
 239  0
                         else if(tab instanceof ComplexPanel){
 240  0
                                 if(labelIndex != -1){
 241  0
                                         Widget w = ((ComplexPanel) tab).getWidget(labelIndex);
 242  0
                                         w.removeStyleName("KS-TabPanel-Tab-Label-Hover");
 243  
                                 }
 244  
                         }
 245  0
                 }
 246  
         }
 247  
         
 248  0
         public KSTabPanelImpl(){
 249  
                 //left.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
 250  
                 //right.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
 251  
                 //tabRow.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
 252  0
                 tabRow.add(left);
 253  0
                 tabRow.add(right);
 254  0
                 tabRow.addStyleName("KS-TabPanel-TabRow");
 255  0
                 left.addStyleName("KS-TabPanel-Left-Panel");
 256  0
                 right.addStyleName("KS-TabPanel-Right-Panel");
 257  0
                 container.addStyleName("KS-TabPanel-Full");
 258  0
                 content.addStyleName("KS-TabPanel-Content");
 259  0
                 container.add(tabRow);
 260  0
                 container.add(content);
 261  0
                 this.initWidget(container);
 262  0
         }
 263  
         
 264  0
         public KSTabPanelImpl(TabPanelStyle style){
 265  
                 //left.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
 266  
                 //right.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
 267  
                 //tabRow.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
 268  0
                 tabRow.add(left);
 269  0
                 tabRow.add(right);
 270  0
                 tabRow.addStyleName("KS-TabPanel-TabRow");
 271  0
                 left.addStyleName("KS-TabPanel-Left-Panel");
 272  0
                 right.addStyleName("KS-TabPanel-Right-Panel");
 273  
 
 274  0
                 container.addStyleName("KS-TabPanel");
 275  0
                 content.addStyleName("KS-TabPanel-Content");
 276  0
                 container.add(tabRow);
 277  0
                 container.add(content);
 278  0
                 this.initWidget(container);
 279  0
         }
 280  
         
 281  
         public void setTabPanelStyle(TabPanelStyle style){
 282  0
                 if(style == TabPanelStyle.FULL_PAGE){
 283  0
                         container.setStyleName("KS-TabPanel-Full");
 284  
                 }
 285  0
                 else if(style == TabPanelStyle.SMALL){
 286  0
                         container.setStyleName("KS-TabPanel-Small");
 287  
                 }
 288  0
         }
 289  
 
 290  
         private void deselectCurrentTab() {
 291  0
                 if(selectedTab != null){
 292  0
                         selectedTab.onDeselect();
 293  
                 }
 294  0
         }
 295  
 
 296  
         @Override
 297  
         public void selectTab(String key){
 298  0
                 Tab tab = tabMap.get(key);
 299  0
                 tab.onSelect();
 300  0
         }
 301  
 
 302  
         @Override
 303  
         public void removeTab(String key){
 304  0
                 Tab tab = tabMap.get(key);
 305  0
                 tab.removeFromParent();
 306  0
         }
 307  
         
 308  
         private void positionTab(Tab tab, TabPosition position){
 309  0
                 if(position == TabPosition.LEFT){
 310  0
                         tab.addStyleName("KS-TabPanel-Tab-Left");
 311  0
                         left.add(tab);
 312  
                 }
 313  
                 else{
 314  0
                         tab.addStyleName("KS-TabPanel-Tab-Right");
 315  0
                         right.add(tab);
 316  
                 }
 317  0
         }
 318  
 
 319  
         @Override
 320  
         public void addTab(String key, Widget tabWidget, Widget content, TabPosition position){
 321  0
                 Tab tab = new Tab(key, tabWidget, content);
 322  0
                 tabMap.put(key, tab);
 323  0
                 positionTab(tab, position);
 324  0
         }
 325  
 
 326  
         @Override
 327  
         public void addTab(String key, String label, Widget content, TabPosition position){
 328  0
                 Tab tab = new Tab(key, label, content);
 329  0
                 tabMap.put(key, tab);
 330  0
                 positionTab(tab, position);
 331  0
         }
 332  
 
 333  
         @Override
 334  
         public void addTab(String key, String label, Image image, Widget content, TabPosition position){
 335  0
                 Tab tab = new Tab(key, label, image, content);
 336  0
                 tabMap.put(key, tab);
 337  0
                 positionTab(tab, position);
 338  0
         }
 339  
 
 340  
         @Override
 341  
         public void addTab(String key, String label, Image image, Widget content){
 342  0
                 Tab tab = new Tab(key, label, image, content);
 343  0
                 tabMap.put(key, tab);
 344  0
                 positionTab(tab, TabPosition.LEFT);
 345  0
         }
 346  
 
 347  
         @Override
 348  
         public void addTab(String key, String label, Widget content){
 349  0
                 Tab tab = new Tab(key, label, content);
 350  0
                 tabMap.put(key, tab);
 351  0
                 positionTab(tab, TabPosition.LEFT);
 352  0
         }
 353  
         
 354  
         @Override
 355  
         public void addTab(String key, Widget tabWidget, Widget content){
 356  0
                 Tab tab = new Tab(key, tabWidget, content);
 357  0
                 tabMap.put(key, tab);
 358  0
                 positionTab(tab, TabPosition.LEFT);
 359  0
         }
 360  
 
 361  
         @Override
 362  
         public void addStyleName(String style) {
 363  0
                 container.addStyleName(style);
 364  0
         }
 365  
 
 366  
         @Override
 367  
         public void addTabCustomCallback(final String key, final Callback<String> callback) {
 368  0
                 Tab tab = tabMap.get(key);
 369  0
                 if(tab != null){
 370  0
                         tab.addCallback(callback);
 371  
                 }
 372  
                 
 373  0
         }
 374  
 
 375  
         @Override
 376  
         public String getSelectedTabKey() {
 377  0
                 if(selectedTab != null){
 378  0
                         return selectedTab.getTabKey();
 379  
                 }
 380  
                 else{
 381  0
                         return "";
 382  
                 }
 383  
                 
 384  
         }
 385  
 
 386  
         @Override
 387  
         public int getTabCount() {
 388  0
                 return tabMap.size();
 389  
         }
 390  
 
 391  
         @Override
 392  
         public void removeTabCustomCallbacks(String key) {
 393  0
                 Tab tab = tabMap.get(key);
 394  0
                 if(tab != null){
 395  0
                         tab.emptyCallbacks();
 396  
                 }
 397  
                 
 398  0
         }
 399  
 
 400  
         @Override
 401  
         public boolean hasTabKey(String key) {
 402  0
                 return tabMap.containsKey(key);
 403  
         }
 404  
 
 405  
         
 406  
 }