diff --git a/designer-base/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleDictionaryEditor.java b/designer-base/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleDictionaryEditor.java index c2195512a3..6be31c526a 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleDictionaryEditor.java +++ b/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)); @@ -58,4 +59,4 @@ public class AccessibleDictionaryEditor extends UneditableAccessibleEditor { public Dictionary updateBean() { return (Dictionary) this.getValue(); } -} \ No newline at end of file +} diff --git a/designer-base/src/main/java/com/fr/design/present/dict/DictionaryPane.java b/designer-base/src/main/java/com/fr/design/present/dict/DictionaryPane.java index e50ed86b93..f74138be51 100644 --- a/designer-base/src/main/java/com/fr/design/present/dict/DictionaryPane.java +++ b/designer-base/src/main/java/com/fr/design/present/dict/DictionaryPane.java @@ -83,4 +83,8 @@ public class DictionaryPane extends UIComboBoxPane implements DataCr public void registerDSChangeListener() { tableDataDictPane.registerDSChangeListener(); } + + public void setNeedTableDataChange(boolean needTableDataChange) { + tableDataDictPane.setNeedTableDataChange(needTableDataChange); + } } diff --git a/designer-base/src/main/java/com/fr/design/present/dict/TableDataDictPane.java b/designer-base/src/main/java/com/fr/design/present/dict/TableDataDictPane.java index 3c08c1c9da..53801293ab 100644 --- a/designer-base/src/main/java/com/fr/design/present/dict/TableDataDictPane.java +++ b/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 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 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 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 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 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, Object> worker = new SwingWorker, Object>() { + @Override + protected List 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 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