Browse Source

加一个数据集面板处理器的接口,和jcontrolpane分开

master
zack 9 years ago
parent
commit
7c80cb51a2
  1. 9
      designer_base/src/com/fr/design/data/datapane/ReportTableDataPane.java
  2. 62
      designer_base/src/com/fr/design/data/datapane/TableDataPaneController.java
  3. 523
      designer_base/src/com/fr/design/data/datapane/TableDataPaneListPane.java
  4. 14
      designer_base/src/com/fr/design/data/tabledata/tabledatapane/TableDataManagerPane.java
  5. 4
      designer_base/src/com/fr/design/fun/TableDataPaneProcessor.java
  6. 174
      designer_base/src/com/fr/design/gui/controlpane/JControlPane.java
  7. 82
      designer_base/src/com/fr/design/gui/controlpane/JListControlPane.java

9
designer_base/src/com/fr/design/data/datapane/ReportTableDataPane.java

@ -6,7 +6,6 @@ package com.fr.design.data.datapane;
import com.fr.data.TableDataSource; import com.fr.data.TableDataSource;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.fun.TableDataPaneProcessor; import com.fr.design.fun.TableDataPaneProcessor;
import com.fr.design.gui.controlpane.JControlPane;
import com.fr.design.gui.controlpane.NameableCreator; import com.fr.design.gui.controlpane.NameableCreator;
import com.fr.design.gui.frpane.LoadingBasicPane; import com.fr.design.gui.frpane.LoadingBasicPane;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
@ -22,24 +21,24 @@ import java.util.Map;
* 创建于2011-6-14 * 创建于2011-6-14
*/ */
public class ReportTableDataPane extends LoadingBasicPane { public class ReportTableDataPane extends LoadingBasicPane {
private JControlPane tdPane; private TableDataPaneController tdPane;
@Override @Override
protected void initComponents(JPanel container) { protected void initComponents(JPanel container) {
container.setLayout(FRGUIPaneFactory.createBorderLayout()); container.setLayout(FRGUIPaneFactory.createBorderLayout());
TableDataPaneProcessor paneProcessor = ExtraDesignClassManager.getInstance().getTableDataPaneProcessor(); TableDataPaneProcessor paneProcessor = ExtraDesignClassManager.getInstance().getTableDataPaneProcessor();
JControlPane pane = null; TableDataPaneController pane = null;
if (paneProcessor != null) { if (paneProcessor != null) {
pane = paneProcessor.createServerTableDataPane(); pane = paneProcessor.createServerTableDataPane();
} }
tdPane = pane == null ? new TableDataListPane() { tdPane = pane == null ? new TableDataPaneListPane() {
@Override @Override
public NameableCreator[] createNameableCreators() { public NameableCreator[] createNameableCreators() {
return TableDataCreatorProducer.getInstance().createReportTableDataCreator(); return TableDataCreatorProducer.getInstance().createReportTableDataCreator();
} }
} : pane; } : pane;
container.add(tdPane, BorderLayout.CENTER); container.add(tdPane.getPanel(), BorderLayout.CENTER);
} }
@Override @Override

62
designer_base/src/com/fr/design/data/datapane/TableDataPaneController.java

@ -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();
}

523
designer_base/src/com/fr/design/data/datapane/TableDataListPane.java → designer_base/src/com/fr/design/data/datapane/TableDataPaneListPane.java

@ -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;
}
} }

14
designer_base/src/com/fr/design/data/tabledata/tabledatapane/TableDataManagerPane.java

