Browse Source

REPORT-8114 数据集字典 设计器无响应

master
yaoh.wu 7 years ago
parent
commit
501ea1fb40
  1. 110
      designer-base/src/com/fr/design/data/datapane/ChoosePane.java

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

@ -37,7 +37,11 @@ import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.stable.StringUtils;
import javax.swing.*;
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;
@ -48,7 +52,9 @@ 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.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
@ -85,6 +91,7 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
private PopupMenuListener popupMenuListener = new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
new Thread() {
@Override
@ -94,26 +101,41 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
}.start();
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
}
@Override
public void popupMenuCanceled(PopupMenuEvent e) {
}
};
private PopupMenuListener listener = new PopupMenuListener() {
@Override
public void popupMenuCanceled(PopupMenuEvent e) {
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
}
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
executePopulateWorker();
}
};
private FocusAdapter focusAdapter = new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
if (schemaBox.getSelectedIndex() == -1) {
schemaBox.updateUI();
schemaBox.showPopup();
}
}
};
public ChoosePane() {
this(null);
}
@ -146,6 +168,7 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
private void initBoxListener() {
addDSBoxListener();
schemaBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent evt) {
tableNameComboBox.setSelectedItem("");
}
@ -176,16 +199,9 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
}
protected void addFocusListener() {
schemaBox.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
if (schemaBox.getSelectedIndex() == -1) {
schemaBox.updateUI();
schemaBox.showPopup();
}
}
});
}
@SuppressWarnings("unchecked")
protected void initDsNameComboBox() {
dsNameComboBox.setRefreshingModel(true);
ConnectionConfig connectionConfig = ConnectionConfig.getInstance();
@ -233,12 +249,18 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
}
populateWorker = new SwingWorker<com.fr.data.impl.Connection, Void>() {
protected com.fr.data.impl.Connection doInBackground() throws Exception {
@SuppressWarnings("unchecked")
@Override
protected com.fr.data.impl.Connection doInBackground() {
schemaBox.setRefreshingModel(true);
schemaBox.addItem(Inter.getLocText("FR-Designer_Loading") + "...");
schemaBox.setSelectedItem(null);
schemaBox.setRefreshingModel(false);
return getConnection();
}
@SuppressWarnings("unchecked")
@Override
public void done() {
try {
com.fr.data.impl.Connection selectedDatabase = get();
@ -267,6 +289,8 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
schemaBox.removePopupMenuListener(listener);
schemaBox.setPopupVisible(true);
schemaBox.addPopupMenuListener(listener);
schemaBox.removeFocusListener(focusAdapter);
schemaBox.addFocusListener(focusAdapter);
}
};
populateWorker.execute();
@ -292,7 +316,7 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
return null; // peter:选中了当前的零长度的节点,直接返回.
}
ConnectionConfig connectionConfig = ConnectionConfig.getInstance();
for (Map.Entry<String, Connection> entry: connectionConfig.getConnections().entrySet()) {
for (Map.Entry<String, Connection> entry : connectionConfig.getConnections().entrySet()) {
if (ComparatorUtils.equals(selectedDSName, entry.getKey())) {
return entry.getValue();
}
@ -303,6 +327,7 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
/**
* 刷新没多大用而且要刷新也不是这儿刷新
*/
@Override
public void refresh() {
DBUtils.refreshDatabase();
String schema = StringUtils.isEmpty(schemaBox.getSelectedItem()) ? null : schemaBox.getSelectedItem();
@ -312,6 +337,7 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
}
TreeCellRenderer tableNameTreeRenderer = new DefaultTreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (value instanceof DefaultMutableTreeNode) {
@ -328,6 +354,7 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
};
public static UIComboBoxRenderer listCellRenderer = new UIComboBoxRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof TreePath) {
@ -344,16 +371,18 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
/**
* 添加项目监听事件
* @param aListener 事件监听器
* 添加项目监听事件
*
* @param aListener 事件监听器
*/
public void addItemListener(ItemListener aListener) {
this.tableNameComboBox.addItemListener(aListener);
}
/**
* 删除项目监听事件
* @param aListener 事件监听器
* 删除项目监听事件
*
* @param aListener 事件监听器
*/
public void removeItemListener(ItemListener aListener) {
this.tableNameComboBox.removeItemListener(aListener);
@ -398,9 +427,7 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
}
}
((DefaultTreeModel) tree.getModel()).reload();
/**
* daniel 展开所有tree
*/
// daniel 展开所有tree
TreeNode root = (TreeNode) tree.getModel().getRoot();
TreePath parent = new TreePath(root);
TreeNode node = (TreeNode) parent.getLastPathComponent();
@ -416,42 +443,41 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
/**
* 创建选中的数据集数据
* @return 数据集数据
*
* @return 数据集数据
*/
public TableData createSelectTableData() {
DataBaseItems paras = this.updateBean();
boolean connect = false;
com.fr.data.impl.Connection database = DBUtils.checkDBConnection(paras.getDatabaseName());
if (database == null) {
failedToFindTable();
failedToFindTable();
return TableData.EMPTY_TABLEDATA;
}
try {
connect = FRContext.getCurrentEnv().testConnection(database);
} catch (Exception e1) {
connect = false;
} catch (Exception ignored) {
}
if (!connect) {
DesignerFrame designerFrame = DesignerContext.getDesignerFrame();
JOptionPane.showMessageDialog(designerFrame, Inter.getLocText("Datasource-Connection_failed"),
Inter.getLocText("FR-Designer_Failed"), JOptionPane.INFORMATION_MESSAGE);
failedToFindTable();
Inter.getLocText("FR-Designer_Failed"), JOptionPane.INFORMATION_MESSAGE);
failedToFindTable();
return null;
}
// 显示Table数据.
TableData tableData = null;
if (FRContext.getCurrentEnv() instanceof LocalEnv) {
TableData tableDataLocal = new DBTableData(database, DataCoreUtils.createSelectSQL(paras.getSchemaName(), paras.getTableName(),
tableData = new DBTableData(database, DataCoreUtils.createSelectSQL(paras.getSchemaName(), paras.getTableName(),
DialectFactory.getDialectByName(paras.getDatabaseName())));
tableData = tableDataLocal;
} else {
try {
TableData tableDataLocal = new DBTableData(database, DataCoreUtils.createSelectSQL(paras.getSchemaName(), paras.getTableName(), DialectFactory.getDialectByName(paras.getDatabaseName())));
tableData = FRContext.getCurrentEnv().previewTableData(tableDataLocal, java.util.Collections.EMPTY_MAP,
DesignerEnvManager.getEnvManager().getMaxNumberOrPreviewRow());
} catch (Exception e) {
failedToFindTable();
failedToFindTable();
FRContext.getLogger().error(e.getMessage(), e);
}
}
@ -463,8 +489,8 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
return this.dsNameComboBox.getSelectedItem();
}
protected void failedToFindTable() {
}
protected void failedToFindTable() {
}
protected String getTableName() {
String tableName = "";
@ -485,7 +511,8 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
/**
* 得到当前的ColumnName[]
* @return 返回当前的ColumnName[]
*
* @return 返回当前的ColumnName[]
*/
public String[] currentColumnNames() {
String[] colNames = null;
@ -493,21 +520,19 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
DataBaseItems paras = this.updateBean();
String selectedDSName = paras.getDatabaseName();
if (StringUtils.isBlank(selectedDSName)) {
return colNames = new String[0]; // peter:选中了当前的零长度的节点,直接返回.
// peter:选中了当前的零长度的节点,直接返回.
return new String[0];
}
String selectedTableObject = paras.getTableName();
if (StringUtils.isEmpty(selectedTableObject)) {
return colNames = new String[0];
return new String[0];
}
java.sql.Connection conn = null;
try {
// daniel:增加参数
colNames = FRContext.getCurrentEnv().getColumns(selectedDSName, paras.getSchemaName(), selectedTableObject);
} catch (Exception e2) {
FRContext.getLogger().error(e2.getMessage(), e2);
} finally {
DBUtils.closeConnection(conn);
}
if (colNames == null) {
@ -517,9 +542,10 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
}
/**
* 预览key value对应的数据
* 预览key value对应的数据
*
* @param key
* @param value
* @param value
*/
public void preview(int key, int value) {
PreviewTablePane.previewTableData(createSelectTableData(), key, value);
@ -528,6 +554,7 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
/**
* 默认预览
*/
@Override
public void preview() {
preview(-1, -1);
}
@ -540,10 +567,12 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
}
/**
*注册listener,相应数据集改变
* 注册listener,相应数据集改变
*/
@Override
public void registerDSChangeListener() {
DesignTableDataManager.addDsChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
initDsNameComboBox();
}
@ -578,6 +607,7 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
this.refreshingModel = refreshingModel;
}
@Override
public void setSelectedItem(Object ob) {
this.getModel().setSelectedItem(ob);
if (ob != null && StringUtils.isEmpty(ob.toString())) {
@ -591,11 +621,13 @@ public class ChoosePane extends BasicBeanPane<DataBaseItems> implements Refresha
private class ComboBoxEditor extends UIComboBoxEditor {
private Object item;
@Override
public void setItem(Object item) {
this.item = item;
textField.setText((item == null) ? "" : item.toString());
}
@Override
public Object getItem() {
return this.item;
}

Loading…
Cancel
Save