Browse Source

Merge pull request #389 in BA/design from ~JU/core-design:dev to dev

* commit '4bf091e613cb08ebfb5596b17caa58f03073c39d':
  代码与UITable比较难兼容,将Table的Renderer和Editor改为UI***来统一风格
  implements DataCreatorUI
  极速分层构建
  implements DataCreatorUI
  极速分层构建
  下拉树极速分层构建
master
superman 8 years ago
parent
commit
383acf2787
  1. 165
      designer_base/src/com/fr/design/gui/frpane/TreeSettingPane.java
  2. 102
      designer_base/src/com/fr/design/gui/frpane/tree/layer/config/LayerDataConfigPane.java
  3. 254
      designer_base/src/com/fr/design/gui/frpane/tree/layer/config/LayerDataControlPane.java
  4. 459
      designer_base/src/com/fr/design/gui/frpane/tree/layer/config/LayerDependenceSettingPane.java
  5. 3
      designer_form/src/com/fr/design/mainframe/widget/wrappers/TreeModelWrapper.java

165
designer_base/src/com/fr/design/gui/frpane/TreeSettingPane.java

@ -1,44 +1,52 @@
package com.fr.design.gui.frpane; package com.fr.design.gui.frpane;
import java.awt.BorderLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import com.fr.data.impl.TreeNodeWrapper;
import com.fr.design.data.DataCreatorUI;
import com.fr.design.gui.ilable.UILabel;
import javax.swing.*;
import com.fr.general.NameObject;
import com.fr.data.impl.TableDataDictionary; import com.fr.data.impl.TableDataDictionary;
import com.fr.data.impl.TreeAttr; import com.fr.data.impl.TreeAttr;
import com.fr.data.impl.TreeNodeAttr; import com.fr.data.impl.TreeNodeAttr;
import com.fr.data.impl.TreeNodeWrapper;
import com.fr.design.data.DataCreatorUI;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.controlpane.NameObjectCreator; import com.fr.design.gui.controlpane.NameObjectCreator;
import com.fr.design.gui.controlpane.NameableCreator; import com.fr.design.gui.controlpane.NameableCreator;
import com.fr.design.gui.frpane.tree.layer.config.LayerDataControlPane;
import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itree.refreshabletree.TreeDataCardPane; import com.fr.design.gui.itree.refreshabletree.TreeDataCardPane;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.dialog.BasicPane;
import com.fr.form.ui.TreeComboBoxEditor; import com.fr.form.ui.TreeComboBoxEditor;
import com.fr.form.ui.TreeEditor; import com.fr.form.ui.TreeEditor;
import com.fr.form.ui.tree.LayerConfig;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.general.NameObject;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class TreeSettingPane extends BasicPane implements DataCreatorUI { public class TreeSettingPane extends BasicPane implements DataCreatorUI {
private JTreeControlPane controlPane; private JTreeControlPane controlPane;
private JTreeAutoBuildPane autoBuildPane; private JTreeAutoBuildPane autoBuildPane;
/**
* 新的分层构建方式
*/
private LayerDataControlPane layerDataControlPane;
private UIComboBox buildBox; private UIComboBox buildBox;
/** /**
* *
*/ */
private static final long serialVersionUID = 1762889323082827111L; private static final long serialVersionUID = 1762889323082827111L;
private String[] buildWay = new String[] { Inter.getLocText("FR-Designer_Layer-Build"), private String[] buildWay = new String[]{Inter.getLocText("FR-Designer_DataTable-Build"),
Inter.getLocText("FR-Designer_Auto-Build") }; Inter.getLocText("FR-Designer_Auto-Build"), Inter.getLocText("FR-Designer_Layer-Build")};
public TreeSettingPane(boolean isEditor) { public TreeSettingPane(boolean isEditor) {
this.initComponents(isEditor); this.initComponents(isEditor);
} }
private void initComponents(boolean isEditor) { private void initComponents(boolean isEditor) {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
@ -58,18 +66,34 @@ public class TreeSettingPane extends BasicPane implements DataCreatorUI {
controlPane = new JTreeControlPane(new NameableCreator[] { treeNode }, controlPane = new JTreeControlPane(new NameableCreator[] { treeNode },
new TreeDataCardPane(), isEditor); new TreeDataCardPane(), isEditor);
autoBuildPane = new JTreeAutoBuildPane(); autoBuildPane = new JTreeAutoBuildPane();
this.add(buildWayPanel, BorderLayout.NORTH); layerDataControlPane = new LayerDataControlPane();
cardChanged(0); this.add(buildWayPanel, BorderLayout.NORTH);
} cardChanged(0);
}
private void cardChanged(int index) { private void cardChanged(int index) {
this.remove(controlPane); this.remove(controlPane);
this.remove(autoBuildPane); this.remove(autoBuildPane);
this.add(index == 0 ? controlPane : autoBuildPane, BorderLayout.CENTER); this.remove(layerDataControlPane);
validate(); switch (index) {
repaint(); case 0:
revalidate(); this.add(layerDataControlPane);
} break;
case 1:
this.add(autoBuildPane);
break;
case 2:
this.add(controlPane);
break;
default:
break;
}
validate();
repaint();
revalidate();
}
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
@ -101,10 +125,19 @@ public class TreeSettingPane extends BasicPane implements DataCreatorUI {
buildBox.setSelectedIndex(1); buildBox.setSelectedIndex(1);
TableDataDictionary dictionary = treeEditor.getDictionary(); TableDataDictionary dictionary = treeEditor.getDictionary();
autoBuildPane.populate(dictionary); autoBuildPane.populate(dictionary);
} else { } else if (treeEditor.isLayerBuild()) {
buildBox.setSelectedIndex(0); buildBox.setSelectedIndex(0);
} java.util.List<LayerConfig> layerConfigList = treeEditor.getLayerConfigs();
} LayerConfig[] layerConfigs = new LayerConfig[layerConfigList.size()];
int i = 0;
for (LayerConfig layerConfig : layerConfigList) {
layerConfigs[i++] = layerConfig;
}
this.layerDataControlPane.populate(new NameObject("tree", layerConfigs));
} else {
buildBox.setSelectedIndex(2);
}
}
/** /**
* 视图树的update * 视图树的update
@ -123,43 +156,46 @@ public class TreeSettingPane extends BasicPane implements DataCreatorUI {
te.setAutoBuild(true); te.setAutoBuild(true);
te.setDictionary(dictionary); te.setDictionary(dictionary);
te.setNodeOrDict(dictionary); te.setNodeOrDict(dictionary);
} else { } else if (buildBox.getSelectedIndex() == 2) {
te.setAutoBuild(false); te.setAutoBuild(false);
NameObject no = this.controlPane.update(); NameObject no = this.controlPane.update();
if (no != null) { if (no != null) {
TreeEditor editor = (TreeEditor) no.getObject(); TreeEditor editor = (TreeEditor) no.getObject();
te.setAllowBlank(editor.isAllowBlank()); te.setAllowBlank(editor.isAllowBlank());
te.setEnabled(editor.isEnabled()); te.setEnabled(editor.isEnabled());
te.setDirectEdit(editor.isDirectEdit()); te.setDirectEdit(editor.isDirectEdit());
te.setErrorMessage(editor.getErrorMessage()); te.setErrorMessage(editor.getErrorMessage());
te.setWidgetName(editor.getWidgetName()); te.setWidgetName(editor.getWidgetName());
te.setVisible(editor.isVisible()); te.setVisible(editor.isVisible());
te.setWaterMark(editor.getWaterMark()); te.setWaterMark(editor.getWaterMark());
te.setRemoveRepeat(editor.isRemoveRepeat()); te.setRemoveRepeat(editor.isRemoveRepeat());
te.setTreeAttr(editor.getTreeAttr()); te.setTreeAttr(editor.getTreeAttr());
te.setTreeNodeAttr(editor.getTreeNodeAttr()); te.setTreeNodeAttr(editor.getTreeNodeAttr());
te.setNodeOrDict(editor.getTreeNodeAttr()); te.setNodeOrDict(editor.getTreeNodeAttr());
te.setPerformanceFirst(editor.isPerformanceFirst()); te.setPerformanceFirst(editor.isPerformanceFirst());
} }
} }
return te; return te;
} }
/** /**
* 树节点属性的update * 树节点属性的update
* @return * @return
*/ */
public Object updateTreeNodeAttrs() { public Object updateTreeNodeAttrs() {
if(buildBox.getSelectedIndex() == 0) {
NameObject no = controlPane.update(); if (buildBox.getSelectedIndex() == 2) {
if (no != null) { NameObject no = controlPane.update();
return no.getObject(); if (no != null) {
return no.getObject();
} }
} else { } else if (buildBox.getSelectedIndex() == 0) {
return autoBuildPane.update(); return layerDataControlPane.update();
} } else {
return null; return autoBuildPane.update();
} }
return null;
}
/** /**
* 下拉树的update * 下拉树的update
@ -172,7 +208,7 @@ public class TreeSettingPane extends BasicPane implements DataCreatorUI {
tcb.setAutoBuild(true); tcb.setAutoBuild(true);
tcb.setDictionary(dictionary); tcb.setDictionary(dictionary);
tcb.setNodeOrDict(dictionary); tcb.setNodeOrDict(dictionary);
} else { } else if (buildBox.getSelectedIndex() == 2) {
tcb.setAutoBuild(false); tcb.setAutoBuild(false);
NameObject no = this.controlPane.update(); NameObject no = this.controlPane.update();
if (no != null) { if (no != null) {
@ -204,12 +240,15 @@ public class TreeSettingPane extends BasicPane implements DataCreatorUI {
*/ */
public void populate(Object nodeOrDict) { public void populate(Object nodeOrDict) {
if(nodeOrDict instanceof TreeNodeAttr[] || nodeOrDict instanceof TreeNodeWrapper) { if(nodeOrDict instanceof TreeNodeAttr[] || nodeOrDict instanceof TreeNodeWrapper) {
buildBox.setSelectedIndex(0); buildBox.setSelectedIndex(2);
NameObject no = new NameObject("name", nodeOrDict); NameObject no = new NameObject("name", nodeOrDict);
controlPane.populate(no); controlPane.populate(no);
} else if(nodeOrDict instanceof TableDataDictionary) { } else if(nodeOrDict instanceof TableDataDictionary) {
buildBox.setSelectedIndex(1); buildBox.setSelectedIndex(1);
autoBuildPane.populate((TableDataDictionary)nodeOrDict); autoBuildPane.populate((TableDataDictionary)nodeOrDict);
} } else if (nodeOrDict instanceof NameObject) {
} buildBox.setSelectedIndex(0);
layerDataControlPane.populate((NameObject) nodeOrDict);
}
}
} }

