| 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.List; |
| 19 |
|
|
| 20 |
|
import org.kuali.student.common.ui.client.mvc.Callback; |
| 21 |
|
import org.kuali.student.common.ui.client.theme.Theme; |
| 22 |
|
import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel; |
| 23 |
|
import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData; |
| 24 |
|
import org.kuali.student.common.ui.client.widgets.menus.MenuChangeEvent; |
| 25 |
|
import org.kuali.student.common.ui.client.widgets.menus.MenuEventHandler; |
| 26 |
|
import org.kuali.student.common.ui.client.widgets.menus.MenuSelectEvent; |
| 27 |
|
import org.kuali.student.common.ui.client.widgets.menus.KSMenu.MenuImageLocation; |
| 28 |
|
import org.kuali.student.common.ui.client.widgets.menus.impl.KSListMenuImpl; |
| 29 |
|
|
| 30 |
|
import com.google.gwt.event.dom.client.ClickEvent; |
| 31 |
|
import com.google.gwt.event.dom.client.ClickHandler; |
| 32 |
|
import com.google.gwt.event.dom.client.FocusEvent; |
| 33 |
|
import com.google.gwt.event.dom.client.FocusHandler; |
| 34 |
|
import com.google.gwt.event.dom.client.KeyDownEvent; |
| 35 |
|
import com.google.gwt.event.dom.client.KeyDownHandler; |
| 36 |
|
import com.google.gwt.event.dom.client.MouseOutEvent; |
| 37 |
|
import com.google.gwt.event.dom.client.MouseOutHandler; |
| 38 |
|
import com.google.gwt.event.dom.client.MouseOverEvent; |
| 39 |
|
import com.google.gwt.event.dom.client.MouseOverHandler; |
| 40 |
|
import com.google.gwt.user.client.ui.Composite; |
| 41 |
|
import com.google.gwt.user.client.ui.HTMLPanel; |
| 42 |
|
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
| 43 |
|
import com.google.gwt.user.client.ui.HorizontalPanel; |
| 44 |
|
import com.google.gwt.user.client.ui.Image; |
| 45 |
|
import com.google.gwt.user.client.ui.PopupPanel; |
| 46 |
|
import com.google.gwt.user.client.ui.Widget; |
| 47 |
|
import com.google.gwt.user.client.ui.KeyboardListener; |
| 48 |
|
|
|
|
|
| 0% |
Uncovered Elements: 170 (170) |
Complexity: 45 |
Complexity Density: 0.41 |
|
| 49 |
|
public class StylishDropDown extends Composite{ |
| 50 |
|
|
| 51 |
|
private ClickablePanel namePanel = new ClickablePanel(); |
| 52 |
|
private SpanPanel parentPanel = new SpanPanel(); |
| 53 |
|
private boolean showSelectedItem = false; |
| 54 |
|
private boolean showTitleIcon = false; |
| 55 |
|
private PopupPanel menuPanel = new PopupPanel(); |
| 56 |
|
private KSListMenuImpl menu = new KSListMenuImpl(); |
| 57 |
|
private HorizontalPanel layout = new HorizontalPanel(); |
| 58 |
|
private KSLabel titleLabel = new KSLabel(); |
| 59 |
|
private Image titleImage = Theme.INSTANCE.getCommonImages().getSpacer(); |
| 60 |
|
private HorizontalPanel titleLayout = new HorizontalPanel(); |
| 61 |
|
private Image defaultArrow = Theme.INSTANCE.getCommonImages().getDropDownIconBlack(); |
| 62 |
|
private boolean mouseOver = false; |
| 63 |
|
private MenuImageLocation imgLoc = MenuImageLocation.RIGHT; |
| 64 |
|
private boolean makeButton = false; |
| 65 |
|
private boolean enabled = true; |
| 66 |
|
|
| 67 |
|
|
| 68 |
|
private KSButton button; |
| 69 |
|
|
| 70 |
|
private ClickHandler panelHandler = new ClickHandler(){ |
| 71 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 72 |
0
|
@Override... |
| 73 |
|
public void onClick(ClickEvent event) { |
| 74 |
0
|
if(enabled){ |
| 75 |
0
|
if(!menuPanel.isShowing()){ |
| 76 |
0
|
StylishDropDown.this.showMenu(); |
| 77 |
|
} |
| 78 |
|
else{ |
| 79 |
0
|
StylishDropDown.this.hideMenu(); |
| 80 |
|
} |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
}; |
| 86 |
|
|
| 87 |
|
private KeyDownHandler downHandler = new KeyDownHandler(){ |
| 88 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 6 |
Complexity Density: 0.75 |
|
| 89 |
0
|
@Override... |
| 90 |
|
public void onKeyDown(KeyDownEvent event) { |
| 91 |
0
|
if(enabled){ |
| 92 |
0
|
if (event.getNativeKeyCode() == KeyboardListener.KEY_DOWN || event.getNativeKeyCode() == KeyboardListener.KEY_ENTER) |
| 93 |
0
|
StylishDropDown.this.showMenu(); |
| 94 |
0
|
else if (event.getNativeKeyCode() == KeyboardListener.KEY_UP) |
| 95 |
0
|
StylishDropDown.this.hideMenu(); |
| 96 |
0
|
else if (event.getNativeKeyCode() == KeyboardListener.KEY_TAB) |
| 97 |
|
{ |
| 98 |
0
|
StylishDropDown.this.showMenu(); |
| 99 |
0
|
titleLayout.removeStyleName("KS-Basic-Menu-Item-Panel-Main-Hover"); |
| 100 |
|
} |
| 101 |
|
} |
| 102 |
|
} |
| 103 |
|
}; |
| 104 |
|
|
| 105 |
|
private FocusHandler focusHandler = new FocusHandler(){ |
| 106 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 107 |
0
|
@Override... |
| 108 |
|
public void onFocus(FocusEvent event) { |
| 109 |
0
|
if(enabled) |
| 110 |
0
|
titleLayout.addStyleName("KS-Basic-Menu-Item-Panel-Main-Hover"); |
| 111 |
|
} |
| 112 |
|
}; |
| 113 |
|
|
| 114 |
|
private MouseOverHandler mouseOverHandler = new MouseOverHandler() { |
| 115 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 116 |
0
|
@Override... |
| 117 |
|
public void onMouseOver(MouseOverEvent event) { |
| 118 |
0
|
titleLayout.addStyleName("KS-Basic-Menu-Item-Panel-Main-Hover"); |
| 119 |
|
} |
| 120 |
|
|
| 121 |
|
}; |
| 122 |
|
|
| 123 |
|
private MouseOutHandler mouseOutHandler = new MouseOutHandler() { |
| 124 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 125 |
0
|
@Override... |
| 126 |
|
public void onMouseOut(MouseOutEvent event) { |
| 127 |
0
|
titleLayout.removeStyleName("KS-Basic-Menu-Item-Panel-Main-Hover"); |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
}; |
| 131 |
|
|
| 132 |
|
private MenuEventHandler menuHandler = new MenuEventHandler(){ |
| 133 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 134 |
0
|
@Override... |
| 135 |
|
public void onChange(MenuChangeEvent e) { |
| 136 |
|
|
| 137 |
|
|
| 138 |
|
} |
| 139 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 140 |
0
|
@Override... |
| 141 |
|
public void onSelect(MenuSelectEvent e) { |
| 142 |
0
|
KSMenuItemData i = (KSMenuItemData) e.getSource(); |
| 143 |
0
|
StylishDropDown.this.hideMenu(); |
| 144 |
0
|
if(showSelectedItem){ |
| 145 |
0
|
titleLayout.clear(); |
| 146 |
0
|
titleLabel.setText(i.getLabel()); |
| 147 |
0
|
titleLayout.add(titleLabel); |
| 148 |
0
|
if(i.getShownIcon() != null){ |
| 149 |
0
|
titleLayout.add(i.getShownIcon()); |
| 150 |
|
} |
| 151 |
|
} |
| 152 |
|
|
| 153 |
|
} |
| 154 |
|
}; |
| 155 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 156 |
0
|
public StylishDropDown(String title){... |
| 157 |
0
|
titleLayout.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); |
| 158 |
0
|
titleLabel.setText(title); |
| 159 |
0
|
titleLayout.add(titleLabel); |
| 160 |
0
|
titleLayout.add(titleImage); |
| 161 |
0
|
init(); |
| 162 |
|
} |
| 163 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 164 |
0
|
public StylishDropDown(String title, Image image, MenuImageLocation imgLoc){... |
| 165 |
0
|
titleLayout.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); |
| 166 |
0
|
titleLabel.setText(title); |
| 167 |
0
|
titleImage = image; |
| 168 |
0
|
titleLayout.add(titleLabel); |
| 169 |
0
|
if(imgLoc == MenuImageLocation.RIGHT){ |
| 170 |
0
|
titleLayout.add(titleImage); |
| 171 |
|
} |
| 172 |
|
else{ |
| 173 |
0
|
titleLayout.insert(titleImage, 0); |
| 174 |
|
} |
| 175 |
0
|
menu.setImageLocation(imgLoc); |
| 176 |
0
|
init(); |
| 177 |
|
} |
| 178 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 179 |
0
|
public StylishDropDown(Widget widget){... |
| 180 |
0
|
titleLayout.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); |
| 181 |
0
|
titleLayout.add(widget); |
| 182 |
0
|
init(); |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
|
| 186 |
|
|
| 187 |
|
|
| 188 |
|
@param |
| 189 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 190 |
0
|
public void makeAButtonWhenOneItem(boolean makeButton){... |
| 191 |
0
|
this.makeButton = makeButton; |
| 192 |
|
} |
| 193 |
|
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
|
| 194 |
0
|
private void init(){... |
| 195 |
0
|
layout.clear(); |
| 196 |
0
|
layout.setWidth("100%"); |
| 197 |
0
|
layout.add(titleLayout); |
| 198 |
0
|
layout.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); |
| 199 |
0
|
layout.add(defaultArrow); |
| 200 |
|
|
| 201 |
0
|
namePanel.setWidget(layout); |
| 202 |
0
|
menu.addGlobalMenuItemSelectCallback(new Callback<KSMenuItemData>(){ |
| 203 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
| 204 |
0
|
@Override... |
| 205 |
|
public void exec(KSMenuItemData item) { |
| 206 |
0
|
if(item.getClickHandler() != null){ |
| 207 |
0
|
StylishDropDown.this.hideMenu(); |
| 208 |
0
|
if(showSelectedItem){ |
| 209 |
0
|
titleLabel.setText(item.getLabel()); |
| 210 |
0
|
if(item.getShownIcon() != null && showTitleIcon){ |
| 211 |
0
|
titleLayout.remove(titleImage); |
| 212 |
0
|
Image image = item.getShownIcon(); |
| 213 |
0
|
titleImage = new Image(image.getUrl(), image.getOriginLeft(), |
| 214 |
|
image.getOriginTop(), image.getWidth(), image.getHeight()); |
| 215 |
0
|
if(imgLoc == MenuImageLocation.RIGHT){ |
| 216 |
0
|
titleLayout.add(titleImage); |
| 217 |
|
} |
| 218 |
|
else{ |
| 219 |
0
|
titleLayout.insert(titleImage, 0); |
| 220 |
|
} |
| 221 |
|
|
| 222 |
|
} |
| 223 |
|
} |
| 224 |
|
} |
| 225 |
|
} |
| 226 |
|
}); |
| 227 |
0
|
menuPanel.setWidget(menu); |
| 228 |
0
|
namePanel.addClickHandler(panelHandler); |
| 229 |
0
|
namePanel.addKeyDownHandler(downHandler); |
| 230 |
0
|
namePanel.addFocusHandler(focusHandler); |
| 231 |
0
|
namePanel.addMouseOverHandler(mouseOverHandler); |
| 232 |
0
|
namePanel.addMouseOutHandler(mouseOutHandler); |
| 233 |
0
|
namePanel.setTabIndex(1); |
| 234 |
0
|
menuPanel.setAutoHideEnabled(true); |
| 235 |
0
|
menuPanel.addAutoHidePartner(namePanel.getElement()); |
| 236 |
0
|
namePanel.getElement().setAttribute("id", HTMLPanel.createUniqueId()); |
| 237 |
0
|
parentPanel.add(namePanel); |
| 238 |
0
|
this.initWidget(parentPanel); |
| 239 |
0
|
titleLabel.addStyleName("KS-CutomDropDown-TitleLabel"); |
| 240 |
0
|
layout.addStyleName("KS-CustomDropDown-TitlePanel"); |
| 241 |
0
|
defaultArrow.addStyleName("KS-CustomDropDown-Arrow"); |
| 242 |
|
} |
| 243 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 244 |
0
|
public void showMenu(){... |
| 245 |
0
|
menuPanel.setPopupPosition(this.getAbsoluteLeft(), this.getAbsoluteTop() + this.getOffsetHeight()); |
| 246 |
0
|
menuPanel.show(); |
| 247 |
|
} |
| 248 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 249 |
0
|
public void hideMenu(){... |
| 250 |
0
|
menuPanel.hide(); |
| 251 |
|
} |
| 252 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 253 |
0
|
public void setArrowImage(Image arrow){... |
| 254 |
0
|
layout.remove(defaultArrow); |
| 255 |
0
|
arrow.addStyleName("KS-CustomDropDown-Arrow"); |
| 256 |
0
|
layout.add(arrow); |
| 257 |
|
} |
| 258 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0.27 |
|
| 259 |
0
|
public void setItems(List<KSMenuItemData> items){... |
| 260 |
0
|
if(makeButton && items.size() == 1){ |
| 261 |
0
|
KSMenuItemData item = items.get(0); |
| 262 |
0
|
button = new KSButton(); |
| 263 |
0
|
button.addStyleName("ks-button-spacing"); |
| 264 |
0
|
button.addClickHandler(item.getClickHandler()); |
| 265 |
0
|
button.setText(item.getLabel()); |
| 266 |
0
|
parentPanel.clear(); |
| 267 |
0
|
parentPanel.add(button); |
| 268 |
|
} |
| 269 |
|
else{ |
| 270 |
0
|
if(!namePanel.isAttached()){ |
| 271 |
0
|
parentPanel.clear(); |
| 272 |
0
|
parentPanel.add(namePanel); |
| 273 |
|
} |
| 274 |
0
|
for(KSMenuItemData item: items){ |
| 275 |
0
|
item.addMenuEventHandler(MenuSelectEvent.TYPE, menuHandler); |
| 276 |
0
|
item.addMenuEventHandler(MenuChangeEvent.TYPE, menuHandler); |
| 277 |
|
} |
| 278 |
0
|
menu.setItems(items); |
| 279 |
|
} |
| 280 |
|
|
| 281 |
|
} |
| 282 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 283 |
0
|
public void setEnabled(boolean enabled){... |
| 284 |
0
|
this.enabled = enabled; |
| 285 |
0
|
if(!enabled){ |
| 286 |
0
|
layout.addStyleName("KS-CustomDropDown-TitlePanel-Disabled"); |
| 287 |
|
} |
| 288 |
|
else{ |
| 289 |
0
|
layout.removeStyleName("KS-CustomDropDown-TitlePanel-Disabled"); |
| 290 |
|
} |
| 291 |
0
|
if(button != null){ |
| 292 |
0
|
button.setEnabled(enabled); |
| 293 |
|
} |
| 294 |
|
} |
| 295 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 296 |
0
|
public void setImageLocation(MenuImageLocation loc){... |
| 297 |
0
|
imgLoc = loc; |
| 298 |
0
|
menu.setImageLocation(loc); |
| 299 |
|
} |
| 300 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 301 |
0
|
@Override... |
| 302 |
|
public void addStyleName(String style){ |
| 303 |
0
|
namePanel.addStyleName(style); |
| 304 |
0
|
menu.addStyleName(style); |
| 305 |
|
} |
| 306 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 307 |
0
|
public boolean isShowingSelectedItem() {... |
| 308 |
0
|
return showSelectedItem; |
| 309 |
|
} |
| 310 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 311 |
0
|
public void setShowSelectedItem(boolean showSelectedItem) {... |
| 312 |
0
|
this.showSelectedItem = showSelectedItem; |
| 313 |
|
} |
| 314 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 315 |
0
|
public void setShowTitleIcon(boolean showTitleIcon){... |
| 316 |
0
|
this.showTitleIcon = showTitleIcon; |
| 317 |
|
} |
| 318 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 319 |
0
|
public boolean isShowingTitleIcon(){... |
| 320 |
0
|
return showTitleIcon; |
| 321 |
|
} |
| 322 |
|
|
| 323 |
|
|
| 324 |
|
} |