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.configurable.mvc.multiplicity;
17  
18  import org.kuali.student.common.ui.client.widgets.KSButton;
19  import org.kuali.student.common.ui.client.widgets.KSLabel;
20  import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
21  
22  import com.google.gwt.event.dom.client.ClickEvent;
23  import com.google.gwt.event.dom.client.ClickHandler;
24  import com.google.gwt.user.client.ui.HorizontalPanel;
25  import com.google.gwt.user.client.ui.Label;
26  import com.google.gwt.user.client.ui.Widget;
27  
28  /**
29   * This wraps a widget item
30   *
31   * @author Kuali Student Team
32   */
33  
34  /**
35   * @deprecated
36   */
37  public class RemovableItemWithHeader extends MultiplicityItem {
38      private String itemLabel = "Item ";
39      private boolean useDeleteLabel = false;
40      private boolean loaded = false;
41      private KSLabel headerLabel;
42      private boolean readOnly=false;
43      protected VerticalFlowPanel itemPanel = new VerticalFlowPanel();
44  
45      public RemovableItemWithHeader(){
46          initWidget(itemPanel);
47      }
48  
49      public void onLoad(){
50      }
51  
52      public void isReadOnly(boolean readOnly){
53          this.readOnly=readOnly;
54      }
55      private Widget generateRemoveWidget() {
56          ClickHandler ch = new ClickHandler() {
57              public void onClick(ClickEvent event) {
58                  getRemoveCallback().exec(RemovableItemWithHeader.this);
59              }
60          };
61  
62          Widget returnWidget;
63  
64          if (useDeleteLabel) {
65              Label deleteLabel = new Label("Delete");
66              deleteLabel.addStyleName("KS-Multiplicity-Link-Label");
67              deleteLabel.addClickHandler(ch);
68              returnWidget = deleteLabel;
69          } else {
70              returnWidget = new KSButton("-", ch);
71          }
72  
73          itemPanel.addStyleName("KS-Multiplicity-Item");
74  
75          if(readOnly){
76              returnWidget.setVisible(false);
77          }
78          else{
79              returnWidget.setVisible(true);
80          }
81  
82          return returnWidget;
83      }
84  
85      /**
86       * @see org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityItem#clear()
87       */
88      @Override
89      public void clear() {
90          loaded = false;
91      }
92  
93      /**
94       * @see org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityItem#redraw()
95       */
96      @Override
97      public void redraw() {
98          Widget item = getItemWidget();
99          if (!loaded){
100             itemPanel.addStyleName("KS-Multiplicity-Item");
101 
102             HorizontalPanel headerPanel = new HorizontalPanel();
103             headerPanel.addStyleName("KS-Multiplicity-Item-Header");
104             headerLabel = new KSLabel(itemLabel + " " + getItemKey());
105             headerPanel.add(headerLabel);
106             headerPanel.add(generateRemoveWidget());
107 
108             itemPanel.add(headerPanel);
109             itemPanel.add(item);
110 
111             loaded = true;
112             headerLabel.setText(itemLabel + " " + getItemKey());
113         }
114 
115 
116         //redraw() removed
117 /*        if (item instanceof Section){
118             ((Section)item).redraw();
119         }*/
120     }
121 
122     public void setItemLabel(String itemLabel) {
123         this.itemLabel = itemLabel;
124     }
125 
126     public void setUseDeleteLabel(boolean useDeleteLabel) {
127         this.useDeleteLabel = useDeleteLabel;
128     }
129 
130 }