Browse Source

REPORT-44961 【10.0.12冒烟】附件模板打开设计器卡死,且布局发生变化

【问题原因】带有数据字典的表单控件,在选中的时候会去连接获取字段信息,当系统中有同名数据连接但是无法连接到数据库的时候,会发生假死。如果没有这个数据连接的名字,那么会直接报错不会假死。主要还是这个数据字典获取数据的操作是耗时操作,不应该在UI线程进行耗时操作。
【改动思路】主要分为两部分,第一是将原本的tdChange()方法中的耗时操作放到SwingWorker中的工作线程中,这样的话即使后台数据连接失败,设计器也不会一直阻塞直到重连超时;第二是应产品的要求,将选中控件就会去请求连接并获取属于当前控件的列名这部分逻辑,修改为用户点击右侧面板中的数据字典旁边的button的时候才会去请求连接,并更换当前数据字典中的列名
research/11.0
Yvan 4 years ago
parent
commit
21c4355bcb
  1. 1
      designer-base/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleDictionaryEditor.java
  2. 4
      designer-base/src/main/java/com/fr/design/present/dict/DictionaryPane.java
  3. 103
      designer-base/src/main/java/com/fr/design/present/dict/TableDataDictPane.java

1
designer-base/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleDictionaryEditor.java

@ -21,6 +21,7 @@ public class AccessibleDictionaryEditor extends UneditableAccessibleEditor {
protected void showEditorPane() {
if (dictPane == null) {
dictPane = new DictionaryPane();
dictPane.setNeedTableDataChange(true);
}
BasicDialog dlg = dictPane.showWindow(SwingUtilities.getWindowAncestor(this));

4
designer-base/src/main/java/com/fr/design/present/dict/DictionaryPane.java

@ -83,4 +83,8 @@ public class DictionaryPane extends UIComboBoxPane<Dictionary> implements DataCr
public void registerDSChangeListener() {
tableDataDictPane.registerDSChangeListener();
}
public void setNeedTableDataChange(boolean needTableDataChange) {
tableDataDictPane.setNeedTableDataChange(needTableDataChange);
}
}

103
designer-base/src/main/java/com/fr/design/present/dict/TableDataDictPane.java

@ -31,17 +31,20 @@ import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingWorker;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
/**
* 数据字典的数据查询面板
@ -60,6 +63,8 @@ public class TableDataDictPane extends FurtherBasicBeanPane<TableDataDictionary>
private DoubleDeckValueEditorPane valueDictPane;
private ItemListener itemListener;
private UIObserverListener uiObserverListener;
private FormulaEditor localFormulaEditor = new FormulaEditor(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Parameter_Formula"));
private boolean needTableDataChange = false;
public TableDataDictPane() {
initBasicComponets();
@ -67,6 +72,14 @@ public class TableDataDictPane extends FurtherBasicBeanPane<TableDataDictionary>
iniListener();
}
/**
* 设置为true后一旦触发TableDataComboBox的itemChange就会通过数据连接更换当前数据字典的列名List
* @param needTableDataChange
*/
public void setNeedTableDataChange(boolean needTableDataChange) {
this.needTableDataChange = needTableDataChange;
}
public static void main(String[] args) {
JFrame jf = new JFrame("test");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@ -80,11 +93,9 @@ public class TableDataDictPane extends FurtherBasicBeanPane<TableDataDictionary>
private void initBasicComponets() {
tableDataNameComboBox = new TableDataComboBox(DesignTableDataManager.getEditingTableDataSource());
tableDataNameComboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
tdChange(e);
}
tableDataNameComboBox.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
tdChange(e, needTableDataChange);
}
});
// keyColumnPane = ValueEditorPaneFactory.createValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor()});
@ -153,44 +164,60 @@ public class TableDataDictPane extends FurtherBasicBeanPane<TableDataDictionary>
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dic_Data_Query");
}
private void tdChange(final ItemEvent e) {
private void tdChange(final ItemEvent e, boolean needTableDataChange) {
TableDataWrapper tableDataWrappe = this.tableDataNameComboBox.getSelectedItem();
if (tableDataWrappe == null) {
return;
}
List<String> namelist = tableDataWrappe.calculateColumnNameList();
String[] columnNames = null;
if (!namelist.isEmpty()) {
columnNames = namelist.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
} else {
columnNames = new String[]{""};
if (itemListener != null) {
itemListener.itemStateChanged(e);
localFormulaEditor.addChangeListener(event -> itemListener.itemStateChanged(e));
}
ColumnNameEditor columnNameEditor1 = new ColumnNameEditor(columnNames);
columnNameEditor1.addItemListener(itemListener);
ColumnIndexEditor columnIndexEditor1 = new ColumnIndexEditor(columnNames.length);
columnIndexEditor1.addItemListener(itemListener);
keyColumnPane.setEditors(new Editor[]{columnNameEditor1, columnIndexEditor1}, columnNames[0]);
if (needTableDataChange) {
changeColumnsName();
}
}
FormulaEditor formulaEditor = new FormulaEditor(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Parameter_Formula"));
formulaEditor.setEnabled(true);
formulaEditor.addChangeListener(new ChangeListener() {
private void changeColumnsName() {
TableDataWrapper tableDataWrappe = this.tableDataNameComboBox.getSelectedItem();
SwingWorker<List<String>, Object> worker = new SwingWorker<List<String>, Object>() {
@Override
protected List<String> doInBackground() {
if (tableDataWrappe == null) {
return new ArrayList<>();
}
return tableDataWrappe.calculateColumnNameList();
}
@Override
public void stateChanged(ChangeEvent ee) {
if (itemListener != null) {
itemListener.itemStateChanged(e);
protected void done() {
try {
List<String> namelist = get();
String[] columnNames = null;
if (!namelist.isEmpty()) {
columnNames = namelist.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
} else {
columnNames = new String[]{""};
}
ColumnNameEditor columnNameEditor1 = new ColumnNameEditor(columnNames);
columnNameEditor1.addItemListener(itemListener);
ColumnIndexEditor columnIndexEditor1 = new ColumnIndexEditor(columnNames.length);
columnIndexEditor1.addItemListener(itemListener);
keyColumnPane.setEditors(new Editor[]{columnNameEditor1, columnIndexEditor1}, columnNames[0]);
localFormulaEditor.setEnabled(true);
ColumnNameEditor columnNameEditor2 = new ColumnNameEditor(columnNames);
columnNameEditor2.addItemListener(itemListener);
ColumnIndexEditor columnIndexEditor2 = new ColumnIndexEditor(columnNames.length);
columnIndexEditor2.addItemListener(itemListener);
valueDictPane.setEditors(new Editor[]{columnNameEditor2, columnIndexEditor2, localFormulaEditor}, columnNames[0]);
} catch (InterruptedException | ExecutionException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
});
ColumnNameEditor columnNameEditor2 = new ColumnNameEditor(columnNames);
columnNameEditor2.addItemListener(itemListener);
ColumnIndexEditor columnIndexEditor2 = new ColumnIndexEditor(columnNames.length);
columnIndexEditor2.addItemListener(itemListener);
valueDictPane.setEditors(new Editor[]{columnNameEditor2, columnIndexEditor2, formulaEditor}, columnNames[0]);
if (itemListener != null) {
itemListener.itemStateChanged(e);
}
};
worker.execute();
}
@Override

Loading…
Cancel
Save