Browse Source

Pull request #2330: REPORT-39757 AlphaFine无法搜索含空格的模板名称

Merge in DESIGN/design from ~YYMING/design:release/10.0 to release/10.0

* commit '9b25fb0625ff48a20f042c7881331cdc217f47ff':
  REPORT-39757 处理搜索词高亮
  REPORT-39757 少个空格
  REPORT-39757 AlphaFine无法搜索含空格的模板名称
feature/big-screen
Yyming 4 years ago
parent
commit
be61530ffb
  1. 7
      designer-base/src/main/java/com/fr/design/DesignerEnvManager.java
  2. 2
      designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java
  3. 4
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/BottomModel.java
  4. 24
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java
  5. 44
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  6. 2
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/PluginPreviewPane.java
  7. 4
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/RobotPreviewPane.java
  8. 12
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java
  9. 5
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java
  10. 79
      designer-realize/src/test/java/com.fr/design/mainframe/alphafine/search/manager/impl/FileSearchManagerTest.java
  11. 23
      designer-realize/src/test/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRenderTest.java

7
designer-base/src/main/java/com/fr/design/DesignerEnvManager.java

@ -218,14 +218,9 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
if (needCheckEnv) {
checkNameEnvMap();
}
GeneralContext.addEnvChangedListener(new EnvChangedListener() {
@Override
public void envChanged() {
GeneralContext.addEnvChangedListener(() -> {
designerEnvManager.setCurrentDirectoryPrefix(FILEFactory.ENV_PREFIX);
designerEnvManager.setDialogCurrentDirectory(ProjectConstants.REPORTLETS_NAME);
}
});
}

2
designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java

@ -218,7 +218,7 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
paramTexts[0] = SqlUtils.tryPureSqlText(sqlTextPane.getText());
paramTexts[1] = SqlUtils.tryPureSqlText(pageQuery);
List<ParameterProvider> existParameterList = editorPane.update();
Parameter[] ps = existParameterList == null ? new Parameter[0] : existParameterList.toArray(new Parameter[existParameterList.size()]);
Parameter[] ps = existParameterList == null ? new Parameter[0] : existParameterList.toArray(new Parameter[0]);
editorPane.populate(ParameterUtils.analyzeAndUnionParameters(paramTexts, ps));
}

4
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/BottomModel.java

@ -49,9 +49,7 @@ public class BottomModel extends AlphaCellModel {
public void doAction() {
try {
Desktop.getDesktop().browse(new URI(AlphaFineConstants.ALPHA_GO_TO_FORUM));
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage());
} catch (URISyntaxException e) {
} catch (IOException | URISyntaxException e) {
FineLoggerFactory.getLogger().error(e.getMessage());
}
}

24
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java

