zack
9 years ago
7 changed files with 418 additions and 450 deletions
@ -0,0 +1,62 @@ |
|||||||
|
package com.fr.design.data.datapane; |
||||||
|
|
||||||
|
import com.fr.data.TableDataSource; |
||||||
|
import com.fr.file.DatasourceManagerProvider; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Coder: zack |
||||||
|
* Date: 2016/5/18 |
||||||
|
* Time: 10:13 |
||||||
|
*/ |
||||||
|
public interface TableDataPaneController { |
||||||
|
/** |
||||||
|
* 获取数据集名字变更集合 |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
Map<String, String> getDsNameChangedMap(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 数据集重命名 |
||||||
|
* |
||||||
|
* @param oldName |
||||||
|
* @param newName |
||||||
|
*/ |
||||||
|
void rename(String oldName, String newName); |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否合法 |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
void checkValid() throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* 名字是否允许 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
boolean isNamePermitted(); |
||||||
|
|
||||||
|
void populate(DatasourceManagerProvider datasourceManagerProvider); |
||||||
|
|
||||||
|
void update(DatasourceManagerProvider datasourceManagerProvider); |
||||||
|
|
||||||
|
void populate(TableDataSource datasourceManagerProvider); |
||||||
|
|
||||||
|
void update(TableDataSource datasourceManagerProvider); |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置选中项 |
||||||
|
* @param index |
||||||
|
*/ |
||||||
|
void setSelectedIndex(int index); |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回当前数据集面板 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
JPanel getPanel(); |
||||||
|
|
||||||
|
} |
@ -1,260 +1,265 @@ |
|||||||
package com.fr.design.data.datapane; |
package com.fr.design.data.datapane; |
||||||
|
|
||||||
import com.fr.base.TableData; |
import com.fr.base.TableData; |
||||||
import com.fr.data.TableDataSource; |
import com.fr.data.TableDataSource; |
||||||
import com.fr.data.impl.storeproc.StoreProcedure; |
import com.fr.data.impl.storeproc.StoreProcedure; |
||||||
import com.fr.design.data.DesignTableDataManager; |
import com.fr.design.data.DesignTableDataManager; |
||||||
import com.fr.design.gui.controlpane.JListControlPane; |
import com.fr.design.gui.controlpane.JListControlPane; |
||||||
import com.fr.design.gui.controlpane.NameableCreator; |
import com.fr.design.gui.controlpane.NameableCreator; |
||||||
import com.fr.design.gui.ilist.ListModelElement; |
import com.fr.design.gui.ilist.ListModelElement; |
||||||
import com.fr.file.DatasourceManagerProvider; |
import com.fr.file.DatasourceManagerProvider; |
||||||
import com.fr.general.ComparatorUtils; |
import com.fr.general.ComparatorUtils; |
||||||
import com.fr.general.Inter; |
import com.fr.general.Inter; |
||||||
import com.fr.general.NameObject; |
import com.fr.general.NameObject; |
||||||
import com.fr.stable.Nameable; |
import com.fr.stable.Nameable; |
||||||
import com.fr.stable.StringUtils; |
import com.fr.stable.StringUtils; |
||||||
import com.fr.stable.core.PropertyChangeAdapter; |
import com.fr.stable.core.PropertyChangeAdapter; |
||||||
|
|
||||||
import javax.swing.*; |
import javax.swing.*; |
||||||
import java.util.*; |
import java.util.*; |
||||||
|
|
||||||
/** |
/** |
||||||
* TableDataList Pane. |
* TableDataList Pane. |
||||||
*/ |
*/ |
||||||
public class TableDataListPane extends JListControlPane { |
public class TableDataPaneListPane extends JListControlPane implements TableDataPaneController { |
||||||
private boolean isNamePermitted = true; |
private boolean isNamePermitted = true; |
||||||
|
private Map<String, String> dsNameChangedMap = new HashMap<String, String>(); |
||||||
public TableDataListPane() { |
|
||||||
super(); |
public TableDataPaneListPane() { |
||||||
dsNameChangedMap.clear(); |
super(); |
||||||
this.addEditingListner(new PropertyChangeAdapter() { |
dsNameChangedMap.clear(); |
||||||
@Override |
this.addEditingListner(new PropertyChangeAdapter() { |
||||||
public void propertyChange() { |
@Override |
||||||
isNamePermitted = true; |
public void propertyChange() { |
||||||
TableDataSource source = DesignTableDataManager.getEditingTableDataSource(); |
isNamePermitted = true; |
||||||
String[] allDSNames = DesignTableDataManager.getAllDSNames(source); |
TableDataSource source = DesignTableDataManager.getEditingTableDataSource(); |
||||||
String[] allListNames = nameableList.getAllNames(); |
String[] allDSNames = DesignTableDataManager.getAllDSNames(source); |
||||||
allListNames[nameableList.getSelectedIndex()] = StringUtils.EMPTY; |
String[] allListNames = nameableList.getAllNames(); |
||||||
String tempName = getEditingName(); |
allListNames[nameableList.getSelectedIndex()] = StringUtils.EMPTY; |
||||||
Object editingType = getEditingType(); |
String tempName = getEditingName(); |
||||||
if (StringUtils.isEmpty(tempName)) { |
Object editingType = getEditingType(); |
||||||
String[] warning = new String[]{"NOT_NULL_Des", "Please_Rename"}; |
if (StringUtils.isEmpty(tempName)) { |
||||||
String[] sign = new String[]{",", "!"}; |
String[] warning = new String[]{"NOT_NULL_Des", "Please_Rename"}; |
||||||
isNamePermitted = false; |
String[] sign = new String[]{",", "!"}; |
||||||
nameableList.stopEditing(); |
isNamePermitted = false; |
||||||
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(TableDataListPane.this), Inter.getLocText(warning, sign)); |
nameableList.stopEditing(); |
||||||
setWarnigText(editingIndex); |
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(TableDataPaneListPane.this), Inter.getLocText(warning, sign)); |
||||||
return; |
setWarnigText(editingIndex); |
||||||
} |
return; |
||||||
|
} |
||||||
if (!ComparatorUtils.equals(tempName, selectedName) |
|
||||||
&& isNameRepeted(new List[]{Arrays.asList(allDSNames), Arrays.asList(allListNames)}, tempName)) { |
if (!ComparatorUtils.equals(tempName, selectedName) |
||||||
String[] waning = new String[]{"already_exists", "TableData", "Please_Rename"}; |
&& isNameRepeted(new List[]{Arrays.asList(allDSNames), Arrays.asList(allListNames)}, tempName)) { |
||||||
String[] sign = new String[]{"", tempName + ",", "!"}; |
String[] waning = new String[]{"already_exists", "TableData", "Please_Rename"}; |
||||||
isNamePermitted = false; |
String[] sign = new String[]{"", tempName + ",", "!"}; |
||||||
nameableList.stopEditing(); |
isNamePermitted = false; |
||||||
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(TableDataListPane.this), Inter.getLocText(waning, sign)); |
nameableList.stopEditing(); |
||||||
setWarnigText(editingIndex); |
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(TableDataPaneListPane.this), Inter.getLocText(waning, sign)); |
||||||
} else if (editingType instanceof StoreProcedure && isIncludeUnderline(tempName)) { |
setWarnigText(editingIndex); |
||||||
String[] datasource_underline = new String[]{"Datasource-Stored_Procedure", "Name", "can_not_include_underline"}; |
} else if (editingType instanceof StoreProcedure && isIncludeUnderline(tempName)) { |
||||||
String[] sign = new String[]{"", "", "!"}; |
String[] datasource_underline = new String[]{"Datasource-Stored_Procedure", "Name", "can_not_include_underline"}; |
||||||
isNamePermitted = false; |
String[] sign = new String[]{"", "", "!"}; |
||||||
nameableList.stopEditing(); |
isNamePermitted = false; |
||||||
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(TableDataListPane.this), Inter.getLocText(datasource_underline, sign)); |
nameableList.stopEditing(); |
||||||
setWarnigText(editingIndex); |
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(TableDataPaneListPane.this), Inter.getLocText(datasource_underline, sign)); |
||||||
} |
setWarnigText(editingIndex); |
||||||
if (nameableList.getSelectedValue() instanceof ListModelElement) { |
} |
||||||
Nameable selected = ((ListModelElement) nameableList.getSelectedValue()).wrapper; |
if (nameableList.getSelectedValue() instanceof ListModelElement) { |
||||||
if (!ComparatorUtils.equals(tempName, selected.getName())) { |
Nameable selected = ((ListModelElement) nameableList.getSelectedValue()).wrapper; |
||||||
rename(selected.getName(), tempName); |
if (!ComparatorUtils.equals(tempName, selected.getName())) { |
||||||
|
rename(selected.getName(), tempName); |
||||||
} |
|
||||||
} |
} |
||||||
} |
} |
||||||
}); |
} |
||||||
} |
}); |
||||||
|
} |
||||||
protected void rename(String oldName, String newName) { |
|
||||||
dsNameChangedMap.put(oldName, newName); |
public void rename(String oldName, String newName) { |
||||||
} |
dsNameChangedMap.put(oldName, newName); |
||||||
|
} |
||||||
/** |
|
||||||
* 名字是否允许 |
/** |
||||||
* |
* 名字是否允许 |
||||||
* @return 是/否 |
* |
||||||
*/ |
* @return 是/否 |
||||||
public boolean isNamePermitted() { |
*/ |
||||||
return isNamePermitted; |
public boolean isNamePermitted() { |
||||||
} |
return isNamePermitted; |
||||||
|
} |
||||||
|
|
||||||
/** |
|
||||||
* 检查按钮可用状态 Check button enabled. |
/** |
||||||
*/ |
* 检查按钮可用状态 Check button enabled. |
||||||
public void checkButtonEnabled() { |
*/ |
||||||
super.checkButtonEnabled(); |
public void checkButtonEnabled() { |
||||||
isNamePermitted = !isContainsRename(); |
super.checkButtonEnabled(); |
||||||
} |
isNamePermitted = !isContainsRename(); |
||||||
|
} |
||||||
private boolean isIncludeUnderline(String name) { |
|
||||||
return ComparatorUtils.equals(name.indexOf(StoreProcedure.SPLIT), -1) ? false : true; |
private boolean isIncludeUnderline(String name) { |
||||||
} |
return ComparatorUtils.equals(name.indexOf(StoreProcedure.SPLIT), -1) ? false : true; |
||||||
|
} |
||||||
/** |
|
||||||
* 创建服务器数据集所需要的NameableCreator数组 |
/** |
||||||
* |
* 创建服务器数据集所需要的NameableCreator数组 |
||||||
* @return 数组 |
* |
||||||
*/ |
* @return 数组 |
||||||
public NameableCreator[] createNameableCreators() { |
*/ |
||||||
return TableDataCreatorProducer.getInstance().createServerTableDataCreator(); |
public NameableCreator[] createNameableCreators() { |
||||||
} |
return TableDataCreatorProducer.getInstance().createServerTableDataCreator(); |
||||||
|
} |
||||||
|
|
||||||
// 只能保证当前模板不重名了
|
|
||||||
|
// 只能保证当前模板不重名了
|
||||||
/** |
|
||||||
* 新建不重名的面板 |
/** |
||||||
* |
* 新建不重名的面板 |
||||||
* @param prefix 前缀字符 |
* |
||||||
* @return 生成的名字 |
* @param prefix 前缀字符 |
||||||
*/ |
* @return 生成的名字 |
||||||
@Override |
*/ |
||||||
public String createUnrepeatedName(String prefix) { |
@Override |
||||||
TableDataSource source = DesignTableDataManager.getEditingTableDataSource(); |
public String createUnrepeatedName(String prefix) { |
||||||
if (source == null) { |
TableDataSource source = DesignTableDataManager.getEditingTableDataSource(); |
||||||
return super.createUnrepeatedName(prefix); |
if (source == null) { |
||||||
} |
return super.createUnrepeatedName(prefix); |
||||||
String[] allDsNames = DesignTableDataManager.getAllDSNames(source); |
} |
||||||
DefaultListModel model = this.getModel(); |
String[] allDsNames = DesignTableDataManager.getAllDSNames(source); |
||||||
Nameable[] all = new Nameable[model.getSize()]; |
DefaultListModel model = this.getModel(); |
||||||
for (int i = 0; i < model.size(); i++) { |
Nameable[] all = new Nameable[model.getSize()]; |
||||||
all[i] = ((ListModelElement) model.get(i)).wrapper; |
for (int i = 0; i < model.size(); i++) { |
||||||
} |
all[i] = ((ListModelElement) model.get(i)).wrapper; |
||||||
// richer:生成的名字从1开始. kunsnat: 添加属性从0开始.
|
} |
||||||
int count = all.length + 1; |
// richer:生成的名字从1开始. kunsnat: 添加属性从0开始.
|
||||||
while (true) { |
int count = all.length + 1; |
||||||
String name_test = prefix + count; |
while (true) { |
||||||
boolean repeated = false; |
String name_test = prefix + count; |
||||||
for (int i = 0, len = model.size(); i < len; i++) { |
boolean repeated = false; |
||||||
Nameable nameable = all[i]; |
for (int i = 0, len = model.size(); i < len; i++) { |
||||||
if (ComparatorUtils.equals(nameable.getName(), name_test)) { |
Nameable nameable = all[i]; |
||||||
repeated = true; |
if (ComparatorUtils.equals(nameable.getName(), name_test)) { |
||||||
break; |
repeated = true; |
||||||
} |
break; |
||||||
} |
} |
||||||
for (String dsname : allDsNames) { |
} |
||||||
if (ComparatorUtils.equals(dsname, name_test)) { |
for (String dsname : allDsNames) { |
||||||
repeated = true; |
if (ComparatorUtils.equals(dsname, name_test)) { |
||||||
break; |
repeated = true; |
||||||
} |
break; |
||||||
} |
} |
||||||
|
} |
||||||
if (!repeated) { |
|
||||||
return name_test; |
if (!repeated) { |
||||||
} |
return name_test; |
||||||
|
} |
||||||
count++; |
|
||||||
} |
count++; |
||||||
} |
} |
||||||
|
} |
||||||
@Override |
|
||||||
protected String title4PopupWindow() { |
@Override |
||||||
return "TableData"; |
protected String title4PopupWindow() { |
||||||
} |
return "TableData"; |
||||||
|
} |
||||||
/** |
|
||||||
* Populate. |
/** |
||||||
*/ |
* Populate. |
||||||
public void populate(TableDataSource tds) { |
*/ |
||||||
List<NameObject> nameObjectList = new ArrayList<NameObject>(); |
public void populate(TableDataSource tds) { |
||||||
|
List<NameObject> nameObjectList = new ArrayList<NameObject>(); |
||||||
Iterator tableDataNameIterator = tds.getTableDataNameIterator(); |
|
||||||
while (tableDataNameIterator.hasNext()) { |
Iterator tableDataNameIterator = tds.getTableDataNameIterator(); |
||||||
String tableDataName = (String) tableDataNameIterator.next(); |
while (tableDataNameIterator.hasNext()) { |
||||||
TableData tableData = tds.getTableData(tableDataName); |
String tableDataName = (String) tableDataNameIterator.next(); |
||||||
|
TableData tableData = tds.getTableData(tableDataName); |
||||||
if (tableData != null) { |
|
||||||
nameObjectList.add(new NameObject(tableDataName, tableData)); |
if (tableData != null) { |
||||||
} |
nameObjectList.add(new NameObject(tableDataName, tableData)); |
||||||
} |
} |
||||||
|
} |
||||||
populate(nameObjectList.toArray(new NameObject[nameObjectList.size()])); |
|
||||||
} |
populate(nameObjectList.toArray(new NameObject[nameObjectList.size()])); |
||||||
|
} |
||||||
/** |
|
||||||
* Populate. |
/** |
||||||
*/ |
* Populate. |
||||||
public void populate(DatasourceManagerProvider datasourceManager) { |
*/ |
||||||
Iterator<String> nameIt = datasourceManager.getTableDataNameIterator(); |
public void populate(DatasourceManagerProvider datasourceManager) { |
||||||
Iterator<String> procedurenameIt = datasourceManager.getProcedureNameIterator(); |
Iterator<String> nameIt = datasourceManager.getTableDataNameIterator(); |
||||||
List<NameObject> nameObjectList = new ArrayList<NameObject>(); |
Iterator<String> procedurenameIt = datasourceManager.getProcedureNameIterator(); |
||||||
while (nameIt.hasNext()) { |
List<NameObject> nameObjectList = new ArrayList<NameObject>(); |
||||||
String name = nameIt.next(); |
while (nameIt.hasNext()) { |
||||||
nameObjectList.add(new NameObject(name, datasourceManager.getTableData(name))); |
String name = nameIt.next(); |
||||||
} |
nameObjectList.add(new NameObject(name, datasourceManager.getTableData(name))); |
||||||
while (procedurenameIt.hasNext()) { |
} |
||||||
String name = procedurenameIt.next(); |
while (procedurenameIt.hasNext()) { |
||||||
nameObjectList.add(new NameObject(name, datasourceManager.getProcedureByName(name))); |
String name = procedurenameIt.next(); |
||||||
} |
nameObjectList.add(new NameObject(name, datasourceManager.getProcedureByName(name))); |
||||||
|
} |
||||||
populate(nameObjectList.toArray(new NameObject[nameObjectList.size()])); |
|
||||||
} |
populate(nameObjectList.toArray(new NameObject[nameObjectList.size()])); |
||||||
|
} |
||||||
public void update(DatasourceManagerProvider datasourceManager) { |
|
||||||
datasourceManager.clearAllTableData(); |
public void update(DatasourceManagerProvider datasourceManager) { |
||||||
datasourceManager.clearAllProcedure(); |
datasourceManager.clearAllTableData(); |
||||||
Nameable[] tableDataArray = this.update(); |
datasourceManager.clearAllProcedure(); |
||||||
for (int i = 0; i < tableDataArray.length; i++) { |
Nameable[] tableDataArray = this.update(); |
||||||
NameObject nameObject = (NameObject) tableDataArray[i]; |
for (int i = 0; i < tableDataArray.length; i++) { |
||||||
datasourceManager.putTableData(nameObject.getName(), (TableData) nameObject.getObject()); |
NameObject nameObject = (NameObject) tableDataArray[i]; |
||||||
} |
datasourceManager.putTableData(nameObject.getName(), (TableData) nameObject.getObject()); |
||||||
} |
} |
||||||
|
} |
||||||
public void update(TableDataSource tds) { |
|
||||||
tds.clearAllTableData(); |
public void update(TableDataSource tds) { |
||||||
|
tds.clearAllTableData(); |
||||||
Nameable[] tableDataArray = this.update(); |
|
||||||
for (int i = 0; i < tableDataArray.length; i++) { |
Nameable[] tableDataArray = this.update(); |
||||||
NameObject nameObject = (NameObject) tableDataArray[i]; |
for (int i = 0; i < tableDataArray.length; i++) { |
||||||
tds.putTableData(nameObject.getName(), (TableData) nameObject.getObject()); |
NameObject nameObject = (NameObject) tableDataArray[i]; |
||||||
} |
tds.putTableData(nameObject.getName(), (TableData) nameObject.getObject()); |
||||||
} |
} |
||||||
|
} |
||||||
/** |
|
||||||
* 判断数据集是否重名 |
/** |
||||||
*/ |
* 判断数据集是否重名 |
||||||
public void checkValid() throws Exception { |
*/ |
||||||
List<String> exsitTableDataNameList = new ArrayList<String>(); |
public void checkValid() throws Exception { |
||||||
// _denny: 判断是否有重复的数据集名
|
List<String> exsitTableDataNameList = new ArrayList<String>(); |
||||||
checkRepeatedDSName(exsitTableDataNameList); |
// _denny: 判断是否有重复的数据集名
|
||||||
|
checkRepeatedDSName(exsitTableDataNameList); |
||||||
Nameable[] tableDataArray = this.update(); |
|
||||||
for (int i = 0; i < tableDataArray.length; i++) { |
Nameable[] tableDataArray = this.update(); |
||||||
NameObject nameObject = (NameObject) tableDataArray[i]; |
for (int i = 0; i < tableDataArray.length; i++) { |
||||||
|
NameObject nameObject = (NameObject) tableDataArray[i]; |
||||||
if (exsitTableDataNameList.contains(nameObject.getName())) { |
|
||||||
String[] waring = new String[]{"TableData", "Error_TableDataNameRepeat"}; |
if (exsitTableDataNameList.contains(nameObject.getName())) { |
||||||
String[] sign = new String[]{": " + nameObject.getName()}; |
String[] waring = new String[]{"TableData", "Error_TableDataNameRepeat"}; |
||||||
throw new Exception(Inter.getLocText(waring, sign)); |
String[] sign = new String[]{": " + nameObject.getName()}; |
||||||
} |
throw new Exception(Inter.getLocText(waring, sign)); |
||||||
|
} |
||||||
exsitTableDataNameList.add(nameObject.getName()); |
|
||||||
} |
exsitTableDataNameList.add(nameObject.getName()); |
||||||
} |
} |
||||||
|
} |
||||||
protected void checkRepeatedDSName(List<String> exsitTableDataNameList) { |
|
||||||
} |
protected void checkRepeatedDSName(List<String> exsitTableDataNameList) { |
||||||
|
} |
||||||
/** |
|
||||||
* 在JJControlPane的左侧Tree里面选中某一Item |
/** |
||||||
* |
* 在JJControlPane的左侧Tree里面选中某一Item |
||||||
* @param name 被选择的Item名称 |
* |
||||||
*/ |
* @param name 被选择的Item名称 |
||||||
public void selectName(String name) { |
*/ |
||||||
this.setSelectedName(name); |
public void selectName(String name) { |
||||||
} |
this.setSelectedName(name); |
||||||
|
} |
||||||
public Map<String, String> getDsNameChangedMap() { |
|
||||||
return this.dsNameChangedMap; |
public Map<String, String> getDsNameChangedMap() { |
||||||
} |
return this.dsNameChangedMap; |
||||||
|
} |
||||||
|
|
||||||
|
public JPanel getPanel() { |
||||||
|
return this; |
||||||
|
} |
||||||
} |
} |
Loading…
Reference in new issue