From 21c4355bcbbce04172e455397e2d7914d0784efb Mon Sep 17 00:00:00 2001 From: Yvan Date: Fri, 11 Dec 2020 17:27:36 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-44961=20=E3=80=9010.0.12=E5=86=92?= =?UTF-8?q?=E7=83=9F=E3=80=91=E9=99=84=E4=BB=B6=E6=A8=A1=E6=9D=BF=E6=89=93?= =?UTF-8?q?=E5=BC=80=E8=AE=BE=E8=AE=A1=E5=99=A8=E5=8D=A1=E6=AD=BB=EF=BC=8C?= =?UTF-8?q?=E4=B8=94=E5=B8=83=E5=B1=80=E5=8F=91=E7=94=9F=E5=8F=98=E5=8C=96?= =?UTF-8?q?=20=E3=80=90=E9=97=AE=E9=A2=98=E5=8E=9F=E5=9B=A0=E3=80=91?= =?UTF-8?q?=E5=B8=A6=E6=9C=89=E6=95=B0=E6=8D=AE=E5=AD=97=E5=85=B8=E7=9A=84?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E6=8E=A7=E4=BB=B6=EF=BC=8C=E5=9C=A8=E9=80=89?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=97=B6=E5=80=99=E4=BC=9A=E5=8E=BB=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E8=8E=B7=E5=8F=96=E5=AD=97=E6=AE=B5=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E5=BD=93=E7=B3=BB=E7=BB=9F=E4=B8=AD=E6=9C=89=E5=90=8C?= =?UTF-8?q?=E5=90=8D=E6=95=B0=E6=8D=AE=E8=BF=9E=E6=8E=A5=E4=BD=86=E6=98=AF?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=BF=9E=E6=8E=A5=E5=88=B0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E4=BC=9A=E5=8F=91?= =?UTF-8?q?=E7=94=9F=E5=81=87=E6=AD=BB=E3=80=82=E5=A6=82=E6=9E=9C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1=82=E8=BF=9E=E6=8E=A5=EF=BC=8C=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=8D=A2=E5=BD=93=E5=89=8D=E6=95=B0=E6=8D=AE=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E5=88=97=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AccessibleDictionaryEditor.java | 3 +- .../design/present/dict/DictionaryPane.java | 4 + .../present/dict/TableDataDictPane.java | 103 +++++++++++------- 3 files changed, 71 insertions(+), 39 deletions(-) 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