@ -2,9 +2,9 @@ package com.fr.design.data.tabledata.tabledatapane;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.data.datapane.TableDataListPane; import com.fr.design.data.datapane.TableDataPaneController;
import com.fr.design.data.datapane.TableDataPaneListPane;
import com.fr.design.fun.TableDataPaneProcessor; import com.fr.design.fun.TableDataPaneProcessor;
import com.fr.design.gui.controlpane.JControlPane;
import com.fr.design.gui.frpane.LoadingBasicPane; import com.fr.design.gui.frpane.LoadingBasicPane;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itextfield.UITextField;
@ -21,7 +21,7 @@ import java.util.Map;
public class TableDataManagerPane extends LoadingBasicPane { public class TableDataManagerPane extends LoadingBasicPane {
private UITextField tableDataTextField; private UITextField tableDataTextField;
private JControlPane tableDataPane; private TableDataPaneController tableDataPane;
@Override @Override
protected void initComponents(JPanel container) { protected void initComponents(JPanel container) {
@ -40,17 +40,17 @@ public class TableDataManagerPane extends LoadingBasicPane {
tableDataPathPane.add(tableDataTextField, BorderLayout.CENTER); tableDataPathPane.add(tableDataTextField, BorderLayout.CENTER);
this.tableDataTextField.setEditable(false); this.tableDataTextField.setEditable(false);
TableDataPaneProcessor paneProcessor = ExtraDesignClassManager.getInstance().getTableDataPaneProcessor(); TableDataPaneProcessor paneProcessor = ExtraDesignClassManager.getInstance().getTableDataPaneProcessor();
JControlPane pane = null; TableDataPaneController pane = null;
if (paneProcessor != null) { if (paneProcessor != null) {
pane = paneProcessor.createServerTableDataPane(); pane = paneProcessor.createServerTableDataPane();
} }
tableDataPane = pane == null ? new TableDataListPane() { tableDataPane = pane == null ? new TableDataPaneListPane() {
protected void rename(String oldName, String newName) { public void rename(String oldName, String newName) {
super.rename(oldName, newName); super.rename(oldName, newName);
renameConnection(oldName, newName); renameConnection(oldName, newName);
} }
} : pane; } : pane;
container.add(tableDataPane, BorderLayout.CENTER); container.add(tableDataPane.getPanel(), BorderLayout.CENTER);
} }

4
designer_base/src/com/fr/design/fun/TableDataPaneProcessor.java

@ -2,7 +2,7 @@ package com.fr.design.fun;
import com.fr.design.DesignModelAdapter; import com.fr.design.DesignModelAdapter;
import com.fr.design.data.BasicTableDataTreePane; import com.fr.design.data.BasicTableDataTreePane;
import com.fr.design.gui.controlpane.JControlPane; import com.fr.design.data.datapane.TableDataPaneController;
import com.fr.stable.fun.Level; import com.fr.stable.fun.Level;
/** /**
@ -25,6 +25,6 @@ public interface TableDataPaneProcessor extends Level {
* 服务器数据集面板(模板数据集面板) * 服务器数据集面板(模板数据集面板)
* @return 服务器数据集面板 * @return 服务器数据集面板
*/ */
JControlPane createServerTableDataPane(); TableDataPaneController createServerTableDataPane();
} }

174
designer_base/src/com/fr/design/gui/controlpane/JControlPane.java

@ -1,20 +1,16 @@
package com.fr.design.gui.controlpane; package com.fr.design.gui.controlpane;
import com.fr.data.TableDataSource;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.menu.ToolBarDef; import com.fr.design.menu.ToolBarDef;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.file.DatasourceManagerProvider;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.Nameable; import com.fr.stable.Nameable;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.util.HashMap;
import java.util.Map;
/** /**
* Coder: zack * Coder: zack
@ -24,12 +20,12 @@ import java.util.Map;
public abstract class JControlPane extends BasicPane implements UnrepeatedNameHelper { public abstract class JControlPane extends BasicPane implements UnrepeatedNameHelper {
protected static final int SHORT_WIDTH = 30; //每加一个short Divider位置加30 protected static final int SHORT_WIDTH = 30; //每加一个short Divider位置加30
protected JPanel controlUpdatePane; protected JPanel controlUpdatePane;
protected Map<String, String> dsNameChangedMap = new HashMap<String, String>();
protected ShortCut4JControlPane[] shorts;
protected NameableCreator[] creators;
protected ToolBarDef toolbarDef;
protected UIToolbar toolBar; private ShortCut4JControlPane[] shorts;
private NameableCreator[] creators;
private ToolBarDef toolbarDef;
private UIToolbar toolBar;
// peter:这是整体的一个cardLayout Pane // peter:这是整体的一个cardLayout Pane
protected CardLayout cardLayout; protected CardLayout cardLayout;
@ -46,6 +42,50 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe
*/ */
public abstract NameableCreator[] createNameableCreators(); public abstract NameableCreator[] createNameableCreators();
public ShortCut4JControlPane[] getShorts() {
return shorts;
}
public void setShorts(ShortCut4JControlPane[] shorts) {
this.shorts = shorts;
}
public void setCreators(NameableCreator[] creators) {
this.creators = creators;
}
public ToolBarDef getToolbarDef() {
return toolbarDef;
}
public void setToolbarDef(ToolBarDef toolbarDef) {
this.toolbarDef = toolbarDef;
}
public UIToolbar getToolBar() {
return toolBar;
}
public void setToolBar(UIToolbar toolBar) {
this.toolBar = toolBar;
}
public CardLayout getCardLayout() {
return cardLayout;
}
public void setCardLayout(CardLayout cardLayout) {
this.cardLayout = cardLayout;
}
public JPanel getCardPane() {
return cardPane;
}
public void setCardPane(JPanel cardPane) {
this.cardPane = cardPane;
}
protected void initComponentPane() { protected void initComponentPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.creators = this.createNameableCreators(); this.creators = this.createNameableCreators();
@ -75,7 +115,7 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe
// LeftPane // LeftPane
JPanel leftPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); JPanel leftPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
init(leftPane); initLeftPane(leftPane);
shorts = this.createShortcuts(); shorts = this.createShortcuts();
if (ArrayUtils.isEmpty(shorts)) { if (ArrayUtils.isEmpty(shorts)) {
@ -92,59 +132,10 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe
return leftPane; return leftPane;
} }
public ShortCut4JControlPane[] getShorts() {
return shorts;
}
public void setShorts(ShortCut4JControlPane[] shorts) {
this.shorts = shorts;
}
public NameableCreator[] getCreators() {
return creators;
}
public void setCreators(NameableCreator[] creators) {
this.creators = creators;
}
public ToolBarDef getToolbarDef() {
return toolbarDef;
}
public void setToolbarDef(ToolBarDef toolbarDef) {
this.toolbarDef = toolbarDef;
}
public UIToolbar getToolBar() {
return toolBar;
}
public void setToolBar(UIToolbar toolBar) {
this.toolBar = toolBar;
}
public CardLayout getCardLayout() {
return cardLayout;
}
public void setCardLayout(CardLayout cardLayout) {
this.cardLayout = cardLayout;
}
public JPanel getCardPane() {
return cardPane;
}
public void setCardPane(JPanel cardPane) {
this.cardPane = cardPane;
}
/** /**
* 初始化 * 初始化左边面板
*/ */
protected void init(JPanel leftPane) { protected void initLeftPane(JPanel leftPane) {
} }
@ -152,13 +143,6 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe
return shorts.length * SHORT_WIDTH; return shorts.length * SHORT_WIDTH;
} }
public Map<String, String> getDsNameChangedMap() {
return dsNameChangedMap;
}
public void setDsNameChangedMap(Map<String, String> dsNameChangedMap) {
this.dsNameChangedMap = dsNameChangedMap;
}
protected ShortCut4JControlPane[] createShortcuts() { protected ShortCut4JControlPane[] createShortcuts() {
return new ShortCut4JControlPane[]{ return new ShortCut4JControlPane[]{
@ -183,36 +167,12 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe
protected abstract ShortCut4JControlPane sortItemShortCut(); protected abstract ShortCut4JControlPane sortItemShortCut();
public void setNameListEditable(boolean editable) {
}
public abstract Nameable[] update(); public abstract Nameable[] update();
public void populate(Nameable[] nameableArray) { public void populate(Nameable[] nameableArray) {
} }
public void update(DatasourceManagerProvider datasourceManager) {
}
public void populate(DatasourceManagerProvider datasourceManager) {
}
public void populate(TableDataSource tds) {
}
public void update(TableDataSource tds) {
}
/**
* 名字是否允许
*
* @return 默认返回true
*/
public boolean isNamePermitted() {
return true;
}
/** /**
* 检查按钮可用状态 Check button enabled. * 检查按钮可用状态 Check button enabled.
*/ */
@ -220,37 +180,33 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe
} }
protected void doBeforeRemove() { protected void doBeforeRemove() {
} }
protected void doAfterRemove() { protected void doAfterRemove() {
} }
public NameableCreator[] creators() { public NameableCreator[] creators() {
return creators == null ? new NameableCreator[0] : creators; return creators == null ? new NameableCreator[0] : creators;
} }
/**
* 检查是否符合规范
*
* @throws Exception
*/
public void checkValid() throws Exception {
}
protected abstract boolean hasInvalid(boolean isAdd); protected abstract boolean hasInvalid(boolean isAdd);
/** /**
* 设置选中项 * 刷新 NameableCreator
* *
* @param index 选中项的序列号 * @param creators 生成器
*/ */
public void setSelectedIndex(int index) { public void refreshNameableCreator(NameableCreator[] creators) {
} this.creators = creators;
shorts = this.createShortcuts();
toolbarDef.clearShortCuts();
for (ShortCut4JControlPane sj : shorts) {
toolbarDef.addShortCut(sj.getShortCut());
}
protected void rename(String oldName, String newName) { toolbarDef.updateToolBar(toolBar);
dsNameChangedMap.put(oldName, newName); toolBar.validate();
toolBar.repaint();
this.repaint();
} }
} }

