Example usage for javax.swing.table DefaultTableModel fireTableDataChanged

List of usage examples for javax.swing.table DefaultTableModel fireTableDataChanged

Introduction

In this page you can find the example usage for javax.swing.table DefaultTableModel fireTableDataChanged.

Prototype

public void fireTableDataChanged() 

Source Link

Document

Notifies all listeners that all cell values in the table's rows may have changed.

Usage

From source file:musiccrawler.App.java

private void getAllMusic(DefaultTableModel defaultTableModel) {
    List<Music> musics = musicCrawler.getAllMusic();
    if (CollectionUtils.isNotEmpty(musics)) {
        AtomicInteger count = new AtomicInteger();
        musics.forEach(music -> {//from   ww  w.  j  a  va 2s  .  c o  m
            Object[] row = { count.getAndIncrement(), music.getId(), music.getTitle(), music.getImage(),
                    music.getUrl(), music.getLyric(), music.getDescription(), music.getStream(),
                    music.getQualityType().toString(), music.getSinger().getName(), music.getSinger().getAge(),
                    music.getSinger().getDescription(), music.getSinger().getAvatar() };
            defaultTableModel.addRow(row);
        });
        tbResult.setModel(defaultTableModel);
        defaultTableModel.fireTableDataChanged();
        tbResult.setVisible(true);
    }
}

From source file:musiccrawler.App.java

private void getMusicByOption(Map<String, String> values, DefaultTableModel defaultTableModel) {
    List<Music> musics = musicCrawler.getMusicByOption(values);
    if (!CollectionUtils.isEmpty(musics)) {
        AtomicInteger count = new AtomicInteger();
        musics.forEach(music -> {/*from   w  w  w. j av  a  2  s .c  om*/
            Object[] row = { count.getAndIncrement(), music.getId(), music.getTitle(), music.getImage(),
                    music.getUrl(), music.getLyric(), music.getDescription(), music.getStream(),
                    music.getQualityType().toString(), music.getSinger().getName(), music.getSinger().getAge(),
                    music.getSinger().getDescription(), music.getSinger().getAvatar() };
            defaultTableModel.addRow(row);
        });
        tbResult.setModel(defaultTableModel);
        defaultTableModel.fireTableDataChanged();
        tbResult.setVisible(true);
    }
}

From source file:musiccrawler.App.java

private void btnCrawlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCrawlActionPerformed
    if (Utils.isNull(rdgOptionCrawl.getSelection())) {
        JOptionPane.showMessageDialog(this, "Plz, check option before perform action crawl");
        return;//w  ww . j a v  a 2  s  .c  o  m
    }
    String path = txtUrlInput.getText();
    if (StringUtils.isEmpty(path)) {
        lblError.setText("Path is require");
        lblError.setForeground(Color.RED);
        return;
    }
    boolean isGetAll = rdbGetAll.isSelected();
    path = Validator.validPath(path);
    final DefaultTableModel defaultTableModel = new DefaultTableModel(isGetAll ? COLUMN_NAMES : COLUMN_STREAM,
            0);
    AtomicInteger count = new AtomicInteger();
    if (isGetAll) {
        List<Music> musics = musicCrawler.crawl(path);
        if (CollectionUtils.isNotEmpty(musics)) {
            musics.forEach(music -> {
                Object[] row = { count.getAndIncrement(), music.getId(), music.getTitle(), music.getImage(),
                        music.getUrl(), music.getLyric(), music.getDescription(), music.getStream(),
                        music.getQualityType().toString(), music.getSinger().getName(),
                        music.getSinger().getAge(), music.getSinger().getDescription(),
                        music.getSinger().getAvatar() };
                defaultTableModel.addRow(row);
            });
        }
    } else {
        Map<String, List<String>> results = musicCrawler.reCrawlLinkStream(path);
        List<String> musicIds = results.get("id");
        List<String> listStream = results.get("stream");
        musicIds.forEach(id -> {
            int index = count.getAndIncrement();
            Object[] row = { index, id, listStream.get(index) };
            defaultTableModel.addRow(row);
        });
    }
    tbResultCrawlOnl.setModel(defaultTableModel);
    defaultTableModel.fireTableDataChanged();
    tbResultCrawlOnl.setVisible(true);
}

From source file:GUI.MainWindow.java

public void addAffectedHost() {

    System.out.println("==addAffectedHost");

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) this.VulnTree.getLastSelectedPathComponent();
    if (node == null) {
        return;/*  w  ww . j a v  a 2s.  c  om*/
    }

    Vulnerability vuln = (Vulnerability) node.getUserObject();
    //ManageAffectedHosts.setVisible(true) ;

    // Old way of doing it
    JTextField ip_address = new JTextField();
    JTextField hostname = new JTextField();
    JTextField port_number = new JTextField();
    port_number.setText("0");
    JTextField protocol = new JTextField();
    protocol.setText("tcp");

    Object[] message = { "IP Address:", ip_address, "Hostname:", hostname, "Port Number:", port_number,
            "Protocol:", protocol };

    String new_ip = null;
    String new_hostname = null;
    String new_port_number = null;
    String new_protocol = null;

    while (new_ip == null || new_hostname == null || new_port_number == null || new_protocol == null) {
        int option = JOptionPane.showConfirmDialog(null, message, "Add affected host",
                JOptionPane.OK_CANCEL_OPTION);
        if (option == JOptionPane.OK_OPTION) {

            new_ip = ip_address.getText();
            new_hostname = hostname.getText();
            new_port_number = port_number.getText();
            new_protocol = protocol.getText();
            Host host = new Host();
            host.setIp_address(new_ip);
            host.setHostname(new_hostname);
            host.setPortnumber(new_port_number);
            host.setProtocol(new_protocol);
            vuln.addAffectedHost(host);
            DefaultTableModel dtm = (DefaultTableModel) this.VulnAffectedHostsTable.getModel();
            dtm.addRow(host.getAsVector());
            dtm.fireTableDataChanged();

        } else {
            return; // End the infinite loop
        }

    }

}