102
designer_base/src/com/fr/design/gui/frpane/tree/layer/config/LayerDataConfigPane.java

@ -0,0 +1,102 @@
package com.fr.design.gui.frpane.tree.layer.config;
import com.fr.base.TableData;
import com.fr.data.impl.TableDataDictionary;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
import com.fr.design.present.dict.TableDataDictPane;
import com.fr.form.ui.tree.LayerConfig;
import com.fr.form.ui.tree.LayerDependence;
import java.awt.*;
import java.util.*;
import java.util.List;
/**
* Created by juhaoyu on 16/9/13.
*/
public class LayerDataConfigPane extends BasicBeanPane<LayerConfig> {
/**
* 数据集数据字典选择panel
*/
private TableDataDictPane tableDataDictPane;
/**
* 与父级关联的字段选择
*/
private LayerDependenceSettingPane dependenceSettingPane;
/**
* 当前用户正在修改的LayerData
*/
private LayerConfig layerConfig;
public LayerDataConfigPane() {
//初始化组件及布局
this.tableDataDictPane = new TableDataDictPane();
this.dependenceSettingPane = new LayerDependenceSettingPane(tableDataDictPane);
this.setLayout(new BorderLayout(2, 2));
this.add(tableDataDictPane, BorderLayout.NORTH);
this.add(dependenceSettingPane, BorderLayout.CENTER);
}
/**
* 1.切换层级时
*
* @param layerConfig
*/
@Override
public void populateBean(LayerConfig layerConfig) {
if (layerConfig != null) {
this.layerConfig = layerConfig;
TableDataDictionary ta = layerConfig.getDictionary();
this.tableDataDictPane.populateBean(ta);
this.dependenceSettingPane.populate(layerConfig.getIndex(), layerConfig.getDependenceList());
}
}
@Override
public LayerConfig updateBean() {
if (layerConfig == null) {
return null;
}
//从下层panel中读取数据
TableData tableData = tableDataDictPane.updateBean().getTableData();
TableDataWrapper wrapper = tableDataDictPane.tableDataNameComboBox.getSelectedItem();
List<String> columnNames;
if (wrapper != null) {
columnNames = wrapper.calculateColumnNameList();
} else {
columnNames = new ArrayList<String>();
}
String viewColStr = tableDataDictPane.updateBean().getValueColumnName();
String modelColStr = tableDataDictPane.updateBean().getKeyColumnName();
TableDataDictionary dictionary = tableDataDictPane.updateBean();
int viewCol = columnNames.indexOf(viewColStr);
int modelCol = columnNames.indexOf(modelColStr);
//将数据设置到当前正在修改的layerData中
this.layerConfig.setDictionary(dictionary);
this.layerConfig.setModelColumn(modelCol);
this.layerConfig.setViewColumn(viewCol);
this.layerConfig.setTableData(tableData);
//添加依赖
java.util.List<LayerDependence> dependenceList = dependenceSettingPane.updateLayerDependence();
layerConfig.getDependenceList().clear();
layerConfig.addAll(dependenceList);
return layerConfig;
}
@Override
protected String title4PopupWindow() {
return "Layer Data Config Panel";
}
}

