org.wings.plaf.css.ComboBoxCG Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2000,2005 wingS development team.
*
* This file is part of wingS (http://wingsframework.org).
*
* wingS is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* Please see COPYING for the complete licence.
*/
package org.wings.plaf.css;
import org.wings.*;
import org.wings.io.Device;
import org.wings.io.StringBuilderDevice;
import org.wings.plaf.CGManager;
import org.wings.plaf.Update;
import org.wings.plaf.css.script.OnPageRenderedScript;
import org.wings.script.*;
import java.io.IOException;
public final class ComboBoxCG extends AbstractComponentCG implements org.wings.plaf.ComboBoxCG {
private static final long serialVersionUID = 1L;
@Override
public void installCG(final SComponent comp) {
super.installCG(comp);
final SComboBox component = (SComboBox) comp;
final CGManager manager = component.getSession().getCGManager();
Object value = manager.getObject("SComboBox.renderer", SDefaultListCellRenderer.class);
if (value != null) {
component.setRenderer((SDefaultListCellRenderer) value);
}
}
protected static void writeFormComboBox(Device device, SComboBox component) throws IOException {
Object clientProperty = component.getClientProperty("onChangeSubmitListener");
if (clientProperty == null) {
String event = JavaScriptEvent.ON_CHANGE;
String code = "wingS.request.sendEvent(event, true, " + !component.isReloadForced() + ");";
JavaScriptListener javaScriptListener = new JavaScriptListener(event, code);
component.addScriptListener(javaScriptListener);
component.putClientProperty("onChangeSubmitListener", javaScriptListener);
}
device.print("");
// util method
device.print("");
if (selected == -1) {
component.getSession().getScriptManager().addScriptListener(
new OnPageRenderedScript("document.getElementById(\"" + component.getName() + "\").selectedIndex = -1;"));
}
}
@Override
public void writeInternal(final Device device, final SComponent _c) throws IOException {
final SComboBox comboBox = (SComboBox) _c;
// TODO: implement anchor combobox
//if (comboBox.getShowAsFormComponent()) {
writeFormComboBox(device, comboBox);
//} else {
// writeAnchorComboBox(device, comboBox);
// }
}
@Override
public Update getSelectionUpdate(SComboBox comboBox, int selectedIndex) {
return new SelectionUpdate(comboBox, selectedIndex);
}
protected static class SelectionUpdate extends AbstractUpdate {
private Integer selectedIndex;
public SelectionUpdate(SComponent component, int selectedIndex) {
super(component);
this.selectedIndex = selectedIndex;
}
@Override
public Handler getHandler() {
UpdateHandler handler = new UpdateHandler("selectionComboBox");
handler.addParameter(component.getName());
handler.addParameter(selectedIndex);
return handler;
}
}
}