package com.vci.client.portal.NewNewUI.buttonmng;
|
|
import java.awt.BorderLayout;
|
import java.awt.Component;
|
import java.awt.GridBagConstraints;
|
import java.awt.GridBagLayout;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.KeyAdapter;
|
import java.awt.event.KeyEvent;
|
import java.util.LinkedList;
|
import java.util.List;
|
import java.util.concurrent.ExecutionException;
|
|
import javax.swing.BoxLayout;
|
import javax.swing.DefaultListModel;
|
import javax.swing.JSplitPane;
|
import javax.swing.JTree;
|
import javax.swing.SwingWorker;
|
import javax.swing.border.TitledBorder;
|
import javax.swing.event.ListSelectionEvent;
|
import javax.swing.event.ListSelectionListener;
|
import javax.swing.tree.TreePath;
|
|
import com.vci.client.framework.rightConfig.modelConfig.ModuleTreeCellRenderer;
|
import com.vci.client.omd.btm.ui.BtmClient;
|
import com.vci.client.omd.btm.wrapper.BtmItemWrapper;
|
import com.vci.client.oq.QTClient;
|
import com.vci.client.ui.swing.VCISwingUtil;
|
import com.vci.client.ui.swing.components.VCIJButton;
|
import com.vci.client.ui.swing.components.VCIJDialog;
|
import com.vci.client.ui.swing.components.VCIJList;
|
import com.vci.client.ui.swing.components.VCIJPanel;
|
import com.vci.client.ui.swing.components.VCIJScrollPane;
|
import com.vci.client.ui.swing.components.VCIJTextArea;
|
import com.vci.client.ui.swing.components.VCIJTextField;
|
import com.vci.client.ui.tree.CheckBoxTreeManager;
|
import com.vci.client.ui.tree.VCIBaseTree;
|
import com.vci.client.ui.tree.VCIBaseTreeModel;
|
import com.vci.client.ui.tree.VCIBaseTreeNode;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.omd.btm.BtmItem;
|
|
/**
|
* 复制按钮到其它UI组件里的Dialog
|
*
|
* <p>Title: </p>
|
* <p>Description: </p>
|
* <p>Copyright: Copyright (c) 2016</p>
|
* <p>Company: VCI</p>
|
* @author xiongchao
|
* @time 2016-8-8
|
* @version 1.0
|
*/
|
public class ButtonCopyToOtherComptDialog extends VCIJDialog {
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 6315797437233838187L;
|
private ButtonSettingDialog ownedDialog = null;
|
|
|
private VCIBaseTreeNode rootNode = null;
|
private TreePath rootTreePath = null;
|
private VCIBaseTreeModel treeModel = new VCIBaseTreeModel(rootNode);
|
private VCIBaseTree tree = new VCIBaseTree(treeModel);
|
private CheckBoxTreeManager treeCheckBoxManager = null;
|
|
private VCIJButton btnOk = VCISwingUtil.createVCIJButton("ok", "粘贴", "粘贴", "paste.gif", new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
ok();
|
}
|
});
|
private VCIJButton btnCancel = VCISwingUtil.createVCIJButton("cancel", "取消", "取消", "cancel.gif", new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
cancel();
|
}
|
});
|
public ButtonCopyToOtherComptDialog(ButtonSettingDialog ownedDialog){
|
super(ownedDialog, true);
|
this.ownedDialog = ownedDialog;
|
}
|
|
public void buildDialog(){
|
initUI();
|
setLocationAndSize();
|
}
|
|
private void setLocationAndSize(){
|
setSize(ownedDialog.getSize());
|
setLocation(ownedDialog.getLocation());
|
setLocationRelativeTo(ownedDialog);
|
}
|
|
private VCIJPanel palWestPanel = new VCIJPanel();
|
private VCIJPanel palCenterPanel = new VCIJPanel();
|
private VCIJList listBtmTypes = new VCIJList();
|
private JSplitPane jspWestCenter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, palWestPanel, palCenterPanel);
|
|
private void initUI(){
|
setLayout(new BorderLayout());
|
|
palWestPanel = getWestBtmTypeListPanel();
|
palCenterPanel = getCenterBtmTypeCtxListPanel();
|
VCIJPanel palSouthBtns = getSouthButtonPanel();
|
jspWestCenter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, palWestPanel, palCenterPanel);
|
|
jspWestCenter.setDividerSize(10);
|
jspWestCenter.setDividerLocation(300);
|
jspWestCenter.setContinuousLayout(true);
|
jspWestCenter.setOneTouchExpandable(true);
|
add(jspWestCenter, BorderLayout.CENTER);
|
add(palSouthBtns, BorderLayout.SOUTH);
|
}
|
|
|
private VCIJPanel getSouthButtonPanel(){
|
VCIJPanel pal = new VCIJPanel();
|
pal.add(btnOk);
|
pal.add(btnCancel);
|
return pal;
|
}
|
|
private VCIJPanel getWestBtmTypeListPanel(){
|
palWestPanel = new VCIJPanel();
|
palWestPanel.setLayout(new GridBagLayout());
|
|
GridBagConstraints c = new GridBagConstraints();
|
c.weightx = 1.0;
|
c.weighty = 0.0;
|
c.fill = GridBagConstraints.BOTH;
|
final VCIJTextField txtSearch = new VCIJTextField("");
|
txtSearch.addKeyListener(new KeyAdapter() {
|
public void keyReleased(KeyEvent e) {
|
fillBtmTypeList(txtSearch.getText());
|
}
|
});
|
palWestPanel.add(txtSearch, c);
|
|
c.gridx = 0;
|
c.gridy = 1;
|
c.weightx = 1.0;
|
c.weighty = 1.0;
|
c.fill = GridBagConstraints.BOTH;
|
palWestPanel.setBorder(new TitledBorder("业务类型列表"));
|
palWestPanel.add(new VCIJScrollPane(listBtmTypes), c);
|
fillBtmTypeList("");
|
listBtmTypes.addListSelectionListener(new ListSelectionListener() {
|
@Override
|
public void valueChanged(ListSelectionEvent e) {
|
if(!e.getValueIsAdjusting()) return;
|
BtmItemWrapper biw = (BtmItemWrapper)listBtmTypes.getSelectedValue();
|
btmTypeChange(biw);
|
}
|
});
|
return palWestPanel;
|
}
|
|
private BtmItem[] allBtmItems = null;
|
private void fillBtmTypeList(final String searchKey){
|
SwingWorker<BtmItem[], Void> worker = new SwingWorker<BtmItem[], Void>(){
|
@Override
|
protected BtmItem[] doInBackground() throws Exception {
|
if(allBtmItems == null){
|
allBtmItems = BtmClient.getService().getAllBtmItem("");
|
}
|
return allBtmItems;
|
}
|
|
@Override
|
protected void done() {
|
try {
|
BtmItem[] btmItems = get();
|
DefaultListModel model = new DefaultListModel();
|
for(BtmItem bi : btmItems){
|
if(!"".equals(searchKey)) {
|
if(!(bi.name.contains(searchKey) || bi.label.contains(searchKey))){
|
continue;
|
}
|
}
|
BtmItemWrapper biw = new BtmItemWrapper(bi){
|
@Override
|
public String toString() {
|
return " " + btmItem.name + "(" + btmItem.label + ")";
|
}
|
};
|
model.addElement(biw);
|
}
|
listBtmTypes.setModel(model);
|
} catch (InterruptedException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
} catch (ExecutionException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
};
|
worker.run();
|
}
|
|
private void btmTypeChange(final BtmItemWrapper biw){
|
SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>(){
|
|
String[][] btmCtxs = null;
|
@Override
|
protected Object doInBackground() throws Exception {
|
btmCtxs = getCtxNames(biw.btmItem.name);
|
return btmCtxs;
|
}
|
|
@Override
|
protected void done() {
|
try {
|
rootNode.removeAllChildren();
|
tree.updateUI();
|
fillTree(btmCtxs);
|
tree.expandAllTreeNode(rootTreePath, true);
|
tree.updateUI();
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
};
|
worker.run();
|
}
|
|
private String TREE_NODE_CONTEXT = "ctx";
|
private String TREE_NODE_TAB = "tab";
|
private String TREE_NODE_COMPT = "compt";
|
private void fillTree(String[][] btmCtxs) throws VCIError{
|
for(String[] ctxs : btmCtxs){
|
SimpleDataStruct sds = new SimpleDataStruct(ctxs[0], ctxs[1], ctxs[2], TREE_NODE_CONTEXT);
|
VCIBaseTreeNode newChild = getNewTreeNod(sds, true, false);
|
treeModel.insertNodeInto(newChild, rootNode, rootNode.getChildCount());
|
|
loadTabPage(sds, newChild);
|
}
|
}
|
|
private void loadTabPage(SimpleDataStruct ctxData, VCIBaseTreeNode parentNode) throws VCIError{
|
String[][] tabs = getTabNames(ctxData.getOid());
|
for(String[] tab : tabs){
|
SimpleDataStruct sds = new SimpleDataStruct(tab[0], tab[1], tab[2], TREE_NODE_TAB);
|
VCIBaseTreeNode newChild = getNewTreeNod(sds, true, false);
|
treeModel.insertNodeInto(newChild, parentNode, parentNode.getChildCount());
|
|
loadCompt(sds, newChild);
|
}
|
}
|
|
private void loadCompt(SimpleDataStruct tabData, VCIBaseTreeNode parentNode) throws VCIError{
|
String[][] compts = getComptNames(tabData.getOid());
|
for(String[] compt : compts){
|
SimpleDataStruct sds = new SimpleDataStruct(compt[0], compt[1], compt[2], TREE_NODE_COMPT);
|
VCIBaseTreeNode newChild = getNewTreeNod(sds, true, true);
|
treeModel.insertNodeInto(newChild, parentNode, parentNode.getChildCount());
|
}
|
}
|
|
private VCIBaseTreeNode getNewTreeNod(SimpleDataStruct sds, boolean isExpand, boolean isLeaf){
|
VCIBaseTreeNode newChild = new VCIBaseTreeNode(sds.toString(), sds);
|
newChild.setExpand(isExpand);
|
newChild.setLeaf(isLeaf);
|
return newChild;
|
}
|
|
private String[][] getCtxNames(String btmType) throws VCIError{
|
String sql = "select ploid,plcode,plname from pluilayout pld" +
|
" where pld.plrelatedtype='" + btmType + "'";
|
String[][] res = QTClient.getService().queryBySqlWithoutKey(sql);
|
return res;
|
}
|
private String[][] getTabNames(String ctxOid) throws VCIError{
|
String sql = "select ploid,plcode,plname from pltabpage tp " +
|
" where tp.plpagedefinationoid='" + ctxOid + "'";
|
String[][] res = QTClient.getService().queryBySqlWithoutKey(sql);
|
return res;
|
}
|
private String[][] getComptNames(String tabOid) throws VCIError{
|
String sql = "select ploid,plname,pldesc from plpagedefination pd" +
|
" where pd.plpagecontextoid='" + tabOid + "'";
|
String[][] res = QTClient.getService().queryBySqlWithoutKey(sql);
|
return res;
|
}
|
|
private class SimpleDataStruct{
|
private String oid = "";
|
private String name = "";
|
private String code = "";
|
private String type = "";
|
public SimpleDataStruct(String oid, String code, String name, String type){
|
this.oid = oid;
|
this.code = code;
|
this.name = name;
|
this.type = type;
|
}
|
public String getOid() {
|
return oid;
|
}
|
public void setOid(String oid) {
|
this.oid = oid;
|
}
|
public String getName() {
|
return name;
|
}
|
public void setName(String name) {
|
this.name = name;
|
}
|
public String getCode() {
|
return code;
|
}
|
public void setCode(String code) {
|
this.code = code;
|
}
|
public String getType() {
|
return type;
|
}
|
public void setType(String type) {
|
this.type = type;
|
}
|
@Override
|
public String toString(){
|
if("".equals(name)){
|
return code;
|
}
|
return code + "(" + name + ")";
|
}
|
}
|
|
private VCIJPanel getCenterBtmTypeCtxListPanel(){
|
VCIJPanel pal = new VCIJPanel(new BorderLayout());
|
rootNode = new VCIBaseTreeNode("UI上下文选项", "root");
|
rootTreePath = new TreePath(rootNode);
|
treeModel = new VCIBaseTreeModel(rootNode);
|
tree = new VCIBaseTree(treeModel, getLocalModuleTreeCellRenderer());
|
treeCheckBoxManager = new CheckBoxTreeManager(tree);
|
pal.add(new VCIJScrollPane(tree));
|
return pal;
|
}
|
|
private ModuleTreeCellRenderer getLocalModuleTreeCellRenderer(){
|
return localTreeCellRender;
|
}
|
|
private ModuleTreeCellRenderer localTreeCellRender = new ModuleTreeCellRenderer(){
|
/**
|
*
|
*/
|
private static final long serialVersionUID = -1759276070762570639L;
|
|
@Override
|
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus){
|
Component compt = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
|
return compt;
|
}
|
};
|
|
private List<String> targetComptOidList = new LinkedList<String>();
|
public List<String> getTargetComptOidList() {
|
return targetComptOidList;
|
}
|
public void setTargetComptOidList(List<String> targetComptOidList) {
|
this.targetComptOidList = targetComptOidList;
|
}
|
|
private void ok(){
|
TreePath[] selTreePaths= treeCheckBoxManager.getSelectionModel().getSelectionPaths();
|
List<String> comptOidList = new LinkedList<String>();
|
|
for(TreePath tp : selTreePaths){
|
VCIBaseTreeNode treeNode = (VCIBaseTreeNode)tp.getLastPathComponent();
|
addComptToList(treeNode, comptOidList);
|
}
|
|
setTargetComptOidList(comptOidList);
|
close(DialogResult.OK);
|
}
|
|
|
private void addComptToList(VCIBaseTreeNode parentNode, List<String> comptOidList){
|
SimpleDataStruct sds = (SimpleDataStruct) parentNode.getObj();
|
if(TREE_NODE_COMPT.equals(sds.getType())){
|
comptOidList.add(sds.getOid());
|
} else {
|
int childCount = parentNode.getChildCount();
|
for (int i = 0; i < childCount; i++) {
|
VCIBaseTreeNode childNode = (VCIBaseTreeNode) parentNode.getChildAt(i);
|
addComptToList(childNode, comptOidList);
|
}
|
}
|
}
|
|
private void cancel(){
|
close(DialogResult.CANCEL);
|
}
|
private void close(DialogResult res){
|
setDialogResult(res);
|
setVisible(false);
|
}
|
}
|