From source file:hw.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

    //        ResultSet rs1;
    //         //  ww w.  j  ava 2  s.c o m
    //        try {
    MongoCollection<Document> coll = db.getCollection("business");
    //MongoCollection<Document> catcollection = db.getCollection("catout");
    MongoCollection<Document> rcoll = db.getCollection("review");
    //final DBCollection collection = db.getCollection("review");
    MongoCollection<Document> ccoll = db.getCollection("checkin");
    String from_dropdown = jComboBox3.getSelectedItem().toString();
    String to_dropdown = jComboBox6.getSelectedItem().toString();

    String from_value = jTextField9.getText();
    String to_value = jTextField10.getText();
    String check_count_value = jTextField11.getText();

    String check_count_dropdown = jComboBox8.getSelectedItem().toString();
    String fromdate_value = jTextField1.getText();
    String todate_value = jTextField3.getText();
    String stars_value = jTextField12.getText();
    String votes_value = jTextField13.getText();
    String stars_dropdown = jComboBox4.getSelectedItem().toString();
    String votes_dropdown = jComboBox12.getSelectedItem().toString();
    String select = jComboBox1.getSelectedItem().toString();
    List<String> category_value = jList2.getSelectedValuesList();
    String poi = jComboBox5.getSelectedItem().toString();
    String proximity = jComboBox2.getSelectedItem().toString();
    BasicDBObject qryBusiness = new BasicDBObject();
    BasicDBObject qryReview = new BasicDBObject();
    BasicDBList BusinessList = new BasicDBList();
    BasicDBList ReviewList = new BasicDBList();
    FindIterable<Document> cursor;
    FindIterable<Document> cursor1;
    List<String> catout = new ArrayList<String>();
    List<String> proout = new ArrayList<String>();
    List<String> checkinout = new ArrayList<String>();
    List<String> reviewout = new ArrayList<String>();
    List<String> finalout = new ArrayList<String>();

    if (category_value.isEmpty())//&& poi == null && proximity == null && from_value == null && fromdate_value == null)
    {
        BasicDBObject nu = new BasicDBObject();
        FindIterable<Document> fi;
        fi = coll.find(nu);
        jTextField8.setText("db.business.find()");
        String Columnames[] = { "business_id", "state", "city", "stars" };
        DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
        dtm.setColumnCount(0);
        dtm.setRowCount(0);
        int numberOfColumns = Columnames.length;

        for (int i = 0; i < numberOfColumns; i++) {
            String name = Columnames[i];
            dtm.addColumn(name);

        }

        fi.forEach(new Block<Document>() {
            @Override
            public void apply(final Document document) {

                Object rowData[] = new Object[numberOfColumns];

                rowData[0] = document.get("business_id");
                rowData[1] = document.get("state");
                rowData[2] = document.get("city");
                rowData[3] = document.get("stars");

                dtm.addRow(rowData);
                rowData = null;
            }
        });

        jTable1.setRowSelectionAllowed(true);
        jTable1.setModel(dtm);

        jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        dtm.fireTableDataChanged();

    } else {

        Object[] l = jList2.getSelectedValues();
        //BasicDBList subcat = new BasicDBList();
        BasicDBList clist = new BasicDBList();
        BasicDBObject qrycategory;
        if (l.length > 0) {
            for (int i = 0; i < l.length; i++) {
                BasicDBObject buinessop = new BasicDBObject("categories", l[i]);
                clist.add(buinessop);
            }
        }
        qrycategory = new BasicDBObject("$or", clist);
        //               subcatquery = new BasicDBObject("$out","subcat");
        //               subcat.add(qrycategory);
        //               subcat.add(subcatquery);
        //               System.out.println(subcat);
        cursor = coll.find(qrycategory);

        System.out.println(qrycategory);
        //BasicDBObject category = new BasicDBObject();
        cursor.forEach(new Block<Document>() {
            @Override
            public void apply(final Document document) {

                System.out.println(document.get("business_id"));
                //category.put((String)document.get("business_id"), db);

                catout.add((String) document.get("business_id"));
                //                                System.out.println(document.get("state"));
                //                                System.out.println(document.get("city"));
                //                                System.out.println(document.get("stars"));
                //                               

            }
        });

        MongoCollection<Document> collecttest = db.getCollection("test");
        String[] addresses5 = { "", "4840 E Indian School Rd\\nSte 101\\nPhoenix, AZ 85018",
                "631 S Main St\\nDe Forest, WI 53532", "5813 Main St\\nMc Farland, WI 53558",
                "2039 Allen Blvd\\nMiddleton, WI 53562", "6230 University Ave\\nMiddleton, WI 53562" };
        String[][] latLong = { { "33.499313000000001", "-111.98375799999999" },
                { "43.2408748", "-89.343721700000003" }, { "43.014164000000001", "-89.288567" },
                { "43.090642000000003", "-89.485168999999999" }, { "43.0910607", "-89.487486700000005" } };

        BasicDBObject queryBusiness = new BasicDBObject();
        BasicDBList businessinputlist = new BasicDBList();

        String selectedAddress = jComboBox5.getSelectedItem().toString();
        String selectedProximity = jComboBox2.getSelectedItem().toString();
        Double pro = Double.parseDouble(selectedProximity) / 3963.2;
        int index = Arrays.asList(addresses5).indexOf(selectedAddress);
        Double Latitude = Double.parseDouble(latLong[index][0]);
        Double Longitude = Double.parseDouble(latLong[index][1]);
        System.out.println("lat" + Latitude);
        System.out.println("longi" + Longitude);
        //BasicDBObject lat = new BasicDBObject(Latitude.toString(),Longitude);
        BasicDBList c1 = new BasicDBList();
        BasicDBList cs = new BasicDBList();
        cs.add(Latitude);
        cs.add(Longitude);
        c1.add(cs);
        c1.add(pro);
        BasicDBObject c = new BasicDBObject("$centerSphere", c1);
        BasicDBObject bq = new BasicDBObject("loc", new BasicDBObject("$geoWithin", c));
        FindIterable<Document> fi;
        fi = collecttest.find(bq);
        System.out.println(bq);
        jTextField8.setText("db.test.find(" + bq + ")");
        fi.forEach(new Block<Document>() {
            @Override
            public void apply(final Document document) {

                System.out.println(document.get("business_id"));

                proout.add((String) document.get("business_id"));

                //System.out.println(document.get("loc"));
            }
        });
        int checkinempty = 0;
        if (from_value == null || to_value == null || check_count_value.equals("0")) {
            checkinempty = 1;
            List<String> pr = new ArrayList<String>(catout);
            System.out.println(pr.size());
            pr.retainAll(proout);
            System.out.println(pr.size());
            String Columnames[] = { "Business_id", "state", "city", "stars" };
            DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
            dtm.setColumnCount(0);
            dtm.setRowCount(0);
            int numberOfColumns = Columnames.length;
            Object rowData[] = new Object[numberOfColumns];

            for (int i = 0; i < numberOfColumns; i++) {
                String name = Columnames[i];
                dtm.addColumn(name);

            }
            for (int i = 0; i < pr.size(); i++) {

                rowData[0] = pr.get(i);
                BasicDBObject c11 = new BasicDBObject("business_id", pr.get(i));
                FindIterable<Document> f1;
                f1 = coll.find(c11);
                f1.forEach(new Block<Document>() {
                    @Override
                    public void apply(final Document document) {

                        Object rowData[] = new Object[numberOfColumns];
                        rowData[0] = document.get("business_id");
                        rowData[1] = document.get("state");
                        rowData[2] = document.get("city");
                        rowData[3] = document.get("stars");
                        dtm.addRow(rowData);
                        rowData = null;

                    }
                });

                //                                
                //                                
                //                              

            }

            jTable1.setRowSelectionAllowed(true);
            jTable1.setModel(dtm);

            jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            dtm.fireTableDataChanged();

        }
        if (checkinempty != 1) {

            BasicDBList checkinputlist = new BasicDBList();
            //               
            ArrayList<String> list1;
            list1 = new ArrayList<String>();
            list1.add("0");
            list1.add("1");
            list1.add("2");
            list1.add("3");
            list1.add("4");
            list1.add("5");
            list1.add("6");

            int from = list1.indexOf(from_dropdown);
            int to = list1.indexOf(to_dropdown);
            int count = to - from;
            int hoursfrom1 = Integer.parseInt(from_value);
            int hoursto1 = Integer.parseInt(to_value);
            int count1 = hoursto1 - hoursfrom1;

            FindIterable<Document> iterable = ccoll.find();

            iterable.forEach(new Block<Document>() {
                @Override
                public void apply(final Document document) {
                    //System.out.println(document.get("checkin_info"));

                    String s = document.toJson();
                    s.replace("Document", "");
                    // System.out.println(s);
                    JSONParser parser = new JSONParser();
                    try {
                        Object obj = parser.parse(s);
                        JSONObject doc = (JSONObject) obj;

                        //System.out.println(doc.get("checkin_info"));
                        JSONObject cinfo = (JSONObject) doc.get("checkin_info");
                        if (count >= 0) {
                            long num_checkin = 0;
                            for (int i = from; i <= to; i++) {
                                if (count1 >= 0) {
                                    for (int j = hoursfrom1; j <= hoursto1; j++) {
                                        //System.out.println(cinfo.get(j+"-"+i));
                                        if (cinfo.containsKey(j + "-" + i)) {
                                            num_checkin = num_checkin + (long) cinfo.get(j + "-" + i);
                                            //                              System.out.println(document.get("checkin_info."+j+"-"+i));

                                        }

                                    }
                                }
                            }
                            if (num_checkin != 0) {
                                if (jComboBox8.getSelectedItem().equals(">")
                                        && num_checkin > Long.parseLong(check_count_value)) {
                                    System.out
                                            .println(num_checkin + " checkins into " + doc.get("business_id"));
                                    checkinout.add((String) document.get("business_id"));

                                }
                                if (jComboBox8.getSelectedItem().equals("<")
                                        && num_checkin < Long.parseLong(check_count_value)) {
                                    System.out
                                            .println(num_checkin + " checkins into  " + doc.get("business_id"));
                                    checkinout.add((String) document.get("business_id"));

                                }
                                if (jComboBox8.getSelectedItem().equals("=")
                                        && num_checkin == Long.parseLong(check_count_value)) {
                                    System.out
                                            .println(num_checkin + " checkins into  " + doc.get("business_id"));
                                    checkinout.add((String) document.get("business_id"));

                                }
                            }

                            num_checkin = 0;

                        }
                    } catch (Exception e) {
                        System.out.println(e);
                    }
                }
            });

            if (fromdate_value != null && todate_value != null) {
                BasicDBObject fdv = new BasicDBObject("date", new BasicDBObject("$gte", fromdate_value));
                ReviewList.add(fdv);
                BasicDBObject tdv = new BasicDBObject("date", new BasicDBObject("$lte", todate_value));
                ReviewList.add(tdv);
            }
            if (stars_value != null) {
                if (stars_dropdown == ">") {
                    BasicDBObject sv = new BasicDBObject("stars",
                            new BasicDBObject("$gt", Integer.parseInt(stars_value)));
                    ReviewList.add(sv);
                }
                if (stars_dropdown == "<") {
                    BasicDBObject sv = new BasicDBObject("stars",
                            new BasicDBObject("$lt", Integer.parseInt(stars_value)));
                    ReviewList.add(sv);
                }
                if (stars_dropdown == "=") {
                    BasicDBObject sv = new BasicDBObject("stars", Integer.parseInt(stars_value));
                    ReviewList.add(sv);
                }
            }

            if (votes_value != null) {
                if (votes_dropdown == ">") {
                    BasicDBObject vv = new BasicDBObject("votes",
                            new BasicDBObject("$gt", Integer.parseInt(votes_value)));
                    //ReviewList.add(vv);
                }
                if (votes_dropdown == "<") {
                    BasicDBObject vv = new BasicDBObject("votes",
                            new BasicDBObject("$lt", Integer.parseInt(votes_value)));
                    //ReviewList.add(vv);
                }
                if (votes_dropdown == "=") {
                    BasicDBObject vv = new BasicDBObject("votes", Integer.parseInt(votes_value));
                    //ReviewList.add(vv);
                }
            }
            qryReview = new BasicDBObject("$and", ReviewList);
            if (qryReview == null) {
                //jTextField8.setText("db.review.find()");
                cursor1 = rcoll.find();

            } else {

                //jTextField8.setText("db.review.find("+qryReview.toString()+")");
                cursor1 = rcoll.find(qryReview);
            }

            cursor1.forEach(new Block<Document>() {
                @Override
                public void apply(final Document document) {
                    System.out.println(document.get("business_id"));
                    reviewout.add((String) document.get("business_id"));

                }
            });
            if ("AND".equals(jComboBox1.getSelectedItem().toString())) {
                //jTextField8.setText("db.checkin.find("+"{}"+","+"{business_id"+":1}"+")");
                List<String> fin = new ArrayList<String>(catout);
                System.out.println(fin.size());
                fin.retainAll(proout);
                System.out.println(fin.size());

                fin.retainAll(checkinout);

                System.out.println(fin.size());

                fin.retainAll(reviewout);

                //
                System.out.println(fin.size());
                String Columnames[] = { "Business_id", "state", "city", "stars" };
                DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
                dtm.setColumnCount(0);
                dtm.setRowCount(0);
                int numberOfColumns = Columnames.length;
                Object rowData[] = new Object[numberOfColumns];

                for (int i = 0; i < numberOfColumns; i++) {
                    String name = Columnames[i];
                    dtm.addColumn(name);

                }
                for (int i = 0; i < fin.size(); i++) {

                    rowData[0] = fin.get(i);
                    BasicDBObject c11 = new BasicDBObject("business_id", fin.get(i));
                    FindIterable<Document> f1;
                    f1 = coll.find(c11);
                    f1.forEach(new Block<Document>() {
                        @Override
                        public void apply(final Document document) {

                            Object rowData[] = new Object[numberOfColumns];
                            rowData[0] = document.get("business_id");
                            rowData[1] = document.get("state");
                            rowData[2] = document.get("city");
                            rowData[3] = document.get("stars");
                            dtm.addRow(rowData);
                            rowData = null;

                        }
                    });

                    //                                
                    //                                
                    //                              

                }

                jTable1.setRowSelectionAllowed(true);
                jTable1.setModel(dtm);

                jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                dtm.fireTableDataChanged();

            }
            if ("OR".equals(jComboBox1.getSelectedItem().toString())) {
                //MongoCollection<Document> = db.getCollection("business");
                //jTextField8.setText("db.checkin.find("+"{}"+","+"{business_id"+":1}"+")");
                List<String> fin = new ArrayList<String>(catout); //create a Set with all the elements in a
                fin.addAll(proout);
                System.out.println(fin.size());
                fin.addAll(checkinout);
                System.out.println(fin.size());
                fin.addAll(reviewout);
                System.out.println(fin.size());

                String Columnames[] = { "Business_id", "state", "city", "stars" };
                DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
                dtm.setColumnCount(0);
                dtm.setRowCount(0);
                int numberOfColumns = Columnames.length;
                //Object rowData[] = new Object[numberOfColumns];
                //Object rd1,rd2,rd3; 

                for (int i = 0; i < numberOfColumns; i++) {
                    String name = Columnames[i];
                    dtm.addColumn(name);

                }
                for (int i = 0; i < fin.size(); i++) {

                    Object rowData[] = new Object[numberOfColumns];

                    rowData[0] = fin.get(i);

                    BasicDBObject c11 = new BasicDBObject("business_id", fin.get(i));
                    FindIterable<Document> f1;
                    f1 = coll.find(c11);
                    f1.forEach(new Block<Document>() {
                        @Override
                        public void apply(final Document document) {

                            Object rowData[] = new Object[numberOfColumns];
                            rowData[0] = document.get("business_id");
                            rowData[1] = document.get("state");
                            rowData[2] = document.get("city");
                            rowData[3] = document.get("stars");
                            dtm.addRow(rowData);
                            rowData = null;
                        }
                    });

                }
                //                       });

                //Object rowData[] = new Object[numberOfColumns];

                //                                
                //                                
                //                              

                jTable1.setRowSelectionAllowed(true);
                jTable1.setModel(dtm);

                jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                dtm.fireTableDataChanged();

            }
            if (qryBusiness == null) {
                //jTextField8.setText("db.business.find()");
                cursor = coll.find();

            } else {

                //jTextField8.setText("db.business.find("+qryBusiness.toString()+")");
                cursor = coll.find(qryBusiness);
            }

            //         } catch (SQLException ex) {
            //             Logger.getLogger(hw.class.getName()).log(Level.SEVERE, null, ex);
            //         }
            //             
            //             
            //         
            //     

        }

    }
}

From source file:hw.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    MongoCollection<Document> coll = db.getCollection("user");
    String member_value = jTextField2.getText();
    String review_value = jTextField4.getText();
    String fans_value = jTextField5.getText();
    String average_stars_value = jTextField6.getText();
    String friends_value = jTextField7.getText();
    String review_dropdown = jComboBox13.getSelectedItem().toString();
    String fans_dropdown = jComboBox14.getSelectedItem().toString();
    String stars_dropdown = jComboBox15.getSelectedItem().toString();
    String friends_dropdown = jComboBox16.getSelectedItem().toString();
    BasicDBObject qryUser = new BasicDBObject();
    BasicDBList UserList = new BasicDBList();
    FindIterable<Document> cursor;
    String select = jComboBox1.getSelectedItem().toString();
    if (member_value == null && review_value.equals("0") && fans_value.equals("0")
            && average_stars_value.equals("0") && friends_value.equals("0")) {

        qryUser = null;//from  w  ww  .ja va  2s.c  o  m

    }
    if (member_value == null || member_value.equals("")) {
        member_value = "1999-01";
    }
    //      if(review_value == null || review_value.equals(""))
    //      {
    //          review_value = "0";
    //      }
    //      if(fans_value == null || fans_value.equals(""))
    //      {
    //          fans_value = "0";
    //      }
    //      if(average_stars_value == null || average_stars_value.equals(""))
    //      {
    //          average_stars_value = "0";
    //      }
    //      if(friends_value == null || friends_value.equals(""))
    //      {
    //          friends_value = "0";
    //      }

    if (!friends_value.equals("0")) {
        BasicDBObject fv = new BasicDBObject("friends." + friends_value, new BasicDBObject("$exists", true));
        UserList.add(fv);
    }
    if (!member_value.equals("0")) {
        BasicDBObject mv = new BasicDBObject("yelping_since", new BasicDBObject("$gt", member_value));
        UserList.add(mv);
    }
    if (!review_value.equals("0")) {
        if (review_dropdown.equals(">")) {
            BasicDBObject rv = new BasicDBObject("review_count",
                    new BasicDBObject("$gt", Integer.parseInt(review_value)));
            UserList.add(rv);
        }
        if (review_dropdown.equals("<")) {
            BasicDBObject rv = new BasicDBObject("review_count",
                    new BasicDBObject("$lt", Integer.parseInt(review_value)));
            UserList.add(rv);
        }
        if (review_dropdown.equals("=")) {
            BasicDBObject rv = new BasicDBObject("review_count", Integer.parseInt(review_value));
            UserList.add(rv);
        }

    }
    if (!fans_value.equals("0")) {
        if (fans_dropdown.equals(">")) {
            BasicDBObject f = new BasicDBObject("fans", new BasicDBObject("$gt", Integer.parseInt(fans_value)));
            UserList.add(f);
        }
        if (review_dropdown.equals("<")) {
            BasicDBObject f = new BasicDBObject("fans", new BasicDBObject("$lt", Integer.parseInt(fans_value)));
            UserList.add(f);
        }
        if (review_dropdown.equals("=")) {
            BasicDBObject f = new BasicDBObject("fans", Integer.parseInt(fans_value));
            UserList.add(f);
        }
    }
    if (!average_stars_value.equals("0")) {
        if (stars_dropdown.equals(">")) {
            BasicDBObject as = new BasicDBObject("average_stars",
                    new BasicDBObject("$gt", Integer.parseInt(average_stars_value)));
            UserList.add(as);
        }
        if (review_dropdown.equals("<")) {
            BasicDBObject as = new BasicDBObject("average_stars",
                    new BasicDBObject("$lt", Integer.parseInt(average_stars_value)));
            UserList.add(as);
        }
        if (review_dropdown.equals("=")) {
            BasicDBObject as = new BasicDBObject("average_stars", Integer.parseInt(average_stars_value));
            UserList.add(as);
        }
    }

    if ("AND".equals(jComboBox1.getSelectedItem().toString())) {
        qryUser = new BasicDBObject("$and", UserList);
    }
    if ("OR".equals(jComboBox1.getSelectedItem().toString())) {
        qryUser = new BasicDBObject("$or", UserList);
    }
    if (qryUser == null) {
        jTextField8.setText("db.user.find()");
        cursor = coll.find();

    } else {

        jTextField8.setText("db.user.find(" + qryUser.toString() + ")");
        cursor = coll.find(qryUser);
    }
    String Columnames[] = { "yelping_since", "review_count", "name", "user_id", "average_stars" };
    DefaultTableModel dtm = (DefaultTableModel) jTable2.getModel();
    dtm.setColumnCount(0);
    dtm.setRowCount(0);
    int numberOfColumns = Columnames.length;

    for (int i = 0; i < numberOfColumns; i++) {
        String name = Columnames[i];
        dtm.addColumn(name);

    }

    cursor.forEach(new Block<Document>() {
        @Override
        public void apply(final Document document) {

            Object rowData[] = new Object[numberOfColumns];

            rowData[0] = document.get("yelping_since");
            rowData[1] = document.get("review_count");
            rowData[2] = document.get("name");
            rowData[3] = document.get("user_id");
            rowData[4] = document.get("average_stars");

            //                                System.out.print(document.get("yelping_since")+"\t");                                
            //                                System.out.print(document.get("review_count")+"\t");                                
            //                                System.out.print(document.get("name")+"\t");                                
            //                                System.out.print(document.get("user_id")+"\t");                                
            //                                System.out.print(document.get("average_stars")+"\t");                                
            //                                System.out.println();
            dtm.addRow(rowData);
            rowData = null;
        }
    });

    jTable2.setRowSelectionAllowed(true);
    jTable2.setModel(dtm);

    jTable2.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    dtm.fireTableDataChanged();

    // mongoClient.close();

    //        
    //        
    //      

}

From source file:GUI.MainJF.java

public void LlenarTabla() {
    String[] columnNames = { "ID", "Nombre", "Email", "Edad", "Tipo", "", "" };
    Object[][] data = null;/*w  w  w  .j  a  v a2 s  .  co m*/
    DefaultTableModel model = new DefaultTableModel(data, columnNames);

    HttpResponse response;
    response = JSON.request(Config.URL + "usuarios/listar.json");
    JSONObject jObject = JSON.JSON(response);
    try {
        JSONArray jsonArr = jObject.getJSONArray("data");

        for (int i = 0; i < jsonArr.length(); i++) {
            JSONObject data_json = jsonArr.getJSONObject(i);
            model.addRow(
                    new Object[] { data_json.get("idUsuario").toString(), data_json.get("nombre").toString(),
                            data_json.get("email").toString(), data_json.get("edad").toString(),
                            data_json.get("descripcion").toString(), "Editar", "Eliminar" });
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    tb_usuarios.setModel(model);

    Action editar = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {

            JTable table = (JTable) e.getSource();
            int modelRow = Integer.valueOf(e.getActionCommand());

            String id = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 0);
            String nombre = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 1);
            String email = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 2);
            String edad = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 3);
            String tipo = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 4);

            FormUsuarios U = new FormUsuarios();

            U.setID(id);
            U.setNombre(nombre);
            U.setEmail(email);
            U.setEdad(edad);
            U.setTipo(tipo);

            U.setLocationRelativeTo(null);
            U.setVisible(true);
        }
    };
    ButtonColumn botonEditar = new ButtonColumn(tb_usuarios, editar, 5);
    botonEditar.setMnemonic(KeyEvent.VK_D);

    Action eliminar = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JTable table = (JTable) e.getSource();
            int modelRow = Integer.valueOf(e.getActionCommand());
            String id = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 0);
            String nombre = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 1);

            int rs = JOptionPane.showConfirmDialog(null,
                    "Estas seguro que deseas eliminas el usuario: " + nombre + " ?", "Eliminar",
                    JOptionPane.YES_NO_OPTION);
            if (rs == JOptionPane.YES_OPTION) {

                List<NameValuePair> parametros = new ArrayList<NameValuePair>();
                parametros.add(new BasicNameValuePair("idUsuario", id));

                HttpResponse response = JSON.request(Config.URL + "usuarios/eliminar.json", parametros);
                JSONObject jObject = JSON.JSON(response);
                int code = Integer.parseInt(jObject.get("code").toString());

                /*if(code == 201){
                JOptionPane.showMessageDialog(null, "Usuario eliminado");
                //((DefaultTableModel)table.getModel()).removeRow(modelRow);
                }else{
                JOptionPane.showMessageDialog(null, "Error eliminar Usuario");
                }*/
            }

        }
    };
    ButtonColumn botonEliminar = new ButtonColumn(tb_usuarios, eliminar, 6);
    botonEliminar.setMnemonic(KeyEvent.VK_D);
    model.fireTableDataChanged();

}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