82
designer_base/src/com/fr/design/gui/controlpane/JListControlPane.java

@ -63,29 +63,7 @@ public abstract class JListControlPane extends JControlPane {
public abstract NameableCreator[] createNameableCreators(); public abstract NameableCreator[] createNameableCreators();
protected JPanel getLeftPane() { protected void initLeftPane(JPanel leftPane) {
// LeftPane
JPanel leftPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
initNameList(leftPane);
shorts = this.createShortcuts();
if (ArrayUtils.isEmpty(shorts)) {
return leftPane;
}
toolbarDef = new ToolBarDef();
for (ShortCut4JControlPane sj : shorts) {
toolbarDef.addShortCut(sj.getShortCut());
}
toolBar = ToolBarDef.createJToolBar();
toolbarDef.updateToolBar(toolBar);
leftPane.add(toolBar, BorderLayout.NORTH);
return leftPane;
}
private void initNameList(JPanel leftPane) {
nameableList = createJNameList(); nameableList = createJNameList();
nameableList.setName(LIST_NAME); nameableList.setName(LIST_NAME);
leftPane.add(new UIScrollPane(nameableList), BorderLayout.CENTER); leftPane.add(new UIScrollPane(nameableList), BorderLayout.CENTER);
@ -127,23 +105,9 @@ public abstract class JListControlPane extends JControlPane {
} }
protected int getLeftPreferredSize() {
return shorts.length * JControlPane.SHORT_WIDTH;
}
protected ShortCut4JControlPane[] createShortcuts() {
return new ShortCut4JControlPane[]{
addItemShortCut(),
removeItemShortCut(),
copyItemShortCut(),
moveUpItemShortCut(),
moveDownItemShortCut(),
sortItemShortCut()
};
}
protected ShortCut4JControlPane addItemShortCut() { protected ShortCut4JControlPane addItemShortCut() {
ShortCut addItemShortCut; ShortCut addItemShortCut;
NameableCreator[] creators = creators();
if (creators.length == 1) { if (creators.length == 1) {
addItemShortCut = new AddItemUpdateAction(creators); addItemShortCut = new AddItemUpdateAction(creators);
} else { } else {
@ -264,25 +228,6 @@ public abstract class JListControlPane extends JControlPane {
return el == null ? null : el.wrapper.getName(); return el == null ? null : el.wrapper.getName();
} }
/**
* 刷新 NameableCreator
*
* @param creators 生成器
*/
public void refreshNameableCreator(NameableCreator[] creators) {
this.creators = creators;
shorts = this.createShortcuts();
toolbarDef.clearShortCuts();
for (ShortCut4JControlPane sj : shorts) {
toolbarDef.addShortCut(sj.getShortCut());
}
toolbarDef.updateToolBar(toolBar);
toolBar.validate();
toolBar.repaint();
this.repaint();
}
protected boolean isNameRepeted(java.util.List[] list, String name) { protected boolean isNameRepeted(java.util.List[] list, String name) {
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
if (list[i].contains(name)) { if (list[i].contains(name)) {
@ -676,7 +621,7 @@ public abstract class JListControlPane extends JControlPane {
// p:右键菜单. // p:右键菜单.
JPopupMenu popupMenu = new JPopupMenu(); JPopupMenu popupMenu = new JPopupMenu();
for (ShortCut4JControlPane sj : shorts) { for (ShortCut4JControlPane sj : getShorts()) {
sj.getShortCut().intoJPopupMenu(popupMenu); sj.getShortCut().intoJPopupMenu(popupMenu);
} }
@ -694,13 +639,14 @@ public abstract class JListControlPane extends JControlPane {
* 检查按钮可用状态 Check button enabled. * 检查按钮可用状态 Check button enabled.
*/ */
public void checkButtonEnabled() { public void checkButtonEnabled() {
int selectedIndex = nameableList.getSelectedIndex(); int selectedIndex = nameableList.getSelectedIndex();
if (selectedIndex == -1) { if (selectedIndex == -1) {
this.cardLayout.show(cardPane, "SELECT"); this.cardLayout.show(cardPane, "SELECT");
} else { } else {
this.cardLayout.show(cardPane, "EDIT"); this.cardLayout.show(cardPane, "EDIT");
} }
for (ShortCut4JControlPane sj : this.shorts) { for (ShortCut4JControlPane sj : getShorts()) {
sj.checkEnable(); sj.checkEnable();
} }
} }
@ -713,10 +659,6 @@ public abstract class JListControlPane extends JControlPane {
} }
public NameableCreator[] creators() {
return creators == null ? new NameableCreator[0] : creators;
}
/* /*
* Nameable的ListCellRenerer * Nameable的ListCellRenerer
*/ */
@ -732,7 +674,7 @@ public abstract class JListControlPane extends JControlPane {
this.setText(((ListModelElement) value).wrapper.getName()); this.setText(((ListModelElement) value).wrapper.getName());
boolean iconSet = false; boolean iconSet = false;
for (NameableCreator creator : JListControlPane.this.creators) { for (NameableCreator creator : JListControlPane.this.creators()) {
if (creator.menuIcon() != null && creator.acceptObject2Populate(wrappee) != null) { if (creator.menuIcon() != null && creator.acceptObject2Populate(wrappee) != null) {
this.setIcon(creator.menuIcon()); this.setIcon(creator.menuIcon());
this.setToolTipText(creator.createTooltip()); this.setToolTipText(creator.createTooltip());
@ -836,6 +778,7 @@ public abstract class JListControlPane extends JControlPane {
} }
private void initUpdatePane() { private void initUpdatePane() {
NameableCreator[] creators = creators();
if (creators == null) { if (creators == null) {
return; return;
} }
@ -855,6 +798,7 @@ public abstract class JListControlPane extends JControlPane {
} }
elEditing = el; elEditing = el;
NameableCreator[] creators = creators();
for (int i = 0, len = updatePanes.length; i < len; i++) { for (int i = 0, len = updatePanes.length; i < len; i++) {
Object ob2Populate = creators[i].acceptObject2Populate(el.wrapper); Object ob2Populate = creators[i].acceptObject2Populate(el.wrapper);
@ -884,13 +828,14 @@ public abstract class JListControlPane extends JControlPane {
} }
public void update() { public void update() {
NameableCreator[] creators = creators();
for (int i = 0; i < updatePanes.length; i++) { for (int i = 0; i < updatePanes.length; i++) {
BasicBeanPane pane = updatePanes[i]; BasicBeanPane pane = updatePanes[i];
if (pane != null && pane.isVisible()) { if (pane != null && pane.isVisible()) {
Object bean = pane.updateBean(); Object bean = pane.updateBean();
if (i < JListControlPane.this.creators.length) { if (i < creators.length) {
JListControlPane.this.creators[i].saveUpdatedBean(elEditing, bean); creators[i].saveUpdatedBean(elEditing, bean);
} }
} }
} }
@ -937,8 +882,9 @@ public abstract class JListControlPane extends JControlPane {
// 选项添加个数有限制等情况下 要求能控制快捷按钮的状态 // 选项添加个数有限制等情况下 要求能控制快捷按钮的状态
protected void setToolbarDefEnable(int shortCutIndex, int itemIndex, boolean enabled) { protected void setToolbarDefEnable(int shortCutIndex, int itemIndex, boolean enabled) {
if (this.toolbarDef.getShortCutCount() > shortCutIndex) { ToolBarDef toolbarDef = getToolbarDef();
ShortCut sc = this.toolbarDef.getShortCut(shortCutIndex); if (toolbarDef.getShortCutCount() > shortCutIndex) {
ShortCut sc = toolbarDef.getShortCut(shortCutIndex);
if (sc instanceof AddItemMenuDef) { if (sc instanceof AddItemMenuDef) {
AddItemMenuDef am = (AddItemMenuDef) sc; AddItemMenuDef am = (AddItemMenuDef) sc;
if (am.getShortCutCount() > itemIndex) { if (am.getShortCutCount() > itemIndex) {

Loading…
Cancel
Save