From 6b5301b490c10a8963311e5ce3dda72fade67770 Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 20 May 2020 21:41:53 +0800 Subject: [PATCH] REPORT-31834 && REPORT-31874 --- .../com/fr/design/formula/FormulaPane.java | 34 ++++++++++++++++--- .../design/os/impl/DatabaseDialogAction.java | 12 ++++--- .../com/fr/design/os/impl/PMDialogAction.java | 11 +++--- .../fr/design/formula/FormulaPaneTest.java | 25 ++++++++++++++ 4 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 designer-base/src/test/java/com/fr/design/formula/FormulaPaneTest.java diff --git a/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java b/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java index 32e7030bb6..9259248ac6 100644 --- a/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java +++ b/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java @@ -2,7 +2,6 @@ package com.fr.design.formula; import com.fr.base.BaseFormula; import com.fr.base.BaseUtils; -import com.fr.base.FRContext; import com.fr.design.actions.UpdateAction; import com.fr.design.border.UIRoundedBorder; import com.fr.design.constants.UIConstants; @@ -25,7 +24,6 @@ import com.fr.log.FineLoggerFactory; import com.fr.parser.FRLexer; import com.fr.parser.FRParser; import com.fr.stable.EncodeConstants; -import com.fr.stable.ProductConstants; import com.fr.stable.StringUtils; import com.fr.stable.script.Expression; @@ -54,7 +52,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; -import java.util.Locale; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; /** * 公式编辑面板 @@ -413,14 +414,19 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { if (keyWord.length() != 0) { NameAndDescription[] descriptions = FunctionConstants.ALL.getDescriptions(); int lengthOfDes = descriptions.length; + List list = new ArrayList<>(); for (int i = 0; i < lengthOfDes; i++) { NameAndDescription and = descriptions[i]; String functionName = and.searchResult(keyWord, findDescription); if (StringUtils.isNotBlank(functionName)) { - listModel.addElement(functionName); + list.add(functionName); } } + Collections.sort(list, new SimilarComparator(keyWord)); + for (String name : list) { + listModel.addElement(name); + } if (!listModel.isEmpty()) { tipsList.setSelectedIndex(0); @@ -969,6 +975,26 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { } } + public static class SimilarComparator implements Comparator { + + private String searchKey; + + public SimilarComparator(String searchKey) { + this.searchKey = searchKey.toLowerCase(); + } + + @Override + public int compare(String o1, String o2) { + if (o1.toLowerCase().startsWith(searchKey)) { + return -1; + } + if (o2.toLowerCase().startsWith(searchKey)) { + return 1; + } + return o2.compareTo(o1); + } + } + public static class TextFolderUserObject { private String text; diff --git a/designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java b/designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java index 7db0004937..acd9068974 100644 --- a/designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java +++ b/designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java @@ -24,11 +24,13 @@ public class DatabaseDialogAction implements OSBasedAction { @Override public void execute(Object... objects) { - if (ServerPreferenceConfig.getInstance().isUseUniverseDBM() && !OperatingSystem.isLinux()) { - UniversalDatabaseOpener.showUniverseDatabaseDialog(); - } else { - openDesignDatabaseManager(); - } +// if (ServerPreferenceConfig.getInstance().isUseUniverseDBM() && !OperatingSystem.isLinux()) { +// UniversalDatabaseOpener.showUniverseDatabaseDialog(); +// } else { +// } + // 直接这里屏蔽掉 防止有设置过 导致配置数据库值为true 即使设置界面屏蔽也没用 + openDesignDatabaseManager(); + } private void openDesignDatabaseManager() { diff --git a/designer-base/src/main/java/com/fr/design/os/impl/PMDialogAction.java b/designer-base/src/main/java/com/fr/design/os/impl/PMDialogAction.java index 7e6eccf749..3f2f097283 100644 --- a/designer-base/src/main/java/com/fr/design/os/impl/PMDialogAction.java +++ b/designer-base/src/main/java/com/fr/design/os/impl/PMDialogAction.java @@ -21,11 +21,10 @@ public class PMDialogAction implements OSBasedAction { DesignUtils.visitEnvServerByParameters( PLUGIN_MANAGER_ROUTE,null,null); return; } -// if (ServerPreferenceConfig.getInstance().isUseOptimizedUPM() && !OperatingSystem.isLinux()) { -// UpmFinder.showUPMDialog(); -// } else { -// } - // 直接这里屏蔽掉 防止有设置过 导致配置数据库值为true 即使设置界面屏蔽也没用 - WebViewDlgHelper.createPluginDialog(); + if (ServerPreferenceConfig.getInstance().isUseOptimizedUPM() && !OperatingSystem.isLinux()) { + UpmFinder.showUPMDialog(); + } else { + WebViewDlgHelper.createPluginDialog(); + } } } diff --git a/designer-base/src/test/java/com/fr/design/formula/FormulaPaneTest.java b/designer-base/src/test/java/com/fr/design/formula/FormulaPaneTest.java new file mode 100644 index 0000000000..c82423daa3 --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/formula/FormulaPaneTest.java @@ -0,0 +1,25 @@ +package com.fr.design.formula; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; + + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/5/20 + */ +public class FormulaPaneTest extends TestCase { + + @Test + public void testSimilarComparator() { + String[] strs = new String[] {"ScriptEval", "SPLIT", "SUMPRECISE"}; + String[] result = new String[] {"SPLIT", "ScriptEval", "SUMPRECISE"}; + Arrays.sort(strs, new FormulaPane.SimilarComparator("sp")); + Assert.assertArrayEquals(result, strs); + } + +} \ No newline at end of file