Browse Source

REPORT-58227 远程设计 设计器切换已经打开的模板卡顿

bugfix/10.0
hades 3 years ago
parent
commit
1b7f5cf776
  1. 44
      designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java
  2. 47
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ItemEditableComboBoxPanel.java

44
designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java

@ -25,6 +25,7 @@ import com.fr.design.gui.icombobox.UIComboBoxEditor;
import com.fr.design.gui.icombobox.UIComboBoxRenderer;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
@ -39,7 +40,16 @@ import com.fr.stable.StringUtils;
import com.fr.workspace.WorkContext;
import com.fr.workspace.server.connection.DBConnectAuth;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.util.Collections;
import java.util.concurrent.CancellationException;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.SwingWorker;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.PopupMenuEvent;
@ -50,7 +60,6 @@ import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
@ -70,6 +79,9 @@ import java.util.concurrent.FutureTask;
* @since 2012-7-11下午4:49:39
*/
public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refreshable, Previewable, Prepare4DataSourceChange {
private static final List<String> PENDING_CONTENT = new ArrayList<>(Collections.singletonList(Toolkit.i18nText("Fine-Design_Basic_Loading") + "..."));
private static final double COLUMN_SIZE = 24;
/**
@ -91,6 +103,8 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
private SwingWorker populateWorker;
private SwingWorker<List<String>, Void> initWorker;
private PopupMenuListener popupMenuListener = new PopupMenuListener() {
@Override
@ -213,10 +227,34 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
@SuppressWarnings("unchecked")
protected void initDsNameComboBox() {
if (initWorker != null && !initWorker.isDone()) {
initWorker.cancel(true);
}
dsNameComboBox.setRefreshingModel(true);
FilterableComboBoxModel dsNameComboBoxModel = new FilterableComboBoxModel(getHasAuthConnections());
dsNameComboBox.setModel(new FilterableComboBoxModel(PENDING_CONTENT));
initWorker = new SwingWorker<List<String>, Void>() {
@Override
protected List<String> doInBackground() throws Exception {
return getHasAuthConnections();
}
@Override
protected void done() {
try {
FilterableComboBoxModel dsNameComboBoxModel = new FilterableComboBoxModel(get());
String selected = dsNameComboBox.getSelectedItem();
dsNameComboBox.setModel(dsNameComboBoxModel);
dsNameComboBox.setSelectedItem(selected);
dsNameComboBox.setRefreshingModel(false);
} catch (Exception e) {
if (!(e instanceof CancellationException)) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}
};
initWorker.execute();
}
protected void initComponentsLayout(PreviewLabel previewLabel, int labelSize) {

47
designer-base/src/main/java/com/fr/design/data/datapane/connect/ItemEditableComboBoxPanel.java

@ -3,12 +3,19 @@ package com.fr.design.data.datapane.connect;
import com.fr.base.BaseUtils;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import javax.swing.*;
import java.awt.*;
import com.fr.log.FineLoggerFactory;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.Iterator;
import java.util.concurrent.CancellationException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JPanel;
import javax.swing.SwingWorker;
public abstract class ItemEditableComboBoxPanel extends JPanel {
/**
@ -16,6 +23,8 @@ public abstract class ItemEditableComboBoxPanel extends JPanel {
*/
private static final long serialVersionUID = 1L;
private static final String PENDING = Toolkit.i18nText("Fine-Design_Basic_Loading") + "...";
protected static final Object EMPTY = new Object() {
public String toString() {
return "";
@ -26,6 +35,8 @@ public abstract class ItemEditableComboBoxPanel extends JPanel {
protected UIButton editButton;
protected UIButton refreshButton;
private SwingWorker<Iterator<String>, Void> refreshWorker;
public ItemEditableComboBoxPanel() {
super();
@ -75,26 +86,42 @@ public abstract class ItemEditableComboBoxPanel extends JPanel {
* 刷新itemComboBox的内容
*/
protected void refreshItems() {
// 记录原来选中的Item,重新加载后需要再次选中
Object lastSelectedItem = itemComboBox.getSelectedItem();
if (refreshWorker != null && !refreshWorker.isDone()) {
refreshWorker.cancel(true);
}
DefaultComboBoxModel model = ((DefaultComboBoxModel) itemComboBox.getModel());
model.removeAllElements();
// 先加EMPTY,再加items
model.addElement(EMPTY);
model.addElement(PENDING);
java.util.Iterator<String> itemIt = items();
refreshWorker = new SwingWorker<Iterator<String>, Void>() {
@Override
protected Iterator<String> doInBackground() throws Exception {
return items();
}
@Override
protected void done() {
try {
Iterator<String> itemIt = get();
model.removeElement(PENDING);
while(itemIt.hasNext()) {
model.addElement(itemIt.next());
}
itemComboBox.setMaximumRowCount(itemComboBox.getMaximumRowCount() + 1);
} catch (Exception e) {
if (!(e instanceof CancellationException)) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
// 再次选中之前选中的Item
int idx = model.getIndexOf(lastSelectedItem);
if(idx < 0) {
idx = 0;
}
itemComboBox.setSelectedIndex(idx);
};
refreshWorker.execute();
}
/*

Loading…
Cancel
Save