diff --git a/base/src/org/compiere/model/I_PA_Goal.java b/base/src/org/compiere/model/I_PA_Goal.java index 50c3fbb1f6..381553560b 100644 --- a/base/src/org/compiere/model/I_PA_Goal.java +++ b/base/src/org/compiere/model/I_PA_Goal.java @@ -92,6 +92,19 @@ public interface I_PA_Goal public I_AD_User getAD_User() throws RuntimeException; + /** Column name ChartType */ + public static final String COLUMNNAME_ChartType = "ChartType"; + + /** Set Chart Type. + * Type fo chart to render + */ + public void setChartType (String ChartType); + + /** Get Chart Type. + * Type fo chart to render + */ + public String getChartType(); + /** Column name Created */ public static final String COLUMNNAME_Created = "Created"; @@ -292,19 +305,6 @@ public interface I_PA_Goal public I_PA_ColorSchema getPA_ColorSchema() throws RuntimeException; - /** Column name PA_Goal_ID */ - public static final String COLUMNNAME_PA_Goal_ID = "PA_Goal_ID"; - - /** Set Goal. - * Performance Goal - */ - public void setPA_Goal_ID (int PA_Goal_ID); - - /** Get Goal. - * Performance Goal - */ - public int getPA_Goal_ID(); - /** Column name PA_GoalParent_ID */ public static final String COLUMNNAME_PA_GoalParent_ID = "PA_GoalParent_ID"; @@ -318,6 +318,19 @@ public interface I_PA_Goal */ public int getPA_GoalParent_ID(); + /** Column name PA_Goal_ID */ + public static final String COLUMNNAME_PA_Goal_ID = "PA_Goal_ID"; + + /** Set Goal. + * Performance Goal + */ + public void setPA_Goal_ID (int PA_Goal_ID); + + /** Get Goal. + * Performance Goal + */ + public int getPA_Goal_ID(); + /** Column name PA_Measure_ID */ public static final String COLUMNNAME_PA_Measure_ID = "PA_Measure_ID"; diff --git a/base/src/org/compiere/model/MMeasure.java b/base/src/org/compiere/model/MMeasure.java index 51cfa1fb40..6d672fb841 100644 --- a/base/src/org/compiere/model/MMeasure.java +++ b/base/src/org/compiere/model/MMeasure.java @@ -17,11 +17,14 @@ package org.compiere.model; import java.math.BigDecimal; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.Properties; import java.util.logging.Level; +import org.adempiere.apps.graph.GraphColumn; import org.compiere.util.CCache; import org.compiere.util.DB; import org.compiere.util.Env; @@ -42,7 +45,7 @@ public class MMeasure extends X_PA_Measure /** * */ - private static final long serialVersionUID = -3317015206590431626L; + private static final long serialVersionUID = 6274990637485210675L; /** * Get MMeasure from Cache @@ -87,8 +90,184 @@ public class MMeasure extends X_PA_Measure { super (ctx, rs, trxName); } // MMeasure - - + + public ArrayList getGraphColumnList(MGoal goal) + { + ArrayList list = new ArrayList(); + 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(), + MRole.getDefault()); // logged in role + PreparedStatement pstmt = null; + ResultSet rs = null; + try + { + pstmt = DB.prepareStatement (sql, null); + rs = pstmt.executeQuery (); + ArrayList dataList = new ArrayList(); + while (rs.next ()) + { + BigDecimal data = rs.getBigDecimal(1); + Timestamp date = rs.getTimestamp(2); + GraphColumn bgc = new GraphColumn(mc, data); + bgc.setLabel(date, goal.getMeasureDisplay()); //TODO copy order-loop to other measures + int pos=0; + for (int i = 0; i < dataList.size(); i++) + if (dataList.get(i).before(date)) pos++; + dataList.add(date); // list of dates + 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 + } // Achievement + + // Request + else 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(), MRole.getDefault()); // logged in role + 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; + } + } // Request + + // Project + else 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(), MRole.getDefault()); // logged in role + 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; + } + } // Project + + return list; + } + /** * String Representation * @return info diff --git a/base/src/org/compiere/model/X_PA_Goal.java b/base/src/org/compiere/model/X_PA_Goal.java index 3aa61c6b9f..b169ab1e9e 100644 --- a/base/src/org/compiere/model/X_PA_Goal.java +++ b/base/src/org/compiere/model/X_PA_Goal.java @@ -27,15 +27,15 @@ import org.compiere.util.Env; import org.compiere.util.KeyNamePair; /** Generated Model for PA_Goal - * @author Adempiere (generated) + * @author Adempiere (generated) * @version Release 3.5.3a - $Id$ */ -public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent +public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent { /** * */ - private static final long serialVersionUID = 20081221L; + private static final long serialVersionUID = 20090710L; /** Standard Constructor */ public X_PA_Goal (Properties ctx, int PA_Goal_ID, String trxName) @@ -64,7 +64,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent } /** AccessLevel - * @return 6 - System - Client + * @return 6 - System - Client */ protected int get_AccessLevel() { @@ -85,7 +85,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent return sb.toString(); } - public I_AD_Role getAD_Role() throws RuntimeException + public I_AD_Role getAD_Role() throws RuntimeException { Class clazz = MTable.getClass(I_AD_Role.Table_Name); I_AD_Role result = null; @@ -102,21 +102,21 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent } /** Set Role. - @param AD_Role_ID + @param AD_Role_ID Responsibility Role */ public void setAD_Role_ID (int AD_Role_ID) { - if (AD_Role_ID < 0) + if (AD_Role_ID < 0) set_Value (COLUMNNAME_AD_Role_ID, null); - else + else set_Value (COLUMNNAME_AD_Role_ID, Integer.valueOf(AD_Role_ID)); } /** Get Role. @return Responsibility Role */ - public int getAD_Role_ID () + public int getAD_Role_ID () { Integer ii = (Integer)get_Value(COLUMNNAME_AD_Role_ID); if (ii == null) @@ -124,7 +124,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent return ii.intValue(); } - public I_AD_User getAD_User() throws RuntimeException + public I_AD_User getAD_User() throws RuntimeException { Class clazz = MTable.getClass(I_AD_User.Table_Name); I_AD_User result = null; @@ -141,21 +141,21 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent } /** Set User/Contact. - @param AD_User_ID + @param AD_User_ID User within the system - Internal or Business Partner Contact */ public void setAD_User_ID (int AD_User_ID) { - if (AD_User_ID < 1) + if (AD_User_ID < 1) set_Value (COLUMNNAME_AD_User_ID, null); - else + else set_Value (COLUMNNAME_AD_User_ID, Integer.valueOf(AD_User_ID)); } /** Get User/Contact. @return User within the system - Internal or Business Partner Contact */ - public int getAD_User_ID () + public int getAD_User_ID () { Integer ii = (Integer)get_Value(COLUMNNAME_AD_User_ID); if (ii == null) @@ -163,8 +163,40 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent return ii.intValue(); } + /** ChartType AD_Reference_ID=53315 */ + public static final int CHARTTYPE_AD_Reference_ID=53315; + /** Bar Chart = BC */ + public static final String CHARTTYPE_BarChart = "BC"; + /** Pie Chart = PC */ + public static final String CHARTTYPE_PieChart = "PC"; + /** Ring Chart = RC */ + public static final String CHARTTYPE_RingChart = "RC"; + /** Line Chart = LC */ + public static final String CHARTTYPE_LineChart = "LC"; + /** Area Chart = AC */ + public static final String CHARTTYPE_AreaChart = "AC"; + /** Waterfall Chart = WC */ + public static final String CHARTTYPE_WaterfallChart = "WC"; + /** Set Chart Type. + @param ChartType + Type fo chart to render + */ + public void setChartType (String ChartType) + { + + set_Value (COLUMNNAME_ChartType, ChartType); + } + + /** Get Chart Type. + @return Type fo chart to render + */ + public String getChartType () + { + return (String)get_Value(COLUMNNAME_ChartType); + } + /** Set Date From. - @param DateFrom + @param DateFrom Starting date for a range */ public void setDateFrom (Timestamp DateFrom) @@ -175,13 +207,13 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Date From. @return Starting date for a range */ - public Timestamp getDateFrom () + public Timestamp getDateFrom () { return (Timestamp)get_Value(COLUMNNAME_DateFrom); } /** Set Date last run. - @param DateLastRun + @param DateLastRun Date the process was last run. */ public void setDateLastRun (Timestamp DateLastRun) @@ -192,13 +224,13 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Date last run. @return Date the process was last run. */ - public Timestamp getDateLastRun () + public Timestamp getDateLastRun () { return (Timestamp)get_Value(COLUMNNAME_DateLastRun); } /** Set Date To. - @param DateTo + @param DateTo End date of a date range */ public void setDateTo (Timestamp DateTo) @@ -209,13 +241,13 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Date To. @return End date of a date range */ - public Timestamp getDateTo () + public Timestamp getDateTo () { return (Timestamp)get_Value(COLUMNNAME_DateTo); } /** Set Description. - @param Description + @param Description Optional short description of the record */ public void setDescription (String Description) @@ -226,13 +258,13 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Description. @return Optional short description of the record */ - public String getDescription () + public String getDescription () { return (String)get_Value(COLUMNNAME_Description); } /** Set Performance Goal. - @param GoalPerformance + @param GoalPerformance Target achievement from 0..1 */ public void setGoalPerformance (BigDecimal GoalPerformance) @@ -243,7 +275,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Performance Goal. @return Target achievement from 0..1 */ - public BigDecimal getGoalPerformance () + public BigDecimal getGoalPerformance () { BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_GoalPerformance); if (bd == null) @@ -252,7 +284,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent } /** Set Summary Level. - @param IsSummary + @param IsSummary This is a summary entity */ public void setIsSummary (boolean IsSummary) @@ -263,20 +295,20 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Summary Level. @return This is a summary entity */ - public boolean isSummary () + public boolean isSummary () { Object oo = get_Value(COLUMNNAME_IsSummary); - if (oo != null) + if (oo != null) { - if (oo instanceof Boolean) - return ((Boolean)oo).booleanValue(); + if (oo instanceof Boolean) + return ((Boolean)oo).booleanValue(); return "Y".equals(oo); } return false; } /** Set Measure Actual. - @param MeasureActual + @param MeasureActual Actual value that has been measured. */ public void setMeasureActual (BigDecimal MeasureActual) @@ -287,7 +319,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Measure Actual. @return Actual value that has been measured. */ - public BigDecimal getMeasureActual () + public BigDecimal getMeasureActual () { BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_MeasureActual); if (bd == null) @@ -310,7 +342,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Day = 8 */ public static final String MEASUREDISPLAY_Day = "8"; /** Set Measure Display. - @param MeasureDisplay + @param MeasureDisplay Measure Scope initially displayed */ public void setMeasureDisplay (String MeasureDisplay) @@ -322,7 +354,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Measure Display. @return Measure Scope initially displayed */ - public String getMeasureDisplay () + public String getMeasureDisplay () { return (String)get_Value(COLUMNNAME_MeasureDisplay); } @@ -342,7 +374,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Day = 8 */ public static final String MEASURESCOPE_Day = "8"; /** Set Measure Scope. - @param MeasureScope + @param MeasureScope Performance Measure Scope */ public void setMeasureScope (String MeasureScope) @@ -354,13 +386,13 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Measure Scope. @return Performance Measure Scope */ - public String getMeasureScope () + public String getMeasureScope () { return (String)get_Value(COLUMNNAME_MeasureScope); } /** Set Measure Target. - @param MeasureTarget + @param MeasureTarget Target value for measure */ public void setMeasureTarget (BigDecimal MeasureTarget) @@ -371,7 +403,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Measure Target. @return Target value for measure */ - public BigDecimal getMeasureTarget () + public BigDecimal getMeasureTarget () { BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_MeasureTarget); if (bd == null) @@ -380,7 +412,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent } /** Set Name. - @param Name + @param Name Alphanumeric identifier of the entity */ public void setName (String Name) @@ -391,7 +423,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Name. @return Alphanumeric identifier of the entity */ - public String getName () + public String getName () { return (String)get_Value(COLUMNNAME_Name); } @@ -399,13 +431,13 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Record ID/ColumnName @return ID/ColumnName pair */ - public KeyNamePair getKeyNamePair() + public KeyNamePair getKeyNamePair() { return new KeyNamePair(get_ID(), getName()); } /** Set Note. - @param Note + @param Note Optional additional user defined information */ public void setNote (String Note) @@ -416,12 +448,12 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Note. @return Optional additional user defined information */ - public String getNote () + public String getNote () { return (String)get_Value(COLUMNNAME_Note); } - public I_PA_ColorSchema getPA_ColorSchema() throws RuntimeException + public I_PA_ColorSchema getPA_ColorSchema() throws RuntimeException { Class clazz = MTable.getClass(I_PA_ColorSchema.Table_Name); I_PA_ColorSchema result = null; @@ -438,21 +470,21 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent } /** Set Color Schema. - @param PA_ColorSchema_ID + @param PA_ColorSchema_ID Performance Color Schema */ public void setPA_ColorSchema_ID (int PA_ColorSchema_ID) { - if (PA_ColorSchema_ID < 1) + if (PA_ColorSchema_ID < 1) set_Value (COLUMNNAME_PA_ColorSchema_ID, null); - else + else set_Value (COLUMNNAME_PA_ColorSchema_ID, Integer.valueOf(PA_ColorSchema_ID)); } /** Get Color Schema. @return Performance Color Schema */ - public int getPA_ColorSchema_ID () + public int getPA_ColorSchema_ID () { Integer ii = (Integer)get_Value(COLUMNNAME_PA_ColorSchema_ID); if (ii == null) @@ -460,45 +492,22 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent return ii.intValue(); } - /** Set Goal. - @param PA_Goal_ID - Performance Goal - */ - public void setPA_Goal_ID (int PA_Goal_ID) - { - if (PA_Goal_ID < 1) - set_ValueNoCheck (COLUMNNAME_PA_Goal_ID, null); - else - set_ValueNoCheck (COLUMNNAME_PA_Goal_ID, Integer.valueOf(PA_Goal_ID)); - } - - /** Get Goal. - @return Performance Goal - */ - public int getPA_Goal_ID () - { - Integer ii = (Integer)get_Value(COLUMNNAME_PA_Goal_ID); - if (ii == null) - return 0; - return ii.intValue(); - } - /** Set Parent Goal. - @param PA_GoalParent_ID + @param PA_GoalParent_ID Parent Goal */ public void setPA_GoalParent_ID (int PA_GoalParent_ID) { - if (PA_GoalParent_ID < 1) + if (PA_GoalParent_ID < 1) set_Value (COLUMNNAME_PA_GoalParent_ID, null); - else + else set_Value (COLUMNNAME_PA_GoalParent_ID, Integer.valueOf(PA_GoalParent_ID)); } /** Get Parent Goal. @return Parent Goal */ - public int getPA_GoalParent_ID () + public int getPA_GoalParent_ID () { Integer ii = (Integer)get_Value(COLUMNNAME_PA_GoalParent_ID); if (ii == null) @@ -506,7 +515,30 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent return ii.intValue(); } - public I_PA_Measure getPA_Measure() throws RuntimeException + /** Set Goal. + @param PA_Goal_ID + Performance Goal + */ + public void setPA_Goal_ID (int PA_Goal_ID) + { + if (PA_Goal_ID < 1) + set_ValueNoCheck (COLUMNNAME_PA_Goal_ID, null); + else + set_ValueNoCheck (COLUMNNAME_PA_Goal_ID, Integer.valueOf(PA_Goal_ID)); + } + + /** Get Goal. + @return Performance Goal + */ + public int getPA_Goal_ID () + { + Integer ii = (Integer)get_Value(COLUMNNAME_PA_Goal_ID); + if (ii == null) + return 0; + return ii.intValue(); + } + + public I_PA_Measure getPA_Measure() throws RuntimeException { Class clazz = MTable.getClass(I_PA_Measure.Table_Name); I_PA_Measure result = null; @@ -523,21 +555,21 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent } /** Set Measure. - @param PA_Measure_ID + @param PA_Measure_ID Concrete Performance Measurement */ public void setPA_Measure_ID (int PA_Measure_ID) { - if (PA_Measure_ID < 1) + if (PA_Measure_ID < 1) set_Value (COLUMNNAME_PA_Measure_ID, null); - else + else set_Value (COLUMNNAME_PA_Measure_ID, Integer.valueOf(PA_Measure_ID)); } /** Get Measure. @return Concrete Performance Measurement */ - public int getPA_Measure_ID () + public int getPA_Measure_ID () { Integer ii = (Integer)get_Value(COLUMNNAME_PA_Measure_ID); if (ii == null) @@ -546,7 +578,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent } /** Set Relative Weight. - @param RelativeWeight + @param RelativeWeight Relative weight of this step (0 = ignored) */ public void setRelativeWeight (BigDecimal RelativeWeight) @@ -557,7 +589,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Relative Weight. @return Relative weight of this step (0 = ignored) */ - public BigDecimal getRelativeWeight () + public BigDecimal getRelativeWeight () { BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_RelativeWeight); if (bd == null) @@ -566,7 +598,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent } /** Set Sequence. - @param SeqNo + @param SeqNo Method of ordering records; lowest number comes first */ public void setSeqNo (int SeqNo) @@ -577,7 +609,7 @@ public class X_PA_Goal extends PO implements I_PA_Goal, I_Persistent /** Get Sequence. @return Method of ordering records; lowest number comes first */ - public int getSeqNo () + public int getSeqNo () { Integer ii = (Integer)get_Value(COLUMNNAME_SeqNo); if (ii == null) diff --git a/client/src/org/adempiere/apps/graph/BarGraph.java b/client/src/org/adempiere/apps/graph/BarGraph.java deleted file mode 100644 index 72b5b78cb5..0000000000 --- a/client/src/org/adempiere/apps/graph/BarGraph.java +++ /dev/null @@ -1,520 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.adempiere.apps.graph; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Point; -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.logging.Level; - -import org.compiere.apps.AEnv; -import org.compiere.model.MAchievement; -import org.compiere.model.MGoal; -import org.compiere.model.MMeasure; -import org.compiere.model.MMeasureCalc; -import org.compiere.model.MProjectType; -import org.compiere.model.MQuery; -import org.compiere.model.MRequestType; -import org.compiere.model.MRole; -import org.compiere.model.MStatus; -import org.compiere.swing.CPanel; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.jfree.chart.ChartFactory; -import org.jfree.chart.ChartMouseEvent; -import org.jfree.chart.ChartMouseListener; -import org.jfree.chart.ChartPanel; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.entity.CategoryItemEntity; -import org.jfree.chart.entity.ChartEntity; -import org.jfree.chart.plot.CategoryPlot; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.renderer.category.BarRenderer; -import org.jfree.data.category.DefaultCategoryDataset; - -/** - * Bar Graph - * - * @author Jorg Janke - * @version $Id: BarGraph.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $ - * - * @author Teo Sarca, www.arhipac.ro - *
  • BF [ 2507325 ] BarGraph zoom not working - */ -public class BarGraph extends CPanel implements ChartMouseListener -{ - /** - * - */ - private static final long serialVersionUID = -4150122585550132822L; - - /** - * Constructor - */ - public BarGraph() - { - super(); - this.setLayout(new BorderLayout()); - } // BarGraph - - /** - * Constructor - * @param goal goal - */ - public BarGraph(MGoal goal) - { - this(); - m_goal = goal; - m_Y_AxisLabel = goal.getName(); - m_X_AxisLabel = goal.getXAxisText(); - loadData(); - //addComponentListener(this); - } // BarGraph - - /** The Goal */ - private MGoal m_goal = null; - /** Graph Size */ - //private Dimension m_size = null; - /** Zero/Zero Coordibate point */ - private Point m_point0_0 = null; -// /** Layout */ -// private BarGraphLayout m_layout = new BarGraphLayout(this); - - /** Logger */ - private static CLogger log = CLogger.getCLogger (BarGraph.class); - - /** X Axis Label */ - private String m_X_AxisLabel = "X Axis"; - /** Y Axis Label */ - private String m_Y_AxisLabel = "Y Axis"; -// /** Y Axis Max */ -// private double m_Y_Max = 0; - /** Y Axis Target Line */ - private double m_Y_Target = 0; - /** Y Axis Target Line Label */ - private String m_Y_TargetLabel = null; - private static Dimension paneldimension = new Dimension(180, 150); - - final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); - - /** - * Load Performance Data - */ - ArrayList list = new ArrayList(); - - private void loadData() - { - // Calculated - MMeasure measure = m_goal.getMeasure(); - if (measure == null) - { - log.warning("No Measure for " + m_goal); - return; - } - if (MMeasure.MEASURETYPE_Calculated.equals(measure.getMeasureType())) - { - MMeasureCalc mc = MMeasureCalc.get(Env.getCtx(), measure.getPA_MeasureCalc_ID()); - String sql = mc.getSqlBarChart(m_goal.getRestrictions(false), - m_goal.getMeasureDisplay(), m_goal.getDateFrom(), - MRole.getDefault()); // logged in role - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement (sql, null); - rs = pstmt.executeQuery (); - ArrayList dataList = new ArrayList(); - while (rs.next ()) - { - BigDecimal data = rs.getBigDecimal(1); - Timestamp date = rs.getTimestamp(2); - BarGraphColumn bgc = new BarGraphColumn(mc, data); - bgc.setLabel(date, m_goal.getMeasureDisplay()); //TODO copy order-loop to other measures - int pos=0; - for (int i = 0; i < dataList.size(); i++) - if (dataList.get(i).before(date)) pos++; - dataList.add(date); // list of dates - 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(measure.getMeasureType())) - { - if (MMeasure.MEASUREDATATYPE_StatusQtyAmount.equals(measure.getMeasureDataType())) - { - MAchievement[] achievements = MAchievement.get(measure); - for (int i = 0; i < achievements.length; i++) - { - MAchievement achievement = achievements[i]; - BarGraphColumn bgc = new BarGraphColumn(achievement); - list.add(bgc); - } - } - else // MMeasure.MEASUREDATATYPE_QtyAmountInTime - { - String MeasureDisplay = m_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, measure.getPA_Measure_ID()); - rs = pstmt.executeQuery (); - while (rs.next ()) - { - BigDecimal data = rs.getBigDecimal(1); - Timestamp date = rs.getTimestamp(2); - BarGraphColumn bgc = new BarGraphColumn(m_goal, data); - bgc.setLabel(date, m_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 - } // Achievement - - // Request - else if (MMeasure.MEASURETYPE_Request.equals(measure.getMeasureType())) - { - MRequestType rt = MRequestType.get(Env.getCtx(), measure.getR_RequestType_ID()); - String sql = rt.getSqlBarChart(m_goal.getRestrictions(false), - m_goal.getMeasureDisplay(), measure.getMeasureDataType(), - m_goal.getDateFrom(), MRole.getDefault()); // logged in role - 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); - BarGraphColumn bgc = new BarGraphColumn(rt, data, R_Status_ID); - if (R_Status_ID == 0) - { - Timestamp date = rs.getTimestamp(2); - bgc.setLabel(date, m_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; - } - } // Request - - // Project - else if (MMeasure.MEASURETYPE_Project.equals(measure.getMeasureType())) - { - MProjectType pt = MProjectType.get(Env.getCtx(), measure.getC_ProjectType_ID()); - String sql = pt.getSqlBarChart(m_goal.getRestrictions(false), - m_goal.getMeasureDisplay(), measure.getMeasureDataType(), - m_goal.getDateFrom(), MRole.getDefault()); // logged in role - 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); - BarGraphColumn bgc = new BarGraphColumn(pt, data, id); - bgc.setLabel(date, m_goal.getMeasureDisplay()); - list.add(bgc); - } - } - catch (Exception e) - { - log.log (Level.SEVERE, sql, e); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - } // Project - - // Add last 20 - int startValue = 0; - //if (list.size() > 20) //TODO CHECK - // startValue = list.size()-20; - /* - for (int i = startValue; i < list.size(); i++) - add (list.get(i)); - */ - for (int i = startValue; i < list.size(); i++){ - dataset.addValue(list.get(i).getValue(), list.get(i).getLabel(), list.get(i).getLabel()); - } - - // create the chart... - final JFreeChart chart = ChartFactory.createBarChart( - measure.getName(), // chart title - m_X_AxisLabel, // domain axis label - m_Y_AxisLabel, // range axis label - dataset, // data - PlotOrientation.VERTICAL, // orientation - false, // include legend - true, // tooltips? - true // URLs? - ); - - CategoryPlot plot = chart.getCategoryPlot(); - //plot.setBackgroundPaint(Color.lightGray); //GraphUtil.getForeground(getBackground()) - BarRenderer renderer = (BarRenderer) plot.getRenderer(); - chart.getCategoryPlot().setRenderer(renderer); - renderer.setSeriesPaint(0, new Color(92/255f, 178/255f, 232/255f)); - renderer.setSeriesPaint(1, new Color(56/255f, 97/255f, 119/255f)); - renderer.setSeriesPaint(2, new Color(242/255f, 70/255f, 78/255f)); - renderer.setSeriesPaint(3, Color.orange); - renderer.setSeriesPaint(4, new Color(147/255f, 196/255f, 51/255f)); - renderer.setSeriesPaint(5, new Color(210/255f, 247/255f, 91/255f)); - renderer.setSeriesPaint(6, new Color(129/255f, 235/255f, 249/255f)); - renderer.setSeriesPaint(7, new Color(60/255f, 84/255f, 8/255f)); - renderer.setSeriesPaint(8, new Color(0.8f, 0.8f, 0.8f)); - - chartPanel = new ChartPanel(chart); - chartPanel.setSize(getSize()); - chartPanel.addChartMouseListener(this); - add(chartPanel,BorderLayout.CENTER); - this.setMinimumSize(paneldimension); - } // loadData - private ChartPanel chartPanel; - /** - * Get Point 0_0 - * @return point - */ - public Point getPoint0_0() - { - return m_point0_0; - } // getPoint0_0 - - - /** - * @return Returns the x_AxisLabel. - */ - public String getX_AxisLabel () - { - return m_X_AxisLabel; - } // getX_AxisLabel - - /** - * @param axisLabel The x_AxisLabel to set. - */ - public void setX_AxisLabel (String axisLabel) - { - m_X_AxisLabel = axisLabel; - } // setX_AxisLabel - - /** - * @return Returns the y_AxisLabel. - */ - public String getY_AxisLabel () - { - return m_Y_AxisLabel; - } // getY_AxisLabel - - /** - * @param axisLabel The y_AxisLabel to set. - */ - public void setY_AxisLabel (String axisLabel) - { - m_Y_AxisLabel = axisLabel; - } // setY_AxisLabel - - /** - * @return Returns the y_TargetLabel. - */ - public String getY_TargetLabel () - { - return m_Y_TargetLabel; - } // getY_TargetLabel - - /** - * @param targetLabel The y_TargetLabel to set. - */ - public void setY_TargetLabel (String targetLabel, double target) - { - m_Y_TargetLabel = targetLabel; - m_Y_Target = target; - } // setY_TargetLabel - - - /** - * Add Column - * @param column column - */ - public void add (BarGraphColumn column) - { - super.add (column, "column"); - //column.addActionListener(this); - } // add - - /** - * Get BarGraphColumn for ChartEntity - * @param event - * @return BarGraphColumn or null if not found - */ - private BarGraphColumn getBarGraphColumn(ChartMouseEvent event) - { - ChartEntity entity = event.getEntity(); - String key = null; - if (entity instanceof CategoryItemEntity) - { - Comparable rowKey = ((CategoryItemEntity)entity).getRowKey(); - if (rowKey != null) - { - key = rowKey.toString(); - } - } - if (key == null) - { - return null; - } - for (int i = 0; i < list.size(); i++) - { - final String label = list.get(i).getLabel(); - if (key.equals(label)) - { - return list.get(i); - } - } - // - return null; - } - - public void chartMouseClicked(ChartMouseEvent event) - { - if ((event.getEntity()!=null) && (event.getTrigger().getClickCount() > 1)) - { - setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - try - { - BarGraphColumn bgc = getBarGraphColumn(event); - if (bgc == null) - { - return; - } - log.info(bgc.getName()); - MQuery query = null; - if (bgc.getAchievement() != null) // Single Achievement - { - MAchievement a = bgc.getAchievement(); - query = MQuery.getEqualQuery("PA_Measure_ID", a.getPA_Measure_ID()); - } - else if (bgc.getGoal() != null) // Multiple Achievements - { - MGoal goal = bgc.getGoal(); - query = MQuery.getEqualQuery("PA_Measure_ID", goal.getPA_Measure_ID()); - } - else if (bgc.getMeasureCalc() != null) // Document - { - MMeasureCalc mc = bgc.getMeasureCalc(); - query = mc.getQuery(m_goal.getRestrictions(false), - bgc.getMeasureDisplay(), bgc.getDate(), - MRole.getDefault()); // logged in role - } - else if (bgc.getProjectType() != null) // Document - { - MProjectType pt = bgc.getProjectType(); - query = pt.getQuery(m_goal.getRestrictions(false), - bgc.getMeasureDisplay(), bgc.getDate(), bgc.getID(), - MRole.getDefault()); // logged in role - } - else if (bgc.getRequestType() != null) // Document - { - MRequestType rt = bgc.getRequestType(); - query = rt.getQuery(m_goal.getRestrictions(false), - bgc.getMeasureDisplay(), bgc.getDate(), bgc.getID(), - MRole.getDefault()); // logged in role - } - if (query != null) - AEnv.zoom(query); - else - log.warning("Nothing to zoom to - " + bgc); - } - finally - { - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - } - } - - public void chartMouseMoved(ChartMouseEvent event) - { - } - - public BarGraphColumn[] getBarGraphColumnList() - { - return list.toArray(new BarGraphColumn[list.size()]); - } -} // BarGraph diff --git a/client/src/org/adempiere/apps/graph/BarGraphColumn.java b/client/src/org/adempiere/apps/graph/BarGraphColumn.java deleted file mode 100644 index d915855f24..0000000000 --- a/client/src/org/adempiere/apps/graph/BarGraphColumn.java +++ /dev/null @@ -1,509 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.adempiere.apps.graph; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.geom.AffineTransform; -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.text.DecimalFormat; -import java.text.SimpleDateFormat; - -import javax.swing.JComponent; -import javax.swing.SwingUtilities; -import javax.swing.event.EventListenerList; - -import org.compiere.model.MAchievement; -import org.compiere.model.MGoal; -import org.compiere.model.MMeasureCalc; -import org.compiere.model.MProjectType; -import org.compiere.model.MRequestType; -import org.compiere.util.CLogger; -import org.compiere.util.DisplayType; - -/** - * Bar Graph Column - * - * @author Jorg Janke - * @version $Id: BarGraphColumn.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $ - */ -public class BarGraphColumn extends JComponent implements MouseListener -{ - /** - * - */ - private static final long serialVersionUID = 8249071636376812900L; - - /** - * Base Constructor - * @param label label - * @param value value - */ - public BarGraphColumn (String label, double value) - { - m_label = label; - setValue(value); - addMouseListener(this); - } // BarGraphColumn - - /** - * Single Achievement Constructor - * @param achievement achievement - */ - public BarGraphColumn (MAchievement achievement) - { - this (achievement.getName(), achievement.getManualActual().doubleValue()); - m_achievement = achievement; - } // BarGraphColumn - - /** - * Achievement Goal Constructor - * @param goal goal - * @param data count - */ - public BarGraphColumn (MGoal goal, BigDecimal data) - { - this ("", data == null ? 0 : data.doubleValue()); - m_goal = goal; - } // BarGraphColumn - - /** - * Measure Calc Constructor - * @param mc MeasureCalc - */ - public BarGraphColumn (MMeasureCalc mc, BigDecimal data) - { - this ("", data == null ? 0 : data.doubleValue()); - m_mc = mc; - } // BarGraphColumn - - /** - * Request Type Constructor - * @param rt Request Type - */ - public BarGraphColumn (MRequestType rt, BigDecimal data, int id) - { - this ("", data == null ? 0 : data.doubleValue()); - m_rt = rt; - m_id = id; - } // BarGraphColumn - - /** - * Project Type Constructor - * @param pt Procet Type - */ - public BarGraphColumn (MProjectType pt, BigDecimal data, int id) - { - this ("", data == null ? 0 : data.doubleValue()); - m_pt = pt; - m_id = id; - } // BarGraphColumn - - /** Optional Achievement */ - private MAchievement m_achievement = null; - /** Measure Calc */ - private MMeasureCalc m_mc = null; - /** Goal */ - private MGoal m_goal = null; - - private MRequestType m_rt = null; - private MProjectType m_pt = null; - private int m_id = 0; - - /** Display */ - private String m_measureDisplay = null; - private Timestamp m_date = null; - - /** Column Label */ - private String m_label = null; - /** Column Data Value */ - private double m_value = 0; - /** Column Label Value */ - private String m_labelValue = ""; - /** Column Data Target Value */ - private double m_targetValue = 0; - /** Column Width in pixles */ - private double m_width = 0; - /** Column Height in pixles */ - private double m_height = 0; - - /** Logger */ - private static CLogger log = CLogger.getCLogger (BarGraphColumn.class); - /** Integer Number Format */ - private static DecimalFormat s_format = DisplayType.getNumberFormat(DisplayType.Integer); - - /** - * Get Achievement Goal - * @return achievement or null - */ - public MGoal getGoal() - { - return m_goal; - } // getGoal - - - /** - * Get Single Achievement - * @return achievement or null - */ - public MAchievement getAchievement() - { - return m_achievement; - } // getAchievement - - /** - * Get MeasureCalc - * @return measure - */ - public MMeasureCalc getMeasureCalc() - { - return m_mc; - } // getMeasureCalc - - public MRequestType getRequestType() - { - return m_rt; - } - - public MProjectType getProjectType() - { - return m_pt; - } - - public String getMeasureDisplay() - { - return m_measureDisplay; - } // getMeasureDisplay - - public Timestamp getDate() - { - return m_date; - } // getDate - - public int getID() - { - return m_id; - } - - /** - * Set Background and matching Foreground - * @param bg background - */ - public void setBackground (Color bg) - { - super.setBackground (bg); - setForeground(GraphUtil.getForeground(bg)); - } // setBackground - - /** - * @return Returns the label. - */ - public String getLabel () - { - return m_label; - } // getLabel - - /** - * @param label The label to set. - */ - public void setLabel (String label) - { - m_label = label; - if (m_label != null) - m_labelValue = s_format.format(m_value) + " - " + m_label; - else - m_labelValue = s_format.format(m_value); - setToolTipText(m_labelValue); - setName(m_labelValue); - } // setLabel - - /** - * @param date for label. - * @param MeasureDisplay measure display - */ - public void setLabel (Timestamp date, String MeasureDisplay) - { - if (date == null) - return; - m_date = date; - m_measureDisplay = MeasureDisplay; - // - SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.Date); - String text = format.format(date); - // Month only - if (MGoal.MEASUREDISPLAY_Month.equals(MeasureDisplay) - || MGoal.MEASUREDISPLAY_Quarter.equals(MeasureDisplay)) - { - String pattern = format.toPattern(); - String mmText = text; - int index = pattern.indexOf("dd"); - if (index == 0) // dd.MM.yyyy - mmText = text.substring(3); - else if (index > 0) // MM/dd/yyyy - { - mmText = text.substring(0, index-1); - if (text.length() > index+2) - mmText += text.substring(index+2); - } - setLabel(mmText); - } - else // Day - setLabel(text); - } // setLabel - - /** - * @return Returns the targetValue. - */ - public double getTargetValue () - { - return m_targetValue; - } // getTargetValue - - /** - * @param targetValue The targetValue to set. - */ - public void setTargetValue (double targetValue) - { - m_targetValue = targetValue; - } // setTargetValue - - /** - * @return Returns the data value. - */ - public double getValue () - { - return m_value; - } // getValue - - /** - * @param value The data value to set. - */ - public void setValue (double value) - { - m_value = value; - if (m_label != null) - m_labelValue = s_format.format(m_value) + " - " + m_label; - else - m_labelValue = s_format.format(m_value); - setToolTipText(m_labelValue); - setName(m_labelValue); - } // setValue - - /** - * @return Returns the column width in pixles. - */ - public double getColWidth () - { - return m_width; - } // getColWidth - - /** - * @param width The column width in pixles. - */ - public void setColWidth (double width) - { - m_width = width; - if (isPreferredSizeSet()) - setPreferredSize(null); - } // getColWidth - - /** - * @return Returns the height in pixles. - */ - public double getColHeight() - { - return m_height; - } // getHeight - - /** - * @param height The hight in pixles. - */ - public void setColHeight (double height) - { - m_height = height; - if (isPreferredSizeSet()) - setPreferredSize(null); - } // setHeight - - /** - * Get Maximum Size - * @return size - */ - public Dimension getMaximumSize () - { - return getPreferredSize(); - } // getMaximumSize - - /** - * Get Minimum Size - * @return size - */ - public Dimension getMinimumSize () - { - return getPreferredSize(); - } // getMinimumSize - - /** - * Get Preferred Size - * @return size - */ - public Dimension getPreferredSize () - { - if (!isPreferredSizeSet()) - { - Dimension size = new Dimension((int)m_width, (int)m_height); - setPreferredSize(size); - } - return super.getPreferredSize (); - } // getPreferredSize - - - /** - * Paint Component - * @param g graphics - */ - protected void paintComponent (Graphics g) - { - Graphics2D g2D = (Graphics2D)g; - Rectangle bounds = getBounds(); - // Background - g2D.setColor(getBackground()); - //Dimension size = getPreferredSize(); - Dimension size =getSize(); - log.fine("bgc: " + size.width + " x " + size.height); - g2D.fill3DRect(0, 0, size.width, size.height, true); - - // Paint Label & Value - Color color = getForeground(); - g2D.setPaint(color); - // - Font font = getFont(); - FontMetrics fm = g2D.getFontMetrics(font); - int fontHeight = fm.getHeight(); - AffineTransform transform = AffineTransform.getRotateInstance(Math.PI*3/2); - font = font.deriveFont(transform); - g2D.setFont(font); - // - int x = (int)(size.width/2)+((fontHeight-2)/2); - if (x < fontHeight) - x = fontHeight-2; - int y = (int)(size.height-3); - g2D.drawString(m_labelValue, x, y); - log.finest("x=" + x + ",fontHeight=" + fontHeight + ", y=" + y + " - " + m_labelValue); - // Paint Target - if (m_targetValue != 0) - { - - } - } // paintComponent - - - /************************************************************************** - * Adds an ActionListener to the indicator. - * @param l the ActionListener to be added - */ - public void addActionListener(ActionListener l) - { - if (l != null) - listenerList.add(ActionListener.class, l); - } // addActionListener - - /** - * Removes an ActionListener from the indicator. - * @param l the listener to be removed - */ - public void removeActionListener(ActionListener l) - { - if (l != null) - listenerList.remove(ActionListener.class, l); - } // removeActionListener - - /** - * Returns an array of all the ActionListeners added - * to this indicator with addActionListener(). - * - * @return all of the ActionListeners added or an empty - * array if no listeners have been added - */ - public ActionListener[] getActionListeners() - { - return (ActionListener[])(listenerList.getListeners(ActionListener.class)); - } // getActionListeners - - /** - * Notifies all listeners that have registered interest for - * notification on this event type. The event instance - * is lazily created using the event - * parameter. - * - * @param event the ActionEvent object - * @see EventListenerList - */ - protected void fireActionPerformed(MouseEvent event) - { - // Guaranteed to return a non-null array - ActionListener[] listeners = getActionListeners(); - ActionEvent e = null; - // Process the listeners first to last - for (int i = 0; i < listeners.length; i++) - { - // Lazily create the event: - if (e == null) - e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, - "column"+m_label, event.getWhen(), event.getModifiers()); - listeners[i].actionPerformed(e); - } - } // fireActionPerformed - - - /** - * Mouse Clicked - * @param e mouse event - */ - public void mouseClicked (MouseEvent e) - { - if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) - fireActionPerformed(e); - } // mouseClicked - - public void mousePressed (MouseEvent e) - { - } - - public void mouseReleased (MouseEvent e) - { - } - - public void mouseEntered (MouseEvent e) - { - } - - public void mouseExited (MouseEvent e) - { - } - -} // BarGraphColumn diff --git a/client/src/org/adempiere/apps/graph/BarGraphLayout.java b/client/src/org/adempiere/apps/graph/BarGraphLayout.java deleted file mode 100644 index dc22ad21fb..0000000000 --- a/client/src/org/adempiere/apps/graph/BarGraphLayout.java +++ /dev/null @@ -1,161 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.adempiere.apps.graph; - -import java.awt.Component; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.FontMetrics; -import java.awt.LayoutManager; -import java.awt.Point; -import java.util.ArrayList; - -import org.compiere.util.CLogger; - -/** - * Bar Graph Layout - * - * @author Jorg Janke - * @version $Id: BarGraphLayout.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $ - */ -public class BarGraphLayout - implements LayoutManager -{ - /** - * Bar Graph Layout - * @param parent parenr - */ - public BarGraphLayout (BarGraph parent) - { - m_parent = parent; - } // BarGraphLayout - - /** Parent Container */ - private BarGraph m_parent; - /** List of Components */ - private ArrayList m_list = new ArrayList(); - /** Layout Complete */ - private boolean m_layoutComplete = false; - /** Gap between columns */ - private static int XGAP = 2; - /** Gap to Axix */ - private static int YGAP = 1; - - /** Logger */ - private static CLogger log = CLogger.getCLogger (BarGraphLayout.class); - - /** - * Add Layout Component - * @param name name - * @param comp component - */ - public void addLayoutComponent (String name, Component comp) - { - if (comp instanceof BarGraphColumn) - m_list.add((BarGraphColumn)comp); - else - log.severe("Invalid Class: " + comp); - m_layoutComplete = false; - } // addLayoutComponent - - /** - * Remove Layout Component - * @param comp component - */ - public void removeLayoutComponent (Component comp) - { - m_list.remove(comp); - m_layoutComplete = false; - } // removeLayoutComponent - - /** - * Preferred Layout Size - * @param parent parent - * @return size - */ - public Dimension preferredLayoutSize (Container parent) - { - return parent.getPreferredSize(); - } // preferredLayoutSize - - /** - * Minimum Layout Size - * @param parent parent - * @return size - */ - public Dimension minimumLayoutSize (Container parent) - { - return parent.getMinimumSize(); - } // minimumLayoutSize - - - /** - * Layout Container - * @param parent - */ - public void layoutContainer (Container parent) - { - if (m_layoutComplete) - return; - - // Find Max - double maxValue = 0; - for (int i = 0; i < m_list.size(); i++) - { - BarGraphColumn column = m_list.get(i); - maxValue = Math.max(maxValue, column.getValue()); - } - // - //Dimension size = m_parent.getPreferredSize(); - Dimension size =m_parent.getSize(); - log.fine("bgl: " +size.width + " x " + size.height); - - Point point0_0 = m_parent.getPoint0_0(); - - double graphHeight = size.height - (size.height-point0_0.y) - (2*YGAP); - double graphWidth = size.width - point0_0.x - XGAP; - double columnWidth = (graphWidth - (XGAP*m_list.size())) / m_list.size(); - columnWidth = Math.min(30, columnWidth); - FontMetrics fm = m_parent.getFontMetrics(m_parent.getFont()); - int fontHeight = fm.getHeight(); - columnWidth = Math.max(fontHeight, columnWidth); - - log.fine("Height=" + graphHeight + ", MaxValue=" + maxValue - + ", Width=" + graphWidth + ", ColumnWidth=" + columnWidth); - - int x = point0_0.x + (2*XGAP); - // Set Values - for (int i = 0; i < m_list.size(); i++) - { - BarGraphColumn column = m_list.get(i); - double multiplier = column.getValue() / maxValue; - double height = graphHeight * multiplier; - column.setColHeight(height); - column.setColWidth(columnWidth); - Dimension ps = column.getPreferredSize(); - column.setBackground(GraphUtil.getBackground(i)); - // - int y = point0_0.y - ps.height - YGAP; - column.setLocation(x, y); - column.setBounds(x, y, ps.width, ps.height); - x += ps.width + XGAP; - log.finer(i + " - " + ((int)(multiplier*100)) + "% - " + column.getBounds()); - } - m_layoutComplete = true; - } // layoutContainer - -} // BarGraphLayout diff --git a/client/src/org/adempiere/apps/graph/Graph.java b/client/src/org/adempiere/apps/graph/Graph.java new file mode 100644 index 0000000000..606d1afd97 --- /dev/null +++ b/client/src/org/adempiere/apps/graph/Graph.java @@ -0,0 +1,312 @@ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * For the text or an alternative of this public license, you may reach us * + * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * + * or via info@compiere.org or http://www.compiere.org/license.html * + *****************************************************************************/ +package org.adempiere.apps.graph; + +import java.awt.BorderLayout; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Point; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyVetoException; +import java.beans.VetoableChangeListener; +import java.util.ArrayList; + +import org.compiere.apps.AEnv; +import org.compiere.grid.ed.VLookup; +import org.compiere.model.MGoal; +import org.compiere.model.MLookup; +import org.compiere.model.MLookupFactory; +import org.compiere.model.MLookupInfo; +import org.compiere.model.MQuery; +import org.compiere.swing.CPanel; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.jfree.chart.ChartMouseEvent; +import org.jfree.chart.ChartMouseListener; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.entity.CategoryItemEntity; +import org.jfree.chart.entity.ChartEntity; +import org.jfree.chart.entity.PieSectionEntity; + +/** + * Graph + * + * @author Jorg Janke + * @version $Id: BarGraph.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $ + * + * @author Teo Sarca, www.arhipac.ro + *
  • BF [ 2507325 ] BarGraph zoom not working + * @author hengsin + *
  • Add support for other type of graph + */ +public class Graph extends CPanel implements ChartMouseListener +{ + /** + * + */ + private static final long serialVersionUID = -4150122585550132822L; + + /** + * Constructor + */ + public Graph() + { + super(); + this.setLayout(new BorderLayout()); + builder = new GraphBuilder(); + } // BarGraph + + /** + * Constructor + * @param goal goal + */ + public Graph(MGoal goal) + { + this(goal, false); + } + + /** + * Constructor + * @param goal goal + */ + public Graph(MGoal goal, boolean userSelection) + { + this(); + builder = new GraphBuilder(); + builder.setMGoal(goal); + builder.setYAxisLabel(goal.getName()); + builder.setXAxisLabel(goal.getXAxisText()); + m_userSelection = userSelection; + loadData(); + //addComponentListener(this); + } // BarGraph + + + /** Graph Size */ + //private Dimension m_size = null; + /** Zero/Zero Coordibate point */ + private Point m_point0_0 = null; +// /** Layout */ +// private BarGraphLayout m_layout = new BarGraphLayout(this); + + /** Logger */ + private static CLogger log = CLogger.getCLogger (Graph.class); + + + /** Y Axis Target Line */ + private double m_Y_Target = 0; + /** Y Axis Target Line Label */ + private String m_Y_TargetLabel = null; + private static Dimension paneldimension = new Dimension(180, 150); + + private GraphBuilder builder; + + /** + * Load Performance Data + */ + ArrayList list = new ArrayList(); + private boolean m_userSelection; + + + private void loadData() + { + + list = builder.loadData(); + JFreeChart chart = builder.createChart(builder.getMGoal().getChartType()); + if (chartPanel != null) + remove(chartPanel); + + chartPanel = new ChartPanel(chart); + chartPanel.setSize(getSize()); + chartPanel.addChartMouseListener(this); + add(chartPanel,BorderLayout.CENTER); + + if (m_userSelection) + { + int AD_Reference_Value_ID = DB.getSQLValue(null, "SELECT AD_Reference_ID FROM AD_Reference WHERE Name = ?", "PA_Goal ChartType"); + MLookupInfo info = MLookupFactory.getLookup_List(Env.getLanguage(Env.getCtx()), AD_Reference_Value_ID); + MLookup mLookup = new MLookup(info, 0); + VLookup lookup = new VLookup("ChartType", false, false, true, + mLookup); + lookup.addVetoableChangeListener(new VetoableChangeListener() { + + public void vetoableChange(PropertyChangeEvent evt) + throws PropertyVetoException { + Object value = evt.getNewValue(); + if (value == null) return; + JFreeChart chart = null; + chart = builder.createChart(value.toString()); + + if (chart != null) + { + if (chartPanel != null) + remove(chartPanel); + + chartPanel = new ChartPanel(chart); + chartPanel.setSize(getSize()); + chartPanel.addChartMouseListener(Graph.this); + add(chartPanel,BorderLayout.CENTER); + getParent().validate(); + + } + } + + }); + add(lookup, BorderLayout.NORTH); + } + this.setMinimumSize(paneldimension); + } // loadData + + private ChartPanel chartPanel; + /** + * Get Point 0_0 + * @return point + */ + public Point getPoint0_0() + { + return m_point0_0; + } // getPoint0_0 + + + /** + * @return Returns the x_AxisLabel. + */ + public String getX_AxisLabel () + { + return builder.getXAxisLabel(); + } // getX_AxisLabel + + /** + * @param axisLabel The x_AxisLabel to set. + */ + public void setX_AxisLabel (String axisLabel) + { + builder.setXAxisLabel(axisLabel); + } // setX_AxisLabel + + /** + * @return Returns the y_AxisLabel. + */ + public String getY_AxisLabel () + { + return builder.getYAxisLabel(); + } // getY_AxisLabel + + /** + * @param axisLabel The y_AxisLabel to set. + */ + public void setY_AxisLabel (String axisLabel) + { + builder.setYAxisLabel(axisLabel); + } // setY_AxisLabel + + /** + * @return Returns the y_TargetLabel. + */ + public String getY_TargetLabel () + { + return m_Y_TargetLabel; + } // getY_TargetLabel + + /** + * @param targetLabel The y_TargetLabel to set. + */ + public void setY_TargetLabel (String targetLabel, double target) + { + m_Y_TargetLabel = targetLabel; + m_Y_Target = target; + } // setY_TargetLabel + + + /** + * Get BarGraphColumn for ChartEntity + * @param event + * @return BarGraphColumn or null if not found + */ + private GraphColumn getGraphColumn(ChartMouseEvent event) + { + ChartEntity entity = event.getEntity(); + String key = null; + if (entity instanceof CategoryItemEntity) + { + Comparable colKey = ((CategoryItemEntity)entity).getColumnKey(); + if (colKey != null) + { + key = colKey.toString(); + } + } + else if (entity instanceof PieSectionEntity) + { + Comparable sectionKey = ((PieSectionEntity)entity).getSectionKey(); + if (sectionKey != null) + { + key = sectionKey.toString(); + } + } + if (key == null) + { + return null; + } + for (int i = 0; i < list.size(); i++) + { + final String label = list.get(i).getLabel(); + if (key.equals(label)) + { + return list.get(i); + } + } + // + return null; + } + + public void chartMouseClicked(ChartMouseEvent event) + { + if ((event.getEntity()!=null) && (event.getTrigger().getClickCount() > 1)) + { + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + try + { + GraphColumn bgc = getGraphColumn(event); + if (bgc == null) + { + return; + } + + MQuery query = bgc.getMQuery(builder.getMGoal()); + if (query != null) + AEnv.zoom(query); + else + log.warning("Nothing to zoom to - " + bgc); + } + finally + { + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + } + } + + public void chartMouseMoved(ChartMouseEvent event) + { + } + + public GraphColumn[] getGraphColumnList() + { + return list.toArray(new GraphColumn[list.size()]); + } +} // BarGraph diff --git a/client/src/org/adempiere/apps/graph/GraphBuilder.java b/client/src/org/adempiere/apps/graph/GraphBuilder.java new file mode 100644 index 0000000000..7fa04fd44a --- /dev/null +++ b/client/src/org/adempiere/apps/graph/GraphBuilder.java @@ -0,0 +1,265 @@ +/****************************************************************************** + * Copyright (C) 2009 Low Heng Sin * + * Copyright (C) 2009 Idalica Corporation * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package org.adempiere.apps.graph; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.Calendar; + +import org.compiere.model.MGoal; +import org.compiere.model.MMeasure; +import org.compiere.model.X_PA_Goal; +import org.compiere.util.CLogger; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.renderer.category.CategoryItemRenderer; +import org.jfree.data.category.DefaultCategoryDataset; +import org.jfree.data.general.DefaultPieDataset; + +/** + * + * @author hengsin + * + */ +public class GraphBuilder { + + /** The Goal */ + protected MGoal m_goal = null; + /** X Axis Label */ + protected String m_X_AxisLabel = "X Axis"; + /** Y Axis Label */ + protected String m_Y_AxisLabel = "Y Axis"; + protected DefaultCategoryDataset dataset = new DefaultCategoryDataset(); + protected DefaultCategoryDataset linearDataset = new DefaultCategoryDataset(); + protected DefaultPieDataset pieDataset = new DefaultPieDataset(); + + private static final CLogger log = CLogger.getCLogger(GraphBuilder.class); + + public GraphBuilder() { + super(); + } + + /** + * + * @param type + * @return JFreeChart + */ + public JFreeChart createChart(String type) { + if(X_PA_Goal.CHARTTYPE_BarChart.equals(type)) + { + return createBarChart(); + } + else if (X_PA_Goal.CHARTTYPE_PieChart.equals(type)) + { + return createPieChart(); + } + else if (X_PA_Goal.CHARTTYPE_AreaChart.equals(type)) + { + return createAreaChart(); + } + else if (X_PA_Goal.CHARTTYPE_LineChart.equals(type)) + { + return createLineChart(); + } + else if (X_PA_Goal.CHARTTYPE_RingChart.equals(type)) + { + return createRingChart(); + } + else if (X_PA_Goal.CHARTTYPE_WaterfallChart.equals(type)) + { + return createWaterfallChart(); + } + else + { + throw new IllegalArgumentException("unknown chart type=" + type); + } + } + + private JFreeChart createWaterfallChart() { + JFreeChart chart = ChartFactory.createWaterfallChart( + m_goal.getMeasure().getName(), // chart title + m_X_AxisLabel, // domain axis label + m_Y_AxisLabel, // range axis label + linearDataset, // data + PlotOrientation.VERTICAL, // orientation + false, // include legend + true, // tooltips? + true // URLs? + ); + + setupCategoryChart(chart); + return chart; + } + + private JFreeChart createRingChart() { + final JFreeChart chart = ChartFactory.createRingChart(m_goal.getMeasure().getName(), + pieDataset, false, true, true); + + return chart; + } + + private JFreeChart createBarChart() { + JFreeChart chart = ChartFactory.createBarChart3D( + m_goal.getMeasure().getName(), // chart title + m_X_AxisLabel, // domain axis label + m_Y_AxisLabel, // range axis label + dataset, // data + PlotOrientation.VERTICAL, // orientation + false, // include legend + true, // tooltips? + true // URLs? + ); + + setupCategoryChart(chart); + return chart; + } + + private JFreeChart createPieChart() { + final JFreeChart chart = ChartFactory.createPieChart3D(m_goal.getMeasure().getName(), + pieDataset, false, true, true); + + return chart; + } + + private JFreeChart createAreaChart() { + // create the chart... + JFreeChart chart = ChartFactory.createAreaChart( + m_goal.getMeasure().getName(), // chart title + m_X_AxisLabel, // domain axis label + m_Y_AxisLabel, // range axis label + dataset, // data + PlotOrientation.VERTICAL, // orientation + false, // include legend + true, // tooltips? + true // URLs? + ); + + setupCategoryChart(chart); + return chart; + } + + private void setupCategoryChart(JFreeChart chart) { + CategoryPlot plot = chart.getCategoryPlot(); + CategoryItemRenderer renderer = plot.getRenderer(); + renderer.setSeriesPaint(0, new Color(92/255f, 178/255f, 232/255f)); + renderer.setSeriesPaint(1, new Color(56/255f, 97/255f, 119/255f)); + renderer.setSeriesPaint(2, new Color(242/255f, 70/255f, 78/255f)); + renderer.setSeriesPaint(3, Color.orange); + renderer.setSeriesPaint(4, new Color(147/255f, 196/255f, 51/255f)); + renderer.setSeriesPaint(5, new Color(210/255f, 247/255f, 91/255f)); + renderer.setSeriesPaint(6, new Color(129/255f, 235/255f, 249/255f)); + renderer.setSeriesPaint(7, new Color(60/255f, 84/255f, 8/255f)); + renderer.setSeriesPaint(8, new Color(0.8f, 0.8f, 0.8f)); + } + + private JFreeChart createLineChart() { + // create the chart... + JFreeChart chart = ChartFactory.createLineChart3D( + m_goal.getMeasure().getName(), // chart title + m_X_AxisLabel, // domain axis label + m_Y_AxisLabel, // range axis label + linearDataset, // data + PlotOrientation.VERTICAL, // orientation + false, // include legend + true, // tooltips? + true // URLs? + ); + + setupCategoryChart(chart); + return chart; + } + + /** + * + * @return MGoal + */ + public MGoal getMGoal() { + return m_goal; + } + + /** + * + * @param mgoal + */ + public void setMGoal(MGoal mgoal) { + m_goal = mgoal; + } + + /** + * + * @return X axis label + */ + public String getXAxisLabel() { + return m_X_AxisLabel; + } + + /** + * + * @param axisLabel + */ + public void setXAxisLabel(String axisLabel) { + m_X_AxisLabel = axisLabel; + } + + /** + * + * @return Y axis label + */ + public String getYAxisLabel() { + return m_Y_AxisLabel; + } + + /** + * + * @param axisLabel + */ + public void setYAxisLabel(String axisLabel) { + m_Y_AxisLabel = axisLabel; + } + + /** + * + * @return graph column list + */ + public ArrayList loadData() { + // Calculated + MMeasure measure = getMGoal().getMeasure(); + if (measure == null) + { + log.warning("No Measure for " + getMGoal()); + return null; + } + + ArrayListlist = measure.getGraphColumnList(getMGoal()); + + pieDataset = new DefaultPieDataset(); + dataset = new DefaultCategoryDataset(); + for (int i = 0; i < list.size(); i++){ + String series = m_X_AxisLabel; + if (list.get(i).getDate() != null) { + Calendar cal = Calendar.getInstance(); + cal.setTime(list.get(i).getDate()); + series = Integer.toString(cal.get(Calendar.YEAR)); + } + dataset.addValue(list.get(i).getValue(), series, + list.get(i).getLabel()); + linearDataset.addValue(list.get(i).getValue(), m_X_AxisLabel, + list.get(i).getLabel()); + pieDataset.setValue(list.get(i).getLabel(), list.get(i).getValue()); + } + return list; + } +} \ No newline at end of file diff --git a/client/src/org/adempiere/apps/graph/GraphColumn.java b/client/src/org/adempiere/apps/graph/GraphColumn.java new file mode 100644 index 0000000000..ff10606b78 --- /dev/null +++ b/client/src/org/adempiere/apps/graph/GraphColumn.java @@ -0,0 +1,347 @@ +/****************************************************************************** + * Copyright (C) 2009 Low Heng Sin * + * Copyright (C) 2009 Idalica Corporation * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package org.adempiere.apps.graph; + +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; + +import org.compiere.model.MAchievement; +import org.compiere.model.MGoal; +import org.compiere.model.MMeasureCalc; +import org.compiere.model.MProjectType; +import org.compiere.model.MQuery; +import org.compiere.model.MRequestType; +import org.compiere.model.MRole; +import org.compiere.util.CLogger; +import org.compiere.util.DisplayType; + +/** + * + * @author hengsin + * + */ +public class GraphColumn +{ + + /** + * Base Constructor + * @param label label + * @param value value + */ + public GraphColumn (String label, double value) + { + m_label = label; + setValue(value); + } // BarGraphColumn + + /** + * Single Achievement Constructor + * @param achievement achievement + */ + public GraphColumn (MAchievement achievement) + { + this (achievement.getName(), achievement.getManualActual().doubleValue()); + m_achievement = achievement; + } // GraphColumn + + /** + * Achievement Goal Constructor + * @param goal goal + * @param data count + */ + public GraphColumn (MGoal goal, BigDecimal data) + { + this ("", data == null ? 0 : data.doubleValue()); + m_goal = goal; + } // GraphColumn + + /** + * Measure Calc Constructor + * @param mc MeasureCalc + */ + public GraphColumn (MMeasureCalc mc, BigDecimal data) + { + this ("", data == null ? 0 : data.doubleValue()); + m_mc = mc; + } // GraphColumn + + /** + * Request Type Constructor + * @param rt Request Type + */ + public GraphColumn (MRequestType rt, BigDecimal data, int id) + { + this ("", data == null ? 0 : data.doubleValue()); + m_rt = rt; + m_id = id; + } // GraphColumn + + /** + * Project Type Constructor + * @param pt Procet Type + */ + public GraphColumn (MProjectType pt, BigDecimal data, int id) + { + this ("", data == null ? 0 : data.doubleValue()); + m_pt = pt; + m_id = id; + } // BarGraphColumn + + /** Optional Achievement */ + private MAchievement m_achievement = null; + /** Measure Calc */ + private MMeasureCalc m_mc = null; + /** Goal */ + private MGoal m_goal = null; + + private MRequestType m_rt = null; + private MProjectType m_pt = null; + private int m_id = 0; + + /** Display */ + private String m_measureDisplay = null; + private Timestamp m_date = null; + + /** Column Label */ + private String m_label = null; + /** Column Data Value */ + private double m_value = 0; + /** Column Label Value */ + private String m_labelValue = ""; + /** Column Data Target Value */ + private double m_targetValue = 0; + /** Column Width in pixles */ + private double m_width = 0; + /** Column Height in pixles */ + private double m_height = 0; + + /** Logger */ + private static CLogger log = CLogger.getCLogger (GraphColumn.class); + /** Integer Number Format */ + private static DecimalFormat s_format = DisplayType.getNumberFormat(DisplayType.Integer); + + /** + * Get Achievement Goal + * @return achievement or null + */ + public MGoal getGoal() + { + return m_goal; + } // getGoal + + + /** + * Get Single Achievement + * @return achievement or null + */ + public MAchievement getAchievement() + { + return m_achievement; + } // getAchievement + + /** + * Get MeasureCalc + * @return measure + */ + public MMeasureCalc getMeasureCalc() + { + return m_mc; + } // getMeasureCalc + + public MRequestType getRequestType() + { + return m_rt; + } + + public MProjectType getProjectType() + { + return m_pt; + } + + public String getMeasureDisplay() + { + return m_measureDisplay; + } // getMeasureDisplay + + public Timestamp getDate() + { + return m_date; + } // getDate + + public int getID() + { + return m_id; + } + + /** + * @return Returns the label. + */ + public String getLabel () + { + return m_label; + } // getLabel + + /** + * @param label The label to set. + */ + public void setLabel (String label) + { + m_label = label; + if (m_label != null) + m_labelValue = s_format.format(m_value) + " - " + m_label; + else + m_labelValue = s_format.format(m_value); + } // setLabel + + /** + * @param date for label. + * @param MeasureDisplay measure display + */ + public void setLabel (Timestamp date, String MeasureDisplay) + { + if (date == null) + return; + m_date = date; + m_measureDisplay = MeasureDisplay; + // + SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.Date); + String text = format.format(date); + // Month only + if (MGoal.MEASUREDISPLAY_Month.equals(MeasureDisplay) + || MGoal.MEASUREDISPLAY_Quarter.equals(MeasureDisplay)) + { + String pattern = format.toPattern(); + String mmText = text; + int index = pattern.indexOf("dd"); + if (index == 0) // dd.MM.yyyy + mmText = text.substring(3); + else if (index > 0) // MM/dd/yyyy + { + mmText = text.substring(0, index-1); + if (text.length() > index+2) + mmText += text.substring(index+2); + } + setLabel(mmText); + } + else // Day + setLabel(text); + } // setLabel + + /** + * @return Returns the targetValue. + */ + public double getTargetValue () + { + return m_targetValue; + } // getTargetValue + + /** + * @param targetValue The targetValue to set. + */ + public void setTargetValue (double targetValue) + { + m_targetValue = targetValue; + } // setTargetValue + + /** + * @return Returns the data value. + */ + public double getValue () + { + return m_value; + } // getValue + + /** + * @param value The data value to set. + */ + public void setValue (double value) + { + m_value = value; + if (m_label != null) + m_labelValue = s_format.format(m_value) + " - " + m_label; + else + m_labelValue = s_format.format(m_value); + } // setValue + + /** + * @return Returns the column width in pixles. + */ + public double getColWidth () + { + return m_width; + } // getColWidth + + /** + * @param width The column width in pixles. + */ + public void setColWidth (double width) + { + m_width = width; + } // getColWidth + + /** + * @return Returns the height in pixles. + */ + public double getColHeight() + { + return m_height; + } // getHeight + + /** + * @param height The hight in pixles. + */ + public void setColHeight (double height) + { + m_height = height; + } // setHeight + + public MQuery getMQuery(MGoal mGoal) + { + MQuery query = null; + if (getAchievement() != null) // Single Achievement + { + MAchievement a = getAchievement(); + query = MQuery.getEqualQuery("PA_Measure_ID", a.getPA_Measure_ID()); + } + else if (getGoal() != null) // Multiple Achievements + { + MGoal goal = getGoal(); + query = MQuery.getEqualQuery("PA_Measure_ID", goal.getPA_Measure_ID()); + } + else if (getMeasureCalc() != null) // Document + { + MMeasureCalc mc = getMeasureCalc(); + query = mc.getQuery(mGoal.getRestrictions(false), + getMeasureDisplay(), getDate(), + MRole.getDefault()); // logged in role + } + else if (getProjectType() != null) // Document + { + MProjectType pt = getProjectType(); + query = pt.getQuery(mGoal.getRestrictions(false), + getMeasureDisplay(), getDate(), getID(), + MRole.getDefault()); // logged in role + } + else if (getRequestType() != null) // Document + { + MRequestType rt = getRequestType(); + query = rt.getQuery(mGoal.getRestrictions(false), + getMeasureDisplay(), getDate(), getID(), + MRole.getDefault()); // logged in role + } + return query; + } +} diff --git a/client/src/org/adempiere/apps/graph/HtmlDashboard.java b/client/src/org/adempiere/apps/graph/HtmlDashboard.java index 9caff8dd9d..f848d6986e 100644 --- a/client/src/org/adempiere/apps/graph/HtmlDashboard.java +++ b/client/src/org/adempiere/apps/graph/HtmlDashboard.java @@ -207,12 +207,12 @@ public class HtmlDashboard extends JPanel implements MouseListener, output += "Target" + m_goals[i].getMeasureTarget() + "\n"; output += "Actual" + m_goals[i].getMeasureActual() + "\n"; //if (mc.getTableName()!=null) output += "table: " + mc.getAD_Table_ID() + "
    \n"; - BarGraph barPanel = new BarGraph(m_goals[i]); - BarGraphColumn[] bList = barPanel.getBarGraphColumnList(); + Graph barPanel = new Graph(m_goals[i]); + GraphColumn[] bList = barPanel.getGraphColumnList(); MQuery query = null; output += "" + m_goals[i].getXAxisText() + "\n"; for (int k=0; k0) output += ""; if (bgc.getAchievement() != null) // Single Achievement { diff --git a/client/src/org/adempiere/apps/graph/PAPanel.java b/client/src/org/adempiere/apps/graph/PAPanel.java index 7a3f4d2560..9a94c5ba2d 100644 --- a/client/src/org/adempiere/apps/graph/PAPanel.java +++ b/client/src/org/adempiere/apps/graph/PAPanel.java @@ -142,7 +142,7 @@ public class PAPanel extends CPanel implements ActionListener for (int i = 0; i < java.lang.Math.min(2, m_goals.length); i++) { if (m_goals[i].getMeasure() != null) //MGoal goal = pi.getGoal(); - boxH1.add ( new BarGraph(m_goals[i]), BorderLayout.SOUTH); + boxH1.add ( new Graph(m_goals[i]), BorderLayout.SOUTH); } boxV2.add(boxH1, BorderLayout.SOUTH); diff --git a/client/src/org/adempiere/apps/graph/PerformanceDetail.java b/client/src/org/adempiere/apps/graph/PerformanceDetail.java index d9f36d0edb..488b903925 100644 --- a/client/src/org/adempiere/apps/graph/PerformanceDetail.java +++ b/client/src/org/adempiere/apps/graph/PerformanceDetail.java @@ -40,7 +40,7 @@ public class PerformanceDetail extends CFrame /** * */ - private static final long serialVersionUID = 806635848484287844L; + private static final long serialVersionUID = -5994488373513922522L; /** * Constructor. @@ -51,12 +51,12 @@ public class PerformanceDetail extends CFrame { super (goal.getName()); setIconImage(Adempiere.getImage16()); - barPanel = new BarGraph(goal); + barPanel = new Graph(goal, true); init(); AEnv.showCenterScreen(this); } // PerformanceDetail - BarGraph barPanel = null; + Graph barPanel = null; ConfirmPanel confirmPanel = new ConfirmPanel(); /** diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WBarGraph.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WBarGraph.java deleted file mode 100644 index 001aaf5031..0000000000 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WBarGraph.java +++ /dev/null @@ -1,514 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2008 Low Heng Sin * - * Copyright (C) 2008 Idalica Corporation * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - *****************************************************************************/ -package org.adempiere.webui.apps.graph; - -import java.awt.Color; -import java.awt.Point; -import java.awt.image.BufferedImage; -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.logging.Level; - -import org.adempiere.apps.graph.BarGraphColumn; -import org.adempiere.webui.apps.AEnv; -import org.adempiere.webui.component.Panel; -import org.compiere.model.MAchievement; -import org.compiere.model.MGoal; -import org.compiere.model.MMeasure; -import org.compiere.model.MMeasureCalc; -import org.compiere.model.MProjectType; -import org.compiere.model.MQuery; -import org.compiere.model.MRequestType; -import org.compiere.model.MRole; -import org.compiere.model.MStatus; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.jfree.chart.ChartFactory; -import org.jfree.chart.ChartMouseEvent; -import org.jfree.chart.ChartRenderingInfo; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.encoders.EncoderUtil; -import org.jfree.chart.encoders.ImageFormat; -import org.jfree.chart.entity.ChartEntity; -import org.jfree.chart.plot.CategoryPlot; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.renderer.category.BarRenderer; -import org.jfree.data.category.DefaultCategoryDataset; -import org.zkoss.image.AImage; -import org.zkoss.zk.ui.event.Event; -import org.zkoss.zk.ui.event.EventListener; -import org.zkoss.zk.ui.event.Events; -import org.zkoss.zk.ui.event.MouseEvent; -import org.zkoss.zul.Area; -import org.zkoss.zul.Imagemap; - -/** - * Bar Graph - * - * @author hengsin - */ -public class WBarGraph extends Panel -{ - /** - * - */ - private static final long serialVersionUID = -975989183542113080L; - - /** - * Constructor - */ - public WBarGraph() - { - super(); - } // BarGraph - - /** - * Constructor - * @param goal goal - */ - public WBarGraph(MGoal goal) - { - this(); - m_goal = goal; - m_Y_AxisLabel = goal.getName(); - m_X_AxisLabel = goal.getXAxisText(); - loadData(); - } // BarGraph - - /** The Goal */ - private MGoal m_goal = null; - /** Zero/Zero Coordibate point */ - private Point m_point0_0 = null; - - /** Logger */ - private static CLogger log = CLogger.getCLogger (WBarGraph.class); - - /** X Axis Label */ - private String m_X_AxisLabel = "X Axis"; - /** Y Axis Label */ - private String m_Y_AxisLabel = "Y Axis"; - /** Y Axis Target Line Label */ - private String m_Y_TargetLabel = null; - - final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); - - /** - * Load Performance Data - */ - ArrayList list = new ArrayList(); - - private void loadData() - { - // Calculated - MMeasure measure = m_goal.getMeasure(); - if (measure == null) - { - log.warning("No Measure for " + m_goal); - return; - } - if (MMeasure.MEASURETYPE_Calculated.equals(measure.getMeasureType())) - { - MMeasureCalc mc = MMeasureCalc.get(Env.getCtx(), measure.getPA_MeasureCalc_ID()); - String sql = mc.getSqlBarChart(m_goal.getRestrictions(false), - m_goal.getMeasureDisplay(), null, - MRole.getDefault()); // logged in role - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement (sql, null); - rs = pstmt.executeQuery (); - ArrayList dataList = new ArrayList(); - while (rs.next ()) - { - BigDecimal data = rs.getBigDecimal(1); - Timestamp date = rs.getTimestamp(2); - BarGraphColumn bgc = new BarGraphColumn(mc, data); - bgc.setLabel(date, m_goal.getMeasureDisplay()); //TODO copy order-loop to other measures - int pos=0; - for (int i = 0; i < dataList.size(); i++) - if (dataList.get(i).before(date)) pos++; - dataList.add(date); // list of dates - 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(measure.getMeasureType())) - { - if (MMeasure.MEASUREDATATYPE_StatusQtyAmount.equals(measure.getMeasureDataType())) - { - MAchievement[] achievements = MAchievement.get(measure); - for (int i = 0; i < achievements.length; i++) - { - MAchievement achievement = achievements[i]; - BarGraphColumn bgc = new BarGraphColumn(achievement); - list.add(bgc); - } - } - else // MMeasure.MEASUREDATATYPE_QtyAmountInTime - { - String MeasureDisplay = m_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, measure.getPA_Measure_ID()); - rs = pstmt.executeQuery (); - while (rs.next ()) - { - BigDecimal data = rs.getBigDecimal(1); - Timestamp date = rs.getTimestamp(2); - BarGraphColumn bgc = new BarGraphColumn(m_goal, data); - bgc.setLabel(date, m_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 - } // Achievement - - // Request - else if (MMeasure.MEASURETYPE_Request.equals(measure.getMeasureType())) - { - MRequestType rt = MRequestType.get(Env.getCtx(), measure.getR_RequestType_ID()); - String sql = rt.getSqlBarChart(m_goal.getRestrictions(false), - m_goal.getMeasureDisplay(), measure.getMeasureDataType(), - null, MRole.getDefault()); // logged in role - 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); - BarGraphColumn bgc = new BarGraphColumn(rt, data, R_Status_ID); - if (R_Status_ID == 0) - { - Timestamp date = rs.getTimestamp(2); - bgc.setLabel(date, m_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; - } - } // Request - - // Project - else if (MMeasure.MEASURETYPE_Project.equals(measure.getMeasureType())) - { - MProjectType pt = MProjectType.get(Env.getCtx(), measure.getC_ProjectType_ID()); - String sql = pt.getSqlBarChart(m_goal.getRestrictions(false), - m_goal.getMeasureDisplay(), measure.getMeasureDataType(), - null, MRole.getDefault()); // logged in role - 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); - BarGraphColumn bgc = new BarGraphColumn(pt, data, id); - bgc.setLabel(date, m_goal.getMeasureDisplay()); - list.add(bgc); - } - } - catch (Exception e) - { - log.log (Level.SEVERE, sql, e); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - } // Project - - // Add last 20 - int startValue = 0; - for (int i = startValue; i < list.size(); i++){ - dataset.addValue(list.get(i).getValue(), list.get(i).getLabel(), list.get(i).getLabel()); - } - - // create the chart... - final JFreeChart chart = ChartFactory.createBarChart( - measure.getName(), // chart title - m_X_AxisLabel, // domain axis label - m_Y_AxisLabel, // range axis label - dataset, // data - PlotOrientation.VERTICAL, // orientation - false, // include legend - true, // tooltips? - true // URLs? - ); - - CategoryPlot plot = chart.getCategoryPlot(); - //plot.setBackgroundPaint(Color.lightGray); //GraphUtil.getForeground(getBackground()) - BarRenderer renderer = (BarRenderer) plot.getRenderer(); - chart.getCategoryPlot().setRenderer(renderer); - renderer.setSeriesPaint(0, new Color(92/255f, 178/255f, 232/255f)); - renderer.setSeriesPaint(1, new Color(56/255f, 97/255f, 119/255f)); - renderer.setSeriesPaint(2, new Color(242/255f, 70/255f, 78/255f)); - renderer.setSeriesPaint(3, Color.orange); - renderer.setSeriesPaint(4, new Color(147/255f, 196/255f, 51/255f)); - renderer.setSeriesPaint(5, new Color(210/255f, 247/255f, 91/255f)); - renderer.setSeriesPaint(6, new Color(129/255f, 235/255f, 249/255f)); - renderer.setSeriesPaint(7, new Color(60/255f, 84/255f, 8/255f)); - renderer.setSeriesPaint(8, new Color(0.8f, 0.8f, 0.8f)); - - ChartRenderingInfo info = new ChartRenderingInfo(); - BufferedImage bi = chart.createBufferedImage(700, 500, BufferedImage.TRANSLUCENT, info); - try { - byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); - - AImage image = new AImage("", bytes); - Imagemap myImage = new Imagemap(); - - myImage.setContent(image); - appendChild(myImage); - - int count = 0; - for(Iterator it = info.getEntityCollection().getEntities().iterator(); it.hasNext(); ) - { - ChartEntity ce = ( ChartEntity ) it.next(); - - String tooltip = ce.getToolTipText(); - if(tooltip == null) continue; - - Area area = new Area(); - myImage.appendChild(area); - area.setCoords(ce.getShapeCoords()); - area.setShape(ce.getShapeType()); - area.setTooltiptext(tooltip); - area.setId("WBG_"+tooltip); - count++; - } - - myImage.addEventListener(Events.ON_CLICK, new EventListener() - { - public void onEvent(Event event) throws Exception - { - MouseEvent me = (MouseEvent) event; - String areaId = me.getArea(); - if(areaId != null) - { - for(int i = 0; i < list.size(); i++) - { - String s = "WBG_(" + list.get(i).getLabel() + ", " + list.get(i).getLabel() + ") = "; - if(areaId.startsWith(s)) - { - chartMouseClicked(i); - return; - } - } - } - } - }); - } - catch (Exception e) { - log.log (Level.SEVERE, "", e); - } - } // loadData - /** - * Get Point 0_0 - * - * @return point - */ - public Point getPoint0_0() - { - return m_point0_0; - } // getPoint0_0 - - - /** - * @return Returns the x_AxisLabel. - */ - public String getX_AxisLabel () - { - return m_X_AxisLabel; - } // getX_AxisLabel - - /** - * @param axisLabel The x_AxisLabel to set. - */ - public void setX_AxisLabel (String axisLabel) - { - m_X_AxisLabel = axisLabel; - } // setX_AxisLabel - - /** - * @return Returns the y_AxisLabel. - */ - public String getY_AxisLabel () - { - return m_Y_AxisLabel; - } // getY_AxisLabel - - /** - * @param axisLabel The y_AxisLabel to set. - */ - public void setY_AxisLabel (String axisLabel) - { - m_Y_AxisLabel = axisLabel; - } // setY_AxisLabel - - /** - * @return Returns the y_TargetLabel. - */ - public String getY_TargetLabel () - { - return m_Y_TargetLabel; - } // getY_TargetLabel - - /** - * @param targetLabel The y_TargetLabel to set. - */ - public void setY_TargetLabel (String targetLabel, double target) - { - m_Y_TargetLabel = targetLabel; -// m_Y_Target = target; - } // setY_TargetLabel - - - /** - * Add Column - * @param column column - */ - public void add (BarGraphColumn column) - { -// super.add (column, "column"); - //column.addActionListener(this); - } // add - - - /************************************************************************** - * Paint Component - * @param g graphics - */ - - public void chartMouseClicked(int index) - { - BarGraphColumn bgc = list.get(index); - if (null == bgc) - return; - log.info(bgc.getName()); - MQuery query = null; - if (bgc.getAchievement() != null) // Single Achievement - { - MAchievement a = bgc.getAchievement(); - query = MQuery.getEqualQuery("PA_Measure_ID", a.getPA_Measure_ID()); - } - else if (bgc.getGoal() != null) // Multiple Achievements - { - MGoal goal = bgc.getGoal(); - query = MQuery.getEqualQuery("PA_Measure_ID", goal - .getPA_Measure_ID()); - } - else if (bgc.getMeasureCalc() != null) // Document - { - MMeasureCalc mc = bgc.getMeasureCalc(); - query = mc.getQuery(m_goal.getRestrictions(false), bgc - .getMeasureDisplay(), bgc.getDate(), MRole.getDefault()); // logged - // in - // role - } - else if (bgc.getProjectType() != null) // Document - { - MProjectType pt = bgc.getProjectType(); - query = pt.getQuery(m_goal.getRestrictions(false), bgc - .getMeasureDisplay(), bgc.getDate(), bgc.getID(), MRole - .getDefault()); // logged in role - } - else if (bgc.getRequestType() != null) // Document - { - MRequestType rt = bgc.getRequestType(); - query = rt.getQuery(m_goal.getRestrictions(false), bgc - .getMeasureDisplay(), bgc.getDate(), bgc.getID(), MRole - .getDefault()); // logged in role - } - if (query != null) - AEnv.zoom(query); - else - log.warning("Nothing to zoom to - " + bgc); - } - - public void chartMouseMoved(ChartMouseEvent event) {} - - public BarGraphColumn[] getBarGraphColumnList() - { - BarGraphColumn[] array = new BarGraphColumn[list.size()]; - for (int i = 0; i < list.size(); i++){ - array[i] = list.get(i); - } - return array; - } -} // BarGraph diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WGraph.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WGraph.java new file mode 100644 index 0000000000..ffd8c6ff6b --- /dev/null +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WGraph.java @@ -0,0 +1,471 @@ +/****************************************************************************** + * Copyright (C) 2008 Low Heng Sin * + * Copyright (C) 2008 Idalica Corporation * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package org.adempiere.webui.apps.graph; + +import java.awt.Point; +import java.awt.image.BufferedImage; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.logging.Level; + +import org.adempiere.apps.graph.GraphBuilder; +import org.adempiere.apps.graph.GraphColumn; +import org.adempiere.webui.apps.AEnv; +import org.adempiere.webui.editor.WTableDirEditor; +import org.adempiere.webui.event.ValueChangeEvent; +import org.adempiere.webui.event.ValueChangeListener; +import org.compiere.model.MGoal; +import org.compiere.model.MLookup; +import org.compiere.model.MLookupFactory; +import org.compiere.model.MLookupInfo; +import org.compiere.model.MQuery; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.jfree.chart.ChartMouseEvent; +import org.jfree.chart.ChartRenderingInfo; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.encoders.EncoderUtil; +import org.jfree.chart.encoders.ImageFormat; +import org.jfree.chart.entity.CategoryItemEntity; +import org.jfree.chart.entity.ChartEntity; +import org.jfree.chart.entity.PieSectionEntity; +import org.zkoss.image.AImage; +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.IdSpace; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; +import org.zkoss.zk.ui.event.Events; +import org.zkoss.zk.ui.event.MouseEvent; +import org.zkoss.zkex.zul.Borderlayout; +import org.zkoss.zkex.zul.Center; +import org.zkoss.zkex.zul.East; +import org.zkoss.zkex.zul.West; +import org.zkoss.zul.Area; +import org.zkoss.zul.Button; +import org.zkoss.zul.Div; +import org.zkoss.zul.Hbox; +import org.zkoss.zul.Html; +import org.zkoss.zul.Imagemap; +import org.zkoss.zul.Panel; +import org.zkoss.zul.Panelchildren; +import org.zkoss.zul.Toolbar; + +/** + * Bar Graph + * + * @author hengsin + */ +public class WGraph extends Div implements IdSpace +{ + /** + * + */ + private static final long serialVersionUID = -975989183542113080L; + + private static final String ZOOM_KEY = "queryZoom"; + + private boolean m_hideTitle; + + private Panel panel; + + private boolean m_showDetail; + + /** + * Constructor + */ + public WGraph() + { + super(); + builder = new GraphBuilder(); + } // BarGraph + + /** + * Constructor + * @param goal goal + */ + public WGraph(MGoal goal) + { + this(goal, 0, false, false, false); + } + + /** + * Constructor + * @param goal goal + */ + public WGraph(MGoal goal, int zoom, boolean userSelection, boolean hideTitle, boolean showDetail) + { + this(); + builder.setMGoal(goal); + builder.setYAxisLabel(goal.getName()); + builder.setXAxisLabel(goal.getXAxisText()); + m_userSelection = userSelection; + zoomFactor = zoom; + m_hideTitle = hideTitle; + m_showDetail = showDetail; + panel = new Panel(); + Borderlayout layout = new Borderlayout(); + if (m_showDetail) + { + layout = new Borderlayout(); + appendChild(layout); + layout.setStyle("height: 100%; width: 100%; position: absolute;"); + Center center = new Center(); + layout.appendChild(center); + center.appendChild(panel); + } + else + { + appendChild(panel); + } + loadData(); + if (m_showDetail) + { + Html html = new Html(); + html.setContent(renderGoal()); + East east = new East(); + layout.appendChild(east); + east.appendChild(html); + } + } // BarGraph + + /** Zero/Zero Coordibate point */ + private Point m_point0_0 = null; + + /** Logger */ + private static CLogger log = CLogger.getCLogger (WGraph.class); + + /** Y Axis Target Line Label */ + private String m_Y_TargetLabel = null; + + /** + * Load Performance Data + */ + ArrayList list = new ArrayList(); + + private GraphBuilder builder; + + private boolean m_userSelection; + + private int zoomFactor = 0; + + private void loadData() + { + list = builder.loadData(); + + if (m_userSelection) + { + Toolbar toolbar = new Toolbar(); + panel.appendChild(toolbar); + + int AD_Reference_Value_ID = DB.getSQLValue(null, "SELECT AD_Reference_ID FROM AD_Reference WHERE Name = ?", "PA_Goal ChartType"); + MLookupInfo info = MLookupFactory.getLookup_List(Env.getLanguage(Env.getCtx()), AD_Reference_Value_ID); + MLookup mLookup = new MLookup(info, 0); + WTableDirEditor editor = new WTableDirEditor("ChartType", false, false, true, mLookup); + toolbar.appendChild(editor.getComponent()); + editor.addValueChangeListener(new ValueChangeListener() { + + public void valueChange(ValueChangeEvent evt) { + Object value = evt.getNewValue(); + if (value == null || value.toString().trim().length() == 0) return; + JFreeChart chart = null; + chart = builder.createChart(value.toString()); + if (chart != null) + render(chart); + } + + }); + } + JFreeChart chart = builder.createChart(builder.getMGoal().getChartType()); + + render(chart); + } // loadData + + private void render(JFreeChart chart) { + ChartRenderingInfo info = new ChartRenderingInfo(); + int width = 560; + int height = 400; + if (zoomFactor > 0) + { + width = width * zoomFactor / 100; + height = height * zoomFactor / 100; + } + if (m_hideTitle) + { + chart.setTitle(""); + } + BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info); + try { + byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); + + AImage image = new AImage("", bytes); + Imagemap myImage = new Imagemap(); + + myImage.setContent(image); + if (panel.getPanelchildren() != null) { + panel.getPanelchildren().getChildren().clear(); + panel.getPanelchildren().appendChild(myImage); + } else { + Panelchildren pc = new Panelchildren(); + panel.appendChild(pc); + pc.appendChild(myImage); + } + + int count = 0; + for(Iterator it = info.getEntityCollection().getEntities().iterator(); it.hasNext(); ) + { + ChartEntity entity = ( ChartEntity ) it.next(); + + String key = null; + if (entity instanceof CategoryItemEntity) + { + Comparable colKey = ((CategoryItemEntity)entity).getColumnKey(); + if (colKey != null) + { + key = colKey.toString(); + } + } + else if (entity instanceof PieSectionEntity) + { + Comparable sectionKey = ((PieSectionEntity)entity).getSectionKey(); + if (sectionKey != null) + { + key = sectionKey.toString(); + } + } + if (key == null) + { + continue; + } + + Area area = new Area(); + myImage.appendChild(area); + area.setCoords(entity.getShapeCoords()); + area.setShape(entity.getShapeType()); + area.setTooltiptext(entity.getToolTipText()); + area.setId("WG_"+key); + count++; + } + + myImage.addEventListener(Events.ON_CLICK, new EventListener() + { + public void onEvent(Event event) throws Exception + { + MouseEvent me = (MouseEvent) event; + String areaId = me.getArea(); + if(areaId != null) + { + for(int i = 0; i < list.size(); i++) + { + String s = "WG_" + list.get(i).getLabel(); + if(areaId.equals(s)) + { + chartMouseClicked(i); + return; + } + } + } + } + }); + } + catch (Exception e) { + log.log (Level.SEVERE, "", e); + } + } + /** + * Get Point 0_0 + * + * @return point + */ + public Point getPoint0_0() + { + return m_point0_0; + } // getPoint0_0 + + + /** + * @return Returns the x_AxisLabel. + */ + public String getX_AxisLabel () + { + return builder.getXAxisLabel(); + } // getX_AxisLabel + + /** + * @param axisLabel The x_AxisLabel to set. + */ + public void setX_AxisLabel (String axisLabel) + { + builder.setXAxisLabel(axisLabel); + } // setX_AxisLabel + + /** + * @return Returns the y_AxisLabel. + */ + public String getY_AxisLabel () + { + return builder.getYAxisLabel(); + } // getY_AxisLabel + + /** + * @param axisLabel The y_AxisLabel to set. + */ + public void setY_AxisLabel (String axisLabel) + { + builder.setYAxisLabel(axisLabel); + } // setY_AxisLabel + + /** + * @return Returns the y_TargetLabel. + */ + public String getY_TargetLabel () + { + return m_Y_TargetLabel; + } // getY_TargetLabel + + /** + * @param targetLabel The y_TargetLabel to set. + */ + public void setY_TargetLabel (String targetLabel, double target) + { + m_Y_TargetLabel = targetLabel; +// m_Y_Target = target; + } // setY_TargetLabel + + + /************************************************************************** + * 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); + } + + public void chartMouseMoved(ChartMouseEvent event) {} + + public GraphColumn[] getGraphColumnList() + { + GraphColumn[] array = new GraphColumn[list.size()]; + for (int i = 0; i < list.size(); i++){ + array[i] = list.get(i); + } + return array; + } + + public int getZoomFactor() { + return zoomFactor; + } + + public void setZoomFactor(int zoomFactor) { + this.zoomFactor = zoomFactor; + } + + protected String renderGoal() + { + String output = "
    "; + + output += "\n"; + output += "\n"; + output += "\n"; + + GraphColumn[] bList = getGraphColumnList(); + output += "\n"; + + for (int k = 0; k < bList.length; k++) + { + GraphColumn bgc = bList[k]; + if (k > 0) + output += ""; + + output += ""; + } + output += "" + + "" + + "
    Target" + + builder.getMGoal().getMeasureTarget().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + + "
    Actual" + + builder.getMGoal().getMeasureActual().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + + "
    " + + builder.getMGoal().getXAxisText() + "
    " + bgc.getLabel() + + ""; + if (bgc.getMQuery(builder.getMGoal()) != null) { + Button btn = new Button(); + btn.setId(String.valueOf(ZOOM_KEY + k)); + btn.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())); + } + } + + }); + btn.setVisible(false); + appendChild(btn); + + BigDecimal value = new BigDecimal(bgc.getValue()); + output += "" + + value.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + + "\n"; + + } else { + output += bgc.getValue(); + } + output += "
    " + + builder.getMGoal().getDescription() + + "
    " + + stripHtml(builder.getMGoal().getColorSchema() + .getDescription(), true) + "
    \n"; + + output += "
    "; + bList = null; + + return output; + } + + protected String stripHtml(String htmlString, boolean all) { + htmlString = htmlString + .replace("", "") + .replace("", "") + .replace("", "") + .replace("", "") + .replace("", "") + .replace("", ""); + + if (all) + htmlString = htmlString + .replace(">", ">") + .replace("<", "<"); + return htmlString; + } +} // BarGraph diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WPerformanceDetail.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WPerformanceDetail.java index 0b58c51bbc..4b456f81c6 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WPerformanceDetail.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WPerformanceDetail.java @@ -27,11 +27,13 @@ public class WPerformanceDetail extends Window { super(); setTitle(goal.getName()); - - WBarGraph barPanel = new WBarGraph(goal); + + WGraph barPanel = new WGraph(goal, 0, true, false, true); appendChild(barPanel); this.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED); + this.setStyle("height: 100%; width: 100%; position: absolute; overflow: auto"); + barPanel.setStyle("height: 100%; width: 100%; position: absolute; overflow: visible"); SessionManager.getAppDesktop().showWindow(this); } // PerformanceDetail } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WViewPI.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WViewPI.java new file mode 100644 index 0000000000..14a2c670be --- /dev/null +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/graph/WViewPI.java @@ -0,0 +1,18 @@ +package org.adempiere.webui.apps.graph; + +import org.adempiere.webui.panel.ADForm; + +public class WViewPI extends ADForm { + + /** + * + */ + private static final long serialVersionUID = -755873621984745607L; + + @Override + protected void initForm() { + WPAPanel paPanel = WPAPanel.get(); + appendChild(paPanel); + } + +} diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/AbstractDesktop.java b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/AbstractDesktop.java index f656324f80..bd5e6b1694 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/AbstractDesktop.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/AbstractDesktop.java @@ -16,29 +16,13 @@ package org.adempiere.webui.desktop; import java.util.ArrayList; import java.util.List; -import org.adempiere.apps.graph.BarGraphColumn; import org.adempiere.webui.ClientInfo; -import org.adempiere.webui.apps.AEnv; -import org.adempiere.webui.apps.graph.WBarGraph; import org.adempiere.webui.component.Window; import org.adempiere.webui.exception.ApplicationException; import org.adempiere.webui.part.AbstractUIPart; -import org.compiere.model.MAchievement; -import org.compiere.model.MGoal; -import org.compiere.model.MMeasureCalc; import org.compiere.model.MMenu; -import org.compiere.model.MProjectType; -import org.compiere.model.MQuery; -import org.compiere.model.MRequestType; -import org.compiere.model.MRole; import org.compiere.util.CLogger; import org.compiere.util.Env; -import org.zkoss.zhtml.Button; -import org.zkoss.zk.ui.Component; -import org.zkoss.zk.ui.event.Event; -import org.zkoss.zk.ui.event.EventListener; -import org.zkoss.zk.ui.event.Events; -import org.zkoss.zul.Panelchildren; /** * Base class for desktop implementation @@ -48,20 +32,13 @@ import org.zkoss.zul.Panelchildren; public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop { private transient ClientInfo clientInfo; - - private List windows = null; - - private MGoal[] m_goals = null; - - private List queryZoom = null; - + + private List windows = null; + private static final CLogger logger = CLogger.getCLogger(AbstractDesktop.class); - - private static final String ZOOM_KEY = "queryZoom"; - - public AbstractDesktop() { + + public AbstractDesktop() { windows = new ArrayList(); - queryZoom = new ArrayList(); } /** @@ -264,120 +241,7 @@ public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop win.doHighlighted(); } - - protected String renderGoals(int AD_Table_ID, Panelchildren panel) - { - String output = ""; - if (m_goals == null) - { - m_goals = MGoal.getUserGoals(Env.getCtx(), Env.getAD_User_ID(Env.getCtx())); - if (m_goals == null) - return output; - } - - for (int i = 0; i < m_goals.length; i++) - { - MMeasureCalc mc = MMeasureCalc.get(Env.getCtx(), m_goals[i].getMeasure().getPA_MeasureCalc_ID()); - - if (AD_Table_ID == m_goals[i].getPA_Goal_ID()) - { - output += "\n\n"; - output += "\n"; - output += "\n"; - WBarGraph barPanel = new WBarGraph(m_goals[i]); - BarGraphColumn[] bList = barPanel.getBarGraphColumnList(); - MQuery query = null; - output += "\n"; - - for (int k = 0; k < bList.length; k++) - { - BarGraphColumn bgc = bList[k]; - if (k > 0) - output += ""; - if (bgc.getAchievement() != null) // Single Achievement - { - MAchievement a = bgc.getAchievement(); - query = MQuery.getEqualQuery("PA_Measure_ID", a.getPA_Measure_ID()); - } - else if (bgc.getGoal() != null) // Multiple Achievements - { - MGoal goal = bgc.getGoal(); - query = MQuery.getEqualQuery("PA_Measure_ID", goal.getPA_Measure_ID()); - } - else if (bgc.getMeasureCalc() != null) // Document - { - mc = bgc.getMeasureCalc(); - query = mc.getQuery(m_goals[i].getRestrictions(false), bgc.getMeasureDisplay(), - bgc.getDate(), MRole.getDefault()); // logged in role - } - else if (bgc.getProjectType() != null) // Document - { - MProjectType pt = bgc.getProjectType(); - query = pt.getQuery(m_goals[i].getRestrictions(false), bgc.getMeasureDisplay(), - bgc.getDate(), bgc.getID(), MRole.getDefault()); // logged in role - } - else if (bgc.getRequestType() != null) // Document - { - MRequestType rt = bgc.getRequestType(); - query = rt.getQuery(m_goals[i].getRestrictions(false), bgc.getMeasureDisplay(), - bgc.getDate(), bgc.getID(), MRole.getDefault()); // logged in role - } - output += ""; - } - output += "" - + "" - + "
    " - + m_goals[i].getName() + "
    Target" - + m_goals[i].getMeasureTarget() + "
    Actual" - + m_goals[i].getMeasureActual() + "
    " - + m_goals[i].getXAxisText() + "
    " + bgc.getLabel() - + ""; - if (query != null) { - Button btn = new Button(); - btn.setId(String.valueOf(ZOOM_KEY + queryZoom.size())); - btn.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)); - if ((index >= 0) && (index < queryZoom.size())) - AEnv.zoom(queryZoom.get(index)); - } - } - - }); - btn.setVisible(false); - panel.appendChild(btn); - - output += "" - + bgc.getValue() - + "
    \n"; - - queryZoom.add(query); - } else { - logger.info("Nothing to zoom to - " + bgc); - output += bgc.getValue(); - } - output += "
    " - + m_goals[i].getDescription() - + "
    " - + stripHtml(m_goals[i].getColorSchema() - .getDescription(), true) + "
    \n"; - bList = null; - barPanel = null; - } - } - - return output; - } - protected String stripHtml(String htmlString, boolean all) { htmlString = htmlString .replace("", "") diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java index e868418029..75ee5e945f 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java @@ -26,6 +26,8 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.logging.Level; +import org.adempiere.webui.apps.graph.WGraph; +import org.adempiere.webui.apps.graph.WPerformanceDetail; import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.dashboard.DPActivities; @@ -36,6 +38,7 @@ import org.adempiere.webui.panel.HeaderPanel; import org.adempiere.webui.panel.SidePanel; import org.adempiere.webui.util.IServerPushCallback; import org.adempiere.webui.util.ServerPushTemplate; +import org.compiere.model.MGoal; import org.compiere.model.MMenu; import org.compiere.model.X_AD_Menu; import org.compiere.model.X_PA_DashboardContent; @@ -58,6 +61,7 @@ import org.zkoss.zkmax.zul.Portallayout; import org.zkoss.zul.Html; import org.zkoss.zul.Panel; import org.zkoss.zul.Panelchildren; +import org.zkoss.zul.Toolbarbutton; /** * @@ -70,7 +74,7 @@ import org.zkoss.zul.Panelchildren; public class DefaultDesktop extends TabbedDesktop implements MenuListener, Serializable, EventListener, IServerPushCallback { - private static final long serialVersionUID = 9056511175189603883L; + private static final long serialVersionUID = 6320678631023300467L; private static final CLogger logger = CLogger.getCLogger(DefaultDesktop.class); @@ -255,28 +259,24 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria int PA_Goal_ID = rs.getInt(X_PA_DashboardContent.COLUMNNAME_PA_Goal_ID); if(PA_Goal_ID > 0) { - StringBuffer result = new StringBuffer(""); + //link to open performance detail + Toolbarbutton link = new Toolbarbutton(); + link.setImage("/images/Zoom16.png"); + link.setAttribute("PA_Goal_ID", PA_Goal_ID); + link.addEventListener(Events.ON_CLICK, new EventListener() { - URL url = getClass().getClassLoader(). - getResource("org/compiere/images/PAPanel.css"); - InputStreamReader ins; - try { - ins = new InputStreamReader(url.openStream()); - BufferedReader bufferedReader = new BufferedReader( ins ); - String cssLine; - while ((cssLine = bufferedReader.readLine()) != null) - result.append(cssLine + "\n"); - } catch (IOException e1) { - logger.log(Level.SEVERE, e1.getLocalizedMessage(), e1); - } + public void onEvent(Event event) throws Exception { + int PA_Goal_ID = (Integer)event.getTarget().getAttribute("PA_Goal_ID"); + MGoal goal = new MGoal(Env.getCtx(), PA_Goal_ID, null); + new WPerformanceDetail(goal); + } - result.append("
    \n"); - result.append(renderGoals(PA_Goal_ID, content)); - result.append("
    \n\n\n"); + }); + content.appendChild(link); - Html html = new Html(); - html.setContent(result.toString()); - content.appendChild(html); + MGoal goal = new MGoal(Env.getCtx(), PA_Goal_ID, null); + WGraph graph = new WGraph(goal, 55, false, true, false); + content.appendChild(graph); panelEmpty = false; } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/NavBar2Desktop.java b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/NavBar2Desktop.java index d9c9fc69ff..580f42a3ce 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/NavBar2Desktop.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/NavBar2Desktop.java @@ -22,6 +22,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.logging.Level; +import org.adempiere.webui.apps.graph.WGraph; import org.adempiere.webui.component.Accordion; import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.ToolBarButton; @@ -33,6 +34,7 @@ import org.adempiere.webui.panel.HeaderPanel; import org.adempiere.webui.panel.SidePanel; import org.adempiere.webui.util.IServerPushCallback; import org.adempiere.webui.util.ServerPushTemplate; +import org.compiere.model.MGoal; import org.compiere.model.MMenu; import org.compiere.model.X_AD_Menu; import org.compiere.model.X_PA_DashboardContent; @@ -63,12 +65,12 @@ import org.zkoss.zul.Panelchildren; public class NavBar2Desktop extends TabbedDesktop implements MenuListener, Serializable, EventListener, IServerPushCallback { + private static final long serialVersionUID = -7483133591812825441L; + private static final String FAVOURITES_PATH = "/zul/favourites.zul"; private static final String ACTIVITIES_PATH = "/zul/activities.zul"; - private static final long serialVersionUID = 9056511175189603883L; - private static final CLogger logger = CLogger.getCLogger(DefaultDesktop.class); private Center windowArea; @@ -295,28 +297,9 @@ public class NavBar2Desktop extends TabbedDesktop implements MenuListener, Seria int PA_Goal_ID = rs.getInt(X_PA_DashboardContent.COLUMNNAME_PA_Goal_ID); if(PA_Goal_ID > 0) { - StringBuffer result = new StringBuffer(""); - - URL url = getClass().getClassLoader(). - getResource("org/compiere/images/PAPanel.css"); - InputStreamReader ins; - try { - ins = new InputStreamReader(url.openStream()); - BufferedReader bufferedReader = new BufferedReader( ins ); - String cssLine; - while ((cssLine = bufferedReader.readLine()) != null) - result.append(cssLine + "\n"); - } catch (IOException e1) { - logger.log(Level.SEVERE, e1.getLocalizedMessage(), e1); - } - - result.append("
    \n"); - result.append(renderGoals(PA_Goal_ID, content)); - result.append("
    \n\n\n"); - - Html html = new Html(); - html.setContent(result.toString()); - content.appendChild(html); + MGoal goal = new MGoal(Env.getCtx(), PA_Goal_ID, null); + WGraph graph = new WGraph(goal, 55, false, true, false); + content.appendChild(graph); panelEmpty = false; } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/NavBarDesktop.java b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/NavBarDesktop.java index 3af85f3fb5..6c12c86096 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/NavBarDesktop.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/NavBarDesktop.java @@ -22,6 +22,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.logging.Level; +import org.adempiere.webui.apps.graph.WGraph; import org.adempiere.webui.component.Accordion; import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.ToolBarButton; @@ -34,6 +35,7 @@ import org.adempiere.webui.panel.HeaderPanel; import org.adempiere.webui.panel.SidePanel; import org.adempiere.webui.util.IServerPushCallback; import org.adempiere.webui.util.ServerPushTemplate; +import org.compiere.model.MGoal; import org.compiere.model.MMenu; import org.compiere.model.X_AD_Menu; import org.compiere.model.X_PA_DashboardContent; @@ -67,14 +69,14 @@ import org.zkoss.zul.Treerow; public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serializable, EventListener, IServerPushCallback { + private static final long serialVersionUID = 4721048271543882164L; + private static final String FAVOURITES_PATH = "/zul/favourites.zul"; private static final String ACTIVITIES_PATH = "/zul/activities.zul"; private static final String VIEWS_PATH = "/zul/views.zul"; - private static final long serialVersionUID = 9056511175189603883L; - private static final CLogger logger = CLogger.getCLogger(DefaultDesktop.class); private Center windowArea; @@ -298,28 +300,9 @@ public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serial int PA_Goal_ID = rs.getInt(X_PA_DashboardContent.COLUMNNAME_PA_Goal_ID); if(PA_Goal_ID > 0) { - StringBuffer result = new StringBuffer(""); - - URL url = getClass().getClassLoader(). - getResource("org/compiere/images/PAPanel.css"); - InputStreamReader ins; - try { - ins = new InputStreamReader(url.openStream()); - BufferedReader bufferedReader = new BufferedReader( ins ); - String cssLine; - while ((cssLine = bufferedReader.readLine()) != null) - result.append(cssLine + "\n"); - } catch (IOException e1) { - logger.log(Level.SEVERE, e1.getLocalizedMessage(), e1); - } - - result.append("
    \n"); - result.append(renderGoals(PA_Goal_ID, content)); - result.append("
    \n\n\n"); - - Html html = new Html(); - html.setContent(result.toString()); - content.appendChild(html); + MGoal goal = new MGoal(Env.getCtx(), PA_Goal_ID, null); + WGraph graph = new WGraph(goal, 55, false, true, false); + content.appendChild(graph); panelEmpty = false; } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/util/ADClassNameMap.java b/zkwebui/WEB-INF/src/org/adempiere/webui/util/ADClassNameMap.java index 3698a85e12..7d971758fa 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/util/ADClassNameMap.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/util/ADClassNameMap.java @@ -13,6 +13,7 @@ public class ADClassNameMap { map.put("org.compiere.apps.wf.WFPanel", "org.adempiere.webui.apps.wf.WFEditor"); map.put("org.compiere.process.InvoicePrint", "org.adempiere.webui.process.InvoicePrint"); map.put("org.compiere.process.CacheReset", "org.adempiere.webui.process.CacheReset"); + map.put("org.adempiere.apps.graph.ViewPI", "org.adempiere.webui.apps.graph.WViewPI"); } /** diff --git a/zkwebui/css/PAPanel.css b/zkwebui/css/PAPanel.css new file mode 100755 index 0000000000..0713e69e00 --- /dev/null +++ b/zkwebui/css/PAPanel.css @@ -0,0 +1,45 @@ +.pa-header { + background-color: #B5C6C6; +} +.pa-content { + width: 90%; + margin: 20px; + background-color: #FFFFFF; +} +.pa-hrefNode { + color: #000000; + text-decoration: none; +} +.pa-dataGrid { + border-width: 1px; + border-color: #BBBBBB; + border-style: solid; + border-collapse: collapse; + width: 60%; + background-color: #EBF1EF; +} +.pa-dataGrid th { + text-align: center; + padding: 2px; + font-weight: normal; + font-size: 13px; + background-color: #C6D1CD; + border-width: 1px; + border-color: #BBBBBB; + border-style: solid; +} +.pa-dataGrid td { + border-width: 1px; + border-color: #BBBBBB; + border-style: solid; +} +.pa-label { + background-color: #C6D1CD; +} +.pa-tdlabel { + background-color: #D6E1DD; +} +.pa-tdvalue { + background-color: #EBF1EF; + text-align: right; +} \ No newline at end of file diff --git a/zkwebui/index.zul b/zkwebui/index.zul index 3b02fb2a47..e961e6a630 100644 --- a/zkwebui/index.zul +++ b/zkwebui/index.zul @@ -6,6 +6,7 @@ Copyright (C) 2007 Ashley G Ramdass. + \ No newline at end of file