254
designer_base/src/com/fr/design/gui/frpane/tree/layer/config/LayerDataControlPane.java

@ -0,0 +1,254 @@
package com.fr.design.gui.frpane.tree.layer.config;
import com.fr.base.BaseUtils;
import com.fr.design.actions.UpdateAction;
import com.fr.design.gui.controlpane.ControlPane;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.menu.ToolBarDef;
import com.fr.form.ui.tree.LayerConfig;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.general.NameObject;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
/**
* Created by juhaoyu on 16/9/21.
*/
public class LayerDataControlPane extends ControlPane {
public static final String BEAN_NAME = "Tree Layer Data";
// 添加一个treeNode
private AddTreeNodeAction addTreeNode;
// 移除一个treeNode
private RemoveTreeNodeAction removeTreeNode;
private LayerDataConfigPane configPane;
private JTree tree;
private DefaultTreeModel defaultTreeModel;
public LayerDataControlPane() {
this.setLayout(new BorderLayout(2, 2));
//创建层编辑panel
configPane = new LayerDataConfigPane();
//创建树结构及树控件
JPanel leftPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(Inter.getLocText("FR-Designer_Root"));
defaultTreeModel = new DefaultTreeModel(rootNode);
tree = new JTree(defaultTreeModel);
DefaultMutableTreeNode firstLayer = new DefaultMutableTreeNode(new NameObject(Inter.getLocText("FR-Designer_Gradation") + 1, new LayerConfig(1)));
tree.setRootVisible(false);
((DefaultMutableTreeNode) defaultTreeModel.getRoot()).getLastLeaf().add(firstLayer);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
leftPane.add(new UIScrollPane(tree), BorderLayout.CENTER);
tree.setPreferredSize(new Dimension(170, 350));
tree.setCellRenderer(renderer);
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
configPane.updateBean();
refreshCurrentUpdatePane();
checkButtonEnabled();
}
});
// JTreeControlPane控制栏
ToolBarDef toolbarDef = new ToolBarDef();
toolbarDef.addShortCut(addTreeNode = new AddTreeNodeAction());
toolbarDef.addShortCut(removeTreeNode = new RemoveTreeNodeAction());
UIToolbar toolBar = ToolBarDef.createJToolBar();
toolbarDef.updateToolBar(toolBar);
leftPane.add(toolBar, BorderLayout.NORTH);
this.add(leftPane, BorderLayout.WEST);
this.add(this.configPane, BorderLayout.CENTER);
defaultTreeModel.reload();
TreePath path = new TreePath(defaultTreeModel.getPathToRoot(rootNode.getLastLeaf()));
tree.setSelectionPath(path);
this.checkButtonEnabled();
}
public void refreshCurrentUpdatePane() {
TreePath selectTreePath = this.tree.getSelectionPath();
if (selectTreePath != null) {
NameObject object = (NameObject) ((DefaultMutableTreeNode) selectTreePath.getLastPathComponent()).getUserObject();
if (object != null && object.getObject() != null) {
configPane.populateBean((LayerConfig) object.getObject());
}
}
}
TreeCellRenderer renderer = new DefaultTreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
if (leaf) {
this.setIcon(BaseUtils.readIcon("com/fr/design/images/data/default_widget.png"));
} else {
this.setIcon(BaseUtils.readIcon("com/fr/design/images/data/arrow_branch.png"));
}
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object userObj = node.getUserObject();
if (userObj instanceof NameObject) {
this.setText(((NameObject) userObj).getName());
}
}
this.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));
return this;
}
};
private void checkButtonEnabled() {
this.addTreeNode.setEnabled(true);
this.removeTreeNode.setEnabled(true);
// richer:当选择了树根节点时,不能被删除、上移和下移
DefaultMutableTreeNode root = (DefaultMutableTreeNode) defaultTreeModel.getRoot();
TreePath rootPath = new TreePath(defaultTreeModel.getPathToRoot(root));
if (ComparatorUtils.equals(rootPath, tree.getSelectionPath())) {
this.removeTreeNode.setEnabled(false);
}
}
private class AddTreeNodeAction extends UpdateAction {
public AddTreeNodeAction() {
this.setName(Inter.getLocText("FR-Designer_Add"));
this.setMnemonic('A');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/add.png"));
}
public void actionPerformed(ActionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) defaultTreeModel.getRoot();
DefaultMutableTreeNode innerNode = node;
int nodeCount = 0;
do {
nodeCount++;
} while ((innerNode = innerNode.getNextNode()) != null);
NameObject nameable = new NameObject(Inter.getLocText("FR-Designer_Gradation") + nodeCount, new LayerConfig(nodeCount));
node.getLastLeaf().add(new DefaultMutableTreeNode(nameable));
defaultTreeModel.reload();
TreePath path = new TreePath(defaultTreeModel.getPathToRoot(node.getLastLeaf()));
tree.setSelectionPath(path);
}
}
private class RemoveTreeNodeAction extends UpdateAction {
public RemoveTreeNodeAction() {
this.setName(Inter.getLocText("FR-Designer_Remove"));
this.setMnemonic('R');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/remove.png"));
}
public void actionPerformed(ActionEvent e) {
// TODO remove tree node
int val = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Utils-Are_you_sure_to_remove_the_selected_item") + "?",
Inter.getLocText("FR-Designer_Remove"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (val != JOptionPane.OK_OPTION) {
return;
}
TreePath selectionPath = tree.getSelectionPath();
DefaultMutableTreeNode tmpNode = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
tmpNode.removeFromParent();
defaultTreeModel.reload();
DefaultMutableTreeNode node = (DefaultMutableTreeNode) defaultTreeModel.getRoot();
TreePath path = new TreePath(defaultTreeModel.getPathToRoot(node.getLastLeaf()));
tree.setSelectionPath(path);
}
}
public void populate(NameObject nameObject) {
// 重新添加tree节点的时候需要remove掉原来的所有子节点
((DefaultMutableTreeNode) defaultTreeModel.getRoot()).removeAllChildren();
if (BEAN_NAME.equals(nameObject.getName())) {
Object obj = nameObject.getObject();
LayerConfig[] layerConfigs = null;
if (obj instanceof LayerConfig[]) {
layerConfigs = ((LayerConfig[]) obj);
}
int count = layerConfigs == null ? 0 : layerConfigs.length;
//将树的层次一层一层的加上去
DefaultMutableTreeNode node4root = (DefaultMutableTreeNode) defaultTreeModel.getRoot();
for (int i = 0; i < count; i++) {
DefaultMutableTreeNode node4add = new DefaultMutableTreeNode(
new NameObject(Inter.getLocText("FR-Designer_Gradation") + (i + 1), layerConfigs[i]));
node4root.add(node4add);
node4root = node4add;
}
defaultTreeModel.reload();
expandAll(tree, true);
tree.setSelectionRow(0);
}
}
public NameObject update() {
return new NameObject(BEAN_NAME, updateLayerDatas());
}
private LayerConfig[] updateLayerDatas() {
//保存最后一个设置的层级
configPane.updateBean();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) defaultTreeModel.getRoot();
java.util.List<LayerConfig> nodeList = new ArrayList<LayerConfig>();
for (; root != null; root = root.getNextNode()) {
if (!(root.getUserObject() instanceof NameObject)) {
continue;
}
NameObject no = (NameObject) root.getUserObject();
if (no.getObject() instanceof LayerConfig) {
nodeList.add((LayerConfig) no.getObject());
}
}
return nodeList.toArray(new LayerConfig[nodeList.size()]);
}
@Override
protected String title4PopupWindow() {
return "Layer Data Control Pane";
}
}

459
designer_base/src/com/fr/design/gui/frpane/tree/layer/config/LayerDependenceSettingPane.java

@ -0,0 +1,459 @@
package com.fr.design.gui.frpane.tree.layer.config;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.present.dict.TableDataDictPane;
import com.fr.form.ui.tree.LayerDependence;
import com.fr.general.Inter;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.List;
/**
* Created by juhaoyu on 16/9/19.
*/
public class LayerDependenceSettingPane extends JPanel implements ItemListener {
/**
* 用户选择数据集的pane,在LayerDataConfigPane中传入
*/
private TableDataDictPane tableDataDictPane;
/**
* 添加依赖按钮
*/
private UIButton addButton;
/**
* 删除依赖按钮
*/
private UIButton delButton;
/**
* 依赖关系编辑Table
*/
private JTable dependenceTable;
/**
* Table的数据模型,两个按钮的操作直接对应于model
*/
private LayerDepenceTableModel model;
/**
* 当前该panel所设置的层级
*/
private int currentLayerIndex = 1;
private FieldRenderer fieldRenderer;
private LayerIndexEditor layerIndexEditor;
private FiledEditor fieldEditor;
public LayerDependenceSettingPane(TableDataDictPane tableDictPane) {
//关联数据集选择,并添加监听
this.tableDataDictPane = tableDictPane;
tableDataDictPane.tableDataNameComboBox.addItemListener(this);
//初始化按钮对象
addButton = new UIButton(Inter.getLocText("add"));
delButton = new UIButton(Inter.getLocText("Delete"));
//初始化Table对象,并添加renderer和editor
model = new LayerDepenceTableModel();
dependenceTable = new JTable();
dependenceTable.setModel(model);
//初始化辅助组件
fieldEditor = new FiledEditor(tableDataDictPane);
fieldRenderer = new FieldRenderer(tableDictPane);
layerIndexEditor = new LayerIndexEditor(currentLayerIndex);
//添加renderer
dependenceTable.getColumnModel().getColumn(0).setCellRenderer(new FirstRenderer());
dependenceTable.getColumnModel().getColumn(1).setCellRenderer(fieldRenderer);
//添加第一列editor
dependenceTable.getColumnModel().getColumn(0).setCellEditor(layerIndexEditor);
//添加第二列editor
dependenceTable.getColumnModel().getColumn(1).setCellEditor(fieldEditor);
//添加add按钮监听
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//先要停止编辑,然后再添加
fieldEditor.stopCellEditing();
layerIndexEditor.stopCellEditing();
LayerDependenceSettingPane.this.model.addDependence();
}
});
//添加del按钮监听
delButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (0 == dependenceTable.getSelectedRowCount()) {
return;
}
//获取视图索引,并根据视图索引获取model索引,删除model指定行
int selectedRow = dependenceTable.getSelectedRow();
int selectedRowModelIndex = dependenceTable.convertRowIndexToModel(selectedRow);
//先要停止编辑,然后再删除
fieldEditor.stopCellEditing();
layerIndexEditor.stopCellEditing();
model.delDependence(selectedRowModelIndex);
}
});
//生成布局
this.setLayout(new BorderLayout(2, 2));
//添加按钮panel
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(2));
buttonPanel.add(addButton);
buttonPanel.add(delButton);
this.add(buttonPanel, BorderLayout.NORTH);
//添加Table的panel
JScrollPane tablePanel = new JScrollPane(dependenceTable);
this.add(tablePanel, BorderLayout.CENTER);
}
public void populate(int layerIndex, List<LayerDependence> dependenceList) {
this.currentLayerIndex = layerIndex;
//更新Editor
this.layerIndexEditor.layerChanged(layerIndex);
this.fieldEditor.layerChanged();
this.model.clear();
this.model.addAll(dependenceList);
}
public List<LayerDependence> updateLayerDependence() {
//保存现有编辑
this.fieldEditor.stopCellEditing();
this.layerIndexEditor.stopCellEditing();
return this.model.update();
}
/**
* 当tableDataDictPane变化时,调用该方法
*/
@Override
public void itemStateChanged(ItemEvent e) {
clearDependences();
}
/**
* 清楚当前设置的依赖关系
*/
private void clearDependences() {
this.model.clear();
}
/**
* 第一列renderer
*/
private static final class FirstRenderer extends UILabel implements TableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value != null) {
//value是用户选择的字段索引值,从1开始的
this.setText(String.valueOf(value));
} else {
this.setText("");
}
if (hasFocus) {
this.setBorder(UIManager.getBorder("Table.focusCelHighlightBorder"));
} else {
this.setBorder(null);
}
return this;
}
}
/**
* 第二列renderer
* 由于从model中获取的数据是数据集列的索引值,这里要转换为列的名称
*/
private static final class FieldRenderer extends UILabel implements TableCellRenderer {
//用于将字段索引转换为字段名;保存改pane,是为了当用户选择其他数据集时,renderer可同步更新
private TableDataDictPane tableDataDictPane;
public FieldRenderer(TableDataDictPane tableDataDictPane) {
this.tableDataDictPane = tableDataDictPane;
}
/**
* 由于数据是从tableDataDictPane中现取的,所以用户选择不同的数据集时,renderer同步更新;
* 此时只需要在用户选择数据集时,刷新Table即可,不需要对renderer处理
*/
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value != null) {
List<String> columnNames = getColumnNameList(this.tableDataDictPane);
//value是用户选择的字段索引值,从1开始的
this.setText(columnNames.get(Integer.valueOf(String.valueOf(value))));
} else {
this.setText("");
}
if (hasFocus) {
this.setBorder(UIManager.getBorder("Table.focusCelHighlightBorder"));
} else {
this.setBorder(null);
}
return this;
}
}
/**
* 第一列editor
* 该editor于layerIndex关联,当用户选择不同的层时,这个editor要同步更新
*/
private static final class LayerIndexEditor extends AbstractCellEditor implements TableCellEditor {
private int currentLayerIndex;
private UIComboBox layerChoseCombobox = new UIComboBox();
public LayerIndexEditor(int currentLayerIndex) {
this.currentLayerIndex = currentLayerIndex;
for (int i = 1; i < currentLayerIndex; i++) {
layerChoseCombobox.addItem(i);
}
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
if (value != null) {
layerChoseCombobox.setSelectedIndex(Integer.valueOf(String.valueOf(value)) - 1);
}
return layerChoseCombobox;
}
@Override
public Object getCellEditorValue() {
return layerChoseCombobox.getSelectedItem();
}
public void layerChanged(int newLayerIndex) {
this.currentLayerIndex = newLayerIndex;
layerChoseCombobox.removeAllItems();
for (int i = 1; i < currentLayerIndex; i++) {
layerChoseCombobox.addItem(i);
}
}
}
/**
* 第二列editor
*/
private static final class FiledEditor extends AbstractCellEditor implements TableCellEditor {
private UIComboBox layerChoseCombobox = new UIComboBox();
TableDataDictPane tableDataDictPane;
public FiledEditor(TableDataDictPane tableDataDictPane) {
this.tableDataDictPane = tableDataDictPane;
List<String> columnNames = getColumnNameList(this.tableDataDictPane);
for (String columnName : columnNames) {
this.layerChoseCombobox.addItem(columnName);
}
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
List<String> columnNames = getColumnNameList(this.tableDataDictPane);
layerChoseCombobox.removeAllItems();
for (String columnName : columnNames) {
layerChoseCombobox.addItem(columnName);
}
if (value != null) {
layerChoseCombobox.setSelectedIndex(Integer.valueOf(String.valueOf(value)));
}
return layerChoseCombobox;
}
@Override
public Object getCellEditorValue() {
//转化为数据集的列索引(从0开始)
return layerChoseCombobox.getSelectedIndex();
}
public void layerChanged() {
List<String> columnNames = getColumnNameList(this.tableDataDictPane);
layerChoseCombobox.removeAllItems();
for (String columnName : columnNames) {
layerChoseCombobox.addItem(columnName);
}
}
}
private static List<String> getColumnNameList(TableDataDictPane tableDataDictPane) {
TableDataWrapper wrapper = tableDataDictPane.tableDataNameComboBox.getSelectedItem();
if (wrapper == null) {
return new ArrayList<String>();
} else {
return wrapper.calculateColumnNameList();
}
}
private static class LayerDepenceTableModel extends AbstractTableModel {
private List<LayerDependence> dependences;
public LayerDepenceTableModel() {
dependences = new ArrayList<LayerDependence>();
}
/**
* 添加一条数据,该方法会请求Table进行重绘(通过发送时间,告诉JTable数据更新,JTable会自动重绘)
*/
public void addDependence() {
dependences.add(new LayerDependence());
fireTableRowsInserted(dependences.size(), dependences.size());
}
/**
* 删除一条数据
*
* @param rowIndex
*/
public void delDependence(int rowIndex) {
if (rowIndex < 0 || rowIndex >= dependences.size()) {
return;
}
dependences.remove(rowIndex);
fireTableRowsDeleted(rowIndex + 1, rowIndex + 1);
}
public void addAll(List<LayerDependence> dependenceList) {
dependences.addAll(dependenceList);
fireTableRowsInserted(1, dependenceList.size());
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return true;
}
@Override
public Class<?> getColumnClass(int column) {
return Integer.class;
}
@Override
public String getColumnName(int column) {
String name;
if (column == 0) {
name = Inter.getLocText("FR-Designer_layerIndex");
} else {
name = Inter.getLocText("FR-Designer_filedChosen");
}
return name;
}
@Override
public int getRowCount() {
return dependences.size();
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
LayerDependence dependence = dependences.get(rowIndex);
Object obj;
if (columnIndex == 0) {
obj = dependence.getLayerIndex();
} else {
obj = dependence.getThisColumnIndex();
}
return obj;
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
LayerDependence dependence = dependences.get(rowIndex);
if (aValue != null) {
if (columnIndex == 0) {
dependence.setLayerIndex((Integer) aValue);
} else {
dependence.setThisColumnIndex((Integer) aValue);
}
}
}
public void clear() {
int length = dependences.size();
dependences.clear();
fireTableRowsDeleted(1, length);
}
public List<LayerDependence> update() {
return this.dependences;
}
}
}

3
designer_form/src/com/fr/design/mainframe/widget/wrappers/TreeModelWrapper.java

@ -7,6 +7,7 @@ import com.fr.design.Exception.ValidationException;
import com.fr.design.designer.properties.Decoder; import com.fr.design.designer.properties.Decoder;
import com.fr.design.designer.properties.Encoder; import com.fr.design.designer.properties.Encoder;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.general.NameObject;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
public class TreeModelWrapper implements Encoder, Decoder { public class TreeModelWrapper implements Encoder, Decoder {
@ -21,6 +22,8 @@ public class TreeModelWrapper implements Encoder, Decoder {
} else if (v instanceof TreeNodeWrapper) { } else if (v instanceof TreeNodeWrapper) {
TreeNodeAttr[] treeNodeAttrs = ((TreeNodeWrapper) v).getTreeNodeAttrs(); TreeNodeAttr[] treeNodeAttrs = ((TreeNodeWrapper) v).getTreeNodeAttrs();
return TemplateUtils.render(Inter.getLocText("FR-Designer_Total_N_Grade"), new String[]{"N"}, new String[]{treeNodeAttrs.length + ""}); return TemplateUtils.render(Inter.getLocText("FR-Designer_Total_N_Grade"), new String[]{"N"}, new String[]{treeNodeAttrs.length + ""});
} else if (v instanceof NameObject) {
return Inter.getLocText("FR-Designer_DataTable-Build");
} else { } else {
return Inter.getLocText("FR-Designer_Auto-Build"); return Inter.getLocText("FR-Designer_Auto-Build");
} }

Loading…
Cancel
Save