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
*
*
Title:
* Description:
* Copyright: Copyright (c) 2016
* Company: VCI
* @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 worker = new SwingWorker(){
@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