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   * Date: 14-Jul-2010
16   * Time: 10:52:16 AM
17   */
18  
19  package org.kuali.student.common.ui.client.configurable.mvc.multiplicity;
20  
21  import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityConfiguration.StyleType;
22  import org.kuali.student.common.ui.client.configurable.mvc.sections.BaseSection;
23  import org.kuali.student.common.ui.client.mvc.Callback;
24  import org.kuali.student.common.ui.client.widgets.field.layout.layouts.BorderedHeadedLayout;
25  import org.kuali.student.common.ui.client.widgets.field.layout.layouts.HeadedLayout;
26  import org.kuali.student.common.ui.client.widgets.field.layout.layouts.UnborderedHeadedLayout;
27  
28  import com.google.gwt.event.dom.client.ClickEvent;
29  import com.google.gwt.event.dom.client.ClickHandler;
30  import com.google.gwt.user.client.ui.Widget;
31  
32  public class MultiplicityGroupItem extends BaseSection {
33  	
34      private boolean updateable=false;
35      private Integer itemKey;      
36      private Widget itemWidget;
37      private Callback<MultiplicityGroupItem> removeCallback;
38      private boolean created = true;
39      private boolean deleted = false;
40  	private boolean loaded = false;
41  
42      private MultiplicityConfiguration.StyleType style;
43  
44  	String itemLabel;
45  
46      /**
47       *  Represents a single item within a MultiplicityGroup
48       *
49       * //TODO Should this be an inner class in MultiplicityGroup?
50       *  
51       * @param itemLabel
52       * @param style
53       * @param updateable
54       */
55      public MultiplicityGroupItem(String itemLabel, StyleType style, boolean updateable){
56  
57  		this.itemLabel = itemLabel;
58  		this.style = style;
59  		this.updateable = updateable;
60  	}
61  
62      private void buildLayout() {
63  
64          switch (style) {
65              case TOP_LEVEL_GROUP:
66              case BORDERED_TABLE:
67                  layout = new BorderedHeadedLayout(itemLabel, updateable);
68                  break;
69              case SUB_LEVEL_GROUP:
70              case BORDERLESS_TABLE:
71                  layout = new UnborderedHeadedLayout(itemLabel, updateable);
72                  break;
73          }
74          ((HeadedLayout)layout).setUpdateable(updateable);
75      }
76  
77  	public void redraw() {
78  		if (!loaded){
79  			buildLayout(); 
80  
81  			if(updateable){
82  	    	    ((HeadedLayout)layout).addDeleteHandler(new ClickHandler() {
83  	                public void onClick(ClickEvent event) {
84  	                    getRemoveCallback().exec(MultiplicityGroupItem.this);
85  	                }
86  	            });
87  	    	}
88  	    	
89  	    	layout.addWidget(this.getItemWidget());
90  	    	this.add(layout);
91  		}		
92  	}
93  	public Integer getItemKey() {
94          return itemKey;
95      }
96  
97      public void setItemKey(Integer itemKey) {
98          this.itemKey = itemKey;
99      }
100 
101     public Widget getItemWidget() {
102         return itemWidget;
103     }
104 
105     public void setItemWidget(Widget itemWidget) {
106         this.itemWidget = itemWidget;
107     }
108 
109     public void setRemoveCallback(Callback<MultiplicityGroupItem> callback){
110         removeCallback = callback;
111     }
112 
113     public Callback<MultiplicityGroupItem> getRemoveCallback(){
114         return removeCallback;
115     }
116 
117     public boolean isCreated() {
118         return created;
119     }
120 
121     public void setCreated(boolean created) {
122         this.created = created;
123     }
124 
125     public boolean isDeleted() {
126         return deleted;
127     }
128 
129     public void setDeleted(boolean isDeleted) {
130         this.deleted = isDeleted;
131         if(isDeleted)
132             this.created = false;
133     }
134 }