View Javadoc

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.menus.impl;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.student.common.ui.client.mvc.Callback;
22  import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData;
23  
24  import com.google.gwt.user.client.ui.Composite;
25  import com.google.gwt.user.client.ui.FlowPanel;
26  import com.google.gwt.user.client.ui.HTMLPanel;
27  
28  public class KSBlockMenuImpl extends Composite{
29  	private FlowPanel layout = new FlowPanel();
30  	private FlowPanel container = new FlowPanel();
31  	private List<KSListMenuImpl> menus = new ArrayList<KSListMenuImpl>();
32  	private List<KSMenuItemData> data;
33  
34  	public KSBlockMenuImpl(){
35  		//layout.setStyleName("KS-Block-Menu");
36  		layout.setStyleName("ks-page-sub-navigation");
37  		container.add(layout);
38  		layout.add(new HTMLPanel("<div class=\"clear\">&nbsp;</div>"));
39  		this.initWidget(container);
40  	}
41  
42  	public void addMenu(KSListMenuImpl menu){
43  		menu.setStyleName("ks-page-sub-navigation-menu");
44  		layout.insert(menu, layout.getWidgetCount() -1);
45  		menus.add(menu);
46  		menu.addGlobalMenuItemSelectCallback(new Callback<KSMenuItemData>(){
47  
48  			@Override
49  			public void exec(KSMenuItemData result) {
50  				for(int i=0; i < KSBlockMenuImpl.this.menus.size(); i++){
51  					KSBlockMenuImpl.this.menus.get(i).clearSelected();
52  				}
53  				
54  			}
55  		});
56  
57  	}
58  
59  	public void setMenus(List<KSListMenuImpl> menus){
60  		for(KSListMenuImpl menu: menus){
61  			this.addMenu(menu);
62  		}
63  	}
64  
65  	/**
66  	 * Use the top level menu items of a list of KSMenuItemData to generate separate menus in a block
67  	 * layout
68  	 * @param data
69  	 */
70  	public void setTopLevelItems(List<KSMenuItemData> data){
71  		this.data = data;
72  		refresh();
73  	}
74  	
75  	public void refresh(){
76  		layout.clear();
77  		menus.clear();
78  		layout.add(new HTMLPanel("<div class=\"clear\">&nbsp;</div>"));
79  		for(KSMenuItemData item: data){
80  			List<KSMenuItemData> list = new ArrayList<KSMenuItemData>();
81  			list.add(item);
82  			KSListMenuImpl menu = new KSListMenuImpl();
83  			menu.setItems(list);
84  			this.addMenu(menu);
85  		}
86  	}
87  	
88  }