All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wings.plaf.css.TextFieldCG 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.plaf.Update;
import org.wings.script.*;

import java.io.IOException;

public class TextFieldCG extends AbstractComponentCG implements
        org.wings.plaf.TextFieldCG {

    private static final long serialVersionUID = 1L;

    int horizontalOversize = 4;

    public int getHorizontalOversize() {
        return horizontalOversize;
    }

    public void setHorizontalOversize(int horizontalOversize) {
        this.horizontalOversize = horizontalOversize;
    }

    @Override
    public void installCG(SComponent comp ) {
        super.installCG( comp );
        if (Utils.isMSIE(comp))
            comp.putClientProperty("horizontalOversize", horizontalOversize);
    }

    @Override
    public void writeInternal(final Device device,
                              final SComponent component)
            throws IOException {
        final STextField textField = (STextField) component;

        onChangeSubmitListener(textField);

        SDimension preferredSize = component.getPreferredSize();
        boolean ieTableWrapping = Utils.isMSIE(component) && preferredSize != null && "%".equals(preferredSize.getWidthUnit());
        String actualWidth = null;
        if (ieTableWrapping) {
            actualWidth = preferredSize.getWidth();
            Utils.setPreferredSize(component, "100%", preferredSize.getHeight());
            if (component.getSession().getUserAgent().getMajorVersion() >= 7) {
                device.print("");
            } else {
                device.print("
"); } device.print("
"); } device.print(""); printPostInput(device, textField); if (ieTableWrapping) { Utils.setPreferredSize(component, actualWidth, preferredSize.getHeight()); device.print("
"); } } protected void onChangeSubmitListener(STextField textField) { Object clientProperty = textField.getClientProperty("onChangeSubmitListener"); // If the application developer attached any SDocumentListeners to this // STextField, the surrounding form gets submitted as soon as the content // of this STextField changed. if (textField.getDocumentListeners().length > 1 || textField instanceof SFormattedTextField) { // We need to test if there are at least 2 document // listeners because each text component registers // itself as a listener of its document as well. if (clientProperty == null) { String event = JavaScriptEvent.ON_CHANGE; String code = "wingS.request.sendEvent(event, true, " + !textField.isReloadForced() + ");"; JavaScriptListener javaScriptListener = new JavaScriptListener(event, code); textField.addScriptListener(javaScriptListener); textField.putClientProperty("onChangeSubmitListener", javaScriptListener); } } else if (clientProperty instanceof JavaScriptListener) { textField.removeScriptListener((JavaScriptListener) clientProperty); textField.putClientProperty("onChangeSubmitListener", null); } } protected void printPostInput(Device device, STextField textField) throws IOException { } @Override public Update getTextUpdate(STextField textField, String text) { return new TextUpdate(textField, text); } protected static class TextUpdate extends AbstractUpdate { private String text; public TextUpdate(SComponent component, String text) { super(component); this.text = text; } @Override public Handler getHandler() { UpdateHandler handler = new UpdateHandler("value"); handler.addParameter(component.getName()); handler.addParameter(text == null ? "" : text); return handler; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy