View Javadoc

1   package org.kuali.student.lum.program.client.widgets;
2   
3   import com.google.gwt.event.dom.client.ClickEvent;
4   import com.google.gwt.event.dom.client.ClickHandler;
5   import com.google.gwt.event.shared.HandlerManager;
6   import com.google.gwt.user.client.ui.Composite;
7   import com.google.gwt.user.client.ui.FlowPanel;
8   
9   import org.kuali.student.common.ui.client.application.Application;
10  import org.kuali.student.common.ui.client.widgets.KSButton;
11  import org.kuali.student.common.ui.client.widgets.KSButtonAbstract;
12  import org.kuali.student.common.ui.client.widgets.KSLabel;
13  import org.kuali.student.lum.program.client.ProgramMsgConstants;
14  import org.kuali.student.lum.program.client.events.ChangeViewEvent;
15  
16  /**
17   * @author Igor
18   */
19  public class EditableHeader extends Composite {
20  
21      private FlowPanel content = new FlowPanel();
22  
23      private KSLabel sectionTitle;
24  
25      private KSButton editButton = new KSButton(getLabel(ProgramMsgConstants.COMMON_EDIT), KSButtonAbstract.ButtonStyle.DEFAULT_ANCHOR);
26  
27      private Enum<?> viewToken;
28  
29      private HandlerManager eventBus;
30  
31      public EditableHeader(String title, Enum<?> viewToken, HandlerManager eventBus) {
32          initWidget(content);
33          this.eventBus = eventBus;
34          this.viewToken = viewToken;
35          sectionTitle = new KSLabel(title);
36          buildLayout();
37          setStyles();
38          bind();
39      }
40  
41      private void bind() {
42          editButton.addClickHandler(new ClickHandler() {
43              @Override
44              public void onClick(ClickEvent event) {
45                  eventBus.fireEvent(new ChangeViewEvent(viewToken));
46              }
47          });
48      }
49  
50      private void setStyles() {
51          sectionTitle.addStyleName("sectionTitle");
52          content.addStyleName("editableHeader");
53          editButton.addStyleName("sectionEditLink");
54      }
55  
56      private void buildLayout() {
57          content.add(sectionTitle);
58          content.add(editButton);
59      }
60      
61      protected String getLabel(String messageKey) {
62          return Application.getApplicationContext().getUILabel(ProgramMsgConstants.PROGRAM_MSG_GROUP, messageKey);
63      }
64  }