IDEMPIERE-1157 Adding functionality to add charts on the standard windows / peer review and complete - bringing missing class from Adaxa contribution repo
This commit is contained in:
parent
c3a14d9547
commit
bcc0bc6f73
|
@ -24,7 +24,7 @@ CREATE OR REPLACE VIEW AD_FIELD_V AS
|
|||
f.seqnogrid,
|
||||
c.seqnoselection, f.xposition, f.columnspan, f.numlines,
|
||||
COALESCE(f.istoolbarbutton , c.istoolbarbutton ) As istoolbarbutton,
|
||||
c.FormatPattern, f.isadvancedfield, f.IsDefaultFocus
|
||||
c.FormatPattern, f.isadvancedfield, f.IsDefaultFocus, c.AD_Chart_ID
|
||||
FROM AD_FIELD f
|
||||
INNER JOIN AD_TAB t ON (f.AD_Tab_ID = t.AD_Tab_ID)
|
||||
LEFT OUTER JOIN AD_FIELDGROUP fg ON (f.AD_FieldGroup_ID = fg.AD_FieldGroup_ID)
|
||||
|
|
|
@ -23,7 +23,7 @@ CREATE OR REPLACE VIEW AD_FIELD_VT AS
|
|||
f.seqnogrid,
|
||||
c.seqnoselection, f.xposition, f.columnspan, f.numlines,
|
||||
COALESCE(f.istoolbarbutton , c.istoolbarbutton ) As istoolbarbutton,
|
||||
c.FormatPattern, f.isadvancedfield, f.IsDefaultFocus
|
||||
c.FormatPattern, f.isadvancedfield, f.IsDefaultFocus, c.AD_Chart_ID
|
||||
FROM AD_FIELD f
|
||||
INNER JOIN AD_FIELD_TRL trl ON (f.AD_Field_ID = trl.AD_Field_ID)
|
||||
INNER JOIN AD_TAB t ON (f.AD_Tab_ID = t.AD_Tab_ID)
|
||||
|
|
|
@ -16,7 +16,7 @@ CREATE OR REPLACE VIEW ad_field_v AS
|
|||
COALESCE(f.infofactoryclass, c.infofactoryclass) AS infofactoryclass, c.isautocomplete,
|
||||
COALESCE(f.isallowcopy, c.isallowcopy) AS isallowcopy, f.isdisplayedgrid, f.seqnogrid, c.seqnoselection,
|
||||
f.xposition, f.columnspan, f.numlines, COALESCE(f.istoolbarbutton, c.istoolbarbutton) AS istoolbarbutton,
|
||||
c.formatpattern, f.isadvancedfield, f.IsDefaultFocus
|
||||
c.formatpattern, f.isadvancedfield, f.IsDefaultFocus, c.AD_Chart_ID
|
||||
FROM ad_field f
|
||||
JOIN ad_tab t ON f.ad_tab_id = t.ad_tab_id
|
||||
LEFT JOIN ad_fieldgroup fg ON f.ad_fieldgroup_id = fg.ad_fieldgroup_id
|
||||
|
|
|
@ -17,7 +17,7 @@ f.included_tab_id, fg.fieldgrouptype, fg.iscollapsedbydefault,
|
|||
COALESCE(f.infofactoryclass, c.infofactoryclass) AS infofactoryclass, c.isautocomplete,
|
||||
COALESCE(f.isallowcopy, c.isallowcopy) AS isallowcopy, f.isdisplayedgrid, f.seqnogrid, c.seqnoselection,
|
||||
f.xposition, f.columnspan, f.numlines, COALESCE(f.istoolbarbutton, c.istoolbarbutton) AS istoolbarbutton,
|
||||
c.formatpattern, f.isadvancedfield, f.IsDefaultFocus
|
||||
c.formatpattern, f.isadvancedfield, f.IsDefaultFocus, c.AD_Chart_ID
|
||||
FROM ad_field f
|
||||
JOIN ad_field_trl trl ON f.ad_field_id = trl.ad_field_id
|
||||
JOIN ad_tab t ON f.ad_tab_id = t.ad_tab_id
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
CREATE OR REPLACE VIEW AD_FIELD_V AS
|
||||
SELECT t.AD_Window_ID, f.AD_Tab_ID, f.AD_Field_ID, tbl.AD_Table_ID, f.AD_Column_ID,
|
||||
f.NAME, f.Description, f.Help, f.IsDisplayed, f.DisplayLogic, f.DisplayLength,
|
||||
f.SeqNo, f.SortNo, f.IsSameLine, f.IsHeading, f.IsFieldOnly, f.IsReadOnly,
|
||||
f.IsEncrypted AS IsEncryptedField, f.ObscureType,
|
||||
c.ColumnName, c.ColumnSQL, c.FieldLength, c.VFormat,
|
||||
COALESCE(f.DefaultValue, c.DefaultValue) AS DefaultValue,
|
||||
c.IsKey, c.IsParent,
|
||||
COALESCE(f.IsMandatory, c.IsMandatory) AS IsMandatory,
|
||||
c.IsIdentifier, c.IsTranslated, COALESCE(f.AD_Reference_Value_ID, c.AD_Reference_Value_ID) AS AD_Reference_Value_ID,
|
||||
c.Callout, COALESCE(f.AD_Reference_ID, c.AD_Reference_ID) AS AD_Reference_ID,
|
||||
COALESCE(f.AD_Val_Rule_ID, c.AD_Val_Rule_ID) AS AD_Val_Rule_ID, c.AD_Process_ID,
|
||||
COALESCE(f.Isalwaysupdateable , C.Isalwaysupdateable) As Isalwaysupdateable,
|
||||
COALESCE(f.Readonlylogic, c.Readonlylogic ) As Readonlylogic,
|
||||
COALESCE(f.Mandatorylogic , C.Mandatorylogic) As Mandatorylogic,
|
||||
COALESCE(f.isupdateable, c.isupdateable) AS isupdateable, c.IsEncrypted AS IsEncryptedColumn,
|
||||
c.IsSelectionColumn,
|
||||
tbl.TableName, c.ValueMin, c.ValueMax,
|
||||
fg.NAME AS FieldGroup, vr.Code AS ValidationCode,
|
||||
f.Included_Tab_ID, fg.FieldGroupType, fg.IsCollapsedByDefault,
|
||||
COALESCE(f.InfoFactoryClass, c.InfoFactoryClass) as InfoFactoryClass,
|
||||
c.IsAutocomplete, COALESCE(f.IsAllowCopy, c.IsAllowCopy) AS IsAllowCopy,
|
||||
f.isdisplayedgrid,
|
||||
f.seqnogrid,
|
||||
c.seqnoselection, f.xposition, f.columnspan, f.numlines,
|
||||
COALESCE(f.istoolbarbutton , c.istoolbarbutton ) As istoolbarbutton,
|
||||
c.FormatPattern, f.isadvancedfield, f.IsDefaultFocus, c.AD_Chart_ID
|
||||
FROM AD_FIELD f
|
||||
INNER JOIN AD_TAB t ON (f.AD_Tab_ID = t.AD_Tab_ID)
|
||||
LEFT OUTER JOIN AD_FIELDGROUP fg ON (f.AD_FieldGroup_ID = fg.AD_FieldGroup_ID)
|
||||
LEFT OUTER JOIN AD_COLUMN c ON (f.AD_Column_ID = c.AD_Column_ID)
|
||||
INNER JOIN AD_TABLE tbl ON (c.AD_Table_ID = tbl.AD_Table_ID)
|
||||
LEFT OUTER JOIN AD_VAL_RULE vr ON (vr.AD_Val_Rule_ID = COALESCE(f.AD_Val_Rule_ID, c.AD_Val_Rule_ID))
|
||||
WHERE f.IsActive = 'Y'
|
||||
AND c.IsActive = 'Y'
|
||||
;
|
||||
|
||||
CREATE OR REPLACE VIEW AD_FIELD_VT AS
|
||||
SELECT trl.AD_LANGUAGE, t.AD_Window_ID, f.AD_Tab_ID, f.AD_Field_ID, tbl.AD_Table_ID, f.AD_Column_ID,
|
||||
trl.NAME, trl.Description, trl.Help, f.IsDisplayed, f.DisplayLogic, f.DisplayLength,
|
||||
f.SeqNo, f.SortNo, f.IsSameLine, f.IsHeading, f.IsFieldOnly, f.IsReadOnly,
|
||||
f.IsEncrypted AS IsEncryptedField, f.ObscureType,
|
||||
c.ColumnName, c.ColumnSQL, c.FieldLength, c.VFormat,
|
||||
COALESCE(f.DefaultValue, c.DefaultValue) AS DefaultValue,
|
||||
c.IsKey, c.IsParent,
|
||||
COALESCE(f.IsMandatory, c.IsMandatory) AS IsMandatory,
|
||||
c.IsIdentifier, c.IsTranslated, COALESCE(f.AD_Reference_Value_ID, c.AD_Reference_Value_ID) AS AD_Reference_Value_ID,
|
||||
c.Callout, COALESCE(f.AD_Reference_ID, c.AD_Reference_ID) AS AD_Reference_ID,
|
||||
COALESCE(f.AD_Val_Rule_ID, c.AD_Val_Rule_ID) as AD_Val_Rule_ID, c.AD_Process_ID,
|
||||
COALESCE(f.Isalwaysupdateable , C.Isalwaysupdateable) As Isalwaysupdateable,
|
||||
COALESCE(f.Readonlylogic, c.Readonlylogic ) As Readonlylogic,
|
||||
COALESCE(f.Mandatorylogic , C.Mandatorylogic) As Mandatorylogic,
|
||||
COALESCE(f.isupdateable, c.isupdateable) AS isupdateable, c.IsEncrypted AS IsEncryptedColumn, c.IsSelectionColumn,
|
||||
tbl.TableName, c.ValueMin, c.ValueMax,
|
||||
fgt.NAME AS FieldGroup, vr.Code AS ValidationCode,
|
||||
f.Included_Tab_ID, fg.FieldGroupType, fg.IsCollapsedByDefault,
|
||||
COALESCE(f.InfoFactoryClass, c.InfoFactoryClass) as InfoFactoryClass,
|
||||
c.IsAutocomplete, COALESCE(f.IsAllowCopy, c.IsAllowCopy) AS IsAllowCopy,
|
||||
f.isdisplayedgrid,
|
||||
f.seqnogrid,
|
||||
c.seqnoselection, f.xposition, f.columnspan, f.numlines,
|
||||
COALESCE(f.istoolbarbutton , c.istoolbarbutton ) As istoolbarbutton,
|
||||
c.FormatPattern, f.isadvancedfield, f.IsDefaultFocus, c.AD_Chart_ID
|
||||
FROM AD_FIELD f
|
||||
INNER JOIN AD_FIELD_TRL trl ON (f.AD_Field_ID = trl.AD_Field_ID)
|
||||
INNER JOIN AD_TAB t ON (f.AD_Tab_ID = t.AD_Tab_ID)
|
||||
LEFT OUTER JOIN AD_FIELDGROUP fg ON (f.AD_FieldGroup_ID = fg.AD_FieldGroup_ID)
|
||||
LEFT OUTER JOIN AD_FIELDGROUP_TRL fgt ON
|
||||
(f.AD_FieldGroup_ID = fgt.AD_FieldGroup_ID AND trl.AD_LANGUAGE=fgt.AD_LANGUAGE)
|
||||
LEFT OUTER JOIN AD_COLUMN c ON (f.AD_Column_ID = c.AD_Column_ID)
|
||||
INNER JOIN AD_TABLE tbl ON (c.AD_Table_ID = tbl.AD_Table_ID)
|
||||
LEFT OUTER JOIN AD_VAL_RULE vr ON (vr.AD_Val_Rule_ID=COALESCE(f.AD_Val_Rule_ID, c.AD_Val_Rule_ID))
|
||||
WHERE f.IsActive = 'Y'
|
||||
AND c.IsActive = 'Y'
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201308221905_IDEMPIERE-1157.sql') FROM dual
|
||||
;
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
DROP VIEW ad_field_v;
|
||||
|
||||
CREATE OR REPLACE VIEW ad_field_v AS
|
||||
SELECT t.ad_window_id, f.ad_tab_id, f.ad_field_id, tbl.ad_table_id, f.ad_column_id, f.name, f.description,
|
||||
f.help, f.isdisplayed, f.displaylogic, f.displaylength, f.seqno, f.sortno, f.issameline, f.isheading,
|
||||
f.isfieldonly, f.isreadonly, f.isencrypted AS isencryptedfield, f.obscuretype, c.columnname, c.columnsql,
|
||||
c.fieldlength, c.vformat, COALESCE(f.defaultvalue, c.defaultvalue) AS defaultvalue, c.iskey, c.isparent,
|
||||
COALESCE(f.ismandatory, c.ismandatory) AS ismandatory, c.isidentifier, c.istranslated,
|
||||
COALESCE(f.ad_reference_value_id, c.ad_reference_value_id) AS ad_reference_value_id, c.callout,
|
||||
COALESCE(f.ad_reference_id, c.ad_reference_id) AS ad_reference_id,
|
||||
COALESCE(f.ad_val_rule_id, c.ad_val_rule_id) AS ad_val_rule_id, c.ad_process_id,
|
||||
COALESCE(f.isalwaysupdateable, c.isalwaysupdateable) AS isalwaysupdateable,
|
||||
COALESCE(f.readonlylogic, c.readonlylogic) AS readonlylogic,
|
||||
COALESCE(f.mandatorylogic, c.mandatorylogic) AS mandatorylogic,
|
||||
COALESCE(f.isupdateable, c.isupdateable) AS isupdateable, c.isencrypted AS isencryptedcolumn,
|
||||
c.isselectioncolumn, tbl.tablename, c.valuemin, c.valuemax, fg.name AS fieldgroup,
|
||||
vr.code AS validationcode, f.included_tab_id, fg.fieldgrouptype, fg.iscollapsedbydefault,
|
||||
COALESCE(f.infofactoryclass, c.infofactoryclass) AS infofactoryclass, c.isautocomplete,
|
||||
COALESCE(f.isallowcopy, c.isallowcopy) AS isallowcopy, f.isdisplayedgrid, f.seqnogrid, c.seqnoselection,
|
||||
f.xposition, f.columnspan, f.numlines, COALESCE(f.istoolbarbutton, c.istoolbarbutton) AS istoolbarbutton,
|
||||
c.formatpattern, f.isadvancedfield, f.IsDefaultFocus, c.AD_Chart_ID
|
||||
FROM ad_field f
|
||||
JOIN ad_tab t ON f.ad_tab_id = t.ad_tab_id
|
||||
LEFT JOIN ad_fieldgroup fg ON f.ad_fieldgroup_id = fg.ad_fieldgroup_id
|
||||
LEFT JOIN ad_column c ON f.ad_column_id = c.ad_column_id
|
||||
JOIN ad_table tbl ON c.ad_table_id = tbl.ad_table_id
|
||||
LEFT JOIN ad_val_rule vr ON vr.ad_val_rule_id = COALESCE(f.ad_val_rule_id, c.ad_val_rule_id)
|
||||
WHERE f.isactive = 'Y'::bpchar AND c.isactive = 'Y'::bpchar
|
||||
;
|
||||
|
||||
DROP VIEW ad_field_vt;
|
||||
|
||||
CREATE OR REPLACE VIEW ad_field_vt AS
|
||||
SELECT trl.ad_language, t.ad_window_id, f.ad_tab_id, f.ad_field_id, tbl.ad_table_id, f.ad_column_id,
|
||||
trl.name, trl.description, trl.help, f.isdisplayed, f.displaylogic, f.displaylength, f.seqno, f.sortno,
|
||||
f.issameline, f.isheading, f.isfieldonly, f.isreadonly, f.isencrypted AS isencryptedfield, f.obscuretype,
|
||||
c.columnname, c.columnsql, c.fieldlength, c.vformat,
|
||||
COALESCE(f.defaultvalue, c.defaultvalue) AS defaultvalue, c.iskey, c.isparent,
|
||||
COALESCE(f.ismandatory, c.ismandatory) AS ismandatory, c.isidentifier, c.istranslated,
|
||||
COALESCE(f.ad_reference_value_id, c.ad_reference_value_id) AS ad_reference_value_id, c.callout,
|
||||
COALESCE(f.ad_reference_id, c.ad_reference_id) AS ad_reference_id,
|
||||
COALESCE(f.ad_val_rule_id, c.ad_val_rule_id) AS ad_val_rule_id, c.ad_process_id,
|
||||
COALESCE(f.isalwaysupdateable, c.isalwaysupdateable) AS isalwaysupdateable,
|
||||
COALESCE(f.readonlylogic, c.readonlylogic) AS readonlylogic,
|
||||
COALESCE(f.mandatorylogic, c.mandatorylogic) AS mandatorylogic,
|
||||
COALESCE(f.isupdateable, c.isupdateable) AS isupdateable, c.isencrypted AS isencryptedcolumn,
|
||||
c.isselectioncolumn, tbl.tablename, c.valuemin, c.valuemax, fgt.name AS fieldgroup, vr.code AS validationcode,
|
||||
f.included_tab_id, fg.fieldgrouptype, fg.iscollapsedbydefault,
|
||||
COALESCE(f.infofactoryclass, c.infofactoryclass) AS infofactoryclass, c.isautocomplete,
|
||||
COALESCE(f.isallowcopy, c.isallowcopy) AS isallowcopy, f.isdisplayedgrid, f.seqnogrid, c.seqnoselection,
|
||||
f.xposition, f.columnspan, f.numlines, COALESCE(f.istoolbarbutton, c.istoolbarbutton) AS istoolbarbutton,
|
||||
c.formatpattern, f.isadvancedfield, f.IsDefaultFocus, c.AD_Chart_ID
|
||||
FROM ad_field f
|
||||
JOIN ad_field_trl trl ON f.ad_field_id = trl.ad_field_id
|
||||
JOIN ad_tab t ON f.ad_tab_id = t.ad_tab_id
|
||||
LEFT JOIN ad_fieldgroup fg ON f.ad_fieldgroup_id = fg.ad_fieldgroup_id
|
||||
LEFT JOIN ad_fieldgroup_trl fgt ON f.ad_fieldgroup_id = fgt.ad_fieldgroup_id AND trl.ad_language::text = fgt.ad_language::text
|
||||
LEFT JOIN ad_column c ON f.ad_column_id = c.ad_column_id
|
||||
JOIN ad_table tbl ON c.ad_table_id = tbl.ad_table_id
|
||||
LEFT JOIN ad_val_rule vr ON vr.ad_val_rule_id = COALESCE(f.ad_val_rule_id, c.ad_val_rule_id)
|
||||
WHERE f.isactive = 'Y'::bpchar AND c.isactive = 'Y'::bpchar
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201308221905_IDEMPIERE-1157.sql') FROM dual
|
||||
;
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package org.compiere.grid.ed;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionListener;
|
||||
|
@ -20,6 +21,10 @@ import org.jfree.chart.JFreeChart;
|
|||
import org.jfree.chart.entity.CategoryItemEntity;
|
||||
import org.jfree.chart.entity.ChartEntity;
|
||||
import org.jfree.chart.entity.PieSectionEntity;
|
||||
import org.jfree.chart.entity.XYItemEntity;
|
||||
import org.jfree.data.time.TimeSeries;
|
||||
import org.jfree.data.time.TimeSeriesCollection;
|
||||
import org.jfree.data.time.TimeSeriesDataItem;
|
||||
|
||||
public class VChart extends CPanel implements ChartMouseListener, VEditor {
|
||||
|
||||
|
@ -51,7 +56,6 @@ public class VChart extends CPanel implements ChartMouseListener, VEditor {
|
|||
if (chartPanel != null)
|
||||
remove(chartPanel);
|
||||
|
||||
chartModel.loadData();
|
||||
chartPanel = new ChartPanel(chart);
|
||||
Dimension size = getSize();
|
||||
size.height= chartModel.getWinHeight();
|
||||
|
@ -91,7 +95,7 @@ public class VChart extends CPanel implements ChartMouseListener, VEditor {
|
|||
{
|
||||
ChartEntity entity = event.getEntity();
|
||||
String key = null;
|
||||
String category = null;
|
||||
String seriesName = null;
|
||||
if (entity instanceof CategoryItemEntity)
|
||||
{
|
||||
CategoryItemEntity item = ((CategoryItemEntity)entity);
|
||||
|
@ -100,7 +104,7 @@ public class VChart extends CPanel implements ChartMouseListener, VEditor {
|
|||
if (colKey != null && rowKey !=null)
|
||||
{
|
||||
key = colKey.toString();
|
||||
category = rowKey.toString();
|
||||
seriesName = rowKey.toString();
|
||||
}
|
||||
}
|
||||
else if (entity instanceof PieSectionEntity)
|
||||
|
@ -111,11 +115,24 @@ public class VChart extends CPanel implements ChartMouseListener, VEditor {
|
|||
key = sectionKey.toString();
|
||||
}
|
||||
}
|
||||
if (entity instanceof XYItemEntity)
|
||||
{
|
||||
XYItemEntity item = ((XYItemEntity)entity);
|
||||
if ( item.getDataset() instanceof TimeSeriesCollection )
|
||||
{
|
||||
TimeSeriesCollection data = (TimeSeriesCollection) item.getDataset();
|
||||
TimeSeries series = data.getSeries(item.getSeriesIndex());
|
||||
TimeSeriesDataItem dataitem = series.getDataItem(item.getItem());
|
||||
seriesName = series.getKey().toString();
|
||||
key = dataitem.getPeriod().toString();
|
||||
}
|
||||
}
|
||||
|
||||
if ( key == null )
|
||||
return;
|
||||
|
||||
MQuery query = chartModel.getQuery("null".equals(category) ? key : category + "__" + key);
|
||||
MQuery query = chartModel.getQuery(seriesName == null ? key : seriesName+"__"+key);
|
||||
|
||||
if (query != null)
|
||||
AEnv.zoom(query);
|
||||
|
||||
|
@ -160,4 +177,13 @@ public class VChart extends CPanel implements ChartMouseListener, VEditor {
|
|||
@Override
|
||||
public GridField getField() { return null; }
|
||||
|
||||
/**
|
||||
* Get Focus Component
|
||||
* @return component
|
||||
*/
|
||||
public Component getFocusableComponent()
|
||||
{
|
||||
return this;
|
||||
} // getFocusComponent
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,257 @@
|
|||
/******************************************************************************
|
||||
* Copyright (C) 2007 Low Heng Sin 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. *
|
||||
*****************************************************************************/
|
||||
|
||||
package org.adempiere.webui.editor;
|
||||
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.webui.apps.AEnv;
|
||||
import org.compiere.model.GridField;
|
||||
import org.compiere.model.MChart;
|
||||
import org.compiere.model.MQuery;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.Env;
|
||||
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.jfree.chart.entity.XYItemEntity;
|
||||
import org.jfree.data.time.TimeSeries;
|
||||
import org.jfree.data.time.TimeSeriesCollection;
|
||||
import org.jfree.data.time.TimeSeriesDataItem;
|
||||
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;
|
||||
import org.zkoss.zul.Panel;
|
||||
import org.zkoss.zul.Panelchildren;
|
||||
|
||||
/**
|
||||
* This class is based on org.compiere.grid.ed.WImageEditor and WGraph written by Low Heng Sin.
|
||||
* @author Low Heng Sin
|
||||
*
|
||||
* Modifications - chart display
|
||||
* @author Paul Bowden, Adaxa Pty Ltd
|
||||
*/
|
||||
public class WChartEditor extends WEditor
|
||||
{
|
||||
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK};
|
||||
|
||||
private static final CLogger logger;
|
||||
|
||||
static
|
||||
{
|
||||
logger = CLogger.getCLogger(WChartEditor.class);
|
||||
}
|
||||
|
||||
private MChart chartModel = null;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(WChartEditor.class);
|
||||
|
||||
public WChartEditor(GridField gridField, int windowNo)
|
||||
{
|
||||
super(new Panel(), gridField);
|
||||
chartModel = new MChart(Env.getCtx(), gridField.getAD_Chart_ID(), null);
|
||||
chartModel.setWindowNo(windowNo);
|
||||
init();
|
||||
|
||||
}
|
||||
|
||||
public void createChart() {
|
||||
|
||||
render(chartModel.createChart());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Panel getComponent() {
|
||||
return (Panel) component;
|
||||
}
|
||||
|
||||
private void render(JFreeChart chart) {
|
||||
ChartRenderingInfo info = new ChartRenderingInfo();
|
||||
int width = 400;
|
||||
int height = chartModel.getWinHeight();
|
||||
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();
|
||||
|
||||
Panel panel = getComponent();
|
||||
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;
|
||||
String seriesName = null;
|
||||
if (entity instanceof CategoryItemEntity)
|
||||
{
|
||||
CategoryItemEntity item = ((CategoryItemEntity)entity);
|
||||
Comparable<?> colKey = item.getColumnKey();
|
||||
Comparable<?> rowKey = item.getRowKey();
|
||||
if (colKey != null && rowKey !=null)
|
||||
{
|
||||
key = colKey.toString();
|
||||
seriesName = rowKey.toString();
|
||||
}
|
||||
}
|
||||
else if (entity instanceof PieSectionEntity)
|
||||
{
|
||||
Comparable<?> sectionKey = ((PieSectionEntity)entity).getSectionKey();
|
||||
if (sectionKey != null)
|
||||
{
|
||||
key = sectionKey.toString();
|
||||
}
|
||||
}
|
||||
if (entity instanceof XYItemEntity)
|
||||
{
|
||||
XYItemEntity item = ((XYItemEntity)entity);
|
||||
if ( item.getDataset() instanceof TimeSeriesCollection )
|
||||
{
|
||||
TimeSeriesCollection data = (TimeSeriesCollection) item.getDataset();
|
||||
TimeSeries series = data.getSeries(item.getSeriesIndex());
|
||||
TimeSeriesDataItem dataitem = series.getDataItem(item.getItem());
|
||||
seriesName = series.getKey().toString();
|
||||
key = dataitem.getPeriod().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(count+"_WG__" + seriesName + "__" + 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) {
|
||||
String[] strs = areaId.split("__");
|
||||
if (strs.length == 3)
|
||||
{
|
||||
chartMouseClicked(strs[2], strs[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "", e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void chartMouseClicked(String key, String category) {
|
||||
MQuery query = chartModel.getQuery("null".equals(category) ? key : category + "__" + key);
|
||||
if (query != null)
|
||||
AEnv.zoom(query);
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
AImage img = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplay()
|
||||
{
|
||||
return chartModel.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMandatory()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setMandatory(boolean mandatory)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadWrite() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadWrite(boolean readWrite) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getEvents()
|
||||
{
|
||||
return LISTENER_EVENTS;
|
||||
}
|
||||
|
||||
public void onEvent(Event event) throws Exception
|
||||
{
|
||||
if (Events.ON_CLICK.equals(event.getName()))
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dynamicDisplay() {
|
||||
super.dynamicDisplay();
|
||||
createChart();
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue