diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/SummaryMethodComboBox.java b/designer-base/src/main/java/com/fr/design/data/datapane/SummaryMethodComboBox.java new file mode 100644 index 0000000000..bd57e7ea2a --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/SummaryMethodComboBox.java @@ -0,0 +1,64 @@ +package com.fr.design.data.datapane; + +import com.fr.data.util.function.AbstractDataFunction; +import com.fr.data.util.function.AverageFunction; +import com.fr.data.util.function.CountFunction; +import com.fr.data.util.function.MaxFunction; +import com.fr.data.util.function.MinFunction; +import com.fr.data.util.function.NoneFunction; +import com.fr.data.util.function.SumFunction; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.i18n.Toolkit; +import com.fr.general.ComparatorUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.plugin.chart.base.FirstFunction; + +public class SummaryMethodComboBox extends UIComboBox { + public static final String[] CALCULATE_ARRAY = {Toolkit.i18nText("Fine-Design_Chart_Data_Function_First"), Toolkit.i18nText("Fine-Design_Chart_Data_Function_Last"), + Toolkit.i18nText("Fine-Design_Chart_Data_Function_Sum"), Toolkit.i18nText("Fine-Design_Chart_Data_Function_Average"), + Toolkit.i18nText("Fine-Design_Chart_Data_Function_Max"), Toolkit.i18nText("Fine-Design_Chart_Data_Function_Min"), + Toolkit.i18nText("Fine-Design_Chart_Data_Function_Count")}; + public static final Class[] CLASS_ARRAY = {FirstFunction.class, NoneFunction.class, SumFunction.class, AverageFunction.class, + MaxFunction.class, MinFunction.class, CountFunction.class}; + + public SummaryMethodComboBox() { + super(CALCULATE_ARRAY); + setSelectedIndex(2); + } + + public void reset() { + this.setSelectedItem(Toolkit.i18nText("Fine-Design_Chart_Data_Function_Sum")); + } + + /** + * 更新公式选择. + */ + public void populateBean(AbstractDataFunction function) { + for (int i = 0; i < CLASS_ARRAY.length; i++) { + if (function != null && ComparatorUtils.equals(function.getClass(), CLASS_ARRAY[i])) { + setSelectedIndex(i); + break; + } + } + } + + /** + * 返回当前选择的公式 + */ + public AbstractDataFunction updateBean() { + try { + int selectIndex = getSelectedIndex(); + if (selectIndex >= 0 && selectIndex < CLASS_ARRAY.length) { + return (AbstractDataFunction) CLASS_ARRAY[selectIndex].newInstance(); + } + } catch (InstantiationException e) { + FineLoggerFactory.getLogger().error("Function Error"); + return null; + } catch (IllegalAccessException e) { + FineLoggerFactory.getLogger().error("Function Error"); + return null; + } + + return null; + } +} diff --git a/designer-base/src/main/resources/com/fr/design/images/buttonicon/ds_column_summary.png b/designer-base/src/main/resources/com/fr/design/images/buttonicon/ds_column_summary.png new file mode 100644 index 0000000000..1d7e13aa48 Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/buttonicon/ds_column_summary.png differ diff --git a/designer-chart/src/main/java/com/fr/design/chart/ChartDataHelper.java b/designer-chart/src/main/java/com/fr/design/chart/ChartDataHelper.java new file mode 100644 index 0000000000..e8371a3c12 --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chart/ChartDataHelper.java @@ -0,0 +1,69 @@ +package com.fr.design.chart; + +import com.fr.base.TableData; +import com.fr.base.chart.chartdata.TopDefinitionProvider; +import com.fr.chart.chartattr.Chart; +import com.fr.chart.chartattr.Plot; +import com.fr.chart.chartdata.MoreNameCDDefinition; +import com.fr.chart.chartdata.OneValueCDDefinition; +import com.fr.data.TableDataSource; +import com.fr.design.DesignModelAdapter; +import com.fr.design.data.DesignTableDataManager; +import com.fr.general.ComparatorUtils; +import com.fr.plugin.chart.custom.CustomDefinition; +import com.fr.plugin.chart.custom.type.CustomPlotType; +import com.fr.van.chart.designer.PlotFactory; +import java.util.Map; + +public class ChartDataHelper { + public static String[] getCommonChartFieldNames(Chart chart) { + if (chart == null) { + return null; + } + Plot plot = chart.getPlot(); + if (plot == null) { + return null; + } + + if (!PlotFactory.plotSupportAddTableField(plot)) { + return null; + } + TopDefinitionProvider definition = chart.getFilterDefinition(); + return getFieldNames(definition); + } + + public static String[] getCustomChartTableFieldNames(Chart chart, CustomPlotType plotType) { + if (chart == null || plotType == null) { + return null; + } + + TopDefinitionProvider filterDefinition = chart.getFilterDefinition(); + if (filterDefinition instanceof CustomDefinition) { + CustomDefinition customDefinition = (CustomDefinition) filterDefinition; + Map definitionProviderMap = customDefinition.getDefinitionProviderMap(); + return getFieldNames(definitionProviderMap.get(plotType)); + } + return null; + } + + private static String[] getFieldNames(TopDefinitionProvider definition) { + if (definition == null) { + return null; + } + DesignModelAdapter adapter = DesignModelAdapter.getCurrentModelAdapter(); + TableDataSource tableDataSource = adapter == null ? null : adapter.getBook(); + TableData tableData = null; + if (ComparatorUtils.equals(definition.getDataDefinitionType(), OneValueCDDefinition.DEFINITION_TYPE)) { + OneValueCDDefinition oneValueCDDefinition = (OneValueCDDefinition) definition; + tableData = oneValueCDDefinition.getTableData(); + } else if (ComparatorUtils.equals(definition.getDataDefinitionType(), MoreNameCDDefinition.DEFINITION_TYPE)) { + MoreNameCDDefinition moreNameCDDefinition = (MoreNameCDDefinition) definition; + tableData = moreNameCDDefinition.getTableData(); + } + if (tableData == null) { + return null; + } + return DesignTableDataManager.getSelectedColumnNames(tableDataSource, tableData.getName()); + } + +} diff --git a/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/ChartConditionPane.java b/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/ChartConditionPane.java index af44b6331c..4085c7f10c 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/ChartConditionPane.java +++ b/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/ChartConditionPane.java @@ -7,6 +7,7 @@ import com.fr.design.beans.BasicBeanPane; import com.fr.design.condition.LiteConditionPane; import com.fr.design.editor.ValueEditorPane; import com.fr.design.editor.ValueEditorPaneFactory; +import com.fr.design.editor.editor.Editor; import com.fr.design.formula.CustomVariableResolver; import com.fr.design.formula.VariableResolver; import com.fr.design.gui.icombobox.UIComboBox; @@ -17,6 +18,7 @@ import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.general.ComparatorUtils; import com.fr.plugin.chart.type.ConditionKeyType; +import com.fr.stable.ArrayUtils; import com.fr.stable.StringUtils; import javax.swing.DefaultComboBoxModel; @@ -79,7 +81,10 @@ public class ChartConditionPane extends LiteConditionPane { return this; } }); - conditionValuePane = ValueEditorPaneFactory.createAllValueEditorPane(); + Editor[] editors = ValueEditorPaneFactory.allEditors(); + ColSelectedWithSummaryMethodEditor colSelectedWithSummaryMethodEditor = new ColSelectedWithSummaryMethodEditor(); + Editor[] allEditors = ArrayUtils.add(editors,colSelectedWithSummaryMethodEditor); + conditionValuePane = ValueEditorPaneFactory.createValueEditorPane(allEditors,StringUtils.EMPTY,StringUtils.EMPTY); conditionKeyComboBox.setPreferredSize(new Dimension(175, conditionKeyComboBox.getPreferredSize().height)); conditionOPComboBox.setPreferredSize(new Dimension(80, 20)); Component[][] components = { diff --git a/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/ColSelectedWithSummaryMethodEditor.java b/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/ColSelectedWithSummaryMethodEditor.java new file mode 100644 index 0000000000..6b6fe08cc7 --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/ColSelectedWithSummaryMethodEditor.java @@ -0,0 +1,89 @@ +package com.fr.design.chart.series.SeriesCondition; + +import com.fr.chart.chartattr.Chart; +import com.fr.data.DSColumnWithSummaryMethod; +import com.fr.design.chart.ChartDataHelper; +import com.fr.design.data.datapane.SummaryMethodComboBox; +import com.fr.design.editor.editor.Editor; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.plugin.chart.custom.type.CustomPlotType; +import java.awt.Dimension; +import javax.swing.DefaultComboBoxModel; + +public class ColSelectedWithSummaryMethodEditor extends Editor { + private UIComboBox columnNameComboBox = new UIComboBox(); + private SummaryMethodComboBox summaryMethodComboBox; + private static DefaultComboBoxModel columnNameComboBoxModel = new DefaultComboBoxModel<>(); + private static DefaultComboBoxModel summaryMethodComboBoxModel = new DefaultComboBoxModel<>(SummaryMethodComboBox.CALCULATE_ARRAY); + + public ColSelectedWithSummaryMethodEditor() { + this.setName(Toolkit.i18nText("Fine-Design_Chart_Summary_Array")); + this.setLayout(FRGUIPaneFactory.createLeftZeroLayout()); + if (columnNameComboBox == null) { + columnNameComboBox = new UIComboBox(); + } + columnNameComboBox.setPreferredSize(new Dimension(82, 20)); + this.add(columnNameComboBox); + summaryMethodComboBox = new SummaryMethodComboBox(); + summaryMethodComboBox.setModel(summaryMethodComboBoxModel); + summaryMethodComboBox.setPreferredSize(new Dimension(82, 20)); + this.add(summaryMethodComboBox); + columnNameComboBox.setModel(columnNameComboBoxModel); + } + + public static void refreshCommonChartFieldNames(Chart chart) { + String[] columnNames = ChartDataHelper.getCommonChartFieldNames(chart); + refreshComboBoxModel(columnNames); + } + + public static void refreshCustomChartTableFieldNames(Chart chart, CustomPlotType plotType) { + String[] columnNames = ChartDataHelper.getCustomChartTableFieldNames(chart, plotType); + refreshComboBoxModel(columnNames); + } + + private static void refreshComboBoxModel(String[] columnNames) { + if (columnNames != null) { + columnNameComboBoxModel.removeAllElements(); + for (String columnName : columnNames) { + columnNameComboBoxModel.addElement(columnName); + } + for (String method : SummaryMethodComboBox.CALCULATE_ARRAY) { + summaryMethodComboBoxModel.addElement(method); + } + } else { + columnNameComboBoxModel.removeAllElements(); + summaryMethodComboBoxModel.removeAllElements(); + } + } + + public String getIconName() { + return "ds_column_summary"; + } + + @Override + public DSColumnWithSummaryMethod getValue() { + if (columnNameComboBox.getSelectedItem() == null || summaryMethodComboBox.getSelectedItem() == null) { + return null; + } + DSColumnWithSummaryMethod dsColumnWithSummaryMethod = new DSColumnWithSummaryMethod(); + dsColumnWithSummaryMethod.setFieldName(columnNameComboBox.getSelectedItem().toString()); + dsColumnWithSummaryMethod.setDataFunction(summaryMethodComboBox.updateBean()); + return dsColumnWithSummaryMethod; + } + + @Override + public void setValue(DSColumnWithSummaryMethod value) { + if (value != null) { + columnNameComboBox.setSelectedItem(value.getFieldName()); + summaryMethodComboBox.setSelectedItem(value.getDataFunction()); + } + } + + @Override + public boolean accept(Object object) { + return object instanceof DSColumnWithSummaryMethod; + } + +} diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartOtherPane.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartOtherPane.java index 4bc363306c..36bc56d6b8 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartOtherPane.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartOtherPane.java @@ -5,6 +5,7 @@ import com.fr.chart.chartattr.ChartCollection; import com.fr.chart.chartattr.Plot; import com.fr.chartx.config.info.constant.ConfigType; import com.fr.design.beans.BasicBeanPane; +import com.fr.design.chart.series.SeriesCondition.ColSelectedWithSummaryMethodEditor; import com.fr.design.dialog.BasicPane; import com.fr.design.mainframe.chart.AbstractChartAttrPane; import com.fr.design.mainframe.chart.ChartEditPane; @@ -112,6 +113,7 @@ public class ChartOtherPane extends AbstractChartAttrPane { interactivePane.populateBean(chart); if (ChartOtherPane.this.isHaveCondition()) { VanChartRichEditorPane.refreshCommonChartFieldNames(chart); + ColSelectedWithSummaryMethodEditor.refreshCommonChartFieldNames(chart); conditionAttrPane.populateBean(chart); } } diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/CalculateComboBox.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/CalculateComboBox.java index a1ad223125..61a906a3f2 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/CalculateComboBox.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/CalculateComboBox.java @@ -1,17 +1,6 @@ package com.fr.design.mainframe.chart.gui.data; -import com.fr.data.util.function.AbstractDataFunction; -import com.fr.data.util.function.AverageFunction; -import com.fr.data.util.function.CountFunction; -import com.fr.data.util.function.MaxFunction; -import com.fr.data.util.function.MinFunction; -import com.fr.data.util.function.NoneFunction; -import com.fr.data.util.function.SumFunction; -import com.fr.design.gui.icombobox.UIComboBox; -import com.fr.design.i18n.Toolkit; -import com.fr.general.ComparatorUtils; -import com.fr.log.FineLoggerFactory; -import com.fr.plugin.chart.base.FirstFunction; +import com.fr.design.data.datapane.SummaryMethodComboBox; /** @@ -20,53 +9,11 @@ import com.fr.plugin.chart.base.FirstFunction; * @author kunsnat E-mail:kunsnat@gmail.com * @version 创建时间:2013-1-8 上午09:52:15 */ -public class CalculateComboBox extends UIComboBox { - - public static final String[] CALCULATE_ARRAY = {Toolkit.i18nText("Fine-Design_Chart_Data_Function_First"), Toolkit.i18nText("Fine-Design_Chart_Data_Function_Last"), - Toolkit.i18nText("Fine-Design_Chart_Data_Function_Sum"), Toolkit.i18nText("Fine-Design_Chart_Data_Function_Average"), - Toolkit.i18nText("Fine-Design_Chart_Data_Function_Max"), Toolkit.i18nText("Fine-Design_Chart_Data_Function_Min"), - Toolkit.i18nText("Fine-Design_Chart_Data_Function_Count")}; - public static final Class[] CLASS_ARRAY = {FirstFunction.class, NoneFunction.class, SumFunction.class, AverageFunction.class, - MaxFunction.class, MinFunction.class, CountFunction.class}; +public class CalculateComboBox extends SummaryMethodComboBox { + public static final String[] CALCULATE_ARRAY = SummaryMethodComboBox.CALCULATE_ARRAY; + public static final Class[] CLASS_ARRAY = SummaryMethodComboBox.CLASS_ARRAY; public CalculateComboBox() { - super(CALCULATE_ARRAY); - setSelectedIndex(2); - } - - public void reset() { - this.setSelectedItem(Toolkit.i18nText("Fine-Design_Chart_Data_Function_Sum")); - } - - /** - * 更新公式选择. - */ - public void populateBean(AbstractDataFunction function) { - for (int i = 0; i < CLASS_ARRAY.length; i++) { - if (function != null && ComparatorUtils.equals(function.getClass(), CLASS_ARRAY[i])) { - setSelectedIndex(i); - break; - } - } - } - - /** - * 返回当前选择的公式 - */ - public AbstractDataFunction updateBean() { - try { - int selectIndex = getSelectedIndex(); - if (selectIndex >= 0 && selectIndex < CLASS_ARRAY.length) { - return (AbstractDataFunction) CLASS_ARRAY[selectIndex].newInstance(); - } - } catch (InstantiationException e) { - FineLoggerFactory.getLogger().error("Function Error"); - return null; - } catch (IllegalAccessException e) { - FineLoggerFactory.getLogger().error("Function Error"); - return null; - } - - return null; + super(); } } \ No newline at end of file diff --git a/designer-chart/src/main/java/com/fr/van/chart/custom/other/VanChartCustomPlotConditionAttrTabPane.java b/designer-chart/src/main/java/com/fr/van/chart/custom/other/VanChartCustomPlotConditionAttrTabPane.java index 4cb5c652f6..8c20568578 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/custom/other/VanChartCustomPlotConditionAttrTabPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/custom/other/VanChartCustomPlotConditionAttrTabPane.java @@ -1,6 +1,7 @@ package com.fr.van.chart.custom.other; import com.fr.chart.chartattr.Chart; +import com.fr.design.chart.series.SeriesCondition.ColSelectedWithSummaryMethodEditor; import com.fr.design.dialog.BasicPane; import com.fr.plugin.chart.attr.plot.VanChartPlot; import com.fr.plugin.chart.custom.CustomPlotFactory; @@ -91,6 +92,7 @@ public class VanChartCustomPlotConditionAttrTabPane extends VanChartCustomPlotTa CustomPlotType plotType = CustomPlotFactory.getCustomType(chartPlot); VanChartRichEditorPane.refreshCustomChartTableFieldNames(chart, plotType); + ColSelectedWithSummaryMethodEditor.refreshCustomChartTableFieldNames(chart,plotType); } } diff --git a/designer-chart/src/main/java/com/fr/van/chart/custom/style/VanChartCustomStylePane.java b/designer-chart/src/main/java/com/fr/van/chart/custom/style/VanChartCustomStylePane.java index da4fa2534c..234f2ee1dc 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/custom/style/VanChartCustomStylePane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/custom/style/VanChartCustomStylePane.java @@ -1,6 +1,7 @@ package com.fr.van.chart.custom.style; import com.fr.chart.chartattr.ChartCollection; +import com.fr.design.chart.series.SeriesCondition.ColSelectedWithSummaryMethodEditor; import com.fr.design.dialog.BasicPane; import com.fr.design.gui.frpane.AttributeChangeListener; import com.fr.design.mainframe.chart.gui.style.series.ChartSeriesPane; @@ -75,6 +76,7 @@ public class VanChartCustomStylePane extends VanChartStylePane { public void refreshTableFieldNames(VanChartPlot plot) { CustomPlotType plotType = CustomPlotFactory.getCustomType(plot); VanChartRichEditorPane.refreshCustomChartTableFieldNames(getChart(), plotType); + ColSelectedWithSummaryMethodEditor.refreshCustomChartTableFieldNames(getChart(), plotType); } public void refreshTableFieldNames() { diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/style/VanChartStylePane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/style/VanChartStylePane.java index 7ca77a9fc2..603b5af0a2 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/style/VanChartStylePane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/style/VanChartStylePane.java @@ -1,6 +1,7 @@ package com.fr.van.chart.designer.style; import com.fr.chart.chartattr.Plot; +import com.fr.design.chart.series.SeriesCondition.ColSelectedWithSummaryMethodEditor; import com.fr.design.dialog.BasicPane; import com.fr.design.gui.frpane.AttributeChangeListener; import com.fr.design.mainframe.chart.ChartEditPane; @@ -88,6 +89,7 @@ public class VanChartStylePane extends ChartStylePane { public void refreshTableFieldNames() { VanChartRichEditorPane.refreshCommonChartFieldNames(getChart()); + ColSelectedWithSummaryMethodEditor.refreshCommonChartFieldNames(getChart()); } public void registerChartEditPane(ChartEditPane currentEditPane) {