Example usage for javax.swing DefaultComboBoxModel removeAllElements

List of usage examples for javax.swing DefaultComboBoxModel removeAllElements

Introduction

In this page you can find the example usage for javax.swing DefaultComboBoxModel removeAllElements.

Prototype

public void removeAllElements() 

Source Link

Document

Empties the list.

Usage

From source file:vn.hieptn.interesttopic.InterestTopicMain.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here:
    List<MainTopicEnt> listMainTopic = DataBaseService.GetListMainTopicEnt();
    DefaultComboBoxModel modelMainTopic = (DefaultComboBoxModel) cmbMainTopicResult.getModel();
    modelMainTopic.removeAllElements();

    if (listMainTopic != null && listMainTopic.size() > 0) {
        for (MainTopicEnt tmpMainTopicEnt : listMainTopic) {
            tmpMainTopicEnt.Keyword = "";
            String fileWordmap = ConfigInfo.DIR_DATA_TRAIN + File.separator + tmpMainTopicEnt.TopicName
                    + File.separator + "WordTopic.txt";
            List<String> listWordmap = FunctionUtils.ReadTextFileToList(fileWordmap);
            if (listWordmap != null && listWordmap.size() > 1) {
                tmpMainTopicEnt.NumKeywordNoDuplicate = ConvertUtils.toInt(listWordmap.get(0));
                for (int i = 1; i < listWordmap.size(); i++) {
                    String tmpKeyword = listWordmap.get(i);
                    String[] listWord = StringUtils.split(tmpKeyword, " ");
                    if (!FunctionUtils.IsNullOrEmpty(listWord[0])) {
                        tmpMainTopicEnt.Keyword += listWord[0] + "|";
                    }// w w  w. j  a v  a2s  . c  om
                }
            }

            modelMainTopic.addElement(
                    tmpMainTopicEnt.TopicName + ": " + tmpMainTopicEnt.NumKeywordNoDuplicate + " Tu.");
            //Update MainTopicEnt
            DataBaseService.Update(tmpMainTopicEnt);

            List<TrainTopicEnt> lstTopic = DataBaseService.GetListTrainTopic(tmpMainTopicEnt.Id);
            if (lstTopic != null && lstTopic.size() > 0) {
                for (TrainTopicEnt tmpTopic : lstTopic) {
                    if (tmpTopic != null) {
                        ConfigInfo.MAP_TRAIN_TOPIC.put(tmpTopic.TopicName + "|" + tmpMainTopicEnt.Id, tmpTopic);
                    }
                }
            }
        }
    }
    cmbMainTopicResult.setModel(modelMainTopic);
    //Thong Bao Thanh Cong
    JOptionPane.showMessageDialog(null, "Cp Nht File WordTopic Thnh Cng!", "Read File WordTopic",
            JOptionPane.INFORMATION_MESSAGE);
}

From source file:vn.hieptn.interesttopic.InterestTopicMain.java

private void cmbMainTopicResultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbMainTopicResultActionPerformed
    // TODO add your handling code here:
    if (cmbMainTopicResult != null && cmbMainTopicResult.getSelectedItem() != null) {
        String selectedName = StringUtils.split(cmbMainTopicResult.getSelectedItem().toString(), ":")[0];
        MainTopicEnt tmpMainTopicEnt = DataBaseService.GetMainTopicByName(selectedName);
        if (tmpMainTopicEnt != null && tmpMainTopicEnt.Keyword != null) {
            txtWordTopic.setText(tmpMainTopicEnt.Keyword.replaceAll("\\|", " \n"));
        }/*from  ww w  .  j a  v a 2  s  . co m*/

        //Show Cc Topic ca Ch ? ny
        ConfigInfo.cmbMainTopicResult_ID = tmpMainTopicEnt.Id;
        DefaultComboBoxModel modelTopic = (DefaultComboBoxModel) cmbTrainTopic.getModel();
        modelTopic.removeAllElements();
        List<TrainTopicEnt> lstTopic = DataBaseService.GetListTrainTopic(tmpMainTopicEnt.Id);
        if (lstTopic != null && lstTopic.size() > 0) {
            for (TrainTopicEnt tmpTopic : lstTopic) {
                if (tmpTopic != null) {
                    modelTopic.addElement(tmpTopic.TopicName);
                    ConfigInfo.MAP_TRAIN_TOPIC.put(tmpTopic.TopicName + "|" + tmpMainTopicEnt.Id, tmpTopic);
                }
            }

            cmbTrainTopic.setModel(modelTopic);
        }

    }
}