package com.vci.client.portal.UI; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTable; import com.vci.client.LogonApplication; import com.vci.client.portal.NewNewUI.buttonmng.ButtonSettingDialog; import com.vci.client.portal.utility.PLDefination; import com.vci.client.portal.utility.UITools; import com.vci.client.ui.swing.VCIOptionPane; import com.vci.client.ui.swing.components.VCIJOptionPane; import com.vci.client.ui.table.VCIBaseTableModel; import com.vci.client.ui.table.VCIBaseTableNode; import com.vci.corba.common.VCIError; import com.vci.corba.portal.data.PLCommandParameter; import com.vci.corba.portal.data.PLPageDefination; import com.vci.corba.portal.data.PLUILayout; import com.vci.corba.portal.data.PLTabButton; import com.vci.corba.portal.data.PLTabPage; /** * 上下的区域维护主窗口 * */ public class TabMainDiaolg extends JDialog { /** * */ private static final long serialVersionUID = -8361652535631994346L; private JButton createBtn; private JButton editButton; private JScrollPane scrollPane; private JTable tabTable; private VCIBaseTableModel tabTableModel; String[] columnHeaders = new String[] { "编码", "名称", "是否启用" }; Class types[] = new Class[] { String.class, String.class, String.class }; private JTable uiTable; private VCIBaseTableModel uiTableModel; String[] uiTableColumnHeaders = new String[] { "编号", "名称" }; Class uiTableTypes[] = new Class[] { String.class, String.class, String.class }; private JButton delButton; private final PLUILayout plpagelayoutdefination; private JButton uiEdit; private JButton button; private final String btmName; private static String buttonArea = "tab"; private JScrollPane scrollPane_1; private JSplitPane splitPane; private JPanel panel_2; private JPanel panel_3; private JPanel panel; private JPanel panel_1; private JButton uiAdd; private JButton uiDel; private final short disType; private PLTabPage pltabpage; /** * * @param plpagelayoutdefination 上下文对象 * @param btmName 业务类型 * @param disType 显示区域类型 */ public TabMainDiaolg(PLUILayout plpagelayoutdefination, String btmName, short disType) { super(LogonApplication.frame, true); this.plpagelayoutdefination = plpagelayoutdefination; this.btmName = btmName; this.disType = disType; setBounds(100, 100, 750, 600); init(); actionListener(); initData(); this.setLocationRelativeTo(null); this.setVisible(true); } private void init() { getContentPane().setLayout(new BorderLayout()); { { tabTableModel = new VCIBaseTableModel(columnHeaders, types); uiTableModel = new VCIBaseTableModel(uiTableColumnHeaders, uiTableTypes); } } splitPane = new JSplitPane(); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); getContentPane().add(splitPane, BorderLayout.CENTER); panel_2 = new JPanel(); splitPane.setLeftComponent(panel_2); panel_2.setLayout(new BorderLayout(0, 0)); scrollPane = new JScrollPane(); panel_2.add(scrollPane); tabTable = new JTable(); tabTable.setModel(tabTableModel); scrollPane.setViewportView(tabTable); panel = new JPanel(); panel_2.add(panel, BorderLayout.SOUTH); { createBtn = new JButton("增加"); panel.add(createBtn); } { editButton = new JButton("修改"); panel.add(editButton); } { delButton = new JButton("删除"); panel.add(delButton); } panel_3 = new JPanel(); splitPane.setRightComponent(panel_3); panel_3.setLayout(new BorderLayout(0, 0)); scrollPane_1 = new JScrollPane(); panel_3.add(scrollPane_1); uiTable = new JTable(); uiTable.setModel(uiTableModel); scrollPane_1.setViewportView(uiTable); panel_1 = new JPanel(); panel_3.add(panel_1, BorderLayout.SOUTH); uiAdd = new JButton("新建"); panel_1.add(uiAdd); { uiEdit = new JButton("修改"); panel_1.add(uiEdit); } uiDel = new JButton("删除"); panel_1.add(uiDel); { // button = new JButton("按钮设计"); // panel_1.add(button); //FIXME 按钮设计二 JButton button2 = new JButton("按钮设计"); panel_1.add(button2); button2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int selectedRow = uiTable.getSelectedRow(); int selectedRowCount = uiTable.getSelectedRowCount(); if (selectedRowCount == 0) { VCIOptionPane.showMessage(LogonApplication.frame, "请选择数据!"); return; } if (uiTableModel.list.size() == 0) { VCIOptionPane.showMessage(LogonApplication.frame, "请选择数据!"); return; } VCIBaseTableNode valueAt = uiTableModel.getValueAt(selectedRow); PLPageDefination plPageDefination = (PLPageDefination) valueAt .getObj(); @SuppressWarnings("unused") ButtonSettingDialog dialogdd = new ButtonSettingDialog(TabMainDiaolg.this, plPageDefination, plpagelayoutdefination, buttonArea); } }); //end } splitPane.setDividerLocation(200); } private void actionListener() { tabTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { int selectedRow = tabTable.getSelectedRow(); VCIBaseTableNode valueAt = tabTableModel .getValueAt(selectedRow); PLTabPage pltabpage = (PLTabPage) valueAt.getObj(); initUIData(pltabpage); } }); uiAdd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { UIDesinDialog dialog = new UIDesinDialog( plpagelayoutdefination, null, btmName, disType, pltabpage); dialog.dispose(); initUIData(pltabpage); } }); uiEdit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { int selectedRow = uiTable.getSelectedRow(); int selectedRowCount = uiTable.getSelectedRowCount(); if (selectedRowCount == 0) { VCIOptionPane.showMessage(LogonApplication.frame, "请选择数据!"); return; } VCIBaseTableNode valueAt = uiTableModel.getValueAt(selectedRow); PLPageDefination plPageDefination = (PLPageDefination) valueAt .getObj(); // if("Folder".equals(plPageDefination.name)){ // VCIOptionPane.showMessage(LogonApplication.frame, "Folder不可以进行修改操作!"); // return; // } UIDesinDialog dialog = new UIDesinDialog( plpagelayoutdefination, plPageDefination, btmName, disType, pltabpage); dialog.dispose(); initUIData(pltabpage); } }); uiDel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { int selectedRow = uiTable.getSelectedRow(); int selectedRowCount = uiTable.getSelectedRowCount(); if (selectedRowCount == 0) { VCIOptionPane.showMessage(LogonApplication.frame, "请选择数据!"); return; } VCIBaseTableNode valueAt = uiTableModel.getValueAt(selectedRow); PLPageDefination plPageDefination = (PLPageDefination) valueAt .getObj(); // if("Folder".equals(plPageDefination.name)){ // VCIOptionPane.showMessage(LogonApplication.frame, "Folder不可以进行删除操作!"); // return; // } if(checkBtnLength(plPageDefination)){ VCIOptionPane.showMessage(LogonApplication.frame, "包含子数据,不能删除!"); return; } /*if(!(VCIJOptionPane.showConfirm(LogonApplication.frame, "您确定要删除所选数据吗?") == VCIJOptionPane.YES_OPTION)){ return; }*/ Object[] options = { "Yes", "No" }; int option = JOptionPane .showOptionDialog(LogonApplication.frame, "确认是否删除\"" + plPageDefination.name + "\"", "删除提示", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if(option != JOptionPane.YES_OPTION){ return; } try { boolean flag = UITools.getService().deletePLPageDefination( plPageDefination); initUIData(pltabpage); } catch (VCIError e) { e.printStackTrace(); } } }); createBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { TabDialog dialog = new TabDialog(plpagelayoutdefination, false, null,disType); initData(); } }); editButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { int selectedRow = tabTable.getSelectedRow(); int selectedRowCount = tabTable.getSelectedRowCount(); if (selectedRowCount == 0) { VCIOptionPane.showMessage(LogonApplication.frame, "请选择数据!"); return; } VCIBaseTableNode valueAt = tabTableModel .getValueAt(selectedRow); PLTabPage pltabpage = (PLTabPage) valueAt.getObj(); TabDialog dialog = new TabDialog(plpagelayoutdefination, true, pltabpage,disType); initData(); } }); delButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { int selectedRow = tabTable.getSelectedRow(); int selectedRowCount = tabTable.getSelectedRowCount(); if (selectedRowCount == 0) { VCIOptionPane.showMessage(LogonApplication.frame, "请选择数据!"); return; } VCIBaseTableNode valueAt = tabTableModel .getValueAt(selectedRow); PLTabPage pltabpage = (PLTabPage) valueAt.getObj(); if (check(pltabpage)) { VCIOptionPane.showMessage(LogonApplication.frame, "包含子数据,不能删除!"); return; } /*if(!(VCIJOptionPane.showConfirm(LogonApplication.frame, "您确定要删除所选数据吗?") == VCIJOptionPane.YES_OPTION)){ return; }*/ Object[] options = { "Yes", "No" }; int option = JOptionPane .showOptionDialog(LogonApplication.frame, "确认是否删除\"" + pltabpage.plName + "\"", "删除提示", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if(option != JOptionPane.YES_OPTION){ return; } try { boolean flag = UITools.getService().deletePLTabPage(pltabpage); VCIOptionPane.showMessage(LogonApplication.frame, "删除成功"); } catch (VCIError e) { e.printStackTrace(); VCIOptionPane.showMessage(LogonApplication.frame, "删除失败"); } initData(); } }); // button.addActionListener(new ActionListener() { // @Override // public void actionPerformed(ActionEvent arg0) { // int selectedRow = uiTable.getSelectedRow(); // int selectedRowCount = uiTable.getSelectedRowCount(); // if (selectedRowCount == 0) { // VCIOptionPane.showMessage(LogonApplication.frame, "请选择数据!"); // return; // } // if (uiTableModel.list.size() == 0) { // VCIOptionPane.showMessage(LogonApplication.frame, "请选择数据!"); // return; // } // VCIBaseTableNode valueAt = uiTableModel.getValueAt(selectedRow); // PLPageDefination plPageDefination = (PLPageDefination) valueAt // .getObj(); // ButtonDialog dialog = new ButtonDialog(plPageDefination, // plpagelayoutdefination, buttonArea); // initData(); // } // }); } private void initData() { tabTableModel.list.clear(); tabTableModel = (VCIBaseTableModel) tabTable.getModel(); VCIBaseTableNode vciBaseTableNode = null; PLTabPage[] o; try { o = UITools.getService().getTabPagesByContextIdAndType(plpagelayoutdefination.plOId, disType);//getPLTabPagesByPageDefinationOId( //plpagelayoutdefination.plOId); for (int i = 0; i < o.length; i++) { vciBaseTableNode = new VCIBaseTableNode(o[i]); vciBaseTableNode.setPropertyValueByName( tabTable.getColumnName(0), o[i].plCode); vciBaseTableNode.setPropertyValueByName( tabTable.getColumnName(1), o[i].plName); vciBaseTableNode.setPropertyValueByName(tabTable .getColumnName(2), o[i].plIsOpen == 1 ? "启用" : "未启用"); tabTableModel.addRow(i, vciBaseTableNode); } tabTable.setModel(tabTableModel); tabTable.updateUI(); } catch (VCIError e) { e.printStackTrace(); } } private boolean check(PLTabPage pltabpage) { boolean flag = false; try { PLPageDefination[] obj = UITools.getService() .getPLPageDefinationsByPageContextOId( pltabpage.plOId); if (obj.length > 0 ) { flag = true; } } catch (VCIError e) { e.printStackTrace(); } return flag; } private boolean checkBtnLength(PLPageDefination plPageDefination) { boolean flag = false; try { PLTabButton[] o = UITools.getService().getPLTabButtonsByTableOId(plPageDefination.plOId); for(int i=0;i0){ flag = true; break; } } if (o.length > 0 ) { flag = true; } } catch (VCIError e) { e.printStackTrace(); } return flag; } private void initUIData(PLTabPage pltabpage) { uiTableModel.list.clear(); PLPageDefination[] o; PLDefination p; try { // obj = // Tool.getService().getPLPageDefinationsByPageContextOId(plpagelayoutdefination.plOId); o = UITools.getService().getPLPageDefinationsByPageContextOId( pltabpage.plOId); VCIBaseTableNode vciBaseTableNode = null; for (int i = 0; i < o.length; i++) { if (o[i].plType == disType) { vciBaseTableNode = new VCIBaseTableNode(o[i]); vciBaseTableNode.setPropertyValueByName( uiTable.getColumnName(0), o[i].seq); vciBaseTableNode.setPropertyValueByName( uiTable.getColumnName(1), o[i].name); uiTableModel.addRow(i, vciBaseTableNode); } } uiTable.setModel(uiTableModel); uiTable.updateUI(); this.pltabpage = pltabpage; } catch (VCIError e) { e.printStackTrace(); } catch (Throwable e) { e.printStackTrace(); } } public JButton getButton() { return button; } public void setButton(JButton button) { this.button = button; } }