Example usage for javax.swing.table DefaultTableModel getValueAt

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

Introduction

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

Prototype

public Object getValueAt(int row, int column) 

Source Link

Document

Returns an attribute value for the cell at row and column.

Usage

From source file:org.agmip.ui.afsirs.frames.SWFrame.java

private void jRadioFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioFileActionPerformed
    // TODO add your handling code here:

    if (isPreviousSelectionSavedLocation) {
        DefaultTableModel model = (DefaultTableModel) soilTable.getModel();

        if (prevSoil != null) {
            for (int i = 0; i < model.getRowCount(); i++) {
                prevSoil.getDU()[i] = (Double) model.getValueAt(i, 1);
                prevSoil.getWC()[i] = (Double) model.getValueAt(i, 2);
            }/*w ww .j ava2s  .c  o m*/
        }
        prevSoil = null;
        isPreviousSelectionSavedLocation = false;
    }

    toogleStateOfControls(evt);
    if (jRadioFile.isSelected()) {

        try {
            readFromFile(soilListBox.getSelectedIndex());
            soilNameText.setText(SNAME);
            soilTextureText.setText(TXT[0]);
            NLComboBox.setSelectedIndex(NL - 1);
            waterholdcapacityBox.setSelectedIndex(waterHoldSelectedItemIndex[2]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

From source file:gdt.jgui.tool.JEntityEditor.java

private void deleteRows() {
    try {//  ww w .j a  v a  2  s .com
        JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent();
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
        ListSelectionModel listModel = table.getSelectionModel();
        int rCnt = table.getRowCount();
        ArrayList<Integer> srl = new ArrayList<Integer>();
        for (int i = 0; i < rCnt; i++)
            if (listModel.isSelectedIndex(i)) {
                srl.add(new Integer(i));
            }
        Integer[] sra = srl.toArray(new Integer[0]);
        ArrayList<Core> ol = new ArrayList<Core>();
        Core row;
        boolean skip;
        for (int i = 0; i < rCnt; i++) {
            skip = false;
            for (int aSra : sra) {
                if (i == aSra) {
                    skip = true;
                    break;
                }
            }
            if (!skip) {
                row = new Core((String) tableModel.getValueAt(i, 0), (String) tableModel.getValueAt(i, 1),
                        (String) tableModel.getValueAt(i, 2));
                ol.add(row);
            }
        }
        Core[] ra = ol.toArray(new Core[0]);
        while (tableModel.getRowCount() > 0)
            tableModel.removeRow(0);
        for (Core aRa : ra) {
            tableModel.addRow(new String[] { aRa.type, aRa.name, aRa.value });
        }
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

From source file:ca.uviccscu.lp.server.main.MainFrame.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    l.info("Hash action activated");
    final ActionEvent ev = evt;
    if (!Shared.hashInProgress) {
        //final Game gg;
        if (jTable1.getSelectedRow() >= 0) {
            DefaultTableModel mdl = (DefaultTableModel) jTable1.getModel();
            String name = (String) mdl.getValueAt(jTable1.getSelectedRow(), 0);
            if (name != null) {
                MainFrame.lockInterface();
                SwingWorker worker = new SwingWorker<Void, Void>() {

                    @Override//from   www .  ja va  2 s  . c o m
                    public Void doInBackground() {
                        l.trace("Starting hashing");
                        MainFrame.lockInterface();
                        Shared.hashInProgress = true;
                        int row = jTable1.getSelectedRow();
                        String game = (String) jTable1.getModel().getValueAt(row, 0);
                        l.trace("Selection -  row: " + row + " and name " + game);
                        int status = GamelistStorage.getGame(game).gameStatus;
                        if (status == 0) {
                            File g = new File(GamelistStorage.getGame(game).gameAbsoluteFolderPath);
                            File tp = new File(SettingsManager.getTorrentFolderPath()
                                    + GamelistStorage.getGame(game).gameName + ".torrent");
                            try {
                                updateTask("Preparing to hash - wait!", true);
                                updateProgressBar(0, 0, 0, "...", false, true);
                                jButton5.setText("STOP");
                                //jButton5.setForeground(Color.RED);
                                jButton5.setEnabled(true);
                                jButton5.requestFocusInWindow();
                                MainFrame.setReportingActive();
                                GamelistStorage.getGame(game).gameStatus = 1;
                                MainFrame.updateGameInterfaceFromStorage();
                                TOTorrent t = TrackerManager.createNewTorrent(g, tp,
                                        new HashingProgressListener(game));
                                TrackerManager.getCore().addTorrentToTracker(t, tp.getAbsolutePath(),
                                        g.getAbsolutePath());
                                GamelistStorage.getGame(game).gameStatus = 2;
                                MainFrame.updateGameInterfaceFromStorage();
                                MainFrame.setReportingIdle();
                            } catch (Exception ex) {
                                l.error("Torrent create failed: " + game, ex);
                            }
                        } else if (status == 1 || status == 2) {
                            l.error("Game torrent already created");
                            int ans = JOptionPane.showConfirmDialog(null,
                                    "This game has already been hashed. Rehash?", "Hashing error",
                                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
                            if (ans == JOptionPane.OK_OPTION) {
                                GamelistStorage.getGame(game).gameStatus = 0;
                                File tp = new File(Shared.workingDirectory + Shared.torrentStoreSubDirectory
                                        + "\\" + GamelistStorage.getGame(game).gameName + ".torrent");
                                FileUtils.deleteQuietly(tp);
                                Shared.hashInProgress = false;
                                jButton5ActionPerformed(ev);
                                Shared.hashInProgress = true;
                            } else {
                                //
                            }
                        } else {
                            l.error("Game status invalid - hashing aborted");
                        }
                        return null;
                    }

                    @Override
                    public void done() {
                        MainFrame.setReportingIdle();
                        jButton5.setText("Hash selected");
                        //jButton5.setForeground(Color.WHITE);
                        MainFrame.unlockInterface();
                        Shared.hashInProgress = false;
                        MainFrame.updateGameInterfaceFromStorage();
                    }
                };
                worker.execute();
            } else {
                l.trace("Empty row - no action required");
            }
        }
    } else {
        try {
            l.trace("Stopping current hashing");
            TrackerManager.cancelNewTorrentCreation();
            int row = jTable1.getSelectedRow();
            String game = (String) jTable1.getModel().getValueAt(row, 0);
            GamelistStorage.getGame(game).gameStatus = 0;
            MainFrame.unlockInterface();
            MainFrame.updateGameInterfaceFromStorage();
        } catch (TOTorrentException ex) {
            l.info("Abort exception received as expected", ex);
        } catch (Exception ex) {
            l.error("Hash abort unexpected exception - abort failed");
        }
        jButton5.setText("Hash selected");
        jButton5.setForeground(Color.WHITE);
    }
}

From source file:ca.uviccscu.lp.server.main.MainFrame.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    l.info("Edit game action activated");
    MainFrame.lockInterface();//from w  ww . ja  v a2s .  co m
    MainFrame.updateTask("Editing game...", true);
    l.info("Starting game edit action");
    DefaultTableModel mdl = (DefaultTableModel) jTable1.getModel();
    final int row = jTable1.getSelectedRow();
    if (row >= 0 && mdl.getValueAt(row, 0) != null) {
        AddGameDialog addGameDialog = new AddGameDialog(this, true);
        addGameDialog.setLocationRelativeTo(null);
        //addGameDialog.setVisible(true);
        final Game temp = GamelistStorage.getGame((String) mdl.getValueAt(row, 0));
        final Game g = addGameDialog.popupEditDialog(temp);
        if (g != null) {
            l.trace("Edit done, checking for changes");
            //l.trace("Calculating folder size: " + g.gameAbsoluteFolderPath);
            MainFrame.updateTask("Checking for changes...", true);
            MainFrame.updateGameInterfaceFromStorage();
            boolean changed = true;
            if (temp.gameAbsoluteExecPath.equals(g.gameAbsoluteExecPath)
                    && temp.gameAbsoluteFolderPath.equals(g.gameAbsoluteFolderPath)) {
                l.trace("Location same - assuming no changes made");
                g.gameName = temp.gameName;
                g.gameBatCommands = temp.gameBatCommands;
                g.gamePName = temp.gamePName;
                g.gamePUser = temp.gamePUser;
                g.gamePWName = temp.gamePWName;
                g.gameRuntimeFlags = temp.gameRuntimeFlags;
                changed = false;
            } else {
                l.trace("Locations changed - rescanning the game");
                g.gameStatus = 0;
                MainFrame.updateProgressBar(0, 0, 0, "Calculating game size", true, true);
                final ObjectPlaceholder obj = new ObjectPlaceholder();
                SwingWorker worker = new SwingWorker<Long, Void>() {

                    @Override
                    public Long doInBackground() throws IOException {
                        MainFrame.lockInterface();
                        l.trace("Checking size");
                        MainFrame.updateProgressBar(0, 0, 0, "Analyzing game size", true, true);
                        obj.payload = FileUtils.sizeOfDirectory(new File(g.gameAbsoluteFolderPath));
                        l.trace("Checking files");
                        MainFrame.updateProgressBar(0, 0, 0, "Analyzing game files", true, true);
                        g.gameFileNumber = FileUtils.listFiles(new File(g.gameAbsoluteFolderPath), null, true)
                                .size();
                        l.trace("Checking CRC32");
                        MainFrame.updateProgressBar(0, 0, 0, "Analyzing game signature", true, true);
                        g.gameExecCRC32 = FileUtils.checksumCRC32(new File(g.gameAbsoluteExecPath));
                        return ((Long) obj.payload);
                    }

                    @Override
                    public void done() {
                        l.trace("Finishing game check");
                        MainFrame.updateProgressBar(0, 0, 0, "Finishing game edit", false, false);
                        g.gameSize = ((Long) obj.payload);
                        /*
                        double mbsize = Math.ceil(g.gameSize / (1024 * 1024));
                        jTable1.getModel().setValueAt(mbsize, row, 2);
                         *
                         */
                        g.copyTo(temp);
                        Shared.lastCreatedGame = null;
                        l.trace("Done editing game");
                        MainFrame.updateGameInterfaceFromStorage();
                        MainFrame.unlockInterface();
                        MainFrame.setReportingIdle();
                    }
                };
                worker.execute();
            }
            //we are trusting the size task to finish here ELSE TROUBLE
            /*
            GamelistStorage.removeGame(temp.gameName);
            GamelistStorage.addGame(g);
             * 
             */
            if (!changed) {
                MainFrame.unlockInterface();
                MainFrame.setReportingIdle();
            }
            MainFrame.updateGameInterfaceFromStorage();
        } else {
            MainFrame.unlockInterface();
            MainFrame.setReportingIdle();
            MainFrame.updateGameInterfaceFromStorage();
        }
    } else {
        l.trace("Game edit - bad selection or empty table");
        JOptionPane.showMessageDialog(this, "Invalid selection - can't edit", "Edit error",
                JOptionPane.WARNING_MESSAGE);
        MainFrame.unlockInterface();
        MainFrame.setReportingIdle();
        MainFrame.updateGameInterfaceFromStorage();
    }
}

From source file:gdt.jgui.entity.fields.JFieldsEditor.java

private void deleteRows() {
    try {//from   www.j  a  v  a 2s  .c om
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
        ListSelectionModel listModel = table.getSelectionModel();
        int rCnt = table.getRowCount();
        ArrayList<Integer> srl = new ArrayList<Integer>();
        for (int i = 0; i < rCnt; i++)
            if (listModel.isSelectedIndex(i)) {
                srl.add(new Integer(i));
            }
        Integer[] sra = srl.toArray(new Integer[0]);
        ArrayList<Core> ol = new ArrayList<Core>();
        Core row;
        boolean skip;
        for (int i = 0; i < rCnt; i++) {
            skip = false;
            for (int aSra : sra) {
                if (i == aSra) {
                    skip = true;
                    break;
                }
            }
            if (!skip) {
                row = new Core(null, (String) tableModel.getValueAt(i, 0),
                        (String) tableModel.getValueAt(i, 1));
                ol.add(row);
            }
        }
        Core[] ra = ol.toArray(new Core[0]);
        while (tableModel.getRowCount() > 0)
            tableModel.removeRow(0);
        for (Core aRa : ra) {
            tableModel.addRow(new String[] { aRa.name, aRa.value });
        }
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatMultiplePanel.java

private void createToolbar() {
    ActionListener addAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultTableModel model = (DefaultTableModel) formatSwitchTbl.getModel();
            DataObjSwitchFormatter fmt = formatContainer.getSelectedFormatter();
            DataObjDataFieldFormat fld = new DataObjDataFieldFormat();
            fmt.add(fld);//from ww w.j a  va 2 s. c o  m
            model.addRow(new Object[] { fld.getValue(), fld, ellipsisButtonLabel });
            setHasChanged(true);
            enableUIControls();
        }
    };

    ActionListener delAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int formatColumn = formatSwitchTbl.getColumn(DISPLAY_FORMAT_COL).getModelIndex();
            DefaultTableModel model = (DefaultTableModel) formatSwitchTbl.getModel();
            DataObjSwitchFormatter fmt = formatContainer.getSelectedFormatter();
            int[] rows = formatSwitchTbl.getSelectedRows();
            // sort rows in reverse order otherwise removing the first rows
            // will mess up with the row numbers
            Integer[] intRows = new Integer[rows.length];
            for (int i = 0; i < rows.length; ++i) {
                intRows[i] = new Integer(rows[i]);
            }
            Arrays.sort(intRows, Collections.reverseOrder());
            for (int currentRow : intRows) {
                fmt.remove((DataObjDataFieldFormatIFace) model.getValueAt(currentRow, formatColumn));
                model.removeRow(currentRow);
            }
            formatSwitchTbl.clearSelection();
            setHasChanged(true);
            enableUIControls();
        }
    };

    controlPanel = new EditDeleteAddPanel(null, delAL, addAL);
    controlPanel.getAddBtn().setEnabled(true);
}

From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java

private void fireCalculateReTimingsEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireCalculateReTimingsEvent
    jCalculationSettingsDialog.setVisible(false);
    if (evt.getSource() == jDoCalculateButton) {
        DefaultTableModel model = (DefaultTableModel) jAttackPlanTable.getModel();

        List<String> selectedPlans = new LinkedList<String>();
        for (int i = 0; i < jAttackPlanTable.getRowCount(); i++) {
            int row = jAttackPlanTable.convertRowIndexToModel(i);
            if ((Boolean) model.getValueAt(row, 1)) {
                selectedPlans.add((String) model.getValueAt(row, 0));
            }/* w ww.  j  a  va2  s  .  c  o  m*/
        }

        List<Village> ignore = new LinkedList<Village>();
        //process all plans
        for (String plan : selectedPlans) {
            logger.debug("Checking plan '" + plan + "'");
            List<ManageableType> elements = AttackManager.getSingleton().getAllElements(plan);
            //process all attacks
            for (ManageableType element : elements) {
                Attack a = (Attack) element;
                if (!ignore.contains(a.getSource())) {
                    ignore.add(a.getSource());
                }
            }
        }

        Object[] tags = jTagList.getSelectedValues();
        if (tags == null || tags.length == 0) {
            JOptionPaneHelper.showInformationBox(DSWorkbenchReTimerFrame.this, "Keine Dorfgruppe ausgewhlt",
                    "Information");
            return;
        }

        List<Village> candidates = new LinkedList<Village>();
        for (Object o : tags) {
            Tag t = (Tag) o;
            List<Integer> ids = t.getVillageIDs();
            for (Integer id : ids) {
                //add all villages tagged by current tag
                Village v = DataHolder.getSingleton().getVillagesById().get(id);
                if (!candidates.contains(v) && !ignore.contains(v)) {
                    candidates.add(v);
                }
            }
        }

        if (jRelationBox.isSelected()) {
            //remove all villages that are not tagges by the current tag
            boolean oneFailed = false;
            Village[] aCandidates = candidates.toArray(new Village[] {});
            for (Village v_tmp : aCandidates) {
                for (Object o : tags) {
                    Tag t = (Tag) o;
                    if (!t.tagsVillage(v_tmp.getId())) {
                        oneFailed = true;
                        break;
                    }
                }
                if (oneFailed) {
                    //at least one tag is not valid for village
                    candidates.remove(v_tmp);
                    oneFailed = false;
                }
            }
        }

        Village target = parsedAttack.getSource();
        UnitHolder unit = (UnitHolder) jUnitBox.getSelectedItem();
        Hashtable<Village, Date> timings = new Hashtable<Village, Date>();

        for (Village candidate : candidates) {
            double dist = DSCalculator.calculateDistance(candidate, target);
            long runtime = Math.round(dist * unit.getSpeed() * 60000.0);
            VillageTroopsHolder holder = TroopsManager.getSingleton().getTroopsForVillage(candidate,
                    TroopsManager.TROOP_TYPE.OWN);
            boolean useVillage = true;
            if (holder != null) {
                if (holder.getTroopsOfUnitInVillage(unit) == 0) {
                    useVillage = false;
                }
            }
            if (useVillage) {
                try {
                    double dur = DSCalculator.calculateMoveTimeInSeconds(parsedAttack.getSource(), target,
                            unit.getSpeed()) * 1000.0;
                    double ret = (double) parsedAttack.getArriveTime().getTime() + dur;
                    ret /= 1000;
                    ret = Math.round(ret + .5);
                    ret *= 1000;

                    long sendTime = (long) ret - runtime;
                    if (sendTime > System.currentTimeMillis() + 60000) {
                        timings.put(candidate, new Date(sendTime));
                    }
                } catch (Exception e) {
                }
            }
        }
        buildResults(timings, target, unit);
    }

}

From source file:la2launcher.MainFrame.java

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
    final long initTime = new Date().getTime();
    ReentrantLock lock = new ReentrantLock();
    final String patcherUrl = "http://" + updateHost + "/hf//updater.lst.la2";//new ArrayBlockingQueue<Runnable>(10000)
    final ThreadPoolExecutor tpe = new ThreadPoolExecutor(5, 5, 1, TimeUnit.HOURS,
            new ArrayBlockingQueue<Runnable>(10000));
    filesProcessed = 0;//from w  w w . j  a  v  a2s.  c  om
    tpe.execute(new Runnable() {
        @Override
        public void run() {
            jTextArea2.setText("");
            DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
            jProgressBar1.setMinimum(0);
            jProgressBar1.setMaximum(model.getRowCount());
            jProgressBar1.setValue(0);
            jLabel4.setText("0/" + model.getRowCount());
            for (int i = 0; i < model.getRowCount(); i++) {
                boolean checked = (Boolean) model.getValueAt(i, 1);
                String fileName = (String) model.getValueAt(i, 0);
                if (checked) {
                    tpe.execute(new Runnable() {
                        @Override
                        public void run() {

                            final String fileUrl = "http://" + updateHost + "/hf/" + fileName.replace("\\", "/")
                                    + ".la2";
                            try {
                                printMsg("  " + fileUrl);
                                File file = new File(gamePath + fileName + ".rar");
                                File fileExt = new File(gamePath + fileName);

                                file.getParentFile().mkdirs();
                                FileOutputStream fos = new FileOutputStream(file);
                                CloseableHttpClient httpclient = HttpClients.createDefault();
                                HttpGet httpGet = new HttpGet(fileUrl);
                                CloseableHttpResponse response1 = httpclient.execute(httpGet);

                                HttpEntity entity1 = response1.getEntity();
                                copyStream(entity1.getContent(), fos, new CopyListener() {
                                    @Override
                                    public void transfered(int n) {
                                        bytesRecieved += n;
                                        bytesRecievedTotal += n;
                                    }
                                });
                                response1.close();
                                fos.close();

                                printMsg("?? : " + fileName);

                                lock.lock();
                                //fixBzip2File(file);
                                //printMsg(" ?");

                                extractArchive(file.getAbsolutePath());

                                //BZip2CompressorInputStream bz = new BZip2CompressorInputStream(new FileInputStream(file));
                                //OutputStream pout = new FileOutputStream(fileExt);
                                //copyStream(archStream, pout, null);
                                //pout.close();
                                //archStream.close();
                                //jTextArea2.setText(jTextArea2.getText() + "\r\n? : " + fileName);
                                printMsg("? : " + fileName);
                                //file.delete();

                                //                                    File tgt = new File(gamePath + fileName);
                                //                                    if (tgt.exists()) {
                                //                                        tgt.delete();
                                //                                    }
                                //tgt.getParentFile().mkdirs();
                                //Files.move(fileExt.toPath(), new File(gamePath + fileName).toPath());
                                //jTextArea2.setText(jTextArea2.getText() + "\r\n ??: " + fileName);
                                printMsg(" ??: " + fileName);
                                jProgressBar1.setIndeterminate(false);
                                jLabel4.setText((++filesProcessed) + "/" + model.getRowCount());
                                jProgressBar1.setValue((int) filesProcessed);
                                lock.unlock();
                            } catch (IOException ex) {
                                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (Exception ex) {
                                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    });
                }
            }
        }
    });

    jButton5.setEnabled(false);
    jButton6.setEnabled(false);
    jButton7.setEnabled(false);
    jButton8.setEnabled(false);
    jButton9.setEnabled(false);
    jButton10.setEnabled(false);
    jProgressBar1.setIndeterminate(true);
    new Thread() {
        @Override
        public void run() {
            do {
                long millis = new Date().getTime();
                try {
                    sleep(300);
                } catch (InterruptedException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
                millis = new Date().getTime() - millis;
                BigDecimal totBig = new BigDecimal(bytesRecievedTotal / (1024 * 1024.0));
                totBig = totBig.setScale(2, BigDecimal.ROUND_CEILING);
                jLabel5.setText("?: " + (bytesRecieved / millis) + "KB/s. : "
                        + totBig + " MB");
                bytesRecieved = 0;
            } while (tpe.getActiveCount() > 0);
            tpe.shutdown();
            jButton5.setEnabled(true);
            jButton6.setEnabled(true);
            jButton7.setEnabled(true);
            jButton8.setEnabled(true);
            jButton9.setEnabled(true);
            jButton10.setEnabled(true);
            jProgressBar1.setIndeterminate(false);
            printMsg("  " + (new Date().getTime() - initTime)
                    + " ?.");
        }
    }.start();
}

From source file:grupob.TipoProceso.java

private void btnGuardarRegionesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarRegionesActionPerformed
    ArrayList<Region> listaRegionesPas = listaRegiones;
    DefaultTableModel modelo = (DefaultTableModel) jTableRegiones.getModel();
    for (int i = 0; i < listaRegionesPas.size(); i++) {
        String a = modelo.getValueAt(i, 1).toString();
        String n = modelo.getValueAt(i, 0).toString();
        int num = -1;
        try {// w  w w .j ava 2s.  c  o m
            num = Integer.parseInt(a);
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(null,
                    "Error: Ingreso un valor distinto de un numero en la fila: " + (i + 1) + " columna: 2");
            return;
        }
        if (num < 0) {
            JOptionPane.showMessageDialog(null,
                    "Error: Ingreso un numero negativo en la fila: " + (i + 1) + " columna: 2");
            return;
        }
        Region s = listaRegionesPas.get(i);
        Region r = new Region(s.getId(), n, num);
        listaRegionesPas.set(i, r);
    }
    for (int i = 0; i < listaRegionesPas.size(); i++) {
        Region rd = listaRegionesPas.get(i);
        if (rd.getId() != 0) {
            Manager.updateRegion(rd);
        }
    }
    JOptionPane.showMessageDialog(null, "Se completo de actualizar las regiones");

}

From source file:com.view.PortfolioManagerWindow.java

private void PMSendOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PMSendOrderActionPerformed
    DefaultTableModel dtm = (DefaultTableModel) PMSendOrderTable.getModel();
    int nRow = dtm.getRowCount();
    long currUID = 0;
    int nCol = dtm.getColumnCount();
    Object[][] tableData = new Object[nRow][nCol];
    List<SingleOrder> parsedOrders = new ArrayList();
    String selectedTrader = String.valueOf(PMSelectTraderOptions.getSelectedItem());

    for (int t = 0; t < traderListForBox.size(); t++) {
        if (traderListForBox.get(t).getUsername().equals(selectedTrader)) {
            currUID = traderListForBox.get(t).getU_id();
            System.out.println("OUR TRADER WE ASSIGN TO IS: " + selectedTrader + " HIS ID IS: " + currUID);
        }//  www . j a v a  2s  .c  o  m
    }

    boolean thereAreOrders = false;
    boolean ignoreRowFlag = false;

    for (int i = 0; i < nRow; i++) {
        for (int j = 0; j < nCol; j++) {
            tableData[i][j] = dtm.getValueAt(i, j);
        }
        System.out.println("Retrieved all table data");
        boolean trigg = true;

        for (int k = 0; k < nCol; k++) {
            if (tableData[i][k] != null) {
                ignoreRowFlag = false;
            } else {
                ignoreRowFlag = true;
                System.out.println("IGNORING EMPTY ROW");
            }
        }

        //double check symbol is not null
        if (ignoreRowFlag == false) {
            if (tableData[i][2] == null) {
                trigg = false;
            } else if (tableData[i][2].toString().trim().equals("")) {
                showMessageDialog(null, "Please enter non-empty Symbol.");
                trigg = false;
            } else if (!(tableData[i][2].toString().trim()
                    .equals(tableData[i][2].toString().trim().toUpperCase()))) {
                showMessageDialog(null, "Please enter the Symbol in all capital letters.");
                trigg = false;
            }

            if (tableData[i][0] != null && tableData[i][1] != null && tableData[i][2] != null
                    && tableData[i][3] != null && tableData[i][4] != null && tableData[i][5] != null) {
                if (tableData[i][0] != null) {
                    long portIDC = (long) tableData[i][0];
                    if (portIDC < 0) {
                        showMessageDialog(null,
                                "You have entered a negative portfolio ID value. Please fix this value before submitting the order.");
                        trigg = false;
                    }
                }
                if (tableData[i][3] != null) {
                    int quantityC = (int) tableData[i][3];
                    if (quantityC < 0) {
                        showMessageDialog(null,
                                "You have entered a negative quantity value. Please fix this value before submitting the order.");
                        trigg = false;
                    }
                }
                if (tableData[i][5] != null) {
                    String orderType = (String) tableData[i][5];
                    switch (orderType) {
                    case "Market":
                        if ((tableData[i][6] != null && tableData[i][7] != null)
                                || (tableData[i][6] != null && tableData[i][7] == null)
                                || (tableData[i][6] == null && tableData[i][7] != null)) {
                            showMessageDialog(null,
                                    "A market order should have neither a stop price nor a limit price.");
                            trigg = false;
                        }
                        break;
                    case "Limit":
                        if ((tableData[i][6] != null && tableData[i][7] == null)
                                || (tableData[i][6] != null && tableData[i][7] != null)
                                || (tableData[i][6] == null && tableData[i][7] == null)) {
                            showMessageDialog(null,
                                    "A limit order should have a limit price and no stop price.");
                            trigg = false;
                        }
                        break;
                    case "Stop":
                        if ((tableData[i][6] == null && tableData[i][7] != null)
                                || (tableData[i][6] != null && tableData[i][7] != null)
                                || (tableData[i][6] == null && tableData[i][7] == null)) {
                            showMessageDialog(null,
                                    "A stop order should have a stop price and no limit price.");
                            trigg = false;
                        }
                        break;
                    case "Stop Limit":
                        if ((tableData[i][6] == null && tableData[i][7] == null)
                                || (tableData[i][6] != null && tableData[i][7] == null)
                                || (tableData[i][6] == null && tableData[i][7] != null)) {
                            showMessageDialog(null,
                                    "A Stop Limit order should have both a stop price and a limit price.");
                            trigg = false;
                        }
                        break;
                    default:
                        showMessageDialog(null, "Something messed up in cases for order type.");
                    }
                }

                if (tableData[i][6] != null) {
                    double stopC = (double) tableData[i][6];
                    if (stopC < 0) {
                        showMessageDialog(null,
                                "You have entered a negative stop price value. Please fix this value before submitting the order.");
                        trigg = false;
                    }
                }
                if (tableData[i][7] != null) {
                    double limitC = (double) tableData[i][7];
                    if (limitC < 0) {
                        showMessageDialog(null,
                                "You have entered a negative limit price value. Please fix this value before submitting the order.");
                        trigg = false;
                    }
                }

                if (trigg == true) {
                    thereAreOrders = true;
                    SingleOrder o = new SingleOrder(tableData[i]);
                    parsedOrders.add(o);
                }
            } else {
                String a, b, c, d, e, f;
                if (tableData[i][0] == null) {
                    a = "Portfolio ID";
                } else {
                    a = "";
                }
                if (tableData[i][1] == null) {
                    b = "Stock Exchange";
                } else {
                    b = "";
                }
                if (tableData[i][2] == null || tableData[i][2].toString().trim().equals("")) {
                    c = "Symbol";
                } else {
                    c = "";
                }
                if (tableData[i][3] == null) {
                    d = "Quantity";
                } else {
                    d = "";
                }
                if (tableData[i][4] == null) {
                    e = "Action";
                } else {
                    e = "";
                }
                if (tableData[i][5] == null) {
                    f = "Order Type";
                } else {
                    f = "";
                }

                showMessageDialog(null, "You need to fill in the necessary fields before sending the order:\n"
                        + a + "\n" + b + "\n" + c + "\n" + d + "\n" + e + "\n" + f);
            }
        }
    }

    if (thereAreOrders) {
        showMessageDialog(null, "You have successfully sent your trades.");
        dtm.setRowCount(0);
        dtm.addRow(new Object[] { null, null, null, null, null, null, null, null, null });
        Order toSend = new Order(selectedTrader, parsedOrders);
        toSend.setAssignedTo(currUID);
        Long currID = CMAIN.reportUser().getU_id();
        String currUname = CMAIN.reportUser().getUsername();
        toSend.setPmId(currID);
        toSend.setPmUsername(currUname);
        ControllerPMCreatedOrders.handleOrder(toSend);
    }
}