@ -0,0 +1,88 @@
|
||||
package com.fr.design.formula; |
||||
|
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.parser.FRLexer; |
||||
import com.fr.parser.FRParser; |
||||
import com.fr.script.checker.FunctionCheckerDispatcher; |
||||
import com.fr.script.checker.exception.ConditionCheckWrongException; |
||||
import com.fr.script.checker.exception.FunctionCheckWrongException; |
||||
import com.fr.script.rules.FunctionParameterType; |
||||
import com.fr.script.rules.FunctionRule; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.script.Expression; |
||||
import com.fr.stable.script.Node; |
||||
|
||||
import java.io.StringReader; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Hoky |
||||
* @date 2021/9/28 |
||||
*/ |
||||
public class FormulaChecker { |
||||
private static final String VALID_FORMULA = Toolkit.i18nText("Fine-Design_Basic_FormulaD_Valid_Formula"); |
||||
private static final String INVALID_FORMULA = Toolkit.i18nText("Fine-Design_Basic_FormulaD_Invalid_Formula"); |
||||
public static final String COLON = ":"; |
||||
|
||||
public static String check(String formulaText) { |
||||
StringReader in = new StringReader(formulaText); |
||||
|
||||
FRLexer lexer = new FRLexer(in); |
||||
FRParser parser = new FRParser(lexer); |
||||
|
||||
try { |
||||
Expression expression = parser.parse(); |
||||
Node node = expression.getConditionalExpression(); |
||||
return FunctionCheckerDispatcher.getInstance() |
||||
.getFunctionChecker(node) |
||||
.checkFunction(node) ? VALID_FORMULA : INVALID_FORMULA; |
||||
} catch (ConditionCheckWrongException cce) { |
||||
String functionName = cce.getFunctionName(); |
||||
return functionName + Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Condition_Tips") + COLON; |
||||
} catch (FunctionCheckWrongException ce) { |
||||
List<FunctionRule> rules = ce.getRules(); |
||||
String functionName = ce.getFunctionName(); |
||||
StringBuilder errorMsg = new StringBuilder(functionName + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Error_Tips") + COLON); |
||||
for (int i = 0; i < rules.size(); i++) { |
||||
errorMsg.append("("); |
||||
if (rules.get(i).getParameterList().isEmpty()) { |
||||
errorMsg.append(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_No_Param")); |
||||
} |
||||
for (FunctionParameterType functionParameterType : rules.get(i).getParameterList()) { |
||||
errorMsg.append(getTypeString(functionParameterType)).append(","); |
||||
} |
||||
if (",".equals(errorMsg.charAt(errorMsg.length() - 1) + "")) { |
||||
errorMsg.deleteCharAt(errorMsg.length() - 1); |
||||
} |
||||
errorMsg.append(")"); |
||||
if (i != rules.size() - 1) { |
||||
errorMsg.append(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Or")); |
||||
} |
||||
} |
||||
return errorMsg.toString(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
return INVALID_FORMULA; |
||||
// alex:继续往下面走,expression为null时告知不合法公式
|
||||
} |
||||
} |
||||
|
||||
private static String getTypeString(FunctionParameterType type) { |
||||
switch (type) { |
||||
case NUMBER: |
||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Number"); |
||||
case STRING: |
||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_String"); |
||||
case ANY: |
||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Any"); |
||||
case DATE: |
||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Date"); |
||||
case BOOLEAN: |
||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Boolean"); |
||||
case ARRAY: |
||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Array"); |
||||
} |
||||
return StringUtils.EMPTY; |
||||
} |
||||
} |
@ -1,27 +1,97 @@
|
||||
package com.fr.design.mainframe.authority; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.parser.FunctionCall; |
||||
import com.fr.parser.StringLiteral; |
||||
import com.fr.script.Calculator; |
||||
import com.fr.stable.script.Node; |
||||
import org.jetbrains.annotations.Nullable; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.HashSet; |
||||
import java.util.Set; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
public class FormulaAuthorityChecker extends ElementAuthorityChecker<Formula> { |
||||
private static final Pattern FORMULA_PATTERN = Pattern.compile("^=SQL\\(\"(.+?)\","); |
||||
private static final Set<FormulaParser> CONNECTION_NAME_FORMULA_PARSER = new HashSet<>(); |
||||
private static final Set<FormulaParser> DATASET_NAME_FORMULA_PARSER = new HashSet<>(); |
||||
|
||||
static { |
||||
CONNECTION_NAME_FORMULA_PARSER.add(new FormulaParser("SQL", 0)); |
||||
DATASET_NAME_FORMULA_PARSER.add(new FormulaParser("VALUE", 0)); |
||||
} |
||||
|
||||
@Override |
||||
@Nullable |
||||
public Set<String> getNoAuthConnectionNames(Formula formula, Set<String> authConnectionNames) { |
||||
String content = formula.getContent(); |
||||
Matcher matcher = FORMULA_PATTERN.matcher(content); |
||||
if (matcher.find()) { |
||||
if (!authConnectionNames.contains(matcher.group(1))) { |
||||
return new HashSet<>(Arrays.asList(matcher.group(1))); |
||||
return getNoAuthNames(formula, CONNECTION_NAME_FORMULA_PARSER, authConnectionNames); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
@Nullable |
||||
Set<String> getNoAuthDatasetNames(Formula formula, Set<String> authDatasetNames) { |
||||
return getNoAuthNames(formula, DATASET_NAME_FORMULA_PARSER, authDatasetNames); |
||||
} |
||||
|
||||
private Set<String> getNoAuthNames(Formula formula, Set<FormulaParser> formulaParsers, Set<String> authNames) { |
||||
Set<String> noAuthNames = new HashSet<>(); |
||||
try { |
||||
FunctionCall functionCall = (FunctionCall) Calculator.createCalculator().parse(formula.getContent()).getConditionalExpression(); |
||||
handleNoAuthNames(functionCall, formulaParsers, authNames, noAuthNames); |
||||
} catch (Exception ignore) { |
||||
|
||||
} finally { |
||||
return noAuthNames; |
||||
} |
||||
} |
||||
|
||||
private void handleNoAuthNames(FunctionCall functionCall, Set<FormulaParser> formulaParsers, Set<String> authNames, Set<String> noAuthNames) { |
||||
for (FormulaParser formulaPattern : formulaParsers) { |
||||
String noAuthName = formulaPattern.getNoAuthName(functionCall, authNames); |
||||
if (noAuthName != null) { |
||||
noAuthNames.add(noAuthName); |
||||
} |
||||
} |
||||
Node[] nodes = functionCall.getArguments(); |
||||
if (nodes != null) { |
||||
for (int i = 0; i < nodes.length; i++) { |
||||
Node node = nodes[i]; |
||||
if (node instanceof FunctionCall) { |
||||
handleNoAuthNames((FunctionCall) node, formulaParsers, authNames, noAuthNames); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
static class FormulaParser { |
||||
//函数的名称
|
||||
public String name; |
||||
//要检测的位置
|
||||
public int index; |
||||
|
||||
|
||||
FormulaParser(String name, int index) { |
||||
this.name = name; |
||||
this.index = index; |
||||
} |
||||
|
||||
String getNoAuthName(FunctionCall functionCall, Set<String> authNames) { |
||||
if (functionCall.getName() != null && ComparatorUtils.equals(functionCall.getName().toUpperCase(), name)) { |
||||
Node node = functionCall.getArguments()[index]; |
||||
if (node instanceof StringLiteral) { |
||||
String stringLiteral = node.toString(); |
||||
if (stringLiteral.length() > 2) { |
||||
String value = stringLiteral.substring(1, stringLiteral.length() - 1); |
||||
if (!authNames.contains(value)) { |
||||
return value; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,55 @@
|
||||
package com.fr.design.report.fit; |
||||
|
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.design.report.fit.provider.AbstractFitAttrModelProvider; |
||||
|
||||
import com.fr.form.fit.common.LightTool; |
||||
import com.fr.form.fit.config.FormFitConfig; |
||||
import com.fr.form.main.Form; |
||||
import com.fr.report.fit.ReportFitAttr; |
||||
|
||||
|
||||
public class AdaptiveFrmFitAttrModel extends AbstractFitAttrModelProvider { |
||||
|
||||
public FitType[] getFitTypes() { |
||||
return new FitType[]{ |
||||
FitType.DOUBLE_FIT, |
||||
FitType.HORIZONTAL_FIT, |
||||
FitType.NOT_FIT |
||||
}; |
||||
} |
||||
|
||||
public String getFitName() { |
||||
return Toolkit.i18nText("Fine-Designer_Fit_Report_Scale_Method"); |
||||
} |
||||
|
||||
@Override |
||||
public String getModelName() { |
||||
return Toolkit.i18nText("Fine-Design_New_Decision_Report"); |
||||
} |
||||
|
||||
@Override |
||||
public ReportFitAttr getGlobalReportFitAttr() { |
||||
return FormFitConfig.getInstance().getNewFitAttr(); |
||||
} |
||||
|
||||
@Override |
||||
public void setGlobalReportFitAttr(ReportFitAttr reportFitAttr) { |
||||
FormFitConfig.getInstance().setNewFitAttr(reportFitAttr); |
||||
} |
||||
|
||||
@Override |
||||
public int getPriority() { |
||||
return 2; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isAvailable(JTemplate jTemplate) { |
||||
if (jTemplate.getTarget() instanceof Form) { |
||||
return LightTool.containNewFormFlag((Form) jTemplate.getTarget()); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,229 @@
|
||||
package com.fr.design.report.fit; |
||||
|
||||
import com.fr.design.ExtraDesignClassManager; |
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.gui.ibutton.UIRadioButton; |
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.report.fit.menupane.FitPreviewPane; |
||||
import com.fr.design.report.fit.menupane.FitRadioGroup; |
||||
import com.fr.design.report.fit.menupane.FontRadioGroup; |
||||
import com.fr.design.report.fit.provider.FitAttrModelProvider; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.report.fit.ReportFitAttr; |
||||
|
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.border.EmptyBorder; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.ItemListener; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.Comparator; |
||||
import java.util.Set; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import static com.fr.design.i18n.Toolkit.i18nText; |
||||
|
||||
public abstract class BaseFitAttrPane extends BasicBeanPane<ReportFitAttr> { |
||||
|
||||
protected JPanel contentJPanel; |
||||
protected UIComboBox itemChoose; |
||||
protected java.util.List<FitAttrModel> fitAttrModelList = new ArrayList<>(); |
||||
|
||||
public FontRadioGroup fontRadioGroup; |
||||
public FitRadioGroup adaptRadioGroup; |
||||
public JPanel attrJPanel; |
||||
public FitPreviewPane previewJPanel; |
||||
public FitAttrModel fitAttrModel; |
||||
|
||||
|
||||
protected BaseFitAttrPane() { |
||||
initFitAttrModel(); |
||||
} |
||||
|
||||
private void initFitAttrModel() { |
||||
fitAttrModelList.add(new FrmFitAttrModel()); |
||||
fitAttrModelList.add(new CptFitAttrModel()); |
||||
fitAttrModelList.add(new AdaptiveFrmFitAttrModel()); |
||||
|
||||
Set<FitAttrModelProvider> fitAttrModelProviders = ExtraDesignClassManager.getInstance().getArray(FitAttrModelProvider.XML_TAG); |
||||
|
||||
for (FitAttrModelProvider fitAttrModelProvider : fitAttrModelProviders) { |
||||
fitAttrModelList.add(fitAttrModelProvider); |
||||
} |
||||
|
||||
fitAttrModelList = fitAttrModelList.stream().sorted(Comparator.comparing(FitAttrModel::getPriority).reversed()).collect(Collectors.toList()); |
||||
} |
||||
|
||||
protected void populateModel(FitAttrModel fitAttrModel) { |
||||
this.fitAttrModel = fitAttrModel; |
||||
if (attrJPanel != null) { |
||||
contentJPanel.remove(attrJPanel); |
||||
} |
||||
if (previewJPanel != null) { |
||||
contentJPanel.remove(previewJPanel); |
||||
} |
||||
|
||||
fontRadioGroup = new FontRadioGroup(); |
||||
adaptRadioGroup = new FitRadioGroup(); |
||||
initAttrJPanel(); |
||||
initPreviewJPanel(); |
||||
} |
||||
|
||||
|
||||
protected void initAttrJPanel() { |
||||
int colCount = fitAttrModel.getFitTypes().length + 1; |
||||
Component[][] components = new Component[2][colCount]; |
||||
initFitRadioGroup(fontRadioGroup, i18nText("Fine-Designer_Fit-Font"), new String[]{i18nText("Fine-Designer_Fit"), i18nText("Fine-Designer_Fit-No")}, components[0]); |
||||
initFitRadioGroup(adaptRadioGroup, fitAttrModel.getFitName(), Arrays.stream(fitAttrModel.getFitTypes()).map(FitType::description).toArray(String[]::new), components[1]); |
||||
|
||||
double[] rowSize = new double[2]; |
||||
double[] columnSize = new double[colCount]; |
||||
for (int i = 0; i < rowSize.length; i++) { |
||||
rowSize[i] = 20; |
||||
} |
||||
for (int i = 0; i < columnSize.length; i++) { |
||||
if (i == 0) { |
||||
columnSize[i] = 80; |
||||
} else { |
||||
columnSize[i] = 100; |
||||
} |
||||
} |
||||
|
||||
attrJPanel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
attrJPanel.setBorder(new EmptyBorder(0, 100, 10, 100)); |
||||
contentJPanel.add(attrJPanel); |
||||
} |
||||
|
||||
private void initFitRadioGroup(FitRadioGroup fitRadioGroup, String name, String[] options, Component[] components) { |
||||
components[0] = new UILabel(name); |
||||
for (int i = 0; i < options.length; i++) { |
||||
|
||||
if (options[i] != null) { |
||||
UIRadioButton fontFitRadio = new UIRadioButton(options[i]); |
||||
fitRadioGroup.add(fontFitRadio); |
||||
components[i + 1] = fontFitRadio; |
||||
} else { |
||||
components[i + 1] = null; |
||||
} |
||||
} |
||||
fitRadioGroup.addActionListener(getPreviewActionListener()); |
||||
} |
||||
|
||||
protected ActionListener getPreviewActionListener() { |
||||
return new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
refreshPreviewJPanel(); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
protected void refreshPreviewJPanel() { |
||||
String previewIndex = getPreviewIndex(); |
||||
previewJPanel.refreshPreview(previewIndex, fontRadioGroup.isEnabled()); |
||||
} |
||||
|
||||
protected String getPreviewIndex() { |
||||
return getStateInPC(adaptRadioGroup.getSelectRadioIndex()) + "" + fontRadioGroup.getSelectRadioIndex(); |
||||
} |
||||
|
||||
protected void initPreviewJPanel() { |
||||
previewJPanel = new FitPreviewPane(); |
||||
contentJPanel.add(previewJPanel); |
||||
} |
||||
|
||||
protected int getStateInPC(int index) { |
||||
FitType[] fitTypes = fitAttrModel.getFitTypes(); |
||||
return fitTypes[index].getState(); |
||||
} |
||||
|
||||
protected int getOptionIndex(int state) { |
||||
FitType[] fitTypes = fitAttrModel.getFitTypes(); |
||||
for (int i = 0; i < fitTypes.length; i++) { |
||||
if (ComparatorUtils.equals(state, fitTypes[i].getState())) { |
||||
return i; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void populateBean(ReportFitAttr ob) { |
||||
fontRadioGroup.selectIndexButton(ob.isFitFont() ? 0 : 1); |
||||
adaptRadioGroup.selectIndexButton(getOptionIndex(ob.fitStateInPC())); |
||||
refreshPreviewJPanel(); |
||||
} |
||||
|
||||
@Override |
||||
public ReportFitAttr updateBean() { |
||||
ReportFitAttr reportFitAttr = new ReportFitAttr(); |
||||
reportFitAttr.setFitFont(fontRadioGroup.isFontFit()); |
||||
reportFitAttr.setFitStateInPC(getStateInPC(adaptRadioGroup.getSelectRadioIndex())); |
||||
return reportFitAttr; |
||||
} |
||||
|
||||
|
||||
public void setEnabled(boolean enabled) { |
||||
super.setEnabled(enabled); |
||||
fontRadioGroup.setEnabled(enabled); |
||||
adaptRadioGroup.setEnabled(enabled); |
||||
refreshPreviewJPanel(); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return i18nText("Fine-Designer_PC_Element_Case_Fit_Attr"); |
||||
} |
||||
|
||||
protected abstract String[] getItemNames(); |
||||
|
||||
protected void initComponents() { |
||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
||||
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
||||
contentJPanel = new JPanel(); |
||||
contentJPanel.setLayout(FRGUIPaneFactory.createCenterFlowLayout()); |
||||
this.add(contentJPanel); |
||||
initItemChoose(); |
||||
} |
||||
|
||||
|
||||
private void initItemChoose() { |
||||
JPanel chooseJPanel = new JPanel(); |
||||
chooseJPanel.setLayout(FRGUIPaneFactory.createLabelFlowLayout()); |
||||
ItemListener itemListener = getItemListener(); |
||||
itemChoose = new UIComboBox(getItemNames()); |
||||
itemChoose.addItemListener(itemListener); |
||||
UILabel belowSetLabel = new UILabel(i18nText("Fine-Design_Report_Blow_Set")); |
||||
JPanel buttonPane = GUICoreUtils.createFlowPane(new Component[]{ |
||||
belowSetLabel, itemChoose}, FlowLayout.LEFT, 0, 0); |
||||
chooseJPanel.add(buttonPane); |
||||
chooseJPanel.setPreferredSize(new Dimension(500, 50)); |
||||
JPanel jPanel = new JPanel(); |
||||
jPanel.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
jPanel.add(chooseJPanel, BorderLayout.WEST); |
||||
|
||||
contentJPanel.add(jPanel); |
||||
} |
||||
|
||||
|
||||
protected abstract ItemListener getItemListener(); |
||||
|
||||
|
||||
public void populate(ReportFitAttr reportFitAttr) { |
||||
|
||||
} |
||||
|
||||
protected void refresh() { |
||||
validate(); |
||||
repaint(); |
||||
revalidate(); |
||||
} |
||||
} |
@ -0,0 +1,51 @@
|
||||
package com.fr.design.report.fit; |
||||
|
||||
|
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.report.fit.ReportFitAttr; |
||||
import com.fr.report.fit.ReportFitConfig; |
||||
|
||||
|
||||
public class CptFitAttrModel implements FitAttrModel { |
||||
|
||||
@Override |
||||
public FitType[] getFitTypes() { |
||||
return new FitType[]{ |
||||
FitType.HORIZONTAL_FIT, |
||||
FitType.DOUBLE_FIT, |
||||
FitType.NOT_FIT |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public String getFitName() { |
||||
return Toolkit.i18nText("Fine-Designer_Fit-Element"); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getModelName() { |
||||
return Toolkit.i18nText("Fine-Design_Basic_Plain_Report"); |
||||
} |
||||
|
||||
@Override |
||||
public ReportFitAttr getGlobalReportFitAttr() { |
||||
return ReportFitConfig.getInstance().getCptFitAttr(); |
||||
} |
||||
|
||||
@Override |
||||
public void setGlobalReportFitAttr(ReportFitAttr reportFitAttr) { |
||||
ReportFitConfig.getInstance().setCptFitAttr(reportFitAttr); |
||||
} |
||||
|
||||
@Override |
||||
public int getPriority() { |
||||
return 0; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isAvailable(JTemplate jTemplate) { |
||||
return jTemplate.isJWorkBook(); |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
package com.fr.design.report.fit; |
||||
|
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.report.fit.ReportFitAttr; |
||||
|
||||
public interface FitAttrModel { |
||||
/** |
||||
* @Description 名称,比如:普通报表、决策报表等 |
||||
**/ |
||||
String getModelName(); |
||||
|
||||
/** |
||||
* @Description 自适应选项的名称,比如返回:表格 |
||||
**/ |
||||
String getFitName(); |
||||
|
||||
/** |
||||
* @Description 自适应选项 |
||||
**/ |
||||
FitType[] getFitTypes(); |
||||
|
||||
|
||||
/** |
||||
* @Description 获取全局的自适应属性 |
||||
**/ |
||||
ReportFitAttr getGlobalReportFitAttr(); |
||||
|
||||
/** |
||||
* @Description 设置全局的自适应属性 |
||||
* @param: reportFitAttr |
||||
**/ |
||||
void setGlobalReportFitAttr(ReportFitAttr reportFitAttr); |
||||
|
||||
/** |
||||
* @Description 优先级 |
||||
**/ |
||||
int getPriority(); |
||||
|
||||
/** |
||||
* @Description 是否可用 |
||||
* @param: jTemplate |
||||
**/ |
||||
boolean isAvailable(JTemplate jTemplate); |
||||
} |
@ -0,0 +1,53 @@
|
||||
package com.fr.design.report.fit; |
||||
|
||||
|
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.report.fit.ReportFitAttr; |
||||
import com.fr.report.fit.ReportFitConfig; |
||||
|
||||
|
||||
public class FrmFitAttrModel implements FitAttrModel { |
||||
|
||||
|
||||
@Override |
||||
public String getModelName() { |
||||
return Toolkit.i18nText("Fine-Design_Basic_Decision_Report"); |
||||
} |
||||
|
||||
@Override |
||||
public String getFitName() { |
||||
return Toolkit.i18nText("Fine-Designer_Fit-Element"); |
||||
} |
||||
|
||||
public FitType[] getFitTypes() { |
||||
return new FitType[]{ |
||||
FitType.DEFAULT, |
||||
FitType.HORIZONTAL_FIT, |
||||
FitType.DOUBLE_FIT, |
||||
FitType.NOT_FIT |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public ReportFitAttr getGlobalReportFitAttr() { |
||||
return ReportFitConfig.getInstance().getFrmFitAttr(); |
||||
} |
||||
|
||||
@Override |
||||
public void setGlobalReportFitAttr(ReportFitAttr reportFitAttr) { |
||||
ReportFitConfig.getInstance().setFrmFitAttr(reportFitAttr); |
||||
} |
||||
|
||||
@Override |
||||
public int getPriority() { |
||||
return 1; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isAvailable(JTemplate jTemplate) { |
||||
return !jTemplate.isJWorkBook(); |
||||
} |
||||
|
||||
|
||||
} |
@ -1,55 +1,92 @@
|
||||
package com.fr.design.report.fit.menupane; |
||||
|
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.design.report.fit.BaseFitAttrPane; |
||||
import com.fr.design.report.fit.FitAttrModel; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.report.fit.FitProvider; |
||||
import com.fr.report.fit.ReportFitAttr; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.BoxLayout; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
|
||||
/** |
||||
* Created by 夏翔 on 2016/6/24. |
||||
*/ |
||||
public class TemplateFitAttrPane extends BasicBeanPane<ReportFitAttr> { |
||||
private TemplateBrowserFitAttrPane attrPane; |
||||
|
||||
public class TemplateFitAttrPane extends BaseFitAttrPane { |
||||
|
||||
public TemplateFitAttrPane() { |
||||
private JTemplate jwb; |
||||
|
||||
public TemplateFitAttrPane(JTemplate jwb) { |
||||
this.jwb = jwb; |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
||||
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
||||
attrPane = new TemplateBrowserFitAttrPane(); |
||||
this.add(attrPane); |
||||
@Override |
||||
protected void initComponents() { |
||||
super.initComponents(); |
||||
for (FitAttrModel fitAttrModel : fitAttrModelList) { |
||||
if (fitAttrModel.isAvailable(jwb)) { |
||||
populateModel(fitAttrModel); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(ReportFitAttr reportFitAttr) { |
||||
if (reportFitAttr == null) { |
||||
itemChoose.setSelectedItem(Toolkit.i18nText("Fine-Design_Report_Using_Server_Report_View_Settings")); |
||||
} else { |
||||
itemChoose.setSelectedItem(Toolkit.i18nText("Fine-Design_Report_I_Want_To_Set_Single")); |
||||
} |
||||
populate(reportFitAttr); |
||||
} |
||||
|
||||
public void populate(ReportFitAttr reportFitAttr) { |
||||
if (reportFitAttr == null) { |
||||
reportFitAttr = fitAttrModel.getGlobalReportFitAttr(); |
||||
} |
||||
|
||||
/** |
||||
* 展示界面 |
||||
* |
||||
* @param fitAttr 自适应属性 |
||||
*/ |
||||
public void populateBean(ReportFitAttr fitAttr) { |
||||
attrPane.populateBean(fitAttr); |
||||
super.setEnabled(isTemplateSingleSet()); |
||||
super.populateBean(reportFitAttr); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 提交数据 |
||||
* |
||||
* @return 界面上的更新数据 |
||||
*/ |
||||
public ReportFitAttr updateBean() { |
||||
return attrPane.updateBean(); |
||||
if (!isTemplateSingleSet()) { |
||||
return null; |
||||
} else { |
||||
return super.updateBean(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected String[] getItemNames() { |
||||
return new String[]{Toolkit.i18nText("Fine-Design_Report_Using_Server_Report_View_Settings"), |
||||
Toolkit.i18nText("Fine-Design_Report_I_Want_To_Set_Single")}; |
||||
} |
||||
|
||||
@Override |
||||
protected ItemListener getItemListener() { |
||||
return new ItemListener() { |
||||
@Override |
||||
public void itemStateChanged(ItemEvent e) { |
||||
if (e.getStateChange() == ItemEvent.SELECTED) { |
||||
if(isTemplateSingleSet()){ |
||||
if (jwb != null) { |
||||
FitProvider wbTpl = (FitProvider) jwb.getTarget(); |
||||
ReportFitAttr fitAttr = wbTpl.getReportFitAttr(); |
||||
populate(fitAttr); |
||||
} |
||||
}else { |
||||
populate(fitAttrModel.getGlobalReportFitAttr()); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* 标题 |
||||
* |
||||
* @return 标题 |
||||
*/ |
||||
protected String title4PopupWindow() { |
||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Designer_PC_Fit_Attr"); |
||||
private boolean isTemplateSingleSet() { |
||||
return ComparatorUtils.equals(Toolkit.i18nText("Fine-Design_Report_I_Want_To_Set_Single"), itemChoose.getSelectedItem()); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.design.report.fit.provider; |
||||
|
||||
import com.fr.stable.fun.mark.API; |
||||
|
||||
|
||||
@API(level = FitAttrModelProvider.CURRENT_LEVEL) |
||||
public abstract class AbstractFitAttrModelProvider implements FitAttrModelProvider { |
||||
|
||||
@Override |
||||
public int currentAPILevel() { |
||||
return CURRENT_LEVEL; |
||||
} |
||||
|
||||
@Override |
||||
public String mark4Provider() { |
||||
return getClass().getName(); |
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
package com.fr.design.report.fit.provider; |
||||
|
||||
|
||||
import com.fr.design.report.fit.FitAttrModel; |
||||
import com.fr.stable.fun.mark.Mutable; |
||||
|
||||
|
||||
public interface FitAttrModelProvider extends Mutable, FitAttrModel { |
||||
String XML_TAG = "FitAttrModelProvider"; |
||||
int CURRENT_LEVEL = 1; |
||||
} |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 54 KiB |
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 52 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 32 KiB |
@ -0,0 +1,78 @@
|
||||
package com.fr.design.webattr; |
||||
|
||||
import com.fr.config.Configuration; |
||||
import com.fr.design.report.fit.BaseFitAttrPane; |
||||
import com.fr.design.report.fit.FitAttrModel; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.report.fit.ReportFitAttr; |
||||
import com.fr.report.fit.ReportFitConfig; |
||||
import com.fr.transaction.Configurations; |
||||
import com.fr.transaction.Worker; |
||||
|
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
|
||||
|
||||
public class ServerFitAttrPane extends BaseFitAttrPane { |
||||
|
||||
public ServerFitAttrPane() { |
||||
super(); |
||||
initComponents(); |
||||
} |
||||
|
||||
@Override |
||||
protected void initComponents() { |
||||
super.initComponents(); |
||||
populateModel(fitAttrModelList.get(0)); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void populateBean(ReportFitAttr reportFitAttr) { |
||||
reportFitAttr = fitAttrModel.getGlobalReportFitAttr(); |
||||
super.populateBean(reportFitAttr); |
||||
} |
||||
|
||||
|
||||
public ReportFitAttr updateBean() { |
||||
ReportFitAttr reportFitAttr = super.updateBean(); |
||||
Configurations.update(new Worker() { |
||||
@Override |
||||
public void run() { |
||||
fitAttrModel.setGlobalReportFitAttr(reportFitAttr); |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends Configuration>[] targets() { |
||||
return new Class[]{ReportFitConfig.class}; |
||||
} |
||||
}); |
||||
return null; |
||||
|
||||
} |
||||
|
||||
@Override |
||||
protected String[] getItemNames() { |
||||
return fitAttrModelList.stream().map(FitAttrModel::getModelName).toArray(String[]::new); |
||||
} |
||||
|
||||
@Override |
||||
protected ItemListener getItemListener() { |
||||
ServerFitAttrPane self = this; |
||||
return new ItemListener() { |
||||
@Override |
||||
public void itemStateChanged(ItemEvent e) { |
||||
if (e.getStateChange() == ItemEvent.SELECTED) { |
||||
for (FitAttrModel fitAttrModel : fitAttrModelList) { |
||||
if (ComparatorUtils.equals(e.getItem(), fitAttrModel.getModelName())) { |
||||
self.populateModel(fitAttrModel); |
||||
populateBean(null); |
||||
refresh(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
||||
|