List of usage examples for javax.swing.table DefaultTableModel setRowCount
public void setRowCount(int rowCount)
From source file:grupob.TipoProceso.java
private void btnBuscarInstitucionalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarInstitucionalActionPerformed // TODO add your handling code here: // TODO add your handling code here: if (!txtNombreInstitucional.getText().isEmpty()) { listaInstituciones.clear();/*from w ww . j a v a2 s.c o m*/ listaInstituciones = Manager.queryByNameInstitucion(txtNombreInstitucional.getText()); DefaultTableModel modelo = (DefaultTableModel) tblInstitucional.getModel(); tblInstitucional.getColumn("Eliminar").setCellRenderer(new ButtonRenderer()); modelo.setRowCount(0); String datos[] = new String[4]; for (int i = 0; i < listaInstituciones.size(); i++) { datos[0] = listaInstituciones.get(i).getNombre(); if (listaInstituciones.get(i).getCantidadVotantesRegistrados() == 0) { datos[1] = "0"; } else { datos[1] = Integer.toString(listaInstituciones.get(i).getCantidadVotantesRegistrados()); } String n = Manager.queryLocalById(listaInstituciones.get(i).getIdLocal()).getNombre(); datos[2] = "" + n; datos[3] = "ELIMINAR"; modelo.addRow(datos); } } else JOptionPane.showMessageDialog(null, "El campo buscar no puede estar vacio"); }
From source file:hw.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // ResultSet rs1; // /*from w ww .j ava 2s. com*/ // 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:UserInterface.GarbageCollectorRole.GarbageCollectorWorkAreaJPanel.java
public void populateRequestTable() { DefaultTableModel model = (DefaultTableModel) jGarbageCollector.getModel(); model.setRowCount(0); for (WorkRequest request : userAccount.getWorkQueue().getWorkRequestList()) { Object[] row = new Object[7]; row[0] = request;/*from www . ja va2 s . com*/ String area = ((GarbageCollectorWorkRequest) request).getArea(); row[1] = area; String metal = ((GarbageCollectorWorkRequest) request).getMetalGarbageStatus(); row[2] = metal; row[3] = ((GarbageCollectorWorkRequest) request).getBiodegradableStatus(); row[4] = ((GarbageCollectorWorkRequest) request).getPlasticStatus(); row[5] = ((GarbageCollectorWorkRequest) request).getStatus(); row[6] = ((GarbageCollectorWorkRequest) request).getSender(); model.addRow(row); } }
From source file:UserInterface.GarbageCollectorRole.GarbageCollectorWorkAreaJPanel.java
private void jRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRefreshActionPerformed DefaultTableModel model = (DefaultTableModel) jGarbageCollector.getModel(); model.setRowCount(0); for (WorkRequest request : userAccount.getWorkQueue().getWorkRequestList()) { Object[] row = new Object[17]; row[0] = request;//from w w w .ja va 2s. c o m String area = ((GarbageCollectorWorkRequest) request).getArea(); row[1] = area; String metal = ((GarbageCollectorWorkRequest) request).getMetalGarbageStatus(); row[2] = metal; row[3] = ((GarbageCollectorWorkRequest) request).getBiodegradableStatus(); row[4] = ((GarbageCollectorWorkRequest) request).getPlasticStatus(); row[5] = ((GarbageCollectorWorkRequest) request).getStatus(); row[6] = ((GarbageCollectorWorkRequest) request).getSender(); row[7] = ((GarbageCollectorWorkRequest) request).getCollectedMetal(); row[8] = ((GarbageCollectorWorkRequest) request).getCollectedPlastic(); row[9] = ((GarbageCollectorWorkRequest) request).getCollectedDegradable(); row[10] = ((GarbageCollectorWorkRequest) request).getSegregatedMetal(); row[11] = ((GarbageCollectorWorkRequest) request).getSegregatedPlastic(); row[12] = ((GarbageCollectorWorkRequest) request).getSegregatedDegradable(); row[13] = ((GarbageCollectorWorkRequest) request).getSentToMD(); row[14] = ((GarbageCollectorWorkRequest) request).getSentToPD(); row[15] = ((GarbageCollectorWorkRequest) request).getSentToBD(); row[16] = ((GarbageCollectorWorkRequest) request).getType(); model.addRow(row); } jTypeOfGarbage.setEnabled(true); jRefresh.setEnabled(false); jButton1.setEnabled(true); jButton2.setEnabled(true); }
From source file:GUI.MainWindow.java
/** * This wipes out the UNDO list and clears the interface from previous * selections. It should be called when no vulns are in the tree. *//*from w w w . jav a 2 s. c om*/ private void clearGUI() { undo_manager.setLimit(-1); this.VulnTitleTextField.setText(""); this.VulnDescriptionTextPane.setText(""); this.VulnRecommendationTextPane.setText(""); this.VulnCVSSVectorTextField.setText(""); this.VulnScore.setText(""); this.VulnRiskCategory.setText(""); // TODO clear references. DefaultListModel dlm = (DefaultListModel) this.VulnReferencesList.getModel(); dlm.removeAllElements(); DefaultTableModel dtm = (DefaultTableModel) this.VulnAffectedHostsTable.getModel(); // Clear the existing table dtm.setRowCount(0); }
From source file:GUI.MainWindow.java
private void deleteAffectedHosts() { System.out.println("==deleteAffectedHost"); // Get reference to visible vulnerability DefaultMutableTreeNode node = (DefaultMutableTreeNode) VulnTree.getLastSelectedPathComponent(); Vulnerability vuln = (Vulnerability) node.getUserObject(); // Build the list of hosts to delete int[] rows = this.VulnAffectedHostsTable.getSelectedRows(); for (int i = 0; i < rows.length; i++) { int row = this.VulnAffectedHostsTable.convertRowIndexToModel(rows[i]); Object obj = this.VulnAffectedHostsTable.getModel().getValueAt(row, 0); if (obj instanceof Host) { Host host = (Host) obj;//w ww.j a v a2 s. co m System.out.println("To Delete: " + host + ":" + host.getPortnumber()); vuln.deleteAffectedHost(host); } } // update the GUI DefaultTableModel dtm = (DefaultTableModel) this.VulnAffectedHostsTable.getModel(); // Clear the existing table dtm.setRowCount(0); // Set affected hosts into table Enumeration enums = vuln.getAffectedHosts().elements(); while (enums.hasMoreElements()) { Object obj2 = enums.nextElement(); if (obj2 instanceof Host) { Host host2 = (Host) obj2; Vector vecrow = host2.getAsVector(); // Gets the first two columns from the host dtm.addRow(vecrow); } } }
From source file:GUI.MainWindow.java
private void showVulnerability(Vulnerability vulnerability) { // Unmap document listeners IF at all possible removeDocumentListeners();//from w ww .j av a 2s . c o m this.VulnTitleTextField.setText(vulnerability.getTitle()); if (vulnerability.isIs_custom_risk() == true) { this.VulnCVSSVectorTextField.setText("NO CVSS VECTOR"); } else { this.VulnCVSSVectorTextField.setText(vulnerability.getCvss_vector_string()); } // Set vuln category this.VulnRiskCategory.setText(vulnerability.getRisk_category()); this.VulnScore.setText("" + vulnerability.getRiskScore()); this.VulnDescriptionTextPane.setText(vulnerability.getDescription()); this.VulnRecommendationTextPane.setText(vulnerability.getRecommendation()); // clear old references DefaultListModel ref_model = (DefaultListModel) this.VulnReferencesList.getModel(); ref_model.removeAllElements(); // add in the new references Enumeration ref_enums = vulnerability.getReferences().elements(); while (ref_enums.hasMoreElements()) { Reference ref = (Reference) ref_enums.nextElement(); ref_model.addElement(ref); } // Now setup undo listeners setupUndoListeners(); setupDocumentListeners(); DefaultTableModel dtm = (DefaultTableModel) this.VulnAffectedHostsTable.getModel(); // Clear the existing table dtm.setRowCount(0); // Set affected hosts into table Enumeration enums = vulnerability.getAffectedHosts().elements(); while (enums.hasMoreElements()) { Object obj = enums.nextElement(); if (obj instanceof Host) { Host host = (Host) obj; Vector row = host.getAsVector(); // Gets the first two columns from the host dtm.addRow(row); } } }
From source file:GUI.MainWindow.java
private void EditHostnameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditHostnameActionPerformed System.out.println("Edit Hostname Selected"); DefaultMutableTreeNode node = (DefaultMutableTreeNode) this.VulnTree.getLastSelectedPathComponent(); if (node == null) { return;//w ww. j a va 2 s . c om } Object vuln_obj = node.getUserObject(); if (!(vuln_obj instanceof Vulnerability)) { return; } Vulnerability current = (Vulnerability) vuln_obj; int row = this.VulnAffectedHostsTable.getSelectedRow(); row = this.VulnAffectedHostsTable.convertRowIndexToModel(row); Object obj = this.VulnAffectedHostsTable.getModel().getValueAt(row, 0); if (obj instanceof Host) { Host previous = (Host) obj; JTextField hostname = new JTextField(); hostname.setText(previous.getHostname()); Object[] message = { "Hostname:", hostname }; String new_hostname = null; while (new_hostname == null) { int option = JOptionPane.showConfirmDialog(null, message, "Modify Hostname", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION) { new_hostname = hostname.getText(); Host modified = previous.clone(); // Clone the previous one modified.setHostname(new_hostname); new TreeUtils().modifyHostname((DefaultMutableTreeNode) this.VulnTree.getModel().getRoot(), previous, modified); //current.modifyAffectedHost(previous, modified); // Update the Vulnerability object // Update the affected hosts table DefaultTableModel dtm = (DefaultTableModel) this.VulnAffectedHostsTable.getModel(); // Clear the existing table dtm.setRowCount(0); // Set affected hosts into table Enumeration enums = current.getAffectedHosts().elements(); while (enums.hasMoreElements()) { Object obj2 = enums.nextElement(); if (obj instanceof Host) { Host host = (Host) obj2; Vector row2 = host.getAsVector(); // Gets the first two columns from the host dtm.addRow(row2); } } } else { return; // user cancelled or closed the prompt } } } }
From source file:motor.part.MainPanel.java
private void clear_table(DefaultTableModel model) { model.setRowCount(0); }
From source file:org.fhcrc.cpl.viewer.quant.gui.ProteinQuantSummaryFrame.java
License:asdf
/** * Find all the peptides contributing to the ratio for the FIRST OCCURRENCE of a * protein in the pepXML file, find all quantitative events for those peptides in the * pepXML file, and show them//from w w w . j a va 2 s . c o m * @param pepXmlFile * @param proteins */ public void displayData(File pepXmlFile, File protXmlFile, List<ProtXmlReader.Protein> proteins) { _log.debug("displayData 1***"); this.protXmlFile = protXmlFile; this.pepXmlFile = pepXmlFile; Collections.sort(proteins, new Comparator<ProtXmlReader.Protein>() { public int compare(ProtXmlReader.Protein o1, ProtXmlReader.Protein o2) { return o1.getProteinName().compareTo(o2.getProteinName()); } }); DefaultTableModel proteinRatiosTableModel = new DefaultTableModel(0, 4) { //all cells uneditable public boolean isCellEditable(int row, int column) { return false; } public Class getColumnClass(int columnIndex) { switch (columnIndex) { case 0: return String.class; case 1: return Float.class; case 2: case 3: return Integer.class; } return String.class; } }; proteinRatiosTable.setModel(proteinRatiosTableModel); proteinRatiosTable.getColumnModel().getColumn(0).setHeaderValue("Protein"); proteinRatiosTable.getColumnModel().getColumn(1).setHeaderValue("Ratio"); proteinRatiosTable.getColumnModel().getColumn(2).setHeaderValue("Quant Peptides"); proteinRatiosTable.getColumnModel().getColumn(3).setHeaderValue("Events"); _log.debug("displayData getting protein info"); this.proteinNames = new ArrayList<String>(); List<ProtXmlReader.QuantitationRatio> quantRatios = new ArrayList<ProtXmlReader.QuantitationRatio>(); proteinRatiosTableModel.setRowCount(proteins.size()); for (int i = 0; i < proteins.size(); i++) { String proteinName = proteins.get(i).getProteinName(); ProtXmlReader.QuantitationRatio quantRatio = proteins.get(i).getQuantitationRatio(); quantRatios.add(quantRatio); proteinNames.add(proteinName); //careful -- the 3rd column values are populated below proteinRatiosTableModel.setValueAt(proteinName, i, 0); proteinRatiosTableModel.setValueAt(Rounder.round(quantRatio.getRatioMean(), 2), i, 1); } if (proteinNames.size() == 1) eventsTable.hideProteinColumn(); if (proteinGenesMap == null) eventsTable.hideGeneColumn(); else { eventsTable.setProteinGenesMap(proteinGenesMap); } TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(proteinRatiosTableModel); proteinRatiosTable.setRowSorter(sorter); contentPanel.updateUI(); _log.debug("displayData getting quant events"); quantEvents = new ArrayList<QuantEvent>(); Map<String, Set<String>> peptideProteinsQuantMap = new HashMap<String, Set<String>>(); for (int i = 0; i < proteins.size(); i++) { for (String peptide : quantRatios.get(i).getPeptides()) { Set<String> proteinsThisPep = peptideProteinsQuantMap.get(peptide); if (proteinsThisPep == null) { proteinsThisPep = new HashSet<String>(); peptideProteinsQuantMap.put(peptide, proteinsThisPep); } proteinsThisPep.add(proteins.get(i).getProteinName()); } } _log.debug("peptideProteinsQuantMap has " + peptideProteinsQuantMap.size() + " peptides."); System.err.println("Contains the one? " + peptideProteinsQuantMap.containsKey("QCPYCLLYK")); proteinEventsMap = new HashMap<String, List<QuantEvent>>(); Map<String, Set<String>> proteinPeptidesMap = new HashMap<String, Set<String>>(); try { PepXMLFeatureFileHandler.PepXMLFeatureSetIterator fsi = new PepXMLFeatureFileHandler.PepXMLFeatureSetIterator( pepXmlFile); int numFractions = 0; setMessage("Loading all pepXML fractions..."); _log.debug("Loading all pepXML fractions..."); while (fsi.hasNext()) { boolean thisFracHasEvents = false; FeatureSet featureSet = fsi.next(); setMessage("Checking fraction " + MS2ExtraInfoDef.getFeatureSetBaseName(featureSet)); _log.debug("Checking fraction " + MS2ExtraInfoDef.getFeatureSetBaseName(featureSet)); String featureSetBaseName = MS2ExtraInfoDef.getFeatureSetBaseName(featureSet); //check all features to see if they're in our list of peptides. If so, add to quantEvents for (Feature feature : featureSet.getFeatures()) { String peptide = MS2ExtraInfoDef.getFirstPeptide(feature); if (peptideProteinsQuantMap.containsKey(peptide) && IsotopicLabelExtraInfoDef.hasRatio(feature)) { thisFracHasEvents = true; //pick up the labeled residue from the first feature // if (labeledResidue == null) // { // AnalyzeICAT.IsotopicLabel label = IsotopicLabelExtraInfoDef.getLabel(feature); // if (label != null) // { // labeledResidue = "" + label.getResidue(); // labelMassDiff = label.getHeavy() - label.getLight(); // _log.debug("Found label: " + labeledResidue + ", " + labelMassDiff); // } // } QuantEvent quantEvent = new QuantEvent(feature, featureSetBaseName); quantEvent.setProtein(new ArrayList<String>(peptideProteinsQuantMap.get(peptide)).get(0)); quantEvents.add(quantEvent); for (String protein : peptideProteinsQuantMap.get(peptide)) { Set<String> peptidesThisProtein = proteinPeptidesMap.get(protein); if (peptidesThisProtein == null) { peptidesThisProtein = new HashSet<String>(); proteinPeptidesMap.put(protein, peptidesThisProtein); } peptidesThisProtein.add(quantEvent.getPeptide()); List<QuantEvent> eventsThisProtein = proteinEventsMap.get(protein); if (eventsThisProtein == null) { eventsThisProtein = new ArrayList<QuantEvent>(); proteinEventsMap.put(protein, eventsThisProtein); } eventsThisProtein.add(quantEvent); } } } if (thisFracHasEvents) numFractions++; } _log.debug("Processed all pepXML fractions "); for (int i = 0; i < proteins.size(); i++) { String protein = proteinNames.get(i); if (proteinPeptidesMap.get(proteinNames.get(i)) != null) proteinRatiosTableModel.setValueAt(proteinPeptidesMap.get(protein).size(), i, 2); if (proteinEventsMap.get(proteinNames.get(i)) != null) proteinRatiosTableModel.setValueAt(proteinEventsMap.get(protein).size(), i, 3); } if (numFractions < 2) { setMessage("Loaded all quantitation events from 1 fraction"); _log.debug("Loaded all quantitation events from 1 fraction"); } else { setMessage("Loaded all quantitation events from " + numFractions + " separate fractions"); _log.debug("Loaded all quantitation events from " + numFractions + " separate fractions"); } // if (labeledResidue == null) // infoMessage("WARNING: unable to determine modification used for quantitation. " + // "Cannot collapse light and heavy states or perform assessment."); // else // { // labelType = QuantitationUtilities.inferLabelType(labeledResidue, labelMassDiff); // } } catch (Exception e) { //check if the file has a .pep.xml extension, in case someone put the wrong file in if (pepXmlFile.getName().toLowerCase().endsWith("pep.xml")) errorMessage("Failed to load features from pepXML file: " + e.getMessage(), e); else { infoMessage("Failed to load pepXML file " + pepXmlFile.getName() + ". Extension is not .pep.xml... did you specify the wrong file?"); e.printStackTrace(System.err); } return; } _log.debug("Done loading quant events. Events: " + quantEvents.size()); if (quantEvents.isEmpty()) { throw new RuntimeException("No quantitation events found!"); } //sort by peptide, then fraction, then charge, then modifications Collections.sort(quantEvents, new QuantEvent.ProteinPeptideFractionChargeModificationsRatioAscComparator()); _log.debug("About to display events..."); displayEvents(); if (quantRatios.size() == 1) { eventsTable.setLogRatioHeaderRatio(quantRatios.get(0).getRatioMean()); } _log.debug("About to update extreme ratio GUI..."); updateExtremeRatioGUI(); }