package com.vci.client.portal.UI;
|
|
import java.awt.BorderLayout;
|
import java.awt.FlowLayout;
|
import java.awt.GridBagConstraints;
|
import java.awt.GridBagLayout;
|
import java.awt.Insets;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.util.Arrays;
|
import java.util.Comparator;
|
import java.util.HashMap;
|
import java.util.LinkedList;
|
import java.util.List;
|
|
import com.vci.client.LogonApplication;
|
import com.vci.client.common.PinyinCommon;
|
import com.vci.client.common.VCIBasePanel;
|
import com.vci.client.framework.rightConfig.object.FunctionObject;
|
import com.vci.client.portal.utility.UITools;
|
import com.vci.client.ui.swing.VCIOptionPane;
|
import com.vci.client.ui.swing.VCISwingUtil;
|
import com.vci.client.ui.swing.components.VCIJButton;
|
import com.vci.client.ui.swing.components.VCIJComboBox;
|
import com.vci.client.ui.swing.components.VCIJLabel;
|
import com.vci.client.ui.swing.components.VCIJPanel;
|
import com.vci.client.ui.swing.components.VCIJTextField;
|
import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider;
|
import com.vci.client.ui.swing.components.table.VCIJTableNode;
|
import com.vci.client.ui.swing.components.table.VCIJTablePanel;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.portal.data.Constraint;
|
import com.vci.corba.portal.data.PLAction;
|
|
/**
|
* Action管理
|
*/
|
public class ActionConfPanel extends VCIBasePanel {
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
private VCIJButton addBtn = VCISwingUtil.createVCIJButton("add", "增加", "增加", "add.png");
|
private VCIJButton editBtn = VCISwingUtil.createVCIJButton("edit", "修改", "修改", "edit.png");
|
private VCIJButton delBtn = VCISwingUtil.createVCIJButton("delete", "删除", "查询", "delete.png");
|
|
String[] headerName = new String[] {
|
"编号", "名称","类路径", "链接地址", "类型", "描述"
|
};
|
|
private VCIJLabel lblCode = new VCIJLabel("编号:");
|
private VCIJTextField txtCode = new VCIJTextField("");
|
private VCIJLabel lblName = new VCIJLabel("名称:");
|
private VCIJTextField txtName = new VCIJTextField("");
|
|
private VCIJLabel lblBSClass = new VCIJLabel("B/S类路径:");
|
private VCIJTextField txtBSClass = new VCIJTextField("");
|
private VCIJLabel lblCSClass = new VCIJLabel("C/S类路径:");
|
private VCIJTextField txtCSClass = new VCIJTextField("");
|
|
private VCIJLabel lblType = new VCIJLabel("业务类型:");
|
private VCIJComboBox cbxType = new VCIJComboBox(new String[]{"","业务类型","链接类型"});
|
private VCIJLabel lblDesc = new VCIJLabel("描述:");
|
private VCIJTextField txtDesc = new VCIJTextField("");
|
|
private VCIJButton btnSearch = VCISwingUtil.createVCIJButton("search", "查询", "查询", "search.png");
|
private VCIJButton btnClear = VCISwingUtil.createVCIJButton("clear", "清空", "清空", "clear.gif");
|
public ActionConfPanel(FunctionObject funcObj) {
|
super(funcObj);
|
init();
|
}
|
|
private void init() {
|
initUI();
|
initActionListener();
|
}
|
|
private void initUI(){
|
setLayout(new BorderLayout());
|
add(getNorthPanel(), BorderLayout.NORTH);
|
add(getWestPanel(), BorderLayout.WEST);
|
add(getCenterPanel(), BorderLayout.CENTER);
|
add(getEastPanel(), BorderLayout.EAST);
|
add(getSouthPanel(), BorderLayout.SOUTH);
|
}
|
|
private VCIJPanel getNorthPanel(){
|
VCIJPanel pal = new VCIJPanel(new GridBagLayout());
|
int gridx = 0; int gridy = 0; int padxy = 2;
|
int anchor = GridBagConstraints.NORTHWEST;
|
int fill = GridBagConstraints.BOTH;
|
pal.add(lblCode, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
|
pal.add(txtCode, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
|
pal.add(lblName, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
|
pal.add(txtName, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
|
|
gridx = 0; gridy += 1;
|
pal.add(lblBSClass, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
|
pal.add(txtBSClass, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
|
pal.add(lblCSClass, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
|
pal.add(txtCSClass, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
|
|
gridx = 0; gridy += 1;
|
pal.add(lblType, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
|
pal.add(cbxType, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
|
pal.add(lblDesc, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
|
pal.add(txtDesc, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
|
|
VCIJPanel pp = new VCIJPanel(new BorderLayout());
|
pp.add(pal, BorderLayout.CENTER);
|
|
VCIJPanel pb = new VCIJPanel();
|
pb.add(btnSearch);pb.add(btnClear);
|
pp.add(pb, BorderLayout.SOUTH);
|
|
return pp;
|
}
|
|
private VCIJPanel getWestPanel(){
|
VCIJPanel pal = new VCIJPanel(new BorderLayout());
|
return pal;
|
}
|
|
private VCIJPanel getEastPanel(){
|
VCIJPanel pal = new VCIJPanel(new BorderLayout());
|
return pal;
|
}
|
|
private VCIJPanel getSouthPanel(){
|
VCIJPanel pal = new VCIJPanel(new BorderLayout());
|
return pal;
|
}
|
|
class ActionDataProvider extends AbstractVCIJTableDataProvider<PLAction>{
|
@Override
|
public PLAction[] getDatas(int pageIndex, int pageSize) {
|
PLAction[] res = getTablePanelData();
|
super.total = res.length;
|
return res;
|
}
|
@Override
|
public VCIJTableNode<PLAction> getNewRowNode(PLAction obj) {
|
return getTablePanelNode(obj);
|
}
|
@Override
|
public String[] getSpecialColumns() {
|
return headerName;
|
}
|
@Override
|
public int getTotal() {
|
return total;
|
}
|
}
|
|
private PLAction[] getTablePanelData(){
|
PLAction[] res = getAllActionsFromDB();
|
Arrays.sort(res, new Comparator<PLAction>(){
|
@Override
|
public int compare(PLAction o1, PLAction o2) {
|
String py1 = PinyinCommon.getPingYin(o1.plName);
|
String py2 = PinyinCommon.getPingYin(o2.plName);
|
return py1.compareTo(py2);
|
}});
|
return res;
|
}
|
|
private PLAction[] getAllActionsFromDB(){
|
PLAction[] res = new PLAction[0];
|
try {
|
res = UITools.getService().getPLActionsByConsArray(getFilterConstraints());
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
return res;
|
}
|
|
private Constraint[] getFilterConstraints(){
|
Constraint[] consArray = new Constraint[6];
|
consArray[0] = new Constraint("plcode", txtCode.getText().trim());
|
consArray[1] = new Constraint("plname", txtName.getText().trim());
|
consArray[2] = new Constraint("plbsurl", txtBSClass.getText().trim());
|
consArray[3] = new Constraint("plcsclass", txtCSClass.getText().trim());
|
String type = cbxType.getSelectedItem().toString();
|
if(type.equals("业务类型")){
|
type = "business";
|
} else if(type.equals("链接类型")){
|
type = "link";
|
}
|
consArray[4] = new Constraint("pltypetype", type);
|
consArray[5] = new Constraint("pldesc", txtDesc.getText().trim());
|
return consArray;
|
}
|
|
private VCIJTableNode<PLAction> getTablePanelNode(PLAction obj){
|
VCIJTableNode<PLAction> res = new VCIJTableNode<PLAction>(obj);
|
res.setPropertyValue(headerName[0], obj.plCode);
|
res.setPropertyValue(headerName[1], obj.plName);
|
res.setPropertyValue(headerName[2], obj.plCSClass);
|
res.setPropertyValue(headerName[3], obj.plBSUrl);
|
String plTypeType = obj.plTypeType;
|
String disType = "";
|
if(plTypeType.equals("business")){
|
disType = "业务类型";
|
}
|
else if(plTypeType.equals("link")){
|
disType = "链接类型";
|
}
|
res.setPropertyValue(headerName[4], disType);
|
res.setPropertyValue(headerName[5], obj.plDesc);
|
return res;
|
}
|
|
private VCIJTablePanel<PLAction> tablePanel = null;
|
private VCIJPanel getCenterPanel(){
|
tablePanel = new VCIJTablePanel<PLAction>(new ActionDataProvider());
|
List<VCIJButton> btns = new LinkedList<VCIJButton>();
|
btns.add(addBtn);btns.add(editBtn);btns.add(delBtn);
|
tablePanel.setCustomButtons(btns);
|
tablePanel.setCustomButtonFlowAlign(FlowLayout.CENTER);
|
tablePanel.setPageSizeList(new int[]{100,150,200,250,300,350,400});
|
HashMap<Integer, Integer> columnWidthMap = new HashMap<Integer, Integer>();
|
columnWidthMap.put(1, 150);
|
columnWidthMap.put(2, 250);
|
columnWidthMap.put(3, 400);
|
columnWidthMap.put(4, 500);
|
columnWidthMap.put(5, 300);
|
columnWidthMap.put(6, 200);
|
columnWidthMap.put(7, 500);
|
tablePanel.setColumnWidthMaps(columnWidthMap);
|
tablePanel.buildTablePanel();
|
tablePanel.refreshTableData();
|
return tablePanel;
|
}
|
private GridBagConstraints getGBC(int gridx, int gridy, int gridwidth,
|
int gridheight, double weightx, double weighty, int anchor,
|
int fill, int padxy) {
|
return new GridBagConstraints(gridx, gridy, gridwidth, gridheight,
|
weightx, weighty, anchor, fill, new Insets(padxy, padxy, padxy,
|
padxy), padxy, padxy);
|
}
|
|
private void refreshActionData(){
|
tablePanel.refreshTableData();
|
}
|
|
private PLAction getSelectedAction(){
|
int[] rows = tablePanel.getSelectedRowIndexs();
|
int selectedRowCount = rows.length;
|
if(selectedRowCount == 0){
|
VCIOptionPane.showMessage(LogonApplication.frame, "请选择一条数据!");
|
return null;
|
} else if(selectedRowCount > 1){
|
VCIOptionPane.showMessage(LogonApplication.frame, "一次只能选择一条数据进行此操作!");
|
return null;
|
}
|
return tablePanel.getSpecialObjectByRowIndex(rows[0]);
|
}
|
private void clear(){
|
txtCode.setText("");txtName.setText("");
|
txtBSClass.setText("");txtCSClass.setText("");
|
cbxType.setSelectedIndex(0);
|
cbxType.setSelectedItem("");
|
txtDesc.setText("");
|
}
|
private void initActionListener(){
|
btnClear.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent arg0) {
|
clear();
|
}
|
});
|
btnSearch.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent arg0) {
|
refreshActionData();
|
}
|
});
|
addBtn.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent arg0) {
|
ActionConfDialog dialog = new ActionConfDialog(null);
|
dialog.setVisible(true);
|
refreshActionData();
|
}
|
});
|
editBtn.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent arg0) {
|
PLAction obj = getSelectedAction();
|
if(obj == null) return;
|
|
ActionConfDialog dialog = new ActionConfDialog(obj);
|
dialog.setVisible(true);
|
refreshActionData();
|
}
|
});
|
delBtn.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent arg0) {
|
PLAction obj = getSelectedAction();
|
if(obj == null) return;
|
try {
|
UITools.getService().deletePLAction(obj);
|
VCIOptionPane.showMessage(LogonApplication.frame, "删除成功!");
|
} catch (VCIError e) {
|
VCIOptionPane.showMessage(LogonApplication.frame, "删除失败!");
|
e.printStackTrace();
|
}
|
refreshActionData();
|
}
|
});
|
}
|
}
|