Search in sources :

Example 1 with JSONArray

use of org.zkoss.json.JSONArray in project adempiere by adempiere.

the class DrillCommand method service.

public boolean service(AuRequest request, boolean everError) {
    if (!DrillEvent.ON_DRILL_ACROSS.equals(request.getCommand()) && !DrillEvent.ON_DRILL_DOWN.equals(request.getCommand()))
        return false;
    final Map<?, ?> map = request.getData();
    JSONArray data = (JSONArray) map.get("data");
    final Component comp = request.getComponent();
    if (comp == null)
        throw new UiException(MZk.ILLEGAL_REQUEST_COMPONENT_REQUIRED, this);
    if (data == null || data.size() < 2)
        throw new UiException(MZk.ILLEGAL_REQUEST_WRONG_DATA, new Object[] { Objects.toString(data), this });
    String columnName = (String) data.get(0);
    String tableName = MQuery.getZoomTableName(columnName);
    String code = (String) data.get(1);
    //
    MQuery query = new MQuery(tableName);
    query.addRestriction(columnName, MQuery.EQUAL, code);
    Events.postEvent(new DrillEvent(request.getCommand(), comp, query));
    return true;
}
Also used : JSONArray(org.zkoss.json.JSONArray) DrillEvent(org.adempiere.webui.event.DrillEvent) MQuery(org.compiere.model.MQuery) UiException(org.zkoss.zk.ui.UiException) Component(org.zkoss.zk.ui.Component)

Example 2 with JSONArray

use of org.zkoss.json.JSONArray in project adempiere by adempiere.

the class ZoomCommand method service.

public boolean service(AuRequest request, boolean everError) {
    if (!ZoomEvent.EVENT_NAME.equals(request.getCommand()))
        return false;
    Map<?, ?> map = request.getData();
    JSONArray data = (JSONArray) map.get("data");
    final Component comp = request.getComponent();
    if (comp == null)
        throw new UiException(MZk.ILLEGAL_REQUEST_COMPONENT_REQUIRED, this);
    if (data == null || data.size() < 2)
        throw new UiException(MZk.ILLEGAL_REQUEST_WRONG_DATA, new Object[] { Objects.toString(data), this });
    String columnName = (String) data.get(0);
    String tableName = MQuery.getZoomTableName(columnName);
    Object code = null;
    if (columnName.endsWith("_ID")) {
        try {
            code = Integer.parseInt((String) data.get(1));
        } catch (Exception e) {
            code = data.get(1);
        }
    } else {
        code = data.get(1);
    }
    //
    MQuery query = new MQuery(tableName);
    query.addRestriction(columnName, MQuery.EQUAL, code);
    query.setRecordCount(1);
    Events.postEvent(new ZoomEvent(comp, query));
    return true;
}
Also used : JSONArray(org.zkoss.json.JSONArray) MQuery(org.compiere.model.MQuery) UiException(org.zkoss.zk.ui.UiException) Component(org.zkoss.zk.ui.Component) UiException(org.zkoss.zk.ui.UiException) ZoomEvent(org.adempiere.webui.event.ZoomEvent)

Aggregations

MQuery (org.compiere.model.MQuery)2 JSONArray (org.zkoss.json.JSONArray)2 Component (org.zkoss.zk.ui.Component)2 UiException (org.zkoss.zk.ui.UiException)2 DrillEvent (org.adempiere.webui.event.DrillEvent)1 ZoomEvent (org.adempiere.webui.event.ZoomEvent)1