| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.common.ui.client.widgets; | 
  | 17 |  |   | 
  | 18 |  |  import java.util.ArrayList; | 
  | 19 |  |  import java.util.List; | 
  | 20 |  |   | 
  | 21 |  |  import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; | 
  | 22 |  |  import org.kuali.student.common.ui.client.widgets.menus.KSListPanel; | 
  | 23 |  |   | 
  | 24 |  |  import com.google.gwt.event.dom.client.ClickHandler; | 
  | 25 |  |  import com.google.gwt.user.client.ui.Composite; | 
  | 26 |  |  import com.google.gwt.user.client.ui.HTMLPanel; | 
  | 27 |  |  import com.google.gwt.user.client.ui.HorizontalPanel; | 
  | 28 |  |  import com.google.gwt.user.client.ui.Widget; | 
  | 29 |  |   | 
  | 30 |  |  public class KSActionItemList extends Composite{ | 
  | 31 | 0 |          private KSLabel title = new KSLabel(); | 
  | 32 | 0 |          private KSListPanel listLayout = new KSListPanel(); | 
  | 33 | 0 |          private List<ActionItem> actionItems = new ArrayList<ActionItem>(); | 
  | 34 |  |   | 
  | 35 | 0 |          public static enum ListLocation{TOP, BOTTOM} | 
  | 36 |  |   | 
  | 37 |  |          private static class ActionItem{ | 
  | 38 |  |                  private String text; | 
  | 39 |  |                  private String shortDesc; | 
  | 40 |  |                  private ClickHandler handler; | 
  | 41 |  |   | 
  | 42 |  |                  private KSButton link; | 
  | 43 |  |                  private KSLabel desc; | 
  | 44 | 0 |                  private HorizontalPanel layout = new HorizontalPanel(); | 
  | 45 |  |   | 
  | 46 |  |                  public ActionItem(String text, String shortDesc, | 
  | 47 | 0 |                                  ClickHandler handler) { | 
  | 48 |  |   | 
  | 49 | 0 |                          link.addStyleName("KS-ActionItemList-Link"); | 
  | 50 | 0 |                          desc.addStyleName("KS-ActionItemList-Desc"); | 
  | 51 | 0 |                          this.text = text; | 
  | 52 | 0 |                          this.shortDesc = shortDesc; | 
  | 53 | 0 |                          this.handler = handler; | 
  | 54 | 0 |                          link = new KSButton(text, ButtonStyle.DEFAULT_ANCHOR); | 
  | 55 | 0 |                          desc =  new KSLabel(shortDesc); | 
  | 56 | 0 |                  } | 
  | 57 |  |   | 
  | 58 |  |                  public String getText() { | 
  | 59 | 0 |                          return text; | 
  | 60 |  |                  } | 
  | 61 |  |                  public void setText(String text) { | 
  | 62 | 0 |                          this.text = text; | 
  | 63 | 0 |                  } | 
  | 64 |  |                  public String getShortDesc() { | 
  | 65 | 0 |                          return shortDesc; | 
  | 66 |  |                  } | 
  | 67 |  |                  public void setShortDesc(String shortDesc) { | 
  | 68 | 0 |                          this.shortDesc = shortDesc; | 
  | 69 | 0 |                  } | 
  | 70 |  |                  public ClickHandler getHandler() { | 
  | 71 | 0 |                          return handler; | 
  | 72 |  |                  } | 
  | 73 |  |                  public void setHandler(ClickHandler handler) { | 
  | 74 | 0 |                          this.handler = handler; | 
  | 75 | 0 |                  } | 
  | 76 |  |   | 
  | 77 |  |                  public Widget getWidget(){ | 
  | 78 | 0 |                          String id = HTMLPanel.createUniqueId(); | 
  | 79 | 0 |                      HTMLPanel panel = new HTMLPanel("<a href='javascript:return false;' id='" + id + "'></a>"); | 
  | 80 | 0 |                      panel.add(link, id); | 
  | 81 | 0 |                          link.setText(text); | 
  | 82 | 0 |                          link.addClickHandler(handler); | 
  | 83 | 0 |                          desc.setText(shortDesc); | 
  | 84 | 0 |                          layout.clear(); | 
  | 85 | 0 |                          layout.add(panel); | 
  | 86 | 0 |                          layout.add(desc); | 
  | 87 | 0 |                          return layout; | 
  | 88 |  |                  } | 
  | 89 |  |          } | 
  | 90 |  |   | 
  | 91 | 0 |          public KSActionItemList(String title){ | 
  | 92 | 0 |                  this.title.setText(title); | 
  | 93 | 0 |                  listLayout.addStyleName("KS-ActionItemList-ListPanel"); | 
  | 94 | 0 |                  this.title.addStyleName("KS-ActionItemList-Title"); | 
  | 95 | 0 |                  redrawList(); | 
  | 96 | 0 |                  this.initWidget(listLayout); | 
  | 97 | 0 |          } | 
  | 98 |  |   | 
  | 99 | 0 |          public KSActionItemList(String title, List<ActionItem> items){ | 
  | 100 | 0 |                  this.title.setText(title); | 
  | 101 | 0 |                  listLayout.addStyleName("KS-ActionItemList-ListPanel"); | 
  | 102 | 0 |                  this.title.addStyleName("KS-ActionItemList-Title"); | 
  | 103 | 0 |                  actionItems = items; | 
  | 104 | 0 |                  redrawList(); | 
  | 105 | 0 |                  this.initWidget(listLayout); | 
  | 106 | 0 |          } | 
  | 107 |  |   | 
  | 108 |  |          public void redrawList(){ | 
  | 109 | 0 |                  listLayout.clear(); | 
  | 110 | 0 |                  if(!title.getText().isEmpty()){ | 
  | 111 | 0 |                          listLayout.add(title); | 
  | 112 |  |                  } | 
  | 113 | 0 |                  for(ActionItem item: actionItems){ | 
  | 114 | 0 |                          listLayout.add(item.getWidget()); | 
  | 115 |  |                  } | 
  | 116 |  |   | 
  | 117 | 0 |          } | 
  | 118 |  |   | 
  | 119 |  |          public void setTitle(String title){ | 
  | 120 | 0 |                  this.title.setText(title); | 
  | 121 | 0 |          } | 
  | 122 |  |   | 
  | 123 |  |          public void add(ActionItem item, ListLocation location){ | 
  | 124 | 0 |                  if(location == ListLocation.TOP){ | 
  | 125 | 0 |                          actionItems.add(0, item); | 
  | 126 |  |                  } | 
  | 127 |  |                  else{ | 
  | 128 | 0 |                          actionItems.add(item); | 
  | 129 |  |                  } | 
  | 130 |  |                   | 
  | 131 | 0 |          } | 
  | 132 |  |   | 
  | 133 |  |          public void add(String text, String shortDesc, ClickHandler handler, ListLocation location){ | 
  | 134 | 0 |                  ActionItem item = new ActionItem(text, shortDesc, handler); | 
  | 135 | 0 |                  if(location == ListLocation.TOP){ | 
  | 136 | 0 |                          actionItems.add(0, item); | 
  | 137 |  |                  } | 
  | 138 |  |                  else{ | 
  | 139 | 0 |                          actionItems.add(item); | 
  | 140 |  |                  } | 
  | 141 | 0 |                  redrawList(); | 
  | 142 | 0 |          } | 
  | 143 |  |   | 
  | 144 |  |          public void setActionItems(List<ActionItem> items){ | 
  | 145 | 0 |                  actionItems = items; | 
  | 146 | 0 |                  redrawList(); | 
  | 147 | 0 |          } | 
  | 148 |  |   | 
  | 149 |  |          public void remove(ActionItem item){ | 
  | 150 | 0 |                  actionItems.remove(item); | 
  | 151 | 0 |                  redrawList(); | 
  | 152 | 0 |          } | 
  | 153 |  |   | 
  | 154 |  |          public void removeByText(String text){ | 
  | 155 | 0 |                  for(ActionItem item: actionItems){ | 
  | 156 | 0 |                          if(text.equals(item.getText())){ | 
  | 157 | 0 |                                  actionItems.remove(item); | 
  | 158 | 0 |                                  break; | 
  | 159 |  |                          } | 
  | 160 |  |                  } | 
  | 161 | 0 |                  redrawList(); | 
  | 162 | 0 |          } | 
  | 163 |  |   | 
  | 164 |  |   | 
  | 165 |  |   | 
  | 166 |  |  } |