private void jComboBox1ItemStateChanged(
     java.awt.event.ItemEvent evt) { // GEN-FIRST:event_jComboBox1ItemStateChanged
   String selectedItem = (String) jComboBox1.getSelectedItem();
   if (CommonSession.getGroupName().equals(selectedItem)) {
     jComboBox2.removeAllItems();
     jComboBox2.insertItemAt(CommonConstant.CONSTANT_DEFAULT_DEPARTMENT, 0);
     jComboBox2.setSelectedIndex(0);
     return;
   }
   // 部门的集合 key 是公司
   List<Department> listDepartment = mapDepartment.get(selectedItem);
   //        listDepartment.add(0, "All");
   List<String> departmentStrList = new ArrayList<String>();
   for (int i = 0; i < listDepartment.size(); i++) {
     departmentStrList.add(listDepartment.get(i).getDepartment());
   }
   int size = departmentStrList.size();
   if (size > 0) {
     String[] jModel = (String[]) departmentStrList.toArray(new String[size]);
     jComboBox2.removeAllItems();
     jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(jModel));
     jComboBox2.insertItemAt(CommonConstant.CONSTANT_DEFAULT_DEPARTMENT, 0);
     jComboBox2.setSelectedIndex(0);
   } else {
     jComboBox2.removeAllItems();
     jComboBox2.insertItemAt(CommonConstant.CONSTANT_DEFAULT_DEPARTMENT, 0);
     jComboBox2.setSelectedIndex(0);
   }
 } // GEN-LAST:event_jComboBox1ItemStateChanged
  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT
   * modify this code. The content of this method is always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jButton1 = new javax.swing.JButton();
    jPanel1 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jLabel6 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    jLabel9 = new javax.swing.JLabel();
    jTextField3 = new javax.swing.JTextField();
    jTextField4 = new javax.swing.JTextField();
    jTextField5 = new javax.swing.JTextField();
    jTextField6 = new javax.swing.JTextField();
    jTextField7 = new javax.swing.JTextField();
    jTextField8 = new javax.swing.JTextField();
    jTextField9 = new javax.swing.JTextField();
    jComboBox1 = new javax.swing.JComboBox();
    jComboBox2 = new javax.swing.JComboBox();
    jLabel10 = new javax.swing.JLabel();
    jLabel11 = new javax.swing.JLabel();
    jLabel12 = new javax.swing.JLabel();
    jLabel13 = new javax.swing.JLabel();
    jLabel14 = new javax.swing.JLabel();
    jLabel15 = new javax.swing.JLabel();
    jLabel16 = new javax.swing.JLabel();
    jButton2 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setResizable(false);

    jButton1.setText("保存");
    jButton1.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
          }
        });

    jLabel1.setText("公司:");

    jLabel2.setText("部门:");

    jLabel3.setText("姓名:");

    jLabel4.setText("电话:");

    jLabel5.setText("内线:");

    jLabel6.setText("传真:");

    jLabel7.setText("手机:");

    jLabel8.setText("邮箱:");

    jLabel9.setText("备注:");

    jTextField3.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseClicked(java.awt.event.MouseEvent evt) {
            jTextField3MouseClicked(evt);
          }

          public void mouseExited(java.awt.event.MouseEvent evt) {
            jTextField3MouseExited(evt);
          }
        });
    jTextField3.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jTextField3ActionPerformed(evt);
          }
        });
    jTextField3.addFocusListener(
        new java.awt.event.FocusAdapter() {
          public void focusLost(java.awt.event.FocusEvent evt) {
            jTextField3FocusLost(evt);
          }
        });

    jTextField4.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseClicked(java.awt.event.MouseEvent evt) {
            jTextField4MouseClicked(evt);
          }
        });
    jTextField4.addFocusListener(
        new java.awt.event.FocusAdapter() {
          public void focusLost(java.awt.event.FocusEvent evt) {
            jTextField4FocusLost(evt);
          }
        });

    jTextField5.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseClicked(java.awt.event.MouseEvent evt) {
            jTextField5MouseClicked(evt);
          }
        });
    jTextField5.addFocusListener(
        new java.awt.event.FocusAdapter() {
          public void focusLost(java.awt.event.FocusEvent evt) {
            jTextField5FocusLost(evt);
          }
        });

    jTextField6.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseClicked(java.awt.event.MouseEvent evt) {
            jTextField6MouseClicked(evt);
          }
        });
    jTextField6.addFocusListener(
        new java.awt.event.FocusAdapter() {
          public void focusLost(java.awt.event.FocusEvent evt) {
            jTextField6FocusLost(evt);
          }
        });

    jTextField7.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseClicked(java.awt.event.MouseEvent evt) {
            jTextField7MouseClicked(evt);
          }
        });
    jTextField7.addFocusListener(
        new java.awt.event.FocusAdapter() {
          public void focusLost(java.awt.event.FocusEvent evt) {
            jTextField7FocusLost(evt);
          }
        });

    jTextField8.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseClicked(java.awt.event.MouseEvent evt) {
            jTextField8MouseClicked(evt);
          }
        });
    jTextField8.addFocusListener(
        new java.awt.event.FocusAdapter() {
          public void focusLost(java.awt.event.FocusEvent evt) {
            jTextField8FocusLost(evt);
          }
        });

    jTextField9.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseClicked(java.awt.event.MouseEvent evt) {
            jTextField9MouseClicked(evt);
          }
        });
    jTextField9.addFocusListener(
        new java.awt.event.FocusAdapter() {
          public void focusLost(java.awt.event.FocusEvent evt) {
            jTextField9FocusLost(evt);
          }
        });

    List<String> companyStrList = new ArrayList<String>();
    companyStrList.add(0, CommonSession.getGroupName());
    for (int i = 0; i < listCompany.size(); i++) {
      companyStrList.add(listCompany.get(i).getCompany());
    }
    final int size = companyStrList.size() + 1;
    String[] jModel = (String[]) companyStrList.toArray(new String[size]);
    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(jModel));
    jComboBox1.addItemListener(
        new java.awt.event.ItemListener() {
          public void itemStateChanged(java.awt.event.ItemEvent evt) {
            jComboBox1ItemStateChanged(evt);
          }
        });

    jComboBox2.insertItemAt(CommonConstant.CONSTANT_DEFAULT_DEPARTMENT, 0);
    jComboBox2.setSelectedIndex(0);
    jComboBox2.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jComboBox2ActionPerformed(evt);
          }
        });

    jLabel10.setText("     ");

    jLabel11.setText("     ");

    jLabel12.setText("     ");

    jLabel13.setText("     ");

    jLabel14.setText("     ");

    jLabel15.setText("     ");

    jLabel16.setText("     ");

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel1Layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel9)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField9))
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel8)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField8))
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel7)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField7))
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel6)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField6))
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel5)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField5))
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel4)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField4))
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel3)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField3))
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(
                                        jComboBox2,
                                        0,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE))
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(
                                        jComboBox1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        157,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14)
                            .addComponent(jLabel15)
                            .addComponent(jLabel16))
                    .addContainerGap(22, Short.MAX_VALUE)));
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel1Layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(
                                jComboBox1,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(
                                jComboBox2,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(
                                jTextField3,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(
                                jTextField4,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(
                                jTextField5,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(
                                jTextField6,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(
                                jTextField7,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(
                                jTextField8,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel15))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(
                                jTextField9,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    jButton2.setText("取消");
    jButton2.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton2ActionPerformed(evt);
          }
        });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addGap(41, 41, 41)
                                    .addComponent(jButton1)
                                    .addGap(62, 62, 62)
                                    .addComponent(jButton2))
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addContainerGap()
                                    .addComponent(
                                        jPanel1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    layout.setVerticalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(
                        jPanel1,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE)
                    .addGap(18, 18, 18)
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jButton2))
                    .addGap(21, 21, 21)));

    pack();
  } // </editor-fold>//GEN-END:initComponents
  /**
   * 保存
   *
   * @param evt
   */
  private void jButton1ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed
    String message = "";
    String name = (String) jComboBox1.getSelectedItem();
    if (CommonSession.getGroupName().equals(name)) {
      message = "请选择公司";
      javax.swing.JOptionPane.showConfirmDialog(
          (java.awt.Component) null, message, "提示", javax.swing.JOptionPane.DEFAULT_OPTION);
      return;
    }
    String departmentName = (String) jComboBox2.getSelectedItem();
    if (CommonConstant.CONSTANT_DEFAULT_DEPARTMENT.equals(departmentName)) {
      message = "请选择部门";
      javax.swing.JOptionPane.showConfirmDialog(
          (java.awt.Component) null, message, "提示", javax.swing.JOptionPane.DEFAULT_OPTION);
      return;
    }
    String username = jTextField3.getText();
    if (StringUtil.isNull(username)) {
      message = "姓名为空";
      javax.swing.JOptionPane.showConfirmDialog(
          (java.awt.Component) null, message, "提示", javax.swing.JOptionPane.DEFAULT_OPTION);
      return;
    }

    ContactInfo ci = new ContactInfo();
    // 获取公司 部门ID
    //        String companyId = "";
    //        String departmentId = "";
    //        List<Department> departmentList = mapDepartment.get(name);
    //        for (Department d : departmentList) {
    //            if (d.getDepartment().equalsIgnoreCase(departmentName)) {
    //                companyId = d.getCompany();
    //                departmentId = d.getId();
    //                break;
    //            }
    //        }
    //        ci.setCompany(companyId);
    //        ci.setDepartment(departmentId);

    ci.setCompany((String) jComboBox1.getSelectedItem());
    ci.setDepartment((String) jComboBox2.getSelectedItem());

    ci.setEmail(jTextField8.getText());
    ci.setFax(jTextField6.getText());
    ci.setInside(jTextField5.getText());
    ci.setMobile(jTextField7.getText());
    ci.setName(jTextField3.getText());
    ci.setRemark(jTextField9.getText());
    ci.setTel(jTextField4.getText());
    ContactInfoService contactInfoService = new ContactInfoService();
    contactInfoService.save(ci);
    String sql = "select max(id) from contactinfo ";
    int id = contactInfoService.countByHql(sql);
    ci.setId(String.valueOf(id));
    setVisible(false);
    dispose();
    message = "联系人新增成功";
    javax.swing.JOptionPane.showConfirmDialog(
        (java.awt.Component) null, message, "提示", javax.swing.JOptionPane.DEFAULT_OPTION);

    // 新增系统中的数据
    this.mainJFrame.getListContactInfo().add(ci);
    // 新增JTree1的数据
    this.mainJFrame.getMapContactInfo().get(ci.getCompany()).get(ci.getDepartment()).add(ci);
    // 初始化JTree1
    this.mainJFrame.initJTree1();
  } // GEN-LAST:event_jButton1ActionPerformed