public void fireAddTargetEvent(Village pTarget, int pAmount) {
    DefaultTableModel victimModel = (DefaultTableModel) jVictimTable.getModel();

    if (pTarget != null) {
        boolean contains = false;
        for (int row = 0; row < jVictimTable.getRowCount(); row++) {
            if (jVictimTable.getValueAt(row, 1).equals(pTarget)) {
                contains = true;/*from w  ww  . j av  a  2  s . c  o m*/
                jVictimTable.setValueAt(pAmount, row, 3);
                break;
            }
        }
        if (!contains) {
            victimModel.addRow(
                    new Object[] { pTarget.getTribe(), pTarget, jMarkTargetAsFake.isSelected(), pAmount, 0 });
        }
    }

    updateInfo();
    victimModel.fireTableDataChanged();
}

From source file:com.cch.aj.entryrecorder.frame.SettingsJFrame.java

private void UpdateProductUI(Product currentProduct) {
    txtProductCode.setText(currentProduct.getCode() == null || currentProduct.getCode() == "- Select -" ? ""
            : currentProduct.getCode().toString());
    ;/*from w  w  w  .  j av  a  2s.  c o  m*/
    txtProductDesc
            .setText(currentProduct.getDescription() == null ? "" : currentProduct.getDescription().toString());
    ;
    txtProductPerc1.setText(currentProduct.getAdditiveAPercentage() == null ? ""
            : currentProduct.getAdditiveAPercentage().toString());
    ;
    txtProductPerc2.setText(currentProduct.getAdditiveBPercentage() == null ? ""
            : currentProduct.getAdditiveBPercentage().toString());
    ;
    txtProductPerc3.setText(currentProduct.getAdditiveCPercentage() == null ? ""
            : currentProduct.getAdditiveCPercentage().toString());
    txtProductWeightMax
            .setText(currentProduct.getWeightMax() == null ? "" : currentProduct.getWeightMax().toString());
    txtProductWeightMin
            .setText(currentProduct.getWeightMin() == null ? "" : currentProduct.getWeightMin().toString());
    //combobox
    this.FillMouldComboBox(this.cbProductMould,
            currentProduct.getMouldId() != null ? currentProduct.getMouldId().getId() : 0);
    this.FillPolymerComboBox(this.cbProductPolymer,
            currentProduct.getPolymerId() != null ? currentProduct.getPolymerId().getId() : 0);
    this.FillAdditiveComboBox(this.cbProductAdditive1,
            currentProduct.getAdditiveAId() != null ? currentProduct.getAdditiveAId().getId() : 0);
    this.FillAdditiveComboBox(this.cbProductAdditive2,
            currentProduct.getAdditiveBId() != null ? currentProduct.getAdditiveBId().getId() : 0);
    this.FillAdditiveComboBox(this.cbProductAdditive3,
            currentProduct.getAdditiveCId() != null ? currentProduct.getAdditiveCId().getId() : 0);

    FillEmbossingComboBox(this.cbProductInsert,
            currentProduct.getInsertId() != null ? currentProduct.getInsertId().getId() : 0, "INSERT");
    FillEmbossingComboBox(this.cbProductEmbossing,
            currentProduct.getEmbossingId() != null ? currentProduct.getEmbossingId().getId() : 0, "EMBOSSING");
    List<String> threadBoresA = new ArrayList<String>();
    threadBoresA.add("- Select -");
    if (settingMould.getThreadBoreASize1() != null && !settingMould.getThreadBoreASize1().equals("")) {
        threadBoresA.add(settingMould.getThreadBoreASize1());
    }
    if (settingMould.getThreadBoreASize2() != null && !settingMould.getThreadBoreASize2().equals("")) {
        threadBoresA.add(settingMould.getThreadBoreASize2());
    }
    if (settingMould.getThreadBoreASize3() != null && !settingMould.getThreadBoreASize3().equals("")) {
        threadBoresA.add(settingMould.getThreadBoreASize3());
    }
    this.cbProductBoreA.setModel(new DefaultComboBoxModel(threadBoresA.toArray()));
    this.cbProductBoreA1.setModel(new DefaultComboBoxModel(threadBoresA.toArray()));
    List<String> threadBoresB = new ArrayList<String>();
    threadBoresB.add("- Select -");
    if (settingMould.getThreadBoreBSize1() != null && !settingMould.getThreadBoreBSize1().equals("")) {
        threadBoresB.add(settingMould.getThreadBoreBSize1());
    }
    if (settingMould.getThreadBoreBSize2() != null && !settingMould.getThreadBoreBSize2().equals("")) {
        threadBoresB.add(settingMould.getThreadBoreBSize2());
    }
    if (settingMould.getThreadBoreBSize3() != null && !settingMould.getThreadBoreBSize3().equals("")) {
        threadBoresB.add(settingMould.getThreadBoreBSize3());
    }
    this.cbProductBoreB.setModel(new DefaultComboBoxModel(threadBoresB.toArray()));
    this.cbProductBoreB1.setModel(new DefaultComboBoxModel(threadBoresB.toArray()));
    List<String> threadNecks = new ArrayList<String>();
    threadNecks.add("- Select -");
    if (settingMould.getThreadNeckSize1() != null && !settingMould.getThreadNeckSize1().equals("")) {
        threadNecks.add(settingMould.getThreadNeckSize1());
    }
    if (settingMould.getThreadNeckSize2() != null && !settingMould.getThreadNeckSize2().equals("")) {
        threadNecks.add(settingMould.getThreadNeckSize2());
    }
    if (settingMould.getThreadNeckSize3() != null && !settingMould.getThreadNeckSize3().equals("")) {
        threadNecks.add(settingMould.getThreadNeckSize3());
    }
    this.cbProductNeck.setModel(new DefaultComboBoxModel(threadNecks.toArray()));
    this.cbProductNeck1.setModel(new DefaultComboBoxModel(threadNecks.toArray()));
    if (currentProduct.getBung() != null && !currentProduct.getBung().equals("")) {
        this.cbProductBung.setSelectedItem(currentProduct.getBung().toString());
    }
    if (currentProduct.getPierced() != null && !currentProduct.getPierced().equals("")) {
        this.cbProductPierced.setSelectedItem(currentProduct.getPierced().toString());
    }
    if (currentProduct.getViewLine() != null && !currentProduct.getViewLine().equals("")) {
        this.cbProductViewLine.setSelectedItem(currentProduct.getViewLine().toString());
    }
    if (currentProduct.getDgnondg() != null) {
        this.cbProductDg.setSelectedIndex(currentProduct.getDgnondg());
    }
    if (currentProduct.getThreadBoreA() != null) {
        this.cbProductBoreA.setSelectedIndex(currentProduct.getThreadBoreA());
    }
    if (currentProduct.getThreadBoreB() != null) {
        this.cbProductBoreB.setSelectedIndex(currentProduct.getThreadBoreB());
    }
    if (currentProduct.getThreadNeck() != null) {
        this.cbProductNeck.setSelectedIndex(currentProduct.getThreadNeck());
    }
    if (currentProduct.getThreadBoreA1() != null) {
        this.cbProductBoreA1.setSelectedIndex(currentProduct.getThreadBoreA1());
    }
    if (currentProduct.getThreadBoreB1() != null) {
        this.cbProductBoreB1.setSelectedIndex(currentProduct.getThreadBoreB1());
    }
    if (currentProduct.getThreadNeck1() != null) {
        this.cbProductNeck1.setSelectedIndex(currentProduct.getThreadNeck1());
    }
    if (currentProduct.getClosureType() != null) {
        this.cbProductClosureType.setSelectedItem(currentProduct.getClosureType());
    }
    //
    DefaultTableModel model = (DefaultTableModel) this.tblCheck.getModel();
    model.setRowCount(0);
    model.fireTableDataChanged();
    List<Checkitem> checks = this.checkitemService.GetAllEntities();
    List<Checkitem> list = new ArrayList<Checkitem>();
    for (Checkitem ci : checks) {
        if (ci.getProductCollection().contains(this.settingProduct)) {
            list.add(ci);
        }
    }
    if (list != null) {
        for (Checkitem item : list) {
            model.addRow(new Object[] { item.getId(), item.getDescription() });
        }
    }
    this.txtCheckDesc.setText("");
    //
    if (this.settingProduct.getWeightMin() == null && this.settingProduct.getWeightMax() == null) {
        this.txtProductWeightMin.setText(
                this.settingMould.getWeightDgMin() != null ? this.settingMould.getWeightDgMin().toString()
                        : "");
        this.txtProductWeightMax.setText(
                this.settingMould.getWeightDgMax() != null ? this.settingMould.getWeightDgMax().toString()
                        : "");
    } else {
        this.txtProductWeightMin.setText(
                this.settingProduct.getWeightMin() != null ? this.settingProduct.getWeightMin().toString()
                        : "");
        this.txtProductWeightMax.setText(
                this.settingProduct.getWeightMax() != null ? this.settingProduct.getWeightMax().toString()
                        : "");
    }

    if (currentProduct.getProductImage() != null) {
        this.labDrawingImage1.setText(currentProduct.getProductImage().toString());
        AppHelper.DisplayImage(currentProduct.getProductImage().toString(), this.pnlDrawingImage1);
    } else {
        this.labDrawingImage1.setText("Image File Path");
        this.pnlDrawingImage1.removeAll();
    }

    if (currentProduct.getClosureType() != null && currentProduct.getClosureType().equals("TWIN")) {
        this.cbProductBoreA1.setVisible(true);
        this.cbProductBoreB1.setVisible(true);
        this.cbProductNeck1.setVisible(true);
    } else {
        this.cbProductBoreA1.setVisible(false);
        this.cbProductBoreB1.setVisible(false);
        this.cbProductNeck1.setVisible(false);
    }

}

From source file:org.dc.file.search.ui.DashboardForm.java

private void updateCommentTable() {
    initCommentResultsTable();/* w w w  .ja  v a 2s .  c om*/
    DefaultTableModel model = (DefaultTableModel) tblComments.getModel();
    model.setRowCount(0);

    selectedFile = tblSearchResults.getValueAt(tblSearchResults.getSelectedRow(), FILE_COL_INDEX).toString();
    DFile dFile = resultFiles.get(selectedFile);
    for (int i = 0; i < dFile.getComments().size(); i++) {
        Object[] data = new Object[MAX_COLS];
        data[0] = dFile.getComments().get(i).getCommentId();
        data[1] = dFile.getComments().get(i).getText();
        data[2] = new StarRater(5, dFile.getComments().get(i).getTotalRating(), 0);
        data[3] = new ButtonRenderer(tblComments);
        model.addRow(data);
    }
    tblComments.setModel(model);
    model.fireTableDataChanged();
}