gt:             boolean[] canEdit = new boolean [] {
context: /**
   * Copyright (C) 2015 Johannes Taelman
   *
   * This file is part of Axoloti.
   *
   * Axoloti is free software: you can redistribute it and/or modify it under the
   * terms of the GNU General Public License as published by the Free Software
   * Foundation, either version 3 of the License, or (at your option) any later
   * version.
   *
   * Axoloti is distributed in the hope that it will be useful, but WITHOUT ANY
   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
   * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License along with
   * Axoloti. If not, see <http://www.gnu.org/licenses/>.
   */
  package axoloti.dialogs;
  
  import static axoloti.usb.Usb.DeviceToPath;
  import static axoloti.usb.Usb.PID_AXOLOTI;
  import static axoloti.usb.Usb.PID_STM_DFU;
  import static axoloti.usb.Usb.VID_AXOLOTI;
  import static axoloti.usb.Usb.VID_STM;
  import axoloti.utils.OSDetect;
  import static axoloti.utils.OSDetect.getOS;
  import javax.swing.event.ListSelectionEvent;
  import javax.swing.event.ListSelectionListener;
  import javax.swing.table.DefaultTableModel;
  import org.usb4java.Device;
  import org.usb4java.DeviceDescriptor;
  import org.usb4java.DeviceHandle;
  import org.usb4java.DeviceList;
  import org.usb4java.LibUsb;
  import org.usb4java.LibUsbException;
  
  /**
   *
   * @author Johannes Taelman
   */
  public class USBPortSelectionDlg extends javax.swing.JDialog {
  
      private String cpuid;
      private final String defCPUID;
  
      private final String sDFUBootloader = "STM DFU Bootloader";
      private final String sAxolotiCore = "Axoloti Core";
  
      /**
       * Creates new form USBPortSelectionDlg
       *
       * @param parent parent frame
       * @param modal is modal
       * @param defCPUID default port name
       */
      public USBPortSelectionDlg(java.awt.Frame parent, boolean modal, String defCPUID) {
          super(parent, modal);
          initComponents();
          System.out.println("default cpuid: " + defCPUID);
          this.defCPUID = defCPUID;
          cpuid = defCPUID;
          Populate();
          getRootPane().setDefaultButton(jButtonOK);
          jTable1.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                  DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
                  int r = jTable1.getSelectedRow();
                  if (r >= 0) {
                      String devName = (String) model.getValueAt(r, 0);
                      if (devName.equals(sAxolotiCore)) {
                          jButtonOK.setEnabled(true);
                          cpuid = (String) model.getValueAt(r, 2);
                      } else {
                          jButtonOK.setEnabled(false);
                      }
                  } else {
                      cpuid = null;
                  }
              }
          });
      }
  
      public static String ErrorString(int result) {
          if (result < 0) {
              if (getOS() == OSDetect.OS.WIN) {
                  if (result == LibUsb.ERROR_NOT_FOUND) {
                      return "not accesseable : driver not installed";
                  } else if (result == LibUsb.ERROR_ACCESS) {
                      return "not accesseable : busy?";
                  } else {
                      return "not accesseable : " + result;
                  }
              } else if (getOS() == OSDetect.OS.LINUX) {
                  if (result == LibUsb.ERROR_ACCESS) {
                      return "insufficient permissions";
                      // log message:  - install udev rules by running axoloti/platform/linux/add_udev_rules.sh"
                  } else {
                      return "not accesseable : " + result;
                  }
              } else {
                  return "not accesseable : " + result;
              }
          } else {
              return null;
          }
      }
  
      final void Populate() {
          DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
          model.setRowCount(0);
  
          DeviceList list = new DeviceList();
          int result = LibUsb.getDeviceList(null, list);
          if (result < 0) {
              throw new LibUsbException("Unable to get device list", result);
          }
          try {
              // Iterate over all devices and scan for the right one
              for (Device device : list) {
                  DeviceDescriptor descriptor = new DeviceDescriptor();
                  result = LibUsb.getDeviceDescriptor(device, descriptor);
                  if (result == LibUsb.SUCCESS) {
                      if (descriptor.idVendor() == VID_STM) {
                          if (descriptor.idProduct() == PID_STM_DFU) {
                              DeviceHandle handle = new DeviceHandle();
                              result = LibUsb.open(device, handle);
                              if (result < 0) {
                                  if (getOS() == OSDetect.OS.WIN) {
                                      if (result == LibUsb.ERROR_NOT_SUPPORTED) {
                                          model.addRow(new String[]{sDFUBootloader, DeviceToPath(device), "not accesseable : wrong driver installed"});
                                      } else if (result == LibUsb.ERROR_ACCESS) {
                                          model.addRow(new String[]{sDFUBootloader, DeviceToPath(device), "not accesseable : busy?"});
                                      } else {
                                          model.addRow(new String[]{sDFUBootloader, DeviceToPath(device), "not accesseable : " + result});
                                      }
                                  } else {
                                      model.addRow(new String[]{sDFUBootloader, DeviceToPath(device), "not accesseable : " + result});
                                  }
                              } else {
                                  model.addRow(new String[]{sDFUBootloader, DeviceToPath(device), "driver OK, CPU ID indeterminate"});
                                  LibUsb.close(handle);
                              }
                          }
                      } else if (descriptor.idVendor() == VID_AXOLOTI && descriptor.idProduct() == PID_AXOLOTI) {
                          DeviceHandle handle = new DeviceHandle();
                          result = LibUsb.open(device, handle);
                          if (result < 0) {
                              model.addRow(new String[]{sAxolotiCore, DeviceToPath(device), ErrorString(result)});
                          } else {
                              String serial = LibUsb.getStringDescriptor(handle, descriptor.iSerialNumber());
                              model.addRow(new String[]{sAxolotiCore, DeviceToPath(device), serial});
                              LibUsb.close(handle);
                          }
                      }
                  } else {
                      throw new LibUsbException("Unable to read device descriptor", result);
                  }
              }
              for (int r = 0; r < model.getRowCount(); r++) {
                  String id = (String) model.getValueAt(r, 2);
                  if (id.equals(this.defCPUID)) {
                      jTable1.setRowSelectionInterval(r, r);
                  }
              }
          } finally {
              // Ensure the allocated device list is freed
              LibUsb.freeDeviceList(list, true);
          }
      }
  
      public String getCPUID() {
          return cpuid;
      }
  
      /**
       * This method is called from within the constructor to initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is always
       * regenerated by the Form Editor.
       */
      @SuppressWarnings("unchecked")
      // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
      private void initComponents() {
  
          jButtonOK = new javax.swing.JButton();
          jLabel1 = new javax.swing.JLabel();
          jButtonCancel = new javax.swing.JButton();
          jButton1 = new javax.swing.JButton();
          jScrollPane2 = new javax.swing.JScrollPane();
          jTable1 = new javax.swing.JTable();
  
          setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
          setModal(true);
          setName("Serial port selection"); // NOI18N
  
          jButtonOK.setText("OK");
          jButtonOK.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
          jButtonOK.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  jButtonOKActionPerformed(evt);
              }
          });
  
          jLabel1.setText("Select device:");
  
          jButtonCancel.setText("Cancel");
          jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  jButtonCancelActionPerformed(evt);
              }
          });
  
          jButton1.setText("refresh");
          jButton1.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  jButton1ActionPerformed(evt);
              }
          });
  
          jTable1.setModel(new javax.swing.table.DefaultTableModel(
              new Object [][] {
  
              },
              new String [] {
                  "Device", "Location", "CPU ID"
              }
          ) {
              Class[] types = new Class [] {
                  java.lang.String.class, java.lang.String.class, java.lang.String.class
              };
  