Search in sources :

Example 1 with GraphColumn

use of org.adempiere.apps.graph.GraphColumn in project adempiere by adempiere.

the class WGraph method chartMouseClicked.

/**************************************************************************
	 * Paint Component
	 * 
	 * @param g
	 *            graphics
	 */
public void chartMouseClicked(int index) {
    GraphColumn bgc = list.get(index);
    if (null == bgc)
        return;
    MQuery query = bgc.getMQuery(builder.getMGoal());
    if (query != null)
        AEnv.zoom(query);
    else
        log.warning("Nothing to zoom to - " + bgc);
}
Also used : MQuery(org.compiere.model.MQuery) GraphColumn(org.adempiere.apps.graph.GraphColumn)

Example 2 with GraphColumn

use of org.adempiere.apps.graph.GraphColumn in project adempiere by adempiere.

the class WGraph method renderTable.

private void renderTable(Component parent) {
    Div div = new Div();
    appendChild(div);
    div.setSclass("pa-content");
    parent.appendChild(div);
    Table table = new Table();
    table.setSclass("pa-dataGrid");
    div.appendChild(table);
    Tr tr = new Tr();
    table.appendChild(tr);
    Td td = new Td();
    td.setSclass("pa-label");
    tr.appendChild(td);
    Text text = new Text("Target");
    td.appendChild(text);
    td = new Td();
    td.setDynamicProperty("colspan", "2");
    td.setSclass("pa-tdcontent");
    tr.appendChild(td);
    text = new Text(builder.getMGoal().getMeasureTarget().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    td.appendChild(text);
    tr = new Tr();
    table.appendChild(tr);
    td = new Td();
    td.setSclass("pa-label");
    tr.appendChild(td);
    text = new Text("Actual");
    td.appendChild(text);
    td = new Td();
    td.setDynamicProperty("colspan", "2");
    td.setSclass("pa-tdcontent");
    tr.appendChild(td);
    text = new Text(builder.getMGoal().getMeasureActual().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    td.appendChild(text);
    GraphColumn[] bList = getGraphColumnList();
    tr = new Tr();
    table.appendChild(tr);
    td = new Td();
    tr.appendChild(td);
    td.setDynamicProperty("rowspan", bList.length);
    td.setSclass("pa-label");
    td.setDynamicProperty("valign", "top");
    text = new Text(builder.getMGoal().getXAxisText());
    td.appendChild(text);
    for (int k = 0; k < bList.length; k++) {
        GraphColumn bgc = bList[k];
        if (k > 0) {
            tr = new Tr();
            table.appendChild(tr);
        }
        td = new Td();
        td.setSclass("pa-tdlabel");
        tr.appendChild(td);
        text = new Text(bgc.getLabel());
        td.appendChild(text);
        td = new Td();
        td.setSclass("pa-tdvalue");
        tr.appendChild(td);
        BigDecimal value = new BigDecimal(bgc.getValue());
        if (bgc.getMQuery(builder.getMGoal()) != null) {
            A a = new A();
            a.setSclass("pa-hrefNode");
            td.appendChild(a);
            a.setId(ZOOM_KEY + k);
            a.addEventListener(Events.ON_CLICK, new EventListener() {

                public void onEvent(Event event) throws Exception {
                    Component comp = event.getTarget();
                    String id = comp.getId();
                    if (id.startsWith(ZOOM_KEY)) {
                        String ss = id.substring(ZOOM_KEY.length());
                        int index = Integer.parseInt(String.valueOf(ss));
                        GraphColumn[] colList = getGraphColumnList();
                        if ((index >= 0) && (index < colList.length))
                            AEnv.zoom(colList[index].getMQuery(builder.getMGoal()));
                    }
                }
            });
            a.setDynamicProperty("href", "javascript:;");
            text = new Text(value.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
            a.appendChild(text);
        } else {
            text = new Text(value.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
        }
    }
    tr = new Tr();
    table.appendChild(tr);
    td = new Td();
    td.setDynamicProperty("colspan", "3");
    tr.appendChild(td);
    text = new Text(builder.getMGoal().getDescription());
    td.appendChild(text);
    Br br = new Br();
    td.appendChild(br);
    text = new Text(stripHtml(builder.getMGoal().getColorSchema().getDescription(), true));
    td.appendChild(text);
}
Also used : A(org.zkoss.zhtml.A) Table(org.zkoss.zhtml.Table) Text(org.zkoss.zhtml.Text) Point(java.awt.Point) BigDecimal(java.math.BigDecimal) Div(org.zkoss.zul.Div) Td(org.zkoss.zhtml.Td) Br(org.zkoss.zhtml.Br) ValueChangeEvent(org.adempiere.exceptions.ValueChangeEvent) Event(org.zkoss.zk.ui.event.Event) MouseEvent(org.zkoss.zk.ui.event.MouseEvent) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) GraphColumn(org.adempiere.apps.graph.GraphColumn) EventListener(org.zkoss.zk.ui.event.EventListener) Component(org.zkoss.zk.ui.Component) Tr(org.zkoss.zhtml.Tr)

Example 3 with GraphColumn

use of org.adempiere.apps.graph.GraphColumn in project adempiere by adempiere.

the class MMeasure method getGraphColumnList.

//	MMeasure
public ArrayList<GraphColumn> getGraphColumnList(MGoal goal) {
    ArrayList<GraphColumn> list = new ArrayList<GraphColumn>();
    if (MMeasure.MEASURETYPE_Calculated.equals(getMeasureType())) {
        MMeasureCalc mc = MMeasureCalc.get(getCtx(), getPA_MeasureCalc_ID());
        String sql = mc.getSqlBarChart(goal.getRestrictions(false), goal.getMeasureDisplay(), goal.getDateFrom(), //	logged in role
        MRole.getDefault());
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            pstmt = DB.prepareStatement(sql, null);
            rs = pstmt.executeQuery();
            ArrayList<Timestamp> dataList = new ArrayList<Timestamp>();
            while (rs.next()) {
                BigDecimal data = rs.getBigDecimal(1);
                Timestamp date = rs.getTimestamp(2);
                GraphColumn bgc = new GraphColumn(mc, data);
                //TODO copy order-loop to other measures
                bgc.setLabel(date, goal.getMeasureDisplay());
                int pos = 0;
                for (int i = 0; i < dataList.size(); i++) if (dataList.get(i).before(date))
                    pos++;
                // list of dates
                dataList.add(date);
                list.add(pos, bgc);
            }
        } catch (Exception e) {
            log.log(Level.SEVERE, sql, e);
        } finally {
            DB.close(rs, pstmt);
            rs = null;
            pstmt = null;
        }
    } else if (MMeasure.MEASURETYPE_Achievements.equals(getMeasureType())) {
        if (MMeasure.MEASUREDATATYPE_StatusQtyAmount.equals(getMeasureDataType())) {
            MAchievement[] achievements = MAchievement.get(this);
            for (int i = 0; i < achievements.length; i++) {
                MAchievement achievement = achievements[i];
                GraphColumn bgc = new GraphColumn(achievement);
                list.add(bgc);
            }
        } else //	MMeasure.MEASUREDATATYPE_QtyAmountInTime
        {
            String MeasureDisplay = goal.getMeasureDisplay();
            String trunc = "D";
            if (MGoal.MEASUREDISPLAY_Year.equals(MeasureDisplay))
                trunc = "Y";
            else if (MGoal.MEASUREDISPLAY_Quarter.equals(MeasureDisplay))
                trunc = "Q";
            else if (MGoal.MEASUREDISPLAY_Month.equals(MeasureDisplay))
                trunc = "MM";
            else if (MGoal.MEASUREDISPLAY_Week.equals(MeasureDisplay))
                trunc = "W";
            //	else if (MGoal.MEASUREDISPLAY_Day.equals(MeasureDisplay))
            //		trunc = "D";
            trunc = "TRUNC(DateDoc,'" + trunc + "')";
            StringBuffer sql = new StringBuffer("SELECT SUM(ManualActual), ").append(trunc).append(" FROM PA_Achievement WHERE PA_Measure_ID=? AND IsAchieved='Y' ").append("GROUP BY ").append(trunc).append(" ORDER BY ").append(trunc);
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            try {
                pstmt = DB.prepareStatement(sql.toString(), null);
                pstmt.setInt(1, getPA_Measure_ID());
                rs = pstmt.executeQuery();
                while (rs.next()) {
                    BigDecimal data = rs.getBigDecimal(1);
                    Timestamp date = rs.getTimestamp(2);
                    GraphColumn bgc = new GraphColumn(goal, data);
                    bgc.setLabel(date, goal.getMeasureDisplay());
                    list.add(bgc);
                }
            } catch (Exception e) {
                log.log(Level.SEVERE, sql.toString(), e);
            } finally {
                DB.close(rs, pstmt);
                rs = null;
                pstmt = null;
            }
        }
    //	Achievement in time
    } else //	Request
    if (MMeasure.MEASURETYPE_Request.equals(getMeasureType())) {
        MRequestType rt = MRequestType.get(Env.getCtx(), getR_RequestType_ID());
        String sql = rt.getSqlBarChart(goal.getRestrictions(false), goal.getMeasureDisplay(), getMeasureDataType(), goal.getDateFrom(), //	logged in role
        MRole.getDefault());
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            pstmt = DB.prepareStatement(sql, null);
            rs = pstmt.executeQuery();
            while (rs.next()) {
                BigDecimal data = rs.getBigDecimal(1);
                int R_Status_ID = rs.getInt(3);
                GraphColumn bgc = new GraphColumn(rt, data, R_Status_ID);
                if (R_Status_ID == 0) {
                    Timestamp date = rs.getTimestamp(2);
                    bgc.setLabel(date, goal.getMeasureDisplay());
                } else {
                    MStatus status = MStatus.get(Env.getCtx(), R_Status_ID);
                    bgc.setLabel(status.getName());
                }
                list.add(bgc);
            }
        } catch (Exception e) {
            log.log(Level.SEVERE, sql, e);
        } finally {
            DB.close(rs, pstmt);
            rs = null;
            pstmt = null;
        }
    } else //	Project
    if (MMeasure.MEASURETYPE_Project.equals(getMeasureType())) {
        MProjectType pt = MProjectType.get(Env.getCtx(), getC_ProjectType_ID());
        String sql = pt.getSqlBarChart(goal.getRestrictions(false), goal.getMeasureDisplay(), getMeasureDataType(), goal.getDateFrom(), //	logged in role
        MRole.getDefault());
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            pstmt = DB.prepareStatement(sql, null);
            rs = pstmt.executeQuery();
            while (rs.next()) {
                BigDecimal data = rs.getBigDecimal(1);
                Timestamp date = rs.getTimestamp(2);
                int id = rs.getInt(3);
                GraphColumn bgc = new GraphColumn(pt, data, id);
                bgc.setLabel(date, goal.getMeasureDisplay());
                list.add(bgc);
            }
        } catch (Exception e) {
            log.log(Level.SEVERE, sql, e);
        } finally {
            DB.close(rs, pstmt);
            rs = null;
            pstmt = null;
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) ResultSet(java.sql.ResultSet) GraphColumn(org.adempiere.apps.graph.GraphColumn)

Aggregations

GraphColumn (org.adempiere.apps.graph.GraphColumn)3 BigDecimal (java.math.BigDecimal)2 Point (java.awt.Point)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 ValueChangeEvent (org.adempiere.exceptions.ValueChangeEvent)1 MQuery (org.compiere.model.MQuery)1 ChartMouseEvent (org.jfree.chart.ChartMouseEvent)1 A (org.zkoss.zhtml.A)1 Br (org.zkoss.zhtml.Br)1 Table (org.zkoss.zhtml.Table)1 Td (org.zkoss.zhtml.Td)1 Text (org.zkoss.zhtml.Text)1 Tr (org.zkoss.zhtml.Tr)1 Component (org.zkoss.zk.ui.Component)1 Event (org.zkoss.zk.ui.event.Event)1 EventListener (org.zkoss.zk.ui.event.EventListener)1 MouseEvent (org.zkoss.zk.ui.event.MouseEvent)1