package com.vci.client.portal.NewNewUI.buttonmng;
|
|
import java.awt.BorderLayout;
|
import java.awt.Color;
|
import java.awt.Dialog;
|
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.ArrayList;
|
import java.util.Arrays;
|
import java.util.Collections;
|
import java.util.Comparator;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.swing.BorderFactory;
|
import javax.swing.ButtonGroup;
|
import javax.swing.JDialog;
|
import javax.swing.SwingUtilities;
|
import javax.swing.border.TitledBorder;
|
|
import com.vci.corba.portal.*;
|
import com.vci.corba.portal.data.PLAction;
|
import com.vci.corba.portal.data.PLActionParam;
|
import com.vci.corba.portal.data.PLCommandParameter;
|
import com.vci.corba.portal.data.PLTabButton;
|
import com.vci.client.LogonApplication;
|
import com.vci.client.common.IconSelectDialog;
|
import com.vci.client.portal.NewNewUI.actionmng.ActionSelectDialog;
|
import com.vci.client.portal.utility.UITools;
|
import com.vci.client.ui.image.BundleImage;
|
import com.vci.client.ui.swing.VCISwingUtil;
|
import com.vci.client.ui.swing.components.VCIJButton;
|
import com.vci.client.ui.swing.components.VCIJIntegerTextField;
|
import com.vci.client.ui.swing.components.VCIJLabel;
|
import com.vci.client.ui.swing.components.VCIJOptionPane;
|
import com.vci.client.ui.swing.components.VCIJPanel;
|
import com.vci.client.ui.swing.components.VCIJRadioButton;
|
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.swing.components.VCIJDialog.DialogResult;
|
import com.vci.corba.common.VCIError;
|
|
@SuppressWarnings("deprecation")
|
public class ButtonInfoPanel extends VCIJPanel {
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 3981272454544575927L;
|
|
|
private PLTabButton btn = null;
|
|
private VCIJLabel lblSeq = new VCIJLabel("编号");
|
private VCIJIntegerTextField txtSeq = new VCIJIntegerTextField("");
|
|
private VCIJLabel lblName = new VCIJLabel("名称");
|
private VCIJTextField txtName = new VCIJTextField(true);
|
|
private VCIJLabel lblAction = new VCIJLabel("Action");
|
private VCIJTextField txtAction = new VCIJTextField(true);
|
private VCIJButton btnActionChoose = VCISwingUtil.createVCIJButton("btnActionChoose", "选择", "", "search.png");
|
|
private VCIJLabel lblAuth = new VCIJLabel("是否授权");
|
private VCIJRadioButton rbtnAuthYes = new VCIJRadioButton("是", true);
|
private VCIJRadioButton rbtnAuthNo = new VCIJRadioButton("否", false);
|
private ButtonGroup rbtnAuthGroup = new ButtonGroup();
|
|
private VCIJLabel lblShow = new VCIJLabel("是否显示");
|
private VCIJRadioButton rbtnShowYes = new VCIJRadioButton("是", true);
|
private VCIJRadioButton rbtnShowNo = new VCIJRadioButton("否", false);
|
private ButtonGroup rbtnShowGroup = new ButtonGroup();
|
|
private VCIJLabel lblShowType = new VCIJLabel("显示方式");
|
private VCIJRadioButton rbtnShowTypeText = new VCIJRadioButton("文字", false);
|
private VCIJRadioButton rbtnShowTypeIcon = new VCIJRadioButton("图标", false);
|
private VCIJRadioButton rbtnShowTypeTextAndIcon = new VCIJRadioButton("文字和图标", true);
|
private ButtonGroup rbtnShowTypeGroup = new ButtonGroup();
|
|
private VCIJLabel lblIcon = new VCIJLabel("图标");
|
private VCIJTextField txtIcon = new VCIJTextField(false);
|
private VCIJButton btnIconChoose = VCISwingUtil.createVCIJButton("btnIconChoose", "选择", "", "search.png");
|
|
private VCIJLabel lblTipInfo = new VCIJLabel("提示信息");
|
private VCIJTextArea txtTipInfo = new VCIJTextArea(false);
|
|
private ButtonParamTableCompt paramTablePanel = null;
|
|
private OptMode optMode = OptMode.View;
|
|
private Dialog ownedDialog = null;
|
public ButtonInfoPanel(Dialog ownedDialog, PLTabButton btn){
|
this.ownedDialog = ownedDialog;
|
this.btn = btn;
|
}
|
|
public void buildPanel(){
|
init();
|
}
|
private void init(){
|
initUI();
|
}
|
private void initUI(){
|
setLayout(new BorderLayout());
|
|
add(getAttrInfoPanel(), BorderLayout.NORTH);
|
|
TitledBorder border = BorderFactory.createTitledBorder("参数信息");
|
border.setTitleColor(Color.BLUE);
|
paramTablePanel = new ButtonParamTableCompt(Arrays.asList(new PLCommandParameter[0]));
|
paramTablePanel.setBorder(border);
|
add(paramTablePanel, BorderLayout.CENTER);
|
|
setControlEnable(false);
|
}
|
|
private VCIJPanel getAttrInfoPanel(){
|
VCIJPanel pal = new VCIJPanel(new GridBagLayout());
|
|
TitledBorder border = BorderFactory.createTitledBorder("基础信息");
|
border.setTitleColor(Color.BLUE);
|
pal.setBorder(border);
|
|
int gridy = -1;
|
|
gridy += 1;
|
pal.add(lblSeq, new GridBagConstraints(1, gridy, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
|
pal.add(txtSeq, new GridBagConstraints(2, gridy, 3, 1, 1.0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 1), 0, 0));
|
txtSeq.setRequired(true);
|
|
gridy += 1;
|
pal.add(lblName, new GridBagConstraints(1, gridy, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1, 5, 0, 5), 0, 0));
|
pal.add(txtName, new GridBagConstraints(2, gridy, 3, 1, 1.0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1, 5, 0, 1), 0, 0));
|
|
gridy += 1;
|
pal.add(lblAction, new GridBagConstraints(1, gridy, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
|
pal.add(txtAction, new GridBagConstraints(2, gridy, 2, 1, 1.0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1, 5, 0, 1), 0, 0));
|
pal.add(btnActionChoose, new GridBagConstraints(4, gridy, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 0, 1), 0, 0));
|
|
txtAction.setEditable(false);
|
txtAction.setEnabled(false);
|
btnActionChoose.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
showActionChooseDialog();
|
}
|
});
|
|
gridy += 1;
|
pal.add(lblAuth, new GridBagConstraints(1, gridy, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
|
VCIJPanel palAuth = new VCIJPanel(new FlowLayout(FlowLayout.LEADING));
|
palAuth.add(rbtnAuthYes); palAuth.add(rbtnAuthNo);
|
rbtnAuthGroup.add(rbtnAuthYes); rbtnAuthGroup.add(rbtnAuthNo);
|
pal.add(palAuth, new GridBagConstraints(2, gridy, 3, 1, 1.0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 1), 0, 0));
|
|
gridy += 1;
|
pal.add(lblShow, new GridBagConstraints(1, gridy, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
|
VCIJPanel palShow = new VCIJPanel(new FlowLayout(FlowLayout.LEADING));
|
palShow.add(rbtnShowYes); palShow.add(rbtnShowNo);
|
rbtnShowGroup.add(rbtnShowYes); rbtnShowGroup.add(rbtnShowNo);
|
pal.add(palShow, new GridBagConstraints(2, gridy, 3, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 1), 0, 0));
|
|
ActionListener showChangeAL = new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
if(rbtnShowNo.isSelected()){
|
rbtnShowTypeText.setEnabled(false);
|
rbtnShowTypeIcon.setEnabled(false);
|
rbtnShowTypeTextAndIcon.setEnabled(false);
|
setIconChooseEnable(false);
|
} else {
|
rbtnShowTypeText.setEnabled(true);
|
rbtnShowTypeIcon.setEnabled(true);
|
rbtnShowTypeTextAndIcon.setEnabled(true);
|
rbtnShowTypeTextAndIcon.doClick();
|
}
|
}
|
};
|
rbtnShowYes.addActionListener(showChangeAL); rbtnShowNo.addActionListener(showChangeAL);
|
|
gridy += 1;
|
pal.add(lblShowType, new GridBagConstraints(1, gridy, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
|
VCIJPanel palShowType = new VCIJPanel(new FlowLayout(FlowLayout.LEADING));
|
palShowType.add(rbtnShowTypeText); palShowType.add(rbtnShowTypeIcon);palShowType.add(rbtnShowTypeTextAndIcon);
|
rbtnShowTypeGroup.add(rbtnShowTypeText); rbtnShowTypeGroup.add(rbtnShowTypeIcon);rbtnShowTypeGroup.add(rbtnShowTypeTextAndIcon);
|
pal.add(palShowType, new GridBagConstraints(2, gridy, 3, 1, 1.0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 1), 0, 0));
|
|
ActionListener showTypeChangeAL = new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
boolean enable = false;
|
if(rbtnShowTypeIcon.isSelected() || rbtnShowTypeTextAndIcon.isSelected()){
|
enable = true;
|
} else {
|
enable = false;
|
}
|
setIconChooseEnable(enable);
|
}
|
};
|
rbtnShowTypeText.addActionListener(showTypeChangeAL);
|
rbtnShowTypeIcon.addActionListener(showTypeChangeAL);
|
rbtnShowTypeTextAndIcon.addActionListener(showTypeChangeAL);
|
|
gridy += 1;
|
pal.add(lblIcon, new GridBagConstraints(1, gridy, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
|
pal.add(txtIcon, new GridBagConstraints(2, gridy, 2, 1, 1.0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1, 5, 0, 1), 0, 0));
|
pal.add(btnIconChoose, new GridBagConstraints(4, gridy, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 1, 0, 1), 0, 0));
|
|
btnIconChoose.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
showPicChooseDialog();
|
}
|
});
|
|
gridy += 1;
|
pal.add(lblTipInfo, new GridBagConstraints(1, gridy, 1, 1, 0, 0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
|
txtTipInfo.setRows(3);
|
txtTipInfo.setColumns(10);
|
txtTipInfo.setWrapStyleWord(true);
|
txtTipInfo.setLineWrap(true);
|
//VCIJScrollPane jspTipInfo = new VCIJScrollPane(txtTipInfo);
|
pal.add(txtTipInfo, new GridBagConstraints(2, gridy, 3, 1, 1.0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1, 5, 0, 1), 0, 0));
|
return pal;
|
}
|
|
private PLAction choosedAction = null;
|
private Comparator<PLCommandParameter> paramsComparator = new Comparator<PLCommandParameter>() {
|
@Override
|
public int compare(PLCommandParameter o1, PLCommandParameter o2) {
|
return o1.plKey.compareTo(o2.plKey);
|
}
|
};
|
private void showActionChooseDialog(){
|
ActionSelectDialog dialog = new ActionSelectDialog((JDialog)this.ownedDialog);
|
PLAction action = dialog.getSelectedAction();
|
if(action == null) {
|
this.choosedAction = null;
|
return;
|
}
|
this.choosedAction = action;
|
|
txtAction.setText(action.plName);
|
this.actionMap.put(action.plOId, action);
|
|
List<PLCommandParameter> list = new ArrayList<PLCommandParameter>();
|
try{
|
|
// 查出当前按钮已经存在的按钮参数
|
PLCommandParameter[] btnParams = new PLCommandParameter[0];
|
//获取到重新选择action之前的参数
|
if (this.btn != null && this.btn.plOId != null && !"".equals(this.btn.plOId)) {
|
btnParams = UITools.getService().getPLCommandParametersByCommandOId(this.btn.plOId);
|
}
|
|
// 新选择的Action上定义的参数
|
PLActionParam[] actionParams = UITools.getService().getPLActionParamArrayByActionId(action.plOId);
|
// Action的参数作为按钮参数
|
for (PLActionParam ap : actionParams) {
|
PLCommandParameter bp = new PLCommandParameter();
|
bp.plKey = ap.name;
|
bp.plValue = ap.defaultValue;
|
list.add(bp);
|
|
for (PLCommandParameter commandParam : btnParams) {
|
// 用按钮是已经存在同名的参数值覆盖新选择Action的默认值
|
if(commandParam.plKey.equals(bp.plKey)){
|
bp.plValue = commandParam.plValue;
|
break;
|
}
|
}
|
}
|
|
// for(int i = 0; i < commandParams.length; i++){
|
// list.add(commandParams[i]);
|
// }
|
//
|
// // 新选择的Action上定义的参数
|
// PLActionParam[] actionParams = Tool.getService().getPLActionParamArrayByActionId(action.plOId);
|
// // 依次先循环新选择Action的参数,如果存在key相同,则用Action参数默值
|
// for (PLActionParam ap : actionParams) {
|
//
|
// boolean apExist = false;
|
// for (PLCommandParameter bp : commandParams) {
|
// if(ap.name.equals(bp.plKey)){
|
// apExist = true;
|
// bp.plValue = ap.defaultValue;
|
// break;
|
// }
|
// }
|
// if(!apExist){
|
// PLCommandParameter bpNew = new PLCommandParameter();
|
// bpNew.plKey = ap.name;
|
// bpNew.plValue = ap.defaultValue;
|
// list.add(bpNew);
|
// }
|
// }
|
//
|
// boolean isExist = false;
|
// for(int i = 0;i < commandParams.length;i++){
|
// isExist = false;
|
// for(int j = 0;j<list.size();j++){
|
// if(commandParams[i].plKey.equals(list.get(j).plKey)){
|
// list.get(j).plValue = commandParams[i].plValue;
|
// isExist = true;
|
// break;
|
// }
|
// }
|
// if(!isExist){
|
// list.add(commandParams[i]);
|
// }
|
// }
|
}catch(VCIError e){
|
e.printStackTrace();
|
}
|
reloadTablePanelData(list);
|
}
|
|
private void showPicChooseDialog(){
|
//PicChooseDialog dialog = new PicChooseDialog(this.ownedDialog);
|
IconSelectDialog dialog = new IconSelectDialog("选择图标", true , "", this.btnIconChoose);
|
dialog.setVisible(true);
|
|
if(dialog.getDialogResult() == DialogResult.CANCEL){
|
return;
|
}
|
|
final String imagePath = dialog.getSelectedIcon();
|
//final String imagePath = dialog.getImageURL();
|
txtIcon.setText(imagePath);
|
setImageIcon(imagePath);
|
}
|
|
private void setImageIcon(final String imageIconPath){
|
SwingUtilities.invokeLater(new Runnable() {
|
@Override
|
public void run() {
|
if(imageIconPath == null || "".equals(imageIconPath)){
|
lblIcon.setIcon(null);
|
} else {
|
BundleImage bimage = new BundleImage();
|
lblIcon.setIcon(bimage.createImageIconByPath(imageIconPath));
|
//lblIcon.setIcon(SFServiceClientUtil.getImageIcon(imageIconPath));
|
}
|
}
|
});
|
}
|
public void setTabButton(PLTabButton btn){
|
this.btn = btn;
|
setValueToUI(btn);
|
}
|
|
private Map<String, PLAction> actionMap = new HashMap<String, PLAction>();
|
private void setValueToUI(PLTabButton btn){
|
if(btn == null){
|
txtSeq.setText("");
|
txtName.setText("");
|
txtAction.setText("");
|
|
rbtnAuthYes.setSelected(true);
|
rbtnAuthNo.setSelected(false);
|
|
rbtnShowYes.setSelected(true);
|
rbtnAuthNo.setSelected(false);
|
|
rbtnShowTypeText.setSelected(false);
|
rbtnShowTypeIcon.setSelected(false);
|
rbtnShowTypeTextAndIcon.setSelected(true);
|
|
txtIcon.setText("");
|
txtTipInfo.setText("");
|
|
lblIcon.setIcon(null);
|
|
paramTablePanel.setButtonParams(Arrays.asList(new PLCommandParameter[0]));
|
paramTablePanel.getTablePanel().refreshTableData();
|
return;
|
}
|
|
setImageIcon(btn.iconPath);
|
txtSeq.setText(String.valueOf(btn.plSeq));
|
txtName.setText(btn.plLabel);
|
if(actionMap.containsKey(btn.plActionOId)){
|
txtAction.setText(actionMap.get(btn.plActionOId).plName);
|
} else {
|
PLAction a;
|
try {
|
a = UITools.getService().getPLActionById(btn.plActionOId);
|
actionMap.put(btn.plActionOId, a);
|
txtAction.setText(a.plName);
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
if("0".equals(btn.authorization)){
|
rbtnAuthYes.setSelected(true);
|
} else {
|
rbtnAuthNo.setSelected(true);
|
}
|
if("0".equals(btn.show)){
|
rbtnShowYes.setSelected(true);
|
} else {
|
rbtnShowNo.setSelected(true);
|
}
|
if("text".equals(btn.displayMode)){
|
rbtnShowTypeText.setSelected(true);
|
}else if("image".equals(btn.displayMode)){
|
rbtnShowTypeIcon.setSelected(true);
|
}else{
|
rbtnShowTypeTextAndIcon.setSelected(true);
|
}
|
|
txtIcon.setText(btn.iconPath);
|
txtTipInfo.setText(btn.plDesc);
|
|
try {
|
PLCommandParameter[] params = UITools.getService().getPLCommandParametersByCommandOId(btn.plOId);
|
List<PLCommandParameter> list = Arrays.asList(params);
|
reloadTablePanelData(list);
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
|
public PLTabButton getFillVaueButton(PLTabButton btn){
|
if(btn == null){
|
btn = new PLTabButton();
|
}
|
btn.plSeq = Short.valueOf(txtSeq.getText().trim());
|
btn.plLabel = txtName.getText().trim();
|
if(this.choosedAction != null){
|
btn.plActionOId = this.choosedAction.plOId;
|
}
|
btn.authorization = rbtnAuthYes.isSelected() ? "0" : "1";
|
btn.show = rbtnShowYes.isSelected() ? "0" : "1";
|
if(rbtnShowTypeText.isSelected()){
|
btn.displayMode = "text";
|
} else if(rbtnShowTypeIcon.isSelected()){
|
btn.displayMode = "image";
|
} else if(rbtnShowTypeTextAndIcon.isSelected()){
|
btn.displayMode = "textandimage";
|
}
|
btn.plDesc = txtTipInfo.getText().trim();
|
btn.iconPath = txtIcon.getText().trim();
|
return btn;
|
}
|
|
private void reloadTablePanelData(List<PLCommandParameter> list){
|
Collections.sort(list, paramsComparator);
|
paramTablePanel.setButtonParams(list);
|
this.paramTablePanel.setButtonParams(list);
|
this.paramTablePanel.getTablePanel().refreshTableData();
|
}
|
|
|
public boolean checkInputValueIsOk(){
|
boolean res = false;
|
if(!isNull(lblSeq, txtSeq)){
|
return false;
|
}else if(!isNull(lblName, txtName)){
|
return false;
|
}else if(!isNull(lblAction, txtAction)){
|
return false;
|
}else if(getOptMode() == OptMode.Add && this.choosedAction == null){
|
VCIJOptionPane.showMessage(ownedDialog, "请选择有效的Action!");
|
return false;
|
}
|
return res;
|
}
|
|
private boolean isNull(VCIJLabel lbl, VCIJTextField txt){
|
if("".equals(txt.getText().trim())){
|
txt.requestFocus();
|
VCIJOptionPane.showMessage(ownedDialog, lbl.getText() + " 不能为空!");
|
return false;
|
}
|
return true;
|
}
|
public OptMode getOptMode() {
|
return optMode;
|
}
|
|
public void setOptMode(OptMode optMode) {
|
this.optMode = optMode;
|
}
|
|
public void setControlEnable(boolean enable){
|
btnActionChoose.setEnabled(enable);
|
rbtnAuthYes.setEnabled(enable);
|
rbtnAuthNo.setEnabled(enable);
|
rbtnShowYes.setEnabled(enable);
|
rbtnShowNo.setEnabled(enable);
|
rbtnShowTypeText.setEnabled(enable);
|
rbtnShowTypeIcon.setEnabled(enable);
|
rbtnShowTypeTextAndIcon.setEnabled(enable);
|
|
txtSeq.setEditable(enable);
|
txtName.setEditable(enable);
|
txtTipInfo.setEditable(enable);
|
|
setIconChooseEnable(enable);
|
|
paramTablePanel.getTablePanel().getTable().setEnabled(enable);
|
paramTablePanel.getTablePanel().setEnabled(enable);
|
}
|
|
|
private void setIconChooseEnable(boolean enable){
|
txtIcon.setEnabled(enable);
|
txtIcon.setEditable(enable);
|
btnIconChoose.setEnabled(enable);
|
}
|
|
public ButtonParamTableCompt getParamTablePanel() {
|
return paramTablePanel;
|
}
|
|
public void setParamTablePanel(ButtonParamTableCompt paramTablePanel) {
|
this.paramTablePanel = paramTablePanel;
|
}
|
|
|
}
|