Browse Source

Merge pull request #483 in DESIGN/design from ~ZHENG/c-design:release/10.0 to release/10.0

* commit '4d6e52d550edeb252c161bba0876f85bcef2002e':
  static方法拿出来
  国际化
  update
  CHART-2912 && CHART-2969 扩展接口 自定义字段名
final/10.0
zheng 6 years ago
parent
commit
6e55d13826
  1. 25
      designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/table/AbstractTableDataContentPane.java
  2. 84
      designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/table/DataPaneHelper.java
  3. 43
      designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/table/SeriesNameUseFieldNamePane.java
  4. 39
      designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/table/SeriesNameUseFieldValuePane.java
  5. 46
      designer-chart/src/main/java/com/fr/extended/chart/AbstractExtendedChartReportDataPane.java
  6. 82
      designer-chart/src/main/java/com/fr/extended/chart/AbstractExtendedChartTableDataPane.java
  7. 380
      designer-chart/src/main/java/com/fr/extended/chart/ExtendedCustomFieldComboBoxPane.java
  8. 20
      designer-chart/src/main/java/com/fr/van/chart/gantt/designer/data/data/component/ComboBoxWithButtonPane.java

25
designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/table/AbstractTableDataContentPane.java

@ -5,8 +5,8 @@ import com.fr.design.beans.BasicBeanPane;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
import com.fr.design.gui.icombobox.UIComboBox;
import javax.swing.*;
import java.awt.*;
import javax.swing.JSeparator;
import java.awt.Dimension;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;
@ -47,30 +47,15 @@ public abstract class AbstractTableDataContentPane extends BasicBeanPane<ChartCo
* 刷新Box的选项.
*/
protected void refreshBoxItems(UIComboBox box, List list) {
if(box == null) {
return;
}
Object ob = box.getSelectedItem();
box.removeAllItems();
int length = list.size();
for(int i = 0; i < length; i++) {
box.addItem(list.get(i));
}
box.getModel().setSelectedItem(ob);
DataPaneHelper.refreshBoxItems(box, list);
}
/**
* 清空box里所有东西
* @param box 容器
*/
protected void clearBoxItems(UIComboBox box){
if(box == null){
return;
}
box.removeAllItems();
protected void clearBoxItems(UIComboBox box) {
DataPaneHelper.clearBoxItems(box);
}
protected ItemListener tooltipListener = new ItemListener() {

84
designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/table/DataPaneHelper.java

@ -0,0 +1,84 @@
package com.fr.design.mainframe.chart.gui.data.table;
import com.fr.data.util.function.DataFunction;
import com.fr.data.util.function.NoneFunction;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.mainframe.chart.gui.data.CalculateComboBox;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import java.util.List;
/**
* Created by shine on 2018/9/14.
*/
public class DataPaneHelper {
/**
* 刷新Box的选项.
*/
public static void refreshBoxItems(UIComboBox box, List list) {
if (box == null) {
return;
}
Object ob = box.getSelectedItem();
box.removeAllItems();
int length = list.size();
for (int i = 0; i < length; i++) {
box.addItem(list.get(i));
}
box.getModel().setSelectedItem(ob);
}
/**
* 清空box里所有东西
*
* @param box 容器
*/
public static void clearBoxItems(UIComboBox box) {
if (box != null) {
box.removeAllItems();
}
}
/**
* 根据公式 获取 公式组件下拉框选项
*
* @param function
* @return
*/
public static String getFunctionString(DataFunction function) {
for (int i = 0; i < CalculateComboBox.CLASS_ARRAY.length; i++) {
Class tmp = function.getClass();
if (ComparatorUtils.equals(tmp, CalculateComboBox.CLASS_ARRAY[i])) {
return CalculateComboBox.CALCULATE_ARRAY[i];
}
}
return CalculateComboBox.CALCULATE_ARRAY[0];
}
/**
* 根据公式组件下拉选中项 获取对应公式
*
* @param name
* @return
*/
public static DataFunction getFunctionByName(String name) {
int index = 0;
for (int i = 0; i < CalculateComboBox.CALCULATE_ARRAY.length; i++) {
if (ComparatorUtils.equals(name, CalculateComboBox.CALCULATE_ARRAY[i])) {
index = i;
}
}
try {
return (DataFunction) CalculateComboBox.CLASS_ARRAY[index].newInstance();
} catch (InstantiationException e) {
FineLoggerFactory.getLogger().error("Function Error");
} catch (IllegalAccessException e) {
FineLoggerFactory.getLogger().error("Function Error");
}
return new NoneFunction();
}
}

43
designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/table/SeriesNameUseFieldNamePane.java

@ -5,7 +5,6 @@ import com.fr.base.chart.chartdata.TopDefinitionProvider;
import com.fr.chart.chartattr.ChartCollection;
import com.fr.chart.chartdata.ChartSummaryColumn;
import com.fr.chart.chartdata.MoreNameCDDefinition;
import com.fr.data.util.function.DataFunction;
import com.fr.data.util.function.NoneFunction;
import com.fr.design.beans.FurtherBasicBeanPane;
import com.fr.design.event.UIObserver;
@ -18,14 +17,15 @@ import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.chart.gui.data.CalculateComboBox;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import javax.swing.*;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
@ -198,7 +198,7 @@ public class SeriesNameUseFieldNamePane extends FurtherBasicBeanPane<ChartCollec
List<Object[]> list = new ArrayList<Object[]>();
for (int i = 0; i < chartSummaryColumnArray.length; i++) {
ChartSummaryColumn column = chartSummaryColumnArray[i];
String[] nameArray = {column.getName(), column.getCustomName(), getFunctionString(column.getFunction())};
String[] nameArray = {column.getName(), column.getCustomName(), DataPaneHelper.getFunctionString(column.getFunction())};
list.add(nameArray);
}
seriesDataPane.populateBean(list);
@ -212,16 +212,6 @@ public class SeriesNameUseFieldNamePane extends FurtherBasicBeanPane<ChartCollec
this.populateBean(collection,true);
}
private String getFunctionString(DataFunction function) {
for (int i = 0; i < CalculateComboBox.CLASS_ARRAY.length; i++) {
Class tmp = function.getClass();
if (ComparatorUtils.equals(tmp, CalculateComboBox.CLASS_ARRAY[i])) {
return CalculateComboBox.CALCULATE_ARRAY[i];
}
}
return CalculateComboBox.CALCULATE_ARRAY[0];
}
protected MoreNameCDDefinition createMoreNameCDDefinition() {
return new MoreNameCDDefinition();
}
@ -246,7 +236,7 @@ public class SeriesNameUseFieldNamePane extends FurtherBasicBeanPane<ChartCollec
String second = Utils.objectToString(line[1]);
if(isNeedSummary){
String third = Utils.objectToString(line[2]);
dataArray[i] = new ChartSummaryColumn(first, second, getFcuntionByName(third));
dataArray[i] = new ChartSummaryColumn(first, second, DataPaneHelper.getFunctionByName(third));
} else{
dataArray[i] = new ChartSummaryColumn(first,second,new NoneFunction());
}
@ -255,23 +245,6 @@ public class SeriesNameUseFieldNamePane extends FurtherBasicBeanPane<ChartCollec
collection.getSelectedChart().setFilterDefinition(moreDefinition);
}
private DataFunction getFcuntionByName(String name) {
int index = 0;
for (int i = 0; i < CalculateComboBox.CALCULATE_ARRAY.length; i++) {
if (ComparatorUtils.equals(name, CalculateComboBox.CALCULATE_ARRAY[i])) {
index = i;
}
}
try {
return (DataFunction) CalculateComboBox.CLASS_ARRAY[index].newInstance();
} catch (InstantiationException e) {
FineLoggerFactory.getLogger().error("Function Error");
} catch (IllegalAccessException e) {
FineLoggerFactory.getLogger().error("Function Error");
}
return new NoneFunction();
}
/**
* 保存为新的ChartCollection
*/

39
designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/table/SeriesNameUseFieldValuePane.java

@ -15,9 +15,12 @@ import com.fr.design.mainframe.chart.gui.data.CalculateComboBox;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
import javax.swing.*;
import java.awt.*;
import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;
@ -155,22 +158,16 @@ public class SeriesNameUseFieldValuePane extends FurtherBasicBeanPane<ChartColle
* @param list 列表
*/
public void refreshBoxListWithSelectTableData(List list) {
refreshBoxItems(seriesName, list);
refreshBoxItems(seriesValue, list);
DataPaneHelper.refreshBoxItems(seriesName, list);
DataPaneHelper.refreshBoxItems(seriesValue, list);
}
/**
* 清空所有的box设置
*/
public void clearAllBoxList(){
clearBoxItems(seriesName);
clearBoxItems(seriesValue);
}
private void clearBoxItems(UIComboBox box){
if(box != null){
box.removeAllItems();
}
DataPaneHelper.clearBoxItems(seriesName);
DataPaneHelper.clearBoxItems(seriesValue);
}
private boolean boxItemsContainsObject(UIComboBox box,Object item){
@ -187,22 +184,6 @@ public class SeriesNameUseFieldValuePane extends FurtherBasicBeanPane<ChartColle
return false;
}
private void refreshBoxItems(UIComboBox box, List list) {
if (box == null) {
return;
}
Object ob = box.getSelectedItem();
box.removeAllItems();
int length = list.size();
for (int i = 0; i < length; i++) {
box.addItem(list.get(i));
}
box.getModel().setSelectedItem(ob);
}
/**
* 判断界面是否接受
* @param ob 接受的对象

46
designer-chart/src/main/java/com/fr/extended/chart/AbstractExtendedChartReportDataPane.java

@ -7,18 +7,24 @@ import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.chart.gui.data.report.AbstractReportDataContentPane;
import java.awt.Component;
import java.awt.FlowLayout;
import java.util.Arrays;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.Component;
import java.awt.FlowLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created by shine on 2018/3/7.
*/
public abstract class AbstractExtendedChartReportDataPane<T extends AbstractDataConfig> extends AbstractReportDataContentPane {
private TinyFormulaPane seriesPane;
private TinyFormulaPane valuePane;
public AbstractExtendedChartReportDataPane() {
initComponents();
}
@ -29,15 +35,22 @@ public abstract class AbstractExtendedChartReportDataPane<T extends AbstractData
int len = Math.min(labels.length, formulaPanes.length);
Component[][] components = new Component[len][2];
Component[][] components = new Component[len + (hasCustomFieldPane() ? 2 : 0)][2];
for (int i = 0; i < len; i++) {
components[i] = new Component[]{new UILabel(labels[i], SwingConstants.LEFT), formulaPanes[i]};
}
if (hasCustomFieldPane()) {
seriesPane = new TinyFormulaPane();
valuePane = new TinyFormulaPane();
components[len] = new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Series_Name"), SwingConstants.LEFT), seriesPane};
components[len + 1] = new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Use_Value"), SwingConstants.LEFT), valuePane};
}
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
double[] columnSize = {f, COMPONENT_WIDTH};
double[] rowSize = new double[len];
double[] rowSize = new double[len + (hasCustomFieldPane() ? 2 : 0)];
Arrays.fill(rowSize, p);
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 24, 6);
@ -45,13 +58,17 @@ public abstract class AbstractExtendedChartReportDataPane<T extends AbstractData
this.setLayout(new FlowLayout());
this.add(panel);
this.add(addOtherPane());
this.add(addSouthPane());
}
protected JPanel addOtherPane() {
protected JPanel addSouthPane() {
return new JPanel();
}
protected boolean hasCustomFieldPane() {
return false;
}
protected Component[] fieldComponents() {
return formulaPanes();
}
@ -77,6 +94,11 @@ public abstract class AbstractExtendedChartReportDataPane<T extends AbstractData
if (dataConfig != null) {
populate((T) dataConfig);
if (hasCustomFieldPane() && dataConfig.getCustomFields().size() == 2) {
populateField(seriesPane, dataConfig.getCustomFields().get(0));
populateField(valuePane, dataConfig.getCustomFields().get(1));
}
}
}
}
@ -89,7 +111,15 @@ public abstract class AbstractExtendedChartReportDataPane<T extends AbstractData
if (chart != null) {
ExtendedReportDataSet dataSet = new ExtendedReportDataSet();
dataSet.setDataConfig(update());
AbstractDataConfig dataConfig = update();
dataSet.setDataConfig(dataConfig);
List<ExtendedField> fieldList = new ArrayList<ExtendedField>();
if (hasCustomFieldPane()) {
fieldList.add(new ExtendedField(seriesPane.updateBean()));
fieldList.add(new ExtendedField(valuePane.updateBean()));
}
dataConfig.setCustomFields(fieldList);
chart.setFilterDefinition(dataSet);
}

82
designer-chart/src/main/java/com/fr/extended/chart/AbstractExtendedChartTableDataPane.java

@ -10,21 +10,21 @@ import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.chart.gui.data.CalculateComboBox;
import com.fr.design.mainframe.chart.gui.data.table.AbstractTableDataContentPane;
import com.fr.general.GeneralUtils;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.util.Arrays;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
/**
* Created by shine on 2018/3/2.
*/
public abstract class AbstractExtendedChartTableDataPane<T extends AbstractDataConfig> extends AbstractTableDataContentPane {
private CalculateComboBox function;
private ExtendedCustomFieldComboBoxPane customFieldComboBoxPane;
public AbstractExtendedChartTableDataPane() {
initComponents();
@ -37,30 +37,27 @@ public abstract class AbstractExtendedChartTableDataPane<T extends AbstractDataC
int len = Math.min(labels.length, fieldComponents.length);
Component[][] components = new Component[len + (hasFunction() ? 1 : 0)][2];
Component[][] components = new Component[len][2];
for (int i = 0; i < len; i++) {
Component fieldComponent = fieldComponents[i];
fieldComponent.setPreferredSize(new Dimension(100, 20));
components[i] = new Component[]{new UILabel(labels[i], SwingConstants.LEFT), fieldComponent};
}
if (hasFunction()) {
function = new CalculateComboBox();
components[len] = new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Summary_Method"), SwingConstants.LEFT), function};
components[i] = new Component[]{new UILabel(labels[i], SwingConstants.LEFT), fieldComponents[i]};
}
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
double[] columnSize = {f, COMPONENT_WIDTH};
double[] rowSize = new double[len + (hasFunction() ? 1 : 0)];
double[] columnSize = {TableLayout.FILL, 120};
double[] rowSize = new double[len];
Arrays.fill(rowSize, p);
JPanel panel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
panel.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 15));
this.setLayout(new BorderLayout());
this.add(panel, BorderLayout.CENTER);
this.setLayout(new BorderLayout(0, 6));
this.setBorder(BorderFactory.createEmptyBorder(2, 24, 0, 15));
this.add(panel, BorderLayout.NORTH);
if (hasCustomFieldPane()) {
customFieldComboBoxPane = new ExtendedCustomFieldComboBoxPane();
this.add(customFieldComboBoxPane, BorderLayout.CENTER);
}
this.add(addSouthPane(), BorderLayout.SOUTH);
}
@ -68,7 +65,7 @@ public abstract class AbstractExtendedChartTableDataPane<T extends AbstractDataC
return new JPanel();
}
protected boolean hasFunction() {
protected boolean hasCustomFieldPane() {
return false;
}
@ -98,10 +95,10 @@ public abstract class AbstractExtendedChartTableDataPane<T extends AbstractDataC
AbstractDataConfig dataConfig = dataSet.getDataConfig();
if (dataConfig != null) {
populate((T) dataConfig);
}
if (hasFunction()) {
function.populateBean((AbstractDataFunction) dataSet.getDataFunction());
if (hasCustomFieldPane()) {
customFieldComboBoxPane.populateBean(dataConfig);
}
}
}
@ -118,8 +115,8 @@ public abstract class AbstractExtendedChartTableDataPane<T extends AbstractDataC
ExtendedTableDataSet dataSet = new ExtendedTableDataSet();
dataSet.setDataConfig(update());
if (hasFunction()) {
dataSet.setDataFunction(function.updateBean());
if (hasCustomFieldPane()) {
customFieldComboBoxPane.updateBean(dataSet.getDataConfig());
}
chart.setFilterDefinition(dataSet);
@ -129,8 +126,11 @@ public abstract class AbstractExtendedChartTableDataPane<T extends AbstractDataC
@Override
public void checkBoxUse(boolean hasUse) {
for (UIComboBox comboBox : filedComboBoxes()) {
comboBox.setEnabled(hasUse);
for (Component component : fieldComponents()) {
component.setEnabled(hasUse);
}
if (customFieldComboBoxPane != null) {
customFieldComboBoxPane.checkBoxUse(hasUse);
}
}
@ -139,6 +139,9 @@ public abstract class AbstractExtendedChartTableDataPane<T extends AbstractDataC
for (UIComboBox comboBox : filedComboBoxes()) {
clearBoxItems(comboBox);
}
if (customFieldComboBoxPane != null) {
customFieldComboBoxPane.clearAllBoxList();
}
}
@Override
@ -146,14 +149,33 @@ public abstract class AbstractExtendedChartTableDataPane<T extends AbstractDataC
for (UIComboBox comboBox : filedComboBoxes()) {
refreshBoxItems(comboBox, columnNameList);
}
if (customFieldComboBoxPane != null) {
customFieldComboBoxPane.refreshBoxListWithSelectTableData(columnNameList);
}
}
protected void populateField(UIComboBox comboBox, ExtendedField field) {
comboBox.setSelectedItem(field.getFieldName());
populateFunctionField(comboBox, null, field);
}
protected void updateField(UIComboBox comboBox, ExtendedField field) {
updateFunctionField(comboBox, null, field);
}
protected void populateFunctionField(UIComboBox comboBox, CalculateComboBox calculateComboBox, ExtendedField field) {
comboBox.setSelectedItem(field.getFieldName());
if (calculateComboBox != null) {
calculateComboBox.populateBean((AbstractDataFunction) field.getDataFunction());
}
}
protected void updateFunctionField(UIComboBox comboBox, CalculateComboBox calculateComboBox, ExtendedField field) {
field.setFieldName(GeneralUtils.objectToString(comboBox.getSelectedItem()));
if (calculateComboBox != null) {
field.setDataFunction(calculateComboBox.updateBean());
} else {
field.setDataFunction(null);
}
}
}

380
designer-chart/src/main/java/com/fr/extended/chart/ExtendedCustomFieldComboBoxPane.java

@ -0,0 +1,380 @@
package com.fr.extended.chart;
import com.fr.base.Utils;
import com.fr.data.util.function.AbstractDataFunction;
import com.fr.design.beans.FurtherBasicBeanPane;
import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.frpane.UIComboBoxPane;
import com.fr.design.gui.frpane.UICorrelationPane;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itable.UITable;
import com.fr.design.gui.itable.UITableEditor;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.chart.gui.data.CalculateComboBox;
import com.fr.design.mainframe.chart.gui.data.table.DataPaneHelper;
import com.fr.stable.StringUtils;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.List;
/**
* Created by shine on 2018/9/12.
*/
public class ExtendedCustomFieldComboBoxPane extends UIComboBoxPane<AbstractDataConfig> {
private static final String[] HEADS = {com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Field_Name"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Series_Name"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Summary_Method")};
private UseFieldValuePane useFieldValuePane;
private CustomFieldNamePane customFieldNamePane;
private List<String> fieldList = new ArrayList<String>();
@Override
protected void initLayout() {
this.setLayout(new BorderLayout(0, 6));
JPanel northPane = new JPanel(new BorderLayout());
northPane.add(jcb, BorderLayout.CENTER);
UILabel label = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Series_Name_From"));
label.setPreferredSize(new Dimension(82, 20));
northPane.add(label, BorderLayout.WEST);
this.add(northPane, BorderLayout.NORTH);
this.add(cardPane, BorderLayout.CENTER);
}
@Override
protected List<FurtherBasicBeanPane<? extends AbstractDataConfig>> initPaneList() {
useFieldValuePane = new UseFieldValuePane();
customFieldNamePane = new CustomFieldNamePane();
List<FurtherBasicBeanPane<? extends AbstractDataConfig>> list = new ArrayList<FurtherBasicBeanPane<? extends AbstractDataConfig>>();
list.add(useFieldValuePane);
list.add(customFieldNamePane);
return list;
}
@Override
protected String title4PopupWindow() {
return StringUtils.EMPTY;
}
public void checkBoxUse(boolean hasUse) {
jcb.setEnabled(hasUse);
useFieldValuePane.checkBoxUse(hasUse);
}
public void clearAllBoxList() {
useFieldValuePane.clearAllBoxList();
fieldList.clear();
}
protected void refreshBoxListWithSelectTableData(List columnNameList) {
useFieldValuePane.refreshBoxListWithSelectTableData(columnNameList);
fieldList = columnNameList;
}
@Override
public void populateBean(AbstractDataConfig ob) {
if (ob.isCustomName()) {
customFieldNamePane.populateBean(ob);
jcb.setSelectedIndex(1);
} else {
useFieldValuePane.populateBean(ob);
jcb.setSelectedIndex(0);
}
}
@Override
public void updateBean(AbstractDataConfig ob) {
if (jcb.getSelectedIndex() == 0) {
ob.setCustomName(false);
useFieldValuePane.updateBean(ob);
} else {
ob.setCustomName(true);
customFieldNamePane.updateBean(ob);
}
}
private class UseFieldValuePane extends FurtherBasicBeanPane<AbstractDataConfig> {
private UIComboBox series;
private UIComboBox value;
private CalculateComboBox function;
private UseFieldValuePane() {
initComponents();
}
private void initComponents() {
series = new UIComboBox();
value = new UIComboBox();
function = new CalculateComboBox();
Component[][] components = new Component[][]{
new Component[]{new UILabel(HEADS[1], SwingConstants.LEFT), series},
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Use_Value"), SwingConstants.LEFT), value},
new Component[]{new UILabel(HEADS[2], SwingConstants.LEFT), function},
};
double p = TableLayout.PREFERRED;
double[] columnSize = {76, 120};
double[] rowSize = {p, p, p};
JPanel panel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
this.setLayout(new BorderLayout(0, 6));
this.add(panel, BorderLayout.CENTER);
}
public void checkBoxUse(boolean hasUse) {
series.setEnabled(hasUse);
value.setEnabled(hasUse);
function.setEnabled(hasUse);
}
public void clearAllBoxList() {
DataPaneHelper.clearBoxItems(series);
DataPaneHelper.clearBoxItems(value);
}
public void refreshBoxListWithSelectTableData(List columnNameList) {
DataPaneHelper.refreshBoxItems(series, columnNameList);
DataPaneHelper.refreshBoxItems(value, columnNameList);
}
@Override
public void populateBean(AbstractDataConfig ob) {
List<ExtendedField> list = ob.getCustomFields();
if (list.size() == 2) {
series.setSelectedItem(list.get(0).getFieldName());
value.setSelectedItem(list.get(1).getFieldName());
function.populateBean((AbstractDataFunction) list.get(1).getDataFunction());
}
}
@Override
public void updateBean(AbstractDataConfig ob) {
List<ExtendedField> list = new ArrayList<ExtendedField>();
list.add(new ExtendedField(Utils.objectToString(series.getSelectedItem())));
ExtendedField field = new ExtendedField(Utils.objectToString(value.getSelectedItem()));
field.setDataFunction(function.updateBean());
list.add(field);
ob.setCustomFields(list);
}
@Override
public boolean accept(Object ob) {
return true;
}
@Override
public void reset() {
}
@Override
public String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Enable_Field_Value");
}
@Override
public AbstractDataConfig updateBean() {
return null;
}
}
private class CustomFieldNamePane extends FurtherBasicBeanPane<AbstractDataConfig> {
private UICorrelationPane correlationPane;
public CustomFieldNamePane() {
initComponents();
}
private void initComponents() {
correlationPane = new UICorrelationPane(HEADS) {
@Override
protected ActionListener getAddButtonListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tablePane.addLine(new String[]{StringUtils.EMPTY, StringUtils.EMPTY, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Use_None")});
fireTargetChanged();
}
};
}
public UITableEditor createUITableEditor() {
return new Editor() {
@Override
protected UICorrelationPane getParent() {
return correlationPane;
}
};
}
};
this.setLayout(new BorderLayout());
this.add(correlationPane, BorderLayout.CENTER);
}
@Override
public void populateBean(AbstractDataConfig ob) {
List<ExtendedField> customFields = ob.getCustomFields();
List<Object[]> list = new ArrayList<Object[]>();
for (ExtendedField field : customFields) {
String[] array = {field.getFieldName(), field.getCustomName(), DataPaneHelper.getFunctionString(field.getDataFunction())};
list.add(array);
}
correlationPane.populateBean(list);
}
@Override
public void updateBean(AbstractDataConfig ob) {
List<Object[]> list = correlationPane.updateBean();
List<ExtendedField> customFields = new ArrayList<ExtendedField>();
for (Object[] line : list) {
ExtendedField field = new ExtendedField(Utils.objectToString(line[0]));
field.setCustomName(Utils.objectToString(line[1]));
if (line.length > 2) {
field.setDataFunction(DataPaneHelper.getFunctionByName(Utils.objectToString(line[2])));
}
customFields.add(field);
}
ob.setCustomFields(customFields);
}
@Override
public boolean accept(Object ob) {
return true;
}
@Override
public void reset() {
}
@Override
public String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Enable_Field_Name");
}
@Override
public AbstractDataConfig updateBean() {
return null;
}
}
private abstract class Editor extends UITableEditor {
private JComponent editorComponent;
protected abstract UICorrelationPane getParent();
@Override
public Object getCellEditorValue() {
if (editorComponent instanceof UIComboBox) {
return ((UIComboBox) editorComponent).getSelectedItem();
} else if (editorComponent instanceof UITextField) {
return ((UITextField) editorComponent).getText();
} else if (editorComponent instanceof CalculateComboBox) {
return ((CalculateComboBox) editorComponent).getSelectedItem();
}
return super.getCellEditorValue();
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, final int row, int column) {
switch (column) {
case 0:
editorComponent = createComboBoxEdit(row, value);
break;
case 1:
editorComponent = createTextEdit(value);
break;
default:
editorComponent = createCalculateComboBox(value);
break;
}
return editorComponent;
}
private void setDefaultName(int row) {
UITable table = getParent().getTable();
Object object = table.getValueAt(row, 0);
if (object != null) {
table.setValueAt(object, row, 1);
}
}
private UIComboBox createComboBoxEdit(final int row, Object value) {
UIComboBox uiComboBox = new UIComboBox(fieldList.toArray());
uiComboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
getParent().stopCellEditing();
getParent().fireTargetChanged();
setDefaultName(row);
}
});
if (value != null && StringUtils.isNotEmpty(value.toString())) {
uiComboBox.getModel().setSelectedItem(value);
} else {
uiComboBox.getModel().setSelectedItem(value);
}
return uiComboBox;
}
private UITextField createTextEdit(Object value) {
UITextField uiTextField = new UITextField();
if (value != null) {
uiTextField.setText(value.toString());
}
uiTextField.registerChangeListener(new UIObserverListener() {
@Override
public void doChange() {
getParent().fireTargetChanged();
}
});
return uiTextField;
}
private CalculateComboBox createCalculateComboBox(Object value) {
CalculateComboBox calculateComboBox = new CalculateComboBox();
if (value != null) {
calculateComboBox.setSelectedItem(value);
}
calculateComboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
getParent().stopCellEditing();
getParent().fireTargetChanged();
}
});
return calculateComboBox;
}
}
}

20
designer-chart/src/main/java/com/fr/van/chart/gantt/designer/data/data/component/ComboBoxWithButtonPane.java

@ -4,6 +4,7 @@ import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.chart.gui.data.table.DataPaneHelper;
import javax.swing.BorderFactory;
import javax.swing.Icon;
@ -62,29 +63,14 @@ public abstract class ComboBoxWithButtonPane extends JPanel {
* 刷新Box的选项.
*/
public void refreshBoxItems(java.util.List list) {
if(comboBoxName == null) {
return;
}
Object ob = comboBoxName.getSelectedItem();
comboBoxName.removeAllItems();
int length = list.size();
for(int i = 0; i < length; i++) {
comboBoxName.addItem(list.get(i));
}
comboBoxName.getModel().setSelectedItem(ob);
DataPaneHelper.refreshBoxItems(comboBoxName, list);
}
/**
* 清空box里所有东西
*/
public void clearBoxItems(){
if(comboBoxName == null){
return;
}
comboBoxName.removeAllItems();
DataPaneHelper.clearBoxItems(comboBoxName);
}

Loading…
Cancel
Save