List of usage examples for javax.swing.table DefaultTableModel addRow
public void addRow(Object[] rowData)
From source file:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java
private JPanel addStockPanelToolButtons() { JPanel panel = new JPanel(); panel.setLayout(new MigLayout("insets 0 0 0 0, gapx 0")); List<Integer> editableColumns = new ArrayList<Integer>(); editableColumns.add(stockTablePanel.getTable().getIndexOf(ColumnConstants.ACCESSION)); editableColumns.add(stockTablePanel.getTable().getIndexOf(ColumnConstants.PEDIGREE)); editableColumns.add(stockTablePanel.getTable().getIndexOf(ColumnConstants.GENERATION)); stockTablePanel.getTable().setEditableColumns(editableColumns); ;// w ww .j a v a2s . c o m JButton importStockList = new JButton("Import Stocks By Search"); JButton importHarvestGroup = new JButton("Import Stocks From Harvest Group"); JPanel subPanel1 = new JPanel(); subPanel1.setLayout(new MigLayout("insets 0 0 0 0, gapx 0")); subPanel1.add(importStockList, "gapRight 10"); subPanel1.add(importHarvestGroup, "gapRight 10, wrap"); panel.add(subPanel1, "gapLeft 10, spanx,wrap"); importStockList.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { StocksInfoPanel stockInfoPanel = CreateStocksInfoPanel .createStockInfoPanel("stock annotation popup"); stockInfoPanel.setSize(new Dimension(500, 400)); int option = JOptionPane.showConfirmDialog(null, stockInfoPanel, "Search Stock Packets", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); ArrayList<Integer> stockIds = new ArrayList<Integer>(); if (option == JOptionPane.OK_OPTION) { DefaultTableModel model = (DefaultTableModel) stockTablePanel.getTable().getModel(); CheckBoxIndexColumnTable stocksOutputTable = stockInfoPanel.getSaveTablePanel().getTable(); for (int row = 0; row < stocksOutputTable.getRowCount(); ++row) { int stockId = (Integer) stocksOutputTable.getValueAt(row, stocksOutputTable.getIndexOf(ColumnConstants.STOCK_ID)); stockIds.add(stockId); } List<Stock> stocks = StockDAO.getInstance().getStocksByIds(stockIds); for (Stock stock : stocks) { Object[] rowData = new Object[stockTablePanel.getTable().getColumnCount()]; rowData[0] = new Boolean(false); Passport passport = stock.getPassport(); StockGeneration generation = stock.getStockGeneration(); rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_NAME)] = stock .getStockName(); rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_ID)] = stock .getStockId(); rowData[stockTablePanel.getTable() .getIndexOf(ColumnConstants.GENERATION)] = generation == null ? null : generation.getGeneration(); rowData[stockTablePanel.getTable().getIndexOf( ColumnConstants.PASSPORT_ID)] = passport == null ? null : passport.getPassportId(); rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.ACCESSION)] = passport == null ? null : passport.getAccession_name(); rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.PEDIGREE)] = passport == null ? null : passport.getPedigree(); rowData[stockTablePanel.getTable().getIndexOf( ColumnConstants.CLASSIFICATION_CODE)] = passport.getClassification() == null ? null : passport.getClassification().getClassificationCode(); rowData[stockTablePanel.getTable().getIndexOf( ColumnConstants.CLASSIFICATION_ID)] = passport.getClassification() == null ? null : passport.getClassification().getClassificationId(); rowData[stockTablePanel.getTable() .getIndexOf(ColumnConstants.POPULATION)] = passport.getTaxonomy() == null ? null : passport.getTaxonomy().getPopulation(); rowData[stockTablePanel.getTable() .getIndexOf(ColumnConstants.TAXONOMY_ID)] = passport.getTaxonomy() == null ? null : passport.getTaxonomy().getTaxonomyId(); rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.MODIFIED)] = new Boolean( false); model.addRow(rowData); } } } }); importHarvestGroup.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ArrayList<PMProject> projects = TokenRelationDAO.getInstance() .findProjectObjects(LoginScreen.loginUserId); HashMap<String, Harvesting> name_tap = new HashMap<String, Harvesting>(); for (PMProject project : projects) { List<HarvestingGroup> HarvestingGroups = HarvestingGroupDAO.getInstance() .findByProjectid(project.getProjectId()); for (HarvestingGroup hg : HarvestingGroups) { Harvesting harvestingPanel = (Harvesting) getContext() .getBean("Harvesting - " + project.getProjectId() + hg.getHarvestingGroupName()); name_tap.put(project.getProjectName() + "-" + hg.getHarvestingGroupName(), harvestingPanel); } } JPanel popup = new JPanel(new MigLayout("insets 0, gap 5")); JScrollPane jsp = new JScrollPane(popup) { @Override public Dimension getPreferredSize() { return new Dimension(250, 320); } }; ButtonGroup group = new ButtonGroup(); for (String name : name_tap.keySet()) { JRadioButton button = new JRadioButton(name); group.add(button); popup.add(button, "wrap"); button.setSelected(true); } String selected_group = null; int option = JOptionPane.showConfirmDialog(null, jsp, "Select Harvesting Group Name: ", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION) { for (Enumeration<AbstractButton> buttons = group.getElements(); buttons.hasMoreElements();) { AbstractButton button = buttons.nextElement(); if (button.isSelected()) { selected_group = button.getText(); } } } if (selected_group != null) { Harvesting harvestingPanel = name_tap.get(selected_group); DefaultTableModel model = (DefaultTableModel) stockTablePanel.getTable().getModel(); ArrayList<String> stocknames = harvestingPanel.getStickerGenerator().getCreatedStocks(); List<Stock> stocks = StockDAO.getInstance().getStocksByNames(stocknames); for (Stock stock : stocks) { Object[] rowData = new Object[stockTablePanel.getTable().getColumnCount()]; rowData[0] = new Boolean(false); Passport passport = stock.getPassport(); StockGeneration generation = stock.getStockGeneration(); rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_NAME)] = stock .getStockName(); rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_ID)] = stock .getStockId(); rowData[stockTablePanel.getTable() .getIndexOf(ColumnConstants.GENERATION)] = generation == null ? null : generation.getGeneration(); rowData[stockTablePanel.getTable().getIndexOf( ColumnConstants.PASSPORT_ID)] = passport == null ? null : passport.getPassportId(); rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.ACCESSION)] = passport == null ? null : passport.getAccession_name(); rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.PEDIGREE)] = passport == null ? null : passport.getPedigree(); rowData[stockTablePanel.getTable().getIndexOf( ColumnConstants.CLASSIFICATION_CODE)] = passport.getClassification() == null ? null : passport.getClassification().getClassificationCode(); rowData[stockTablePanel.getTable().getIndexOf( ColumnConstants.CLASSIFICATION_ID)] = passport.getClassification() == null ? null : passport.getClassification().getClassificationId(); rowData[stockTablePanel.getTable() .getIndexOf(ColumnConstants.POPULATION)] = passport.getTaxonomy() == null ? null : passport.getTaxonomy().getPopulation(); rowData[stockTablePanel.getTable() .getIndexOf(ColumnConstants.TAXONOMY_ID)] = passport.getTaxonomy() == null ? null : passport.getTaxonomy().getTaxonomyId(); rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.MODIFIED)] = new Boolean( false); model.addRow(rowData); } } } }); getstockTablePanel().getTable().addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent e) { int row = getstockTablePanel().getTable().getSelectionModel().getAnchorSelectionIndex(); getstockTablePanel().getTable().setValueAt(true, row, getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED)); } }); JPanel subPanel2 = new JPanel(); subPanel2.setLayout(new MigLayout("insets 0 0 0 0 , gapx 0")); subPanel2.add(new JLabel("Pedigree: ")); this.pedigreeField = new JTextField(10); subPanel2.add(pedigreeField); JButton setPedigree = new JButton("set"); setPedigree.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { for (int row : getstockTablePanel().getTable().getSelectedRows()) { getstockTablePanel().getTable().setValueAt(pedigreeField.getText(), row, getstockTablePanel().getTable().getIndexOf(ColumnConstants.PEDIGREE)); getstockTablePanel().getTable().setValueAt(true, row, getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED)); } } }); subPanel2.add(setPedigree, "gapRight 15"); subPanel2.add(new JLabel("Accession: ")); this.accessionField = new JTextField(10); subPanel2.add(accessionField); JButton setAccession = new JButton("set"); setAccession.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { for (int row : getstockTablePanel().getTable().getSelectedRows()) { getstockTablePanel().getTable().setValueAt(accessionField.getText(), row, getstockTablePanel().getTable().getIndexOf(ColumnConstants.ACCESSION)); getstockTablePanel().getTable().setValueAt(true, row, getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED)); } } }); subPanel2.add(setAccession, "gapRight 15"); subPanel2.add(new JLabel("Generarion: ")); this.generarionField = new JTextField(10); subPanel2.add(generarionField); JButton setGeneration = new JButton("set"); setGeneration.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { for (int row : getstockTablePanel().getTable().getSelectedRows()) { getstockTablePanel().getTable().setValueAt(generarionField.getText(), row, getstockTablePanel().getTable().getIndexOf(ColumnConstants.GENERATION)); getstockTablePanel().getTable().setValueAt(true, row, getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED)); } } }); subPanel2.add(setGeneration); panel.add(subPanel2, "gapLeft 10,spanx"); return panel; }
From source file:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java
/** * read and write existing rows of classification_code table in database into classification_code table in interface *///from w w w .ja v a2 s. c o m private void populateClassificationCodeTable() { List<Classification> results = ClassificationDAO.getInstance().findAll(); classificationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); classificationTable.setSingleSelection(true); if (results.size() > 0) { Utils.removeAllRowsFromTable((DefaultTableModel) classificationTable.getModel()); } for (Classification result : results) { Object rowData[] = new Object[classificationTable.getColumnCount()]; rowData[0] = new Boolean(false); rowData[classificationTable.getColumnModel().getColumnIndex("Classification id")] = result .getClassificationId(); rowData[classificationTable.getColumnModel() .getColumnIndex(ColumnConstants.CLASSIFICATION_CODE)] = result.getClassificationCode(); rowData[classificationTable.getColumnModel().getColumnIndex("Classification Type")] = result .getClassificationType(); DefaultTableModel model = (DefaultTableModel) classificationTable.getModel(); model.addRow(rowData); classificationTable.setModel(model); } classificationTable.hideColumn("Classification id"); addClassificationCodeListeners(); }
From source file:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java
/** * read and write existing rows of taxonomy table in database into taxonomy table in interface *//*from ww w.j av a2s . c o m*/ private void populateTaxonomyTable() { List<Taxonomy> results = TaxonomyDAO.getInstance().findAll(); taxonomyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); taxonomyTable.setSingleSelection(true); if (results.size() > 0) { Utils.removeAllRowsFromTable((DefaultTableModel) taxonomyTable.getModel()); } for (Taxonomy result : results) { Object[] rowData = new Object[10]; rowData[0] = new Boolean(false); rowData[1] = result.getTaxonomyId().toString(); rowData[2] = result.getGenus() == null ? "NULL" : result.getGenus(); rowData[3] = result.getSpecies() == null ? "NULL" : result.getSpecies(); rowData[4] = result.getSubspecies() == null ? "NULL" : result.getSubspecies(); rowData[5] = result.getSubtaxa() == null ? "NULL" : result.getSubtaxa(); rowData[6] = result.getRace() == null ? "NULL" : result.getRace(); rowData[7] = result.getCommonName() == null ? "NULL" : result.getCommonName(); rowData[8] = result.getPopulation() == null ? "NULL" : result.getPopulation(); rowData[9] = result.getGto() == null ? "NULL" : result.getGto(); DefaultTableModel model = (DefaultTableModel) taxonomyTable.getModel(); model.addRow(rowData); taxonomyTable.setModel(model); } taxonomyTable.hideColumn("Taxonomy id"); addTaxonomyListeners(); }
From source file:org.accretegb.modules.phenotype.PhenotypeInfoPanel.java
/** * populates field table data/*from ww w . j av a 2s.co m*/ */ public void populateFieldTable() { try { List<Object[]> results = FieldDAO.getInstance().findByLocation(); getFieldTablePanel().getTable().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); if (results.size() > 0) { Utils.removeAllRowsFromTable((DefaultTableModel) getFieldTablePanel().getTable().getModel()); } DefaultTableModel model = (DefaultTableModel) getFieldTablePanel().getTable().getModel(); for (Object[] obj : results) { obj[0] = new Boolean(false); obj[1] = Integer.toString((Integer) obj[1]); model.addRow(obj); } getFieldTablePanel().getTable().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); getFieldTablePanel().getTable().setSingleSelection(true); getFieldTablePanel().getTable().setModel(model); getFieldTablePanel().getTable().getSelectionModel() .addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting() && getFieldTablePanel().getTable().getSelectedRow() != -1) { subsetListComboBox.setSelectedIndex(0); tagname.setText(""); } } }); } catch (Exception e) { } }
From source file:org.dc.file.search.ui.DashboardForm.java
private void updateCommentTable() { initCommentResultsTable();//from w w w .j a v a2 s. co m 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(); }
From source file:org.dc.file.search.ui.DashboardForm.java
private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed int hopCount = DEFAULT_SEARCH_HOPE_COUNT; int timeout = DEFAULT_SEARCH_TIMEOUT_SEC; if (advancedSearchEnabled) { try {/* ww w . j av a2s . c om*/ hopCount = Integer.parseInt(txtHopCount.getText()); timeout = Integer.parseInt(txtTimeoutSec.getText()); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this, "Default search options will be used", "Invalid Search Options!", JOptionPane.ERROR_MESSAGE); } } Store store = Store.getInstance(); String key = txtSearchKey.getText(); Peer localPeer = store.getLocalPeer(); SearchRequest searchRequest = new SearchRequest(Calendar.getInstance().getTimeInMillis(), key, hopCount, localPeer); store.setMySearchRequest(searchRequest); store.addSearchRequest(searchRequest); store.setSearchResults(new ArrayList<>()); List<DFile> results = Store.getInstance().findInFiles(searchRequest.getSearchKey()); if (!results.isEmpty()) { SearchResult searchResult = new SearchResult(key, localPeer, 0, results); store.addSearchResult(searchResult); } for (Map.Entry<String, Peer> entry : Store.getInstance().getPeerMap().entrySet()) { Peer peer = entry.getValue(); MessageUtils.sendUDPMessage(peer.getIp(), peer.getPort(), MessageType.SER + " " + localPeer.getIp() + " " + localPeer.getPort() + " \"" + key + "\" 2"); } Runnable resultTask = () -> { try { List<SearchResult> searchResults = Store.getInstance().getSearchResults(); resultFiles = new HashMap<>(); if (searchResults != null) { DefaultTableModel model = (DefaultTableModel) tblSearchResults.getModel(); model.setRowCount(0); for (int i = 0; i < searchResults.size(); i++) { Object[] data = new Object[MAX_COLS]; SearchResult searchResult = searchResults.get(i); Peer peer = searchResult.getPeerWithResults(); data[0] = peer.getKey(); data[1] = searchResult.getHopCount(); for (DFile dFile : searchResult.getResults()) { data[2] = dFile.getFileName(); data[3] = new StarRater(5, dFile.getTotalRating(), 0); resultFiles.put(dFile.getFileName(), dFile); model.addRow(data); } } tblSearchResults.setModel(model); model.fireTableDataChanged(); } } catch (Throwable t) { System.out.println(t.getMessage()); } finally { btnSearch.setEnabled(true); } }; initSearchResultsTable(); initCommentResultsTable(); btnSearch.setEnabled(false); tblSearchResults.setVisible(true); ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); scheduler.schedule(resultTask, timeout, TimeUnit.SECONDS); resetAndStartProgress(timeout); }
From source file:org.freeplane.view.swing.features.time.mindmapmode.nodelist.NodeList.java
private void updateModel(final DefaultTableModel model, final NodeModel node) { final ReminderExtension hook = ReminderExtension.getExtension(node); Date date = null;/*from www. ja v a2 s. c o m*/ if (hook != null) { date = new Date(hook.getRemindUserAt()); } if (showAllNodes && node.isVisible() || hook != null) { model.addRow(new Object[] { date, new TextHolder(new CoreTextAccessor(node)), new IconsHolder(node), node.getHistoryInformation().getCreatedAt(), node.getHistoryInformation().getLastModifiedAt(), new TextHolder(new DetailTextAccessor(node)), new TextHolder(new NoteTextAccessor(node)) }); } for (final NodeModel child : Controller.getCurrentModeController().getMapController() .childrenUnfolded(node)) { updateModel(model, child); } }
From source file:org.freeplane.view.swing.features.time.mindmapmode.NodeList.java
private void updateModel(final DefaultTableModel model, final NodeModel node) { final ReminderExtension hook = ReminderExtension.getExtension(node); Date date = null;/*from w w w . j a v a2s. c o m*/ if (hook != null) { date = new Date(hook.getRemindUserAt()); } if (showAllNodes && node.isVisible() || hook != null) { model.addRow(new Object[] { date, new NodeHolder(node), new IconsHolder(node), node.getHistoryInformation().getCreatedAt(), node.getHistoryInformation().getLastModifiedAt(), new NotesHolder(node) }); } for (final NodeModel child : Controller.getCurrentModeController().getMapController() .childrenUnfolded(node)) { updateModel(model, child); } }
From source file:org.o3project.optsdn.don.frame.NeFrame.java
/** * Create a pane that displays Information Model ID list. * //from w w w . j a va 2s. c om * @param portList Ports * @return The pane that displays Information Model ID list */ private JScrollPane createInformationModelIdListPane(List<Port> portList) { Collections.sort(portList, new PortComparator()); Object[] columnNames = INFORMATION_MODEL_ID_COLNAME_LIST.toArray(); DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0); for (Port port : portList) { Port[] column = { port, port }; tableModel.addRow(column); } JTable informationModeldTable = new JTable(tableModel); informationModeldTable.getTableHeader().setBackground(Color.WHITE); DefaultTableCellRenderer renderer = new InformationModelIdRenderer(); renderer.setHorizontalAlignment(SwingConstants.CENTER); informationModeldTable.setDefaultRenderer(Object.class, renderer); JScrollPane informationModelIdPane = new JScrollPane(); informationModelIdPane.getViewport().setView(informationModeldTable); informationModelIdPane .setPreferredSize(new Dimension(informationModelIdPane.getPreferredSize().width, TABLE_HEIGHT)); return informationModelIdPane; }
From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.FileSelectionTable.java
/** * Adds the collection of files to the queue. * /* w w w .ja v a2 s. c o m*/ * @param files The files to add. * @param settings The import settings. */ void addFiles(List<FileObject> files, ImportLocationSettings settings) { if (CollectionUtils.isEmpty(files)) return; boolean fad = settings.isParentFolderAsDataset(); GroupData group = settings.getImportGroup(); ExperimenterData user = settings.getImportUser(); enabledControl(true); DefaultTableModel dtm = (DefaultTableModel) table.getModel(); //Check if the file has already List<FileElement> inQueue = new ArrayList<FileElement>(); FileElement element; for (int i = 0; i < table.getRowCount(); i++) { element = (FileElement) dtm.getValueAt(i, this.fileIndex); inQueue.add(element); } Iterator<FileObject> i = files.iterator(); DataNode node = settings.getImportLocation(); if (model.getType() != Importer.SCREEN_TYPE) node.setParent(settings.getParentImportLocation()); String value = null; boolean v; long gID = group.getId(); FileObject f; while (i.hasNext()) { f = i.next(); if (allowAddToQueue(inQueue, f, gID, user.getId())) { element = new FileElement(f, model.getType(), group, user); element.setName(f.getName()); inQueue.add(element); value = null; v = false; value = f.getFolderAsContainerName(); if (f.isDirectory()) { v = fad; if (model.getType() == Importer.SCREEN_TYPE) { value = null; } } else { if (fad) { v = true; element.setToggleContainer(v); } } final Vector<Object> row = new Vector<Object>(); row.setSize(this.columnHeadings.size()); if (this.fileIndex != null) { row.set(this.fileIndex, element); } if (this.groupIndex != null) { row.set(this.groupIndex, group.getName()); } if (this.ownerIndex != null) { row.set(this.ownerIndex, user.getUserName()); } if (this.containerIndex != null) { row.set(this.containerIndex, new DataNodeElement(node, value)); } if (this.folderAsDatasetIndex != null) { row.set(this.folderAsDatasetIndex, v); } if (this.sizeIndex != null) { row.set(this.sizeIndex, element.getFileLengthAsString()); } dtm.addRow(row); } } model.onSelectionChanged(); }