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