Browse Source

规范化API调用

master
richie 5 years ago
parent
commit
f42dc631ec
  1. 31
      src/main/java/com/fanruan/api/design/ui/component/chart/CalculateComboBox.java
  2. 4
      src/main/java/com/fanruan/api/design/ui/component/chart/DataFunctionType.java

31
src/main/java/com/fanruan/api/design/ui/component/chart/CalculateComboBox.java

@ -1,32 +1,38 @@
package com.fanruan.api.design.ui.component.chart;
import com.fanruan.api.design.DesignKit;
import com.fanruan.api.design.ui.component.UIComboBox;
import com.fanruan.api.log.LogKit;
import com.fr.common.annotations.Compatible;
import com.fr.data.util.function.DataFunction;
import com.fr.design.i18n.Toolkit;
import com.fr.log.FineLoggerFactory;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2019-09-23
*/
public class CalculateComboBox extends UIComboBox {
public class CalculateComboBox extends UIComboBox<String> {
private static String[] functionName = initItem();
private static String[] functionName;
private static String[] initItem() {
static {
String[] functionLocaleNames = DataFunctionType.getFunctionLocaleNames();
for (int i = 0; i < functionLocaleNames.length; i++) {
functionLocaleNames[i] = Toolkit.i18nText(functionLocaleNames[i]);
functionLocaleNames[i] = DesignKit.i18nText(functionLocaleNames[i]);
}
return functionLocaleNames;
functionName = functionLocaleNames;
}
public CalculateComboBox() {
super(functionName);
setSelectedIndex(0);
}
/**
* 重置公式下拉选选中的值为第0个
*/
@Compatible
public void reset() {
this.setSelectedItem(0);
}
@ -34,6 +40,7 @@ public class CalculateComboBox extends UIComboBox {
/**
* 通过公式对象更新界面的公式选择
*/
@Compatible
public void populateBean(DataFunction function) {
int index = DataFunctionType.getIndexByFunction(function);
if (index > 0) {
@ -44,15 +51,13 @@ public class CalculateComboBox extends UIComboBox {
/**
* 根据界面选择的公式返回公式对象
*/
@Compatible
public DataFunction updateBean() {
try {
int selectIndex = getSelectedIndex();
DataFunction functionByIndex = DataFunctionType.getFunctionByIndex(selectIndex);
return functionByIndex;
} catch (InstantiationException e) {
FineLoggerFactory.getLogger().error("Function Error");
} catch (IllegalAccessException e) {
FineLoggerFactory.getLogger().error("Function Error");
return DataFunctionType.getFunctionByIndex(selectIndex);
} catch (InstantiationException | IllegalAccessException e) {
LogKit.error("Function Error");
}
return null;
}

4
src/main/java/com/fanruan/api/design/ui/component/chart/DataFunctionType.java

@ -1,5 +1,6 @@
package com.fanruan.api.design.ui.component.chart;
import com.fanruan.api.util.AssistKit;
import com.fr.data.util.function.AverageFunction;
import com.fr.data.util.function.CountFunction;
import com.fr.data.util.function.DataFunction;
@ -7,7 +8,6 @@ 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.general.ComparatorUtils;
/**
* @author Bjorn
@ -39,7 +39,7 @@ public enum DataFunctionType {
return NONE_FUNCTION_INDEX;
}
for (DataFunctionType dataFunctionType : DataFunctionType.values()) {
if (ComparatorUtils.equals(dataFunctionType.functionClass, function.getClass())) {
if (AssistKit.equals(dataFunctionType.functionClass, function.getClass())) {
return dataFunctionType.ordinal();
}
}

Loading…
Cancel
Save