@ -106,11 +106,10 @@ public class ContentCellRender implements ListCellRenderer<Object> {
if (strings == null) {
return modelName;
}
for (int i = 0; i < strings.length; i++) {
String primaryStr = getReplacedString(modelName, strings[i]);
modelName = modelName.replaceAll("(?i)" + strings[i], "|<font color=" + AlphaFineConstants.HIGH_LIGHT_COLOR + ">" + strings[i] + "</font>|");
for (String string : strings) {
String primaryStr = getReplacedString(modelName, string);
if (StringUtils.isNotEmpty(primaryStr)) {
modelName = modelName.replaceAll(strings[i], primaryStr);
modelName = modelName.replaceAll("(?i)" + primaryStr, "|<font color=" + AlphaFineConstants.HIGH_LIGHT_COLOR + ">" + primaryStr + "</font>|");
}
}
modelName = "<html><head><style> .style{" +
@ -121,13 +120,24 @@ public class ContentCellRender implements ListCellRenderer<Object> {
return modelName;
}
private String getReplacedString(String modelName, String string) {
int index = modelName.toLowerCase().indexOf(string.toLowerCase());
//需要考虑modelName有空格的情况
//比如现在是work boo k 搜索词是workb,应该要替换的部分是work b
//先去掉空格进行匹配
String noBlackName = modelName.replaceAll(StringUtils.BLANK, StringUtils.EMPTY).toLowerCase();
int index = noBlackName.indexOf(string.toLowerCase());
if (index == -1) {
return StringUtils.EMPTY;
}
return modelName.substring(index, index + string.length());
StringBuilder result = new StringBuilder();
int count = 0;
while (count < string.length()) {
char pos = modelName.charAt(index++);
result.append(pos);
count += pos == ' ' ? 0 : 1;
}
return result.toString();
}

44
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java

@ -162,10 +162,7 @@ public class AlphaFineDialog extends UIDialog {
* @return
*/
public static AWTEventListener listener() {
return new AWTEventListener() {
@Override
public void eventDispatched(AWTEvent event) {
return event -> {
if (event instanceof KeyEvent) {
KeyEvent e = (KeyEvent) event;
KeyStroke keyStroke = (KeyStroke) KeyStroke.getAWTKeyStrokeForEvent(e);
@ -175,7 +172,6 @@ public class AlphaFineDialog extends UIDialog {
}
}
}
};
}
@ -300,7 +296,7 @@ public class AlphaFineDialog extends UIDialog {
if (winSize.width > screenSize.width) {
winSize.width = screenSize.width;
}
//这里设置位置:水平居中,竖直偏上
//这里设置位置:水平居中,竖直偏上
win.setLocation((screenSize.width - winSize.width) / 2, (screenSize.height - winSize.height) / AlphaFineConstants.SHOW_SIZE);
}
@ -513,7 +509,8 @@ public class AlphaFineDialog extends UIDialog {
* @return
*/
private String getStoreText(String searchText) {
setStoreText(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
//这里也需要先做一个去除不需要空格的处理
setStoreText((searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1)).replaceAll(StringUtils.BLANK, StringUtils.EMPTY));
return storeText;
}
@ -616,9 +613,7 @@ public class AlphaFineDialog extends UIDialog {
rightSearchResultPane.removeAll();
try {
rightSearchResultPane.add(new FilePreviewPane(get()));
} catch (InterruptedException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (ExecutionException e) {
} catch (InterruptedException | ExecutionException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
validate();
@ -651,9 +646,7 @@ public class AlphaFineDialog extends UIDialog {
rightSearchResultPane.add(new FilePreviewPane(get()));
validate();
repaint();
} catch (InterruptedException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (ExecutionException e) {
} catch (InterruptedException | ExecutionException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
@ -819,9 +812,7 @@ public class AlphaFineDialog extends UIDialog {
}
});
Timer timer = new Timer(TIMER_DELAY, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Timer timer = new Timer(TIMER_DELAY, e -> {
if (!alreadyInitHot && StringUtils.isEmpty(searchTextField.getText())) {
alreadyInitHot = true;
removeSearchResult();
@ -867,8 +858,6 @@ public class AlphaFineDialog extends UIDialog {
if (beforeSearchStr.equals(searchTextField.getText()) && beforeSearchStr.length() != 0) {
alreadyInitHot = false;
}
}
});
timer.start();
}
@ -880,7 +869,7 @@ public class AlphaFineDialog extends UIDialog {
searchText = searchText.toLowerCase();
Pattern p = Pattern.compile(AlphaFineConstants.SPECIAL_CHARACTER_REGEX);
Matcher m = p.matcher(searchText);
searchText = m.replaceAll("").trim().replaceAll(" ", "");
searchText = m.replaceAll(StringUtils.EMPTY).trim().replaceAll(StringUtils.BLANK, StringUtils.EMPTY);
if (searchText.length() == 0) {
return null;
}
@ -901,9 +890,7 @@ public class AlphaFineDialog extends UIDialog {
* 当鼠标在搜索界面边界外点击时触发
*/
private void initAWTEventListener() {
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
@Override
public void eventDispatched(AWTEvent event) {
Toolkit.getDefaultToolkit().addAWTEventListener(event -> {
if (!AlphaFineDialog.this.isVisible()) {
return;
}
@ -919,13 +906,12 @@ public class AlphaFineDialog extends UIDialog {
}
}
}
}
}, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
}
@Override
public void checkValid() throws Exception {
//不处理
//不处理
}
/**
@ -948,15 +934,12 @@ public class AlphaFineDialog extends UIDialog {
if (cellModel instanceof BottomModel) {
return;
}
Thread sendThread = new Thread(new Runnable() {
@Override
public void run() {
Thread sendThread = new Thread(() -> {
if (StringUtils.isNotEmpty(storeText)) {
RecentSearchManager searchManager = RecentSearchManager.getInstance();
searchManager.addModel(storeText, cellModel);
sendDataToServer(storeText, cellModel);
}
}
});
sendThread.start();
}
@ -1182,13 +1165,10 @@ public class AlphaFineDialog extends UIDialog {
}
});
addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
addListSelectionListener(e -> {
if (!e.getValueIsAdjusting() && getSelectedValue() != null) {
showResult(getSelectedValue());
}
}
});
addMouseMotionListener(new MouseMotionListener() {

2
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/PluginPreviewPane.java

@ -49,7 +49,7 @@ public class PluginPreviewPane extends JPanel {
nameLabel.setBackground(AlphaFineConstants.BLUE);
nameLabel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20));
line.setBorder(BorderFactory.createEmptyBorder(20, 0, 10, 0));
String price0 = price == 0 ? com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Collect_Information_free") : "¥" + String.valueOf(price);
String price0 = price == 0 ? com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Collect_Information_free") : "¥" + price;
UILabel priceLabel = new UILabel(price0);
priceLabel.setForeground(AlphaFineConstants.RED);
priceLabel.setFont(AlphaFineConstants.MEDIUM_FONT);

4
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/RobotPreviewPane.java

@ -61,9 +61,7 @@ public class RobotPreviewPane extends JPanel {
.replaceAll("'\\)", StringUtils.EMPTY);
try {
Desktop.getDesktop().browse(new URI(AlphaFineConstants.ALPHA_PREVIEW + URLEncoder.encode(s, EncodeConstants.ENCODING_UTF_8)));
} catch (IOException e1) {
FineLoggerFactory.getLogger().error(e1.getMessage());
} catch (URISyntaxException e1) {
} catch (IOException | URISyntaxException e1) {
FineLoggerFactory.getLogger().error(e1.getMessage());
}
}

12
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java

@ -33,7 +33,7 @@ public class FileSearchManager implements AlphaFineSearchProvider {
private FileNode[] fileNodes = null;
//停止搜索
//隐藏的搜索功能,可根据特殊的字符标记判断搜索分类
//隐藏的搜索功能,可根据特殊的字符标记判断搜索分类
private boolean isContainCpt = true;
private boolean isContainFrm = true;
@ -108,20 +108,22 @@ public class FileSearchManager implements AlphaFineSearchProvider {
private void doSearch(String searchText) {
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainTemplate()) {
for (FileNode node : fileNodes) {
if (node.getName().toLowerCase().contains(searchText)) {
String name = node.getName().toLowerCase();
name = name.replaceAll(StringUtils.BLANK, StringUtils.EMPTY);
if (name.contains(searchText)) {
FileModel model = new FileModel(node.getName(), node.getEnvPath());
if (!AlphaFineHelper.getFilterResult().contains(model)) {
AlphaFineHelper.checkCancel();
filterModelList.add(model);
}
}
}
}
}
/**
* 搜索模板内容
*
* @param searchText
*/
private void doFileContentSearch(String searchText) {
@ -140,10 +142,10 @@ public class FileSearchManager implements AlphaFineSearchProvider {
private String dealWithSearchText(String searchText) {
if (searchText.startsWith(FRM_PREFIX)) {
isContainCpt = false;
searchText = searchText.substring(MARK_LENGTH, searchText.length());
searchText = searchText.substring(MARK_LENGTH);
} else if (searchText.startsWith(CPT_PREFIX)) {
isContainFrm = false;
searchText = searchText.substring(MARK_LENGTH, searchText.length());
searchText = searchText.substring(MARK_LENGTH);
}
return searchText;
}

5
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java

@ -42,10 +42,7 @@ public class SegmentationManager {
count = count + 1;
}
}
if (count >= MAX_CHINESE_CHARACTERS_NUM) {
return true;
}
return false;
return count >= MAX_CHINESE_CHARACTERS_NUM;
}
/**

79
designer-realize/src/test/java/com.fr/design/mainframe/alphafine/search/manager/impl/FileSearchManagerTest.java

@ -0,0 +1,79 @@
package com.fr.design.mainframe.alphafine.search.manager.impl;
import com.fr.base.FRContext;
import com.fr.base.extension.FileExtension;
import com.fr.design.DesignerEnvManager;
import com.fr.design.actions.help.alphafine.AlphaFineConfigManager;
import com.fr.design.mainframe.alphafine.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.file.filetree.FileNode;
import com.fr.invoke.Reflect;
import com.fr.stable.project.ProjectConstants;
import com.fr.web.core.SessionPoolManager;
import com.fr.web.utils.WebUtils;
import org.easymock.EasyMock;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
/**
* @author Yyming
* @version 10.0
* Created by Yyming on 2020/9/15
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({AlphaFineHelper.class,DesignerEnvManager.class})
@SuppressStaticInitializationFor("com.fr.design.mainframe.alphafine.AlphaFineHelper")
public class FileSearchManagerTest {
@Test
public void doSearch() {
String searchText = "workb";
FileSearchManager instance = FileSearchManager.getInstance();
FileNode fileNode1 = EasyMock.createMock(FileNode.class);
FileNode fileNode2 = EasyMock.createMock(FileNode.class);
EasyMock.expect(fileNode1.getName()).andReturn("workbook").anyTimes();
EasyMock.expect(fileNode2.getName()).andReturn("work book").anyTimes();
EasyMock.expect(fileNode1.getEnvPath()).andReturn("").anyTimes();
EasyMock.expect(fileNode2.getEnvPath()).andReturn("").anyTimes();
EasyMock.replay(fileNode1,fileNode2);
FileNode[] fileNodes = { fileNode1, fileNode2 };
Reflect.on(instance).set("fileNodes",fileNodes);
AlphaFineConfigManager configManager = EasyMock.createMock(AlphaFineConfigManager.class);
EasyMock.expect(configManager.isContainTemplate()).andReturn(true).anyTimes();
EasyMock.replay(configManager);
DesignerEnvManager manager = EasyMock.createMock(DesignerEnvManager.class);
EasyMock.expect(manager.getAlphaFineConfigManager()).andReturn(configManager).anyTimes();
EasyMock.replay(manager);
PowerMock.mockStatic(DesignerEnvManager.class);
DesignerEnvManager.getEnvManager();
PowerMock.expectLastCall().andReturn(manager).anyTimes();
PowerMock.replay(DesignerEnvManager.class);
List<AlphaCellModel> list = new ArrayList<>();
PowerMock.mockStatic(AlphaFineHelper.class);
AlphaFineHelper.getFilterResult();
PowerMock.expectLastCall().andReturn(list).anyTimes();
AlphaFineHelper.findFolderName("");
PowerMock.expectLastCall().andReturn("").anyTimes();
AlphaFineHelper.checkCancel();
PowerMock.expectLastCall().andVoid().anyTimes();
PowerMock.replay(AlphaFineHelper.class);
SearchResult alphaCellModels = new SearchResult();
Reflect.on(instance).set("filterModelList",alphaCellModels);
Reflect.on(instance).call("doSearch",searchText);
assertEquals(alphaCellModels.size(),2);
}
}

23
designer-realize/src/test/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRenderTest.java

@ -0,0 +1,23 @@
package com.fr.design.mainframe.alphafine.cell.render;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Yyming
* @version 10.0
* Created by Yyming on 2020/9/16
*/
public class ContentCellRenderTest {
@Test
public void highLightModelName() {
String searchText = "workb";
ContentCellRender contentCellRender = new ContentCellRender(searchText,new String[]{searchText});
String workbook = contentCellRender.highLightModelName("workbook", new String[]{searchText});
assertTrue(workbook.endsWith("workb</font>ook</body></HTML>"));
workbook = contentCellRender.highLightModelName("work book", new String[]{searchText});
assertTrue(workbook.endsWith("work b</font>ook</body></HTML>"));
}
}
Loading…
Cancel
Save