From a5b5f640910a5a2714f52c87a9a331e58f25bdea Mon Sep 17 00:00:00 2001 From: "Qinghui.Liu" Date: Tue, 29 Dec 2020 11:22:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=96=B0=E5=A2=9E=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../richText/VanChartFieldButton.java | 3 +- .../richText/VanChartFieldListPane.java | 60 ++++++++++++++++--- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldButton.java b/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldButton.java index a3ccc2a471..4e75b9febd 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldButton.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldButton.java @@ -2,6 +2,7 @@ package com.fr.van.chart.designer.component.richText; import com.fr.base.BaseUtils; import com.fr.data.util.function.DataFunction; +import com.fr.data.util.function.NoneFunction; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIToggleButton; import com.fr.design.layout.TableLayout; @@ -36,7 +37,7 @@ public class VanChartFieldButton extends JPanel { private UIToggleButton fieldButton; private UIButton addButton; - private DataFunction dataFunction; + private DataFunction dataFunction = new NoneFunction(); public VanChartFieldButton(String fieldName, AttrTooltipFormat format, boolean showDataFunction, VanChartFieldListener listener) { this.fieldName = fieldName; diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldListPane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldListPane.java index f7fb81d0cb..e88937a6ad 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldListPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldListPane.java @@ -1,12 +1,17 @@ package com.fr.van.chart.designer.component.richText; import com.fr.data.util.function.AbstractDataFunction; +import com.fr.data.util.function.DataFunction; import com.fr.design.event.UIObserverListener; import com.fr.design.i18n.Toolkit; import com.fr.design.ui.ModernUIPane; import com.fr.general.ComparatorUtils; +import com.fr.log.FineLoggerFactory; import com.fr.plugin.chart.base.AttrTooltipContent; +import com.fr.plugin.chart.base.TableFieldCollection; +import com.fr.plugin.chart.base.TableFieldDefinition; import com.fr.plugin.chart.base.format.AttrTooltipCategoryFormat; +import com.fr.plugin.chart.base.format.AttrTooltipFieldFormat; import com.fr.plugin.chart.base.format.AttrTooltipFormat; import com.fr.plugin.chart.base.format.AttrTooltipPercentFormat; import com.fr.plugin.chart.base.format.AttrTooltipSeriesFormat; @@ -23,6 +28,7 @@ import java.awt.event.ActionListener; import java.text.Format; import java.util.ArrayList; import java.util.List; +import java.util.Map; public class VanChartFieldListPane extends JPanel { @@ -38,13 +44,14 @@ public class VanChartFieldListPane extends JPanel { private ModernUIPane richEditorPane; private List tableFieldNameList; private List tableFieldButtonList = new ArrayList<>(); + private TableFieldCollection tableFieldCollection = new TableFieldCollection(); private VanChartFieldListener fieldListener; public VanChartFieldListPane(List tableFieldNameList, VanChartFieldAttrPane fieldAttrPane, ModernUIPane richEditorPane) { - this.tableFieldNameList = tableFieldNameList; + this.tableFieldNameList = tableFieldNameList == null ? new ArrayList<>() : tableFieldNameList; this.fieldAttrPane = fieldAttrPane; this.richEditorPane = richEditorPane; @@ -104,7 +111,7 @@ public class VanChartFieldListPane extends JPanel { tableField.setLayout(new GridLayout(0, 1, 1, 0)); for (String name : tableFieldNameList) { - VanChartFieldButton fieldButton = new VanChartFieldButton(name, getTableTooltipFormat(name), true, fieldListener); + VanChartFieldButton fieldButton = new VanChartFieldButton(name, new AttrTooltipFieldFormat(name), true, fieldListener); tableField.add(fieldButton); tableFieldButtonList.add(fieldButton); @@ -115,11 +122,6 @@ public class VanChartFieldListPane extends JPanel { return TableLayout4VanChartHelper.createExpandablePaneWithTitleTopGap("数据集字段", tableField); } - // 生成新增字段对应的format - private AttrTooltipFormat getTableTooltipFormat(String fieldName) { - return new AttrTooltipCategoryFormat(); - } - protected List getDefaultFieldButtonList() { List defaultFieldButtonList = new ArrayList<>(); @@ -180,6 +182,16 @@ public class VanChartFieldListPane extends JPanel { } public void addSelectedField(String fieldName, String fieldId) { + if (tableFieldNameList.contains(fieldName)) { + int index = tableFieldNameList.indexOf(fieldName); + + VanChartFieldButton fieldButton = tableFieldButtonList.get(index); + Format fieldFormat = fieldButton.getFormat(); + DataFunction dataFunction = fieldButton.getDataFunction(); + + tableFieldCollection.addFieldDefinition(fieldName, new TableFieldDefinition(fieldName, fieldFormat, dataFunction)); + } + VanChartRichEditorModel model = richEditorPane.update(); model.setAddition(fieldName); VanChartRichEditorPane.richEditorAddField(model); @@ -264,7 +276,35 @@ public class VanChartFieldListPane extends JPanel { } public void populateTableField(AttrTooltipContent tooltipContent) { + TableFieldCollection fieldCollection = tooltipContent.getFieldCollection(); + if (fieldCollection == null) { + return; + } + + Map fieldDefinitionGroup = fieldCollection.getFieldNameFormulaMap(); + + if (fieldDefinitionGroup == null || fieldDefinitionGroup.isEmpty()) { + return; + } + + this.tableFieldCollection = new TableFieldCollection(); + + for (int i = 0, len = tableFieldNameList.size(); i < len; i++) { + String fieldName = tableFieldNameList.get(i); + VanChartFieldButton fieldButton = tableFieldButtonList.get(i); + TableFieldDefinition fieldDefinition = fieldDefinitionGroup.get(fieldName); + + if (fieldDefinitionGroup.containsKey(fieldName)) { + Format fieldFormat = fieldDefinition.getFormat(); + DataFunction dataFunction = fieldDefinition.getDataFunction(); + + fieldButton.setFormat(fieldFormat); + fieldButton.setDataFunction(dataFunction); + + this.tableFieldCollection.addFieldDefinition(fieldName, new TableFieldDefinition(fieldName, fieldFormat, dataFunction)); + } + } } public void update(AttrTooltipContent tooltipContent) { @@ -280,7 +320,11 @@ public class VanChartFieldListPane extends JPanel { } public void updateTableField(AttrTooltipContent tooltipContent) { - + try { + tooltipContent.setFieldCollection(this.tableFieldCollection); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } } public void updateButtonFormat(VanChartFieldButton button, AttrTooltipFormat format) {