Example usage for com.google.gwt.json.client JSONValue isArray

List of usage examples for com.google.gwt.json.client JSONValue isArray

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONValue isArray.

Prototype

public JSONArray isArray() 

Source Link

Document

Returns a non-null reference if this JSONValue is really a JSONArray.

Usage

From source file:ca.nanometrics.gflot.client.options.GridOptions.java

License:Open Source License

/**
 * @return the background color inside the grid area. The array can contains one color or two colors if it's a
 * gradient/*  w w  w .  ja  v  a 2s  .  c o m*/
 */
public String[] getBackgroundColor() {
    JSONValue value = get(BACKGROUND_COLOR_KEY);
    if (value == null) {
        return null;
    }
    JSONString str = value.isString();
    if (null != str) {
        return new String[] { str.stringValue() };
    }
    JSONObject obj = value.isObject();
    if (null != obj) {
        JSONValue colors = obj.get(BACKGROUND_COLORS_KEY);
        JSONArray array = colors.isArray();
        if (null != array) {
            return new String[] { array.get(0).isString().stringValue(),
                    array.get(1).isString().stringValue() };
        }
    }
    return null;
}

From source file:ca.nanometrics.gflot.client.options.LegendOptions.java

License:Open Source License

/**
 * @return the distance to the plot edge. The array can contains one value if the margin is applied to both x and y
 * axis or 2 values if the first one is applied to x axis and the second one to y axis.
 *///from ww w  . ja va  2s.c o m
public Double[] getMargin() {
    JSONValue value = get(MARGIN_KEY);
    if (value == null) {
        return null;
    }
    JSONNumber number = value.isNumber();
    if (null != number) {
        return new Double[] { number.doubleValue() };
    }
    JSONArray array = value.isArray();
    if (null != array) {
        return new Double[] { array.get(0).isNumber().doubleValue(), array.get(1).isNumber().doubleValue() };
    }
    return null;
}

From source file:ca.nanometrics.gflot.client.util.JSONArrayWrapper.java

License:Open Source License

protected JSONArray getArray(int index) {
    JSONValue value = get(index);
    if (value == null) {
        return null;
    }//w  ww .j a va 2 s  .  c om
    return value.isArray();
}

From source file:ca.nanometrics.gflot.client.util.JSONObjectWrapper.java

License:Open Source License

protected JSONArray getArray(String key) {
    JSONValue value = get(key);
    if (value == null) {
        return null;
    }//from  www .  j  a v a2  s.c o m
    return value.isArray();
}

From source file:ccc.client.gwt.core.GWTJson.java

License:Open Source License

/** {@inheritDoc} */
@Override//from w ww.  ja  v  a 2 s.c o  m
public Collection<String> getStrings(final String key) {
    final JSONValue value = _delegate.get(key);
    if (null == value) {
        throw new S11nException("Missing key: " + key);
    } else if (null != value.isNull()) {
        return null;
    }

    final Collection<String> strings = new ArrayList<String>();

    final JSONArray array = value.isArray();
    for (int i = 0; i < array.size(); i++) {
        final JSONValue arrayElement = array.get(i);
        if (null != arrayElement.isNull()) {
            strings.add(null);
        } else {
            strings.add(arrayElement.isString().stringValue());
        }
    }

    return strings;
}

From source file:cimav.client.data.rest.ConceptoREST.java

public void findAll() {

    BaseREST.setDateFormatGET();//from w w w.  j  a v  a  2s  . c om
    String url = BaseREST.URL_REST_BASE + "api/concepto";

    Resource rb = new Resource(url, BaseREST.headers);
    rb.get().send(Ajax.jsonCall(new JsonCallback() {

        @Override
        public void onFailure(Method method, Throwable exception) {
            MethodEvent methodEvent = new MethodEvent(EMethod.FIND_ALL, ETypeResult.FAILURE,
                    exception.getMessage());
            onRESTExecuted(methodEvent);
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {
            List<Concepto> conceptos = new ArrayList<>();
            try {
                JSONArray array = response.isArray();
                for (int i = 0; i < array.size(); i++) {
                    JSONValue val = array.get(i);

                    Concepto concepto = (Concepto) jsonCodec.decode(val);
                    conceptos.add(concepto);
                }
                MethodEvent methodEvent = new MethodEvent(EMethod.FIND_ALL, ETypeResult.SUCCESS, "");
                methodEvent.setResult(conceptos);
                onRESTExecuted(methodEvent);
            } catch (Exception e) {
                String error = "findAll Conceptos >> " + e.getMessage();
                MethodEvent methodEvent = new MethodEvent(EMethod.FIND_ALL, ETypeResult.FAILURE, error);
                onRESTExecuted(methodEvent);
            }
        }

    }));

}

From source file:cimav.client.data.rest.DepartamentoREST.java

public void findAll() {

    BaseREST.setDateFormatGET();/*  w  w  w.  ja v a 2  s.  com*/
    String url = BaseREST.URL_REST_BASE + "api/departamento";

    Resource rb = new Resource(url, headers);
    rb.get().user("TEST").password("tesinf").send(Ajax.jsonCall(new JsonCallback() {

        @Override
        public void onFailure(Method method, Throwable exception) {
            MethodEvent methodEvent = new MethodEvent(EMethod.FIND_ALL, ETypeResult.FAILURE,
                    exception.getMessage());
            onRESTExecuted(methodEvent);
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {
            List<Departamento> departamentos = new ArrayList<>();
            try {
                JSONArray array = response.isArray();
                for (int i = 0; i < array.size(); i++) {
                    JSONValue val = array.get(i);

                    Departamento departamento = (Departamento) jsonCodec.decode(val);
                    departamentos.add(departamento);
                }
                MethodEvent methodEvent = new MethodEvent(EMethod.FIND_ALL, ETypeResult.SUCCESS, "");
                methodEvent.setResult(departamentos);
                onRESTExecuted(methodEvent);
            } catch (Exception e) {
                MethodEvent methodEvent = new MethodEvent(EMethod.FIND_ALL, ETypeResult.FAILURE,
                        e.getMessage());
                onRESTExecuted(methodEvent);
            }
        }

    }));

}

From source file:cimav.client.data.rest.EmpleadoREST.java

public void findAllBaseActivos() {

    BaseREST.setDateFormatGET();/*from  w  w  w.ja v a 2s. co  m*/

    String url = BaseREST.URL_REST_BASE + "api/empleado_base/activos";
    System.out.println("" + url);
    Resource rb = new Resource(url, headers);
    rb.get().send(Ajax.jsonCall(new JsonCallback() {

        @Override
        public void onFailure(Method method, Throwable exception) {
            MethodEvent dbEvent = new MethodEvent(EMethod.FIND_BASE_ALL, ETypeResult.FAILURE,
                    "FindAll " + exception.getMessage());
            onRESTExecuted(dbEvent);
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {
            try {
                List<EmpleadoBase> empleados = new ArrayList<>();
                JSONArray array = response.isArray();
                for (int i = 0; i < array.size(); i++) {
                    JSONValue val = array.get(i);
                    EmpleadoBase empleadoBase = empleadoBaseJsonCodec.decode(val);
                    empleados.add(empleadoBase);
                }
                MethodEvent dbEvent = new MethodEvent(EMethod.FIND_BASE_ALL, ETypeResult.SUCCESS,
                        "findAll listo");
                dbEvent.setResult(empleados);
                onRESTExecuted(dbEvent);
            } catch (Exception e) {
                String error = "EmpleadoREST.FIND_BASE_ALL " + e.getMessage();
                MethodEvent dbEvent = new MethodEvent(EMethod.FIND_BASE_ALL, ETypeResult.FAILURE, error);
                onRESTExecuted(dbEvent);
            }
        }

    }));

}

From source file:cimav.client.data.rest.EmpleadoREST.java

public void findBaseByIdDepto(int idDepto) {

    BaseREST.setDateFormatGET();/*  w  w  w .ja v a2 s  . c  o m*/

    String url = BaseREST.URL_REST_BASE + "api/empleado_base/by_depto/" + idDepto;

    Resource rb = new Resource(url, headers);
    rb.get().send(Ajax.jsonCall(new JsonCallback() {

        @Override
        public void onFailure(Method method, Throwable exception) {
            MethodEvent dbEvent = new MethodEvent(EMethod.FIND_EMPLEADO_BASE_BY_ID_DEPTO, ETypeResult.FAILURE,
                    "findAllByDepto " + exception.getMessage());
            onRESTExecuted(dbEvent);
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {
            try {
                List<EmpleadoBase> empleadosBase = new ArrayList<>();
                JSONArray array = response.isArray();
                for (int i = 0; i < array.size(); i++) {
                    JSONValue val = array.get(i);
                    EmpleadoBase empleadoBase = empleadoBaseJsonCodec.decode(val);
                    empleadosBase.add(empleadoBase);
                }
                MethodEvent dbEvent = new MethodEvent(EMethod.FIND_EMPLEADO_BASE_BY_ID_DEPTO,
                        ETypeResult.SUCCESS, "findAllByDepto listo");
                dbEvent.setResult(empleadosBase);
                onRESTExecuted(dbEvent);
            } catch (Exception e) {
                String error = "EmpleadoREST.FIND_BASE_BY_ID_DEPTO " + e.getMessage();
                MethodEvent dbEvent = new MethodEvent(EMethod.FIND_EMPLEADO_BASE_BY_ID_DEPTO,
                        ETypeResult.FAILURE, error);
                onRESTExecuted(dbEvent);
            }
        }

    }));

}

From source file:cimav.client.data.rest.EmpleadoREST.java

public void findPensionAlimenticia(int idEmpleado) {

    BaseREST.setDateFormatGET();/* w  w w  .j  a  v a2s .  com*/

    String url = BaseREST.URL_REST_BASE + "api/empleado_nomina/pension_alimenticia/" + idEmpleado;

    Resource rb = new Resource(url, headers);
    rb.get().send(Ajax.jsonCall(new JsonCallback() {

        @Override
        public void onFailure(Method method, Throwable exception) {
            MethodEvent dbEvent = new MethodEvent(EMethod.FIND_PENSION_ALIMENTICA_BY_ID_EMPLEADO,
                    ETypeResult.FAILURE, "findPensionAlimenticiaByIdEmpleado " + exception.getMessage());
            onRESTExecuted(dbEvent);
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {
            List<Concepto> conceptos = new ArrayList<>();
            try {
                JSONArray array = response.isArray();
                for (int i = 0; i < array.size(); i++) {
                    JSONValue val = array.get(i);

                    Concepto concepto = (Concepto) jsonCodecConcepto.decode(val);
                    conceptos.add(concepto);
                }
                MethodEvent methodEvent = new MethodEvent(EMethod.FIND_PENSION_ALIMENTICA_BY_ID_EMPLEADO,
                        ETypeResult.SUCCESS, "findPensionAlimenticiaByIdEmpleado");
                methodEvent.setResult(conceptos);
                onRESTExecuted(methodEvent);
            } catch (Exception e) {
                String error = "findPensionAlimenticiaByIdEmpleado " + e.getMessage();
                MethodEvent dbEvent = new MethodEvent(EMethod.FIND_PENSION_ALIMENTICA_BY_ID_EMPLEADO,
                        ETypeResult.FAILURE, error);
                onRESTExecuted(dbEvent);
            }
        }

    }));

}