cimav.client.view.nomina.NomTextInputCell.java Source code

Java tutorial

Introduction

Here is the source code for cimav.client.view.nomina.NomTextInputCell.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cimav.client.view.nomina;

import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.TextInputCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;

/**
 *
 * @author juan.calderon
 */
public class NomTextInputCell extends TextInputCell {

    private static Template template;

    interface Template extends SafeHtmlTemplates {
        @SafeHtmlTemplates.Template("<input type='text' value='{0}' tabindex='-1' style='{1}'></input>")
        SafeHtml input(String value, String style);
    }

    public NomTextInputCell() {
        template = GWT.create(Template.class);
    }

    @Override
    public void render(Cell.Context context, String value, SafeHtmlBuilder sb) {
        // Get the view data.
        Object key = context.getKey();
        TextInputCell.ViewData viewData = this.getViewData(key);
        if (viewData != null && viewData.getCurrentValue().equals(value)) {
            clearViewData(key);
            viewData = null;
        }

        // boolean isEditing = this.isEditing(context, null, value);
        String v = (viewData != null) ? viewData.getCurrentValue() : value;
        if (v == null) // || isEditing)
        {
            sb.appendHtmlConstant("<input type'text' tabindex='-1'></input>");
        } else {
            // this is where we set value, size, style
            sb.append(template.input(v,
                    "width: 130px; text-align: inherit; margin: 0px; height: 22px !important; font-size:11px;"));
        }
    }
}