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 javax.swing.JButton;
|
import javax.swing.JCheckBox;
|
import javax.swing.JLabel;
|
import javax.swing.JPanel;
|
import javax.swing.JScrollPane;
|
import javax.swing.border.EmptyBorder;
|
|
import com.vci.client.LogonApplication;
|
import com.vci.client.portal.utility.UITools;
|
import com.vci.client.ui.swing.VCIOptionPane;
|
import com.vci.client.ui.swing.components.VCIJDialog;
|
import com.vci.client.ui.swing.components.VCIJOptionPane;
|
import com.vci.client.ui.swing.components.VCIJTextArea;
|
import com.vci.client.ui.swing.components.VCIJTextField;
|
import com.vci.common.utility.ObjectUtility;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.omd.btm.BtmItem;
|
import com.vci.corba.portal.data.PLUILayout;
|
|
public class UIContextDialog extends VCIJDialog {
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 2894131990318528996L;
|
|
private final JPanel contentPanel = new JPanel();
|
|
// add by guo
|
private String btname;
|
private boolean isSave;
|
public boolean isSave() {
|
return isSave;
|
}
|
private JButton okButton;
|
private JButton cancelButton;
|
private JLabel label;
|
private VCIJTextField plcode;
|
private JLabel label_1;
|
private VCIJTextField plname;
|
private JLabel label_2;
|
private JPanel panel;
|
private JCheckBox plisshowtab;
|
private JCheckBox plisshowform;
|
private JCheckBox plisshownavigator;
|
private JLabel label_3;
|
private JScrollPane scrollPane;
|
private VCIJTextArea pldesc;
|
|
private BtmItem btmItem;
|
private boolean editflag;
|
private PLUILayout editPLUILayout;
|
|
public UIContextDialog(BtmItem obj,boolean editFlag,PLUILayout plpagelayoutdefination) {
|
super(LogonApplication.frame,true);
|
this.btname = obj.name;
|
this.btmItem = obj;
|
this.editflag = editFlag;
|
this.editPLUILayout = plpagelayoutdefination;
|
setTitle((isEdit()?"编辑":"添加") + " 上下文");
|
setBounds(100, 100, 450, 300);
|
init();
|
actionListener();
|
initData();
|
this.setLocationRelativeTo(null);
|
this.setVisible(true);
|
}
|
private boolean isEdit(){
|
return (this.editflag && this.editPLUILayout != null);
|
}
|
private void init() {
|
getContentPane().setLayout(new BorderLayout());
|
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
gbl_contentPanel.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
|
gbl_contentPanel.rowHeights = new int[]{0, 0, 0, 0};
|
gbl_contentPanel.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
|
gbl_contentPanel.rowWeights = new double[]{0.0, 0.0, 1.0, Double.MIN_VALUE};
|
contentPanel.setLayout(gbl_contentPanel);
|
{
|
label = new JLabel("上下文编码");
|
GridBagConstraints gbc_label = new GridBagConstraints();
|
gbc_label.insets = new Insets(0, 0, 5, 5);
|
gbc_label.anchor = GridBagConstraints.EAST;
|
gbc_label.gridx = 1;
|
gbc_label.gridy = 0;
|
contentPanel.add(label, gbc_label);
|
}
|
{
|
plcode = new VCIJTextField(true);
|
GridBagConstraints gbc_textField = new GridBagConstraints();
|
gbc_textField.fill = GridBagConstraints.HORIZONTAL;
|
gbc_textField.insets = new Insets(0, 0, 5, 5);
|
gbc_textField.gridx = 2;
|
gbc_textField.gridy = 0;
|
contentPanel.add(plcode, gbc_textField);
|
plcode.setColumns(10);
|
}
|
{
|
label_1 = new JLabel("名称");
|
GridBagConstraints gbc_label_1 = new GridBagConstraints();
|
gbc_label_1.anchor = GridBagConstraints.EAST;
|
gbc_label_1.insets = new Insets(0, 0, 5, 5);
|
gbc_label_1.gridx = 3;
|
gbc_label_1.gridy = 0;
|
contentPanel.add(label_1, gbc_label_1);
|
}
|
{
|
plname = new VCIJTextField(true);
|
GridBagConstraints gbc_textField_1 = new GridBagConstraints();
|
gbc_textField_1.insets = new Insets(0, 0, 5, 0);
|
gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
|
gbc_textField_1.gridx = 4;
|
gbc_textField_1.gridy = 0;
|
contentPanel.add(plname, gbc_textField_1);
|
plname.setColumns(10);
|
}
|
{
|
label_2 = new JLabel("显示");
|
GridBagConstraints gbc_label_2 = new GridBagConstraints();
|
gbc_label_2.insets = new Insets(0, 0, 5, 5);
|
gbc_label_2.gridx = 1;
|
gbc_label_2.gridy = 1;
|
contentPanel.add(label_2, gbc_label_2);
|
}
|
{
|
panel = new JPanel();
|
FlowLayout flowLayout = (FlowLayout) panel.getLayout();
|
flowLayout.setAlignment(FlowLayout.LEFT);
|
GridBagConstraints gbc_panel = new GridBagConstraints();
|
gbc_panel.insets = new Insets(0, 0, 5, 0);
|
gbc_panel.gridwidth = 3;
|
gbc_panel.fill = GridBagConstraints.BOTH;
|
gbc_panel.gridx = 2;
|
gbc_panel.gridy = 1;
|
contentPanel.add(panel, gbc_panel);
|
{
|
plisshownavigator = new JCheckBox("导航区");
|
panel.add(plisshownavigator);
|
}
|
{
|
plisshowform = new JCheckBox("控制区");
|
panel.add(plisshowform);
|
}
|
{
|
plisshowtab = new JCheckBox("操作区");
|
panel.add(plisshowtab);
|
}
|
}
|
{
|
label_3 = new JLabel("描述");
|
GridBagConstraints gbc_label_3 = new GridBagConstraints();
|
gbc_label_3.insets = new Insets(0, 0, 0, 5);
|
gbc_label_3.gridx = 1;
|
gbc_label_3.gridy = 2;
|
contentPanel.add(label_3, gbc_label_3);
|
}
|
{
|
scrollPane = new JScrollPane();
|
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
gbc_scrollPane.gridwidth = 3;
|
gbc_scrollPane.insets = new Insets(0, 0, 0, 5);
|
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
gbc_scrollPane.gridx = 2;
|
gbc_scrollPane.gridy = 2;
|
contentPanel.add(scrollPane, gbc_scrollPane);
|
{
|
pldesc = new VCIJTextArea();
|
pldesc.setRows(3);
|
pldesc.setWrapStyleWord(true);
|
pldesc.setLineWrap(true);
|
scrollPane.setViewportView(pldesc);
|
}
|
}
|
{
|
JPanel buttonPane = new JPanel();
|
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
{
|
okButton = new JButton("保存");
|
buttonPane.add(okButton);
|
}
|
{
|
cancelButton = new JButton("关闭");
|
buttonPane.add(cancelButton);
|
}
|
}
|
}
|
|
private void actionListener(){
|
okButton.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent arg0) {
|
if(!canContinue()){
|
return;
|
}
|
save();
|
}
|
private boolean canContinue(){
|
String code = plcode.getText().trim();
|
String name = plname.getText().trim();
|
if("".equals(code)){
|
plname.requestFocus();
|
VCIJOptionPane.showMessage(UIContextDialog.this, label.getText() + " 不能为空!");
|
return false;
|
}
|
if("".equals(name)){
|
plcode.requestFocus();
|
VCIJOptionPane.showMessage(UIContextDialog.this, label_1.getText() + " 不能为空!");
|
return false;
|
}
|
if(!plisshownavigator.isSelected() && !plisshowform.isSelected() && !plisshowtab.isSelected()){
|
VCIJOptionPane.showMessage(UIContextDialog.this, "上下文至少要包含一个区域!");
|
return false;
|
}
|
return true;
|
}
|
|
private boolean nameOrCodeIsExist(String name, String code, boolean isEdit) throws VCIError{
|
boolean res = false;
|
PLUILayout[] plpagelayoutdefinations = UITools.getService().getPLUILayoutsByRelatedType(btname);
|
int length = plpagelayoutdefinations.length;
|
for (int i =0;i<length;i++){
|
String codes = plpagelayoutdefinations[i].plCode;
|
String names = plpagelayoutdefinations[i].plName;
|
String ids = plpagelayoutdefinations[i].plOId;
|
if(isEdit){
|
if(!ids.equals(editPLUILayout.plOId)){
|
if (code.equalsIgnoreCase(codes) || name.equals(names)){
|
res = true;
|
break;
|
}
|
}
|
}
|
else {
|
if (code.equalsIgnoreCase(codes) || name.equals(names)){
|
res = true;
|
break;
|
}
|
}
|
}
|
return res;
|
}
|
|
private void save() {
|
DialogResult res = DialogResult.CANCEL;
|
try {
|
String code = plcode.getText().trim();
|
String name = plname.getText().trim();
|
boolean isEdit = isEdit();
|
boolean isExist = nameOrCodeIsExist(name, code, isEdit);
|
if (isExist == true){
|
VCIOptionPane.showMessageDialog(null, "上下文编码或名称已经存在,请检查!");
|
return;
|
}
|
|
PLUILayout pld = new PLUILayout();
|
pld.plOId = ObjectUtility.getNewObjectID36();
|
if(isEdit){
|
pld.plOId = editPLUILayout.plOId;
|
}
|
pld.plCode = code;
|
pld.plName = name;
|
pld.plRelatedType = btmItem.name;
|
pld.plDesc = pldesc.getText();
|
if(isEdit){
|
pld.plCreateUser = editPLUILayout.plCreateUser;
|
} else {
|
pld.plCreateUser = LogonApplication.getUserEntityObject().getUserName();
|
}
|
pld.plModifyUser = LogonApplication.getUserEntityObject().getUserName();
|
|
if(plisshowform.isSelected()){
|
pld.plIsShowForm = 1;
|
} else {
|
pld.plIsShowForm = 0;
|
}
|
if (plisshownavigator.isSelected()){
|
pld.plIsShowNavigator = 1;
|
} else {
|
pld.plIsShowNavigator = 0;
|
}
|
if (plisshowtab.isSelected()){
|
pld.plIsShowTab = 1;
|
} else {
|
pld.plIsShowTab = 0;
|
}
|
if(isEdit){
|
UITools.getService().updatePLUILayout(pld);
|
}else {
|
UITools.getService().savePLUILayout(pld);
|
}
|
isSave = true;
|
res = DialogResult.OK;
|
} catch (VCIError e) {
|
e.printStackTrace();
|
isSave = false;
|
res = DialogResult.CANCEL;
|
}
|
close(res);
|
}
|
});
|
|
cancelButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent arg0) {
|
close(DialogResult.CANCEL);
|
}
|
});
|
}
|
|
private void close(DialogResult res){
|
setDialogResult(res);
|
setVisible(false);
|
dispose();
|
}
|
|
private void initData(){
|
if(editPLUILayout==null){
|
return;
|
}
|
plcode.setText(editPLUILayout.plCode);
|
plname.setText(editPLUILayout.plName);
|
if(editPLUILayout.plIsShowForm==1){
|
plisshowform.setSelected(true);
|
}
|
if(editPLUILayout.plIsShowNavigator==1){
|
plisshownavigator.setSelected(true);
|
}
|
if(editPLUILayout.plIsShowTab==1){
|
plisshowtab.setSelected(true);
|
}
|
pldesc.setText(editPLUILayout.plDesc);
|
}
|
}
|