Example usage for javax.swing DefaultListModel DefaultListModel

List of usage examples for javax.swing DefaultListModel DefaultListModel

Introduction

In this page you can find the example usage for javax.swing DefaultListModel DefaultListModel.

Prototype

DefaultListModel

Source Link

Usage

From source file:com.vgi.mafscaling.LogView.java

private void createLogViewPanel() {
    logViewPanel = new JPanel();
    GridBagLayout gbl_logViewPanel = new GridBagLayout();
    gbl_logViewPanel.columnWidths = new int[] { 0 };
    gbl_logViewPanel.rowHeights = new int[] { 0, 0 };
    gbl_logViewPanel.columnWeights = new double[] { 1.0 };
    gbl_logViewPanel.rowWeights = new double[] { 1.0, 0.0 };
    logViewPanel.setLayout(gbl_logViewPanel);
    try {//from  www . j a  va 2s .com
        logDataTable = new DBTable();
        logDataTable.copyColumnHeaderNames = true;
        logDataTable.defaultClickCountToStartEditor = 2;
        logDataTable.doNotUseDatabaseSort = true;
        logDataTable.listenKeyPressEventsWholeWindow = true;
        logDataTable.createControlPanel(DBTable.READ_NAVIGATION);
        logDataTable.enableExcelCopyPaste();
        logDataTable.setSortEnabled(false);
        logDataTable.setSkin(new TableSkin());
        logDataTable.refresh(new String[1][25]);
        logDataTable.setComparator(new DoubleComparator());
        logDataTable.getTable().setCellSelectionEnabled(true);
        logDataTable.getTable().setColumnSelectionAllowed(true);
        logDataTable.getTable().setRowSelectionAllowed(true);
        logDataTable.getTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JTextField rowTextField = ((JTextField) logDataTable.getControlPanel().getComponent(3));
        rowTextField.setPreferredSize(null);
        rowTextField.setColumns(5);

        GridBagConstraints gbc_logDataTable = new GridBagConstraints();
        gbc_logDataTable.insets = insets0;
        gbc_logDataTable.anchor = GridBagConstraints.PAGE_START;
        gbc_logDataTable.fill = GridBagConstraints.BOTH;
        gbc_logDataTable.gridx = 0;
        gbc_logDataTable.gridy = 0;
        logViewPanel.add(logDataTable, gbc_logDataTable);
        listModel = new DefaultListModel<JLabel>();

        selectionCombo.removeAllItems();
        String name;
        JTableHeader tableHeader = logDataTable.getTableHeader();
        for (int i = 0; i < logDataTable.getColumnCount(); ++i) {
            Column col = logDataTable.getColumn(i);
            col.setNullable(true);
            col.setHeaderRenderer(new CheckboxHeaderRenderer(i + 1, tableHeader));
            name = col.getHeaderValue().toString();
            selectionCombo.addItem(name);
            listModel.addElement(new JLabel(name, new CheckBoxIcon(), JLabel.LEFT));
        }

        JList<JLabel> menuList = new JList<JLabel>(listModel);
        menuList.setOpaque(false);
        menuList.setCellRenderer(new ImageListCellRenderer());
        menuList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        menuList.setLayoutOrientation(JList.VERTICAL);
        menuList.setFixedCellHeight(25);
        menuList.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                try {
                    if (e.getClickCount() == 1 && colors.size() > 0) {
                        JList<?> list = (JList<?>) e.getSource();
                        int index = list.locationToIndex(e.getPoint());
                        if (index >= 0) {
                            int colIdx = logDataTable.getCurrentIndexForOriginalColumn(index);
                            Column col = logDataTable.getColumn(colIdx);
                            if (col.getHeaderRenderer() instanceof CheckboxHeaderRenderer) {
                                CheckboxHeaderRenderer renderer = (CheckboxHeaderRenderer) col
                                        .getHeaderRenderer();
                                JLabel label = (JLabel) list.getModel().getElementAt(index);
                                CheckBoxIcon checkIcon = (CheckBoxIcon) label.getIcon();
                                checkIcon.setChecked(!checkIcon.isChecked());
                                if (checkIcon.isChecked()) {
                                    checkIcon.setColor(colors.pop());
                                    JTable table = logDataTable.getTable();
                                    TableModel model = table.getModel();
                                    addXYSeries(model, index, col.getHeaderValue().toString(),
                                            checkIcon.getColor());
                                } else {
                                    colors.push(checkIcon.getColor());
                                    checkIcon.setColor(renderer.getDefaultColor());
                                    removeXYSeries(index);
                                }
                                list.repaint();
                            }
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });

        headerScrollPane = new JScrollPane(menuList);
        GridBagConstraints gbc_headersTree = new GridBagConstraints();
        gbc_headersTree.insets = insets0;
        gbc_headersTree.anchor = GridBagConstraints.PAGE_START;
        gbc_headersTree.fill = GridBagConstraints.BOTH;
        gbc_headersTree.gridx = 0;
        gbc_headersTree.gridy = 1;

        logViewPanel.add(headerScrollPane, gbc_headersTree);
        headerScrollPane.setVisible(false);

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

From source file:gtu._work.ui.TextScanUI.java

private void resetGroupList(int groupCount) {
    DefaultListModel model = new DefaultListModel();
    for (int ii = 0; ii <= groupCount; ii++) {
        model.addElement(ii);//w w w  . j  a  v a2 s.  com
    }
    groupList.setModel(model);
}

From source file:gtu._work.ui.TextScanUI.java

private void jTextField2filterAgain(boolean resetGroupListModel) {
    try {//from www .j a  v a 2 s .c  om
        Pattern pat = Pattern.compile(contentFilter.getText());
        Matcher matcher = null;
        DefaultListModel listModel = new DefaultListModel();
        Set<String> set = new HashSet<String>();
        boolean setGroupListModel = false;
        for (String str : contentSet) {
            matcher = pat.matcher(replaceNewLineChar(str));
            if (contextFilter.getSelectedItem().equals("All")) {
                if (matcher.find()) {
                    listModel.addElement(str);
                }
            } else if (contextFilter.getSelectedItem().equals("Match")) {
                List<String> mlist = new ArrayList<String>();
                while (matcher.find()) {
                    for (int ii = 0; ii <= matcher.groupCount(); ii++) {
                        if (!resetGroupListModel) {
                            DefaultListModel model = (DefaultListModel) groupList.getModel();
                            for (Enumeration<?> enu = model.elements(); enu.hasMoreElements();) {
                                Integer gnum = (Integer) enu.nextElement();
                                if (gnum == ii) {
                                    mlist.add(matcher.group(ii));
                                }
                            }
                        } else {
                            mlist.add(matcher.group(ii));
                        }
                    }
                    if (resetGroupListModel && !setGroupListModel) {
                        resetGroupList(matcher.groupCount());
                    }
                }
                set.add(mlist.toString());
            }
        }
        if (contextFilter.getSelectedItem().equals("Match")) {
            List<String> ssset = new ArrayList<String>(set);
            Collections.sort(ssset);
            for (String str : ssset) {
                listModel.addElement(str);
            }
        }
        matchList.setModel(listModel);
        matchLabel.setText(String.valueOf(matchList.getModel().getSize()));
    } catch (Exception ex) {
    }
    sysinfo();
}

From source file:ui.Interface.java

private void butSortInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butSortInsertActionPerformed
    if (txtNumbersInsert.getText().equals("")) {
        JOptionPane.showMessageDialog(this, "Please fill out the Empty fields!", "Sorting Algo Simulator v2.0",
                javax.swing.JOptionPane.ERROR_MESSAGE);
        return;/*www .  j a v  a  2s  . c o  m*/
    }
    try {
        ArrayList simulationSteps = new ArrayList();
        String numbers = txtNumbersInsert.getText();
        numbers = numbers.replaceAll("\\s+", " ");

        String parts[] = numbers.split(" ");
        int size = parts.length;
        InsertionSort insertionSort = new InsertionSort(size);

        int Numbers[] = new int[parts.length];
        for (int i = 0; i < parts.length; i++) {
            Numbers[i] = Integer.parseInt(parts[i]);
        }
        for (int i = 0; i < size; i++) {
            insertionSort.insert(Numbers[i]);
        }
        long startTime = System.nanoTime();
        simulationSteps = insertionSort.insertionSortingAlgo();
        long endTime = System.nanoTime();

        InsertTimeDiff = (endTime - startTime);
        listSortingInsert.setModel(new DefaultListModel());
        Iterator it = simulationSteps.iterator();
        while (it.hasNext()) {
            ((DefaultListModel) listSortingInsert.getModel()).addElement(it.next());
        }
        String lastElement = simulationSteps.get(simulationSteps.size() - 1).toString();
        txtSortedInsert.setText(lastElement);
        txtTimeInsert.setText(String.valueOf(InsertTimeDiff));
        txtCountInsert.setText(String.valueOf(InsertInstructionCount));
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this,
                "Error : Pls recheck the Number Sequence.. Sorry! non Numeric Characters are not allowed here",
                "Sorting Algo Simulator v2.0", javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
}

From source file:AltiConsole.AltiConsoleMainScreen.java

public boolean RetrievingFlight() {
    this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    listData = null;//  w  w  w . j  av a2 s. c  o  m

    listData = new DefaultListModel();

    if (Serial.getConnected() == false) {
        boolean ret = false;
        ret = ConnectToAlti();
        if (!ret) {
            System.out.println("Data retrieval timed out1\n");
            JOptionPane.showMessageDialog(null, trans.get("AltiConsoleMainScreen.dataTimeOut"),
                    trans.get("AltiConsoleMainScreen.ConnectionError"), JOptionPane.ERROR_MESSAGE);
            this.setCursor(Cursor.getDefaultCursor());
            return false;
        }
    }
    // check the connection
    //Serial.DataReady = false;
    Serial.setDataReady(false);
    Serial.writeData("h;\n");
    long startTime; // = System.currentTimeMillis();
    Serial.lastReceived = System.currentTimeMillis();
    while (!Serial.getDataReady()) {
        long currentTime = System.currentTimeMillis();
        startTime = Serial.lastReceived;
        if ((currentTime - startTime) > 130000) {
            // This is some sort of data retrieval timeout
            System.out.println("Data retrieval timed out2 flight\n");
            JOptionPane.showMessageDialog(null, trans.get("AltiConsoleMainScreen.dataTimeOut"),
                    trans.get("AltiConsoleMainScreen.ConnectionError"), JOptionPane.ERROR_MESSAGE);
            this.setCursor(Cursor.getDefaultCursor());
            return false;
        }
    }

    Serial.initFlightData(UserPref.getAppUnits());

    // get the flight data
    //Serial.DataReady = false;
    Serial.setDataReady(false);
    Serial.writeData("a;\n");

    Serial.lastReceived = System.currentTimeMillis();
    while (!Serial.getDataReady()) {
        long currentTime = System.currentTimeMillis();
        startTime = Serial.lastReceived;
        if ((currentTime - startTime) > 130000) {
            // This is some sort of data retrieval timeout
            System.out.println("Data retrieval timed out3\n");
            JOptionPane.showMessageDialog(null, trans.get("AltiConsoleMainScreen.dataTimeOut"),
                    trans.get("AltiConsoleMainScreen.ConnectionError"), JOptionPane.ERROR_MESSAGE);
            this.setCursor(Cursor.getDefaultCursor());
            return false;
        }
    }
    System.out.println("done retrieving flight\n");
    List<String> AllFlightNames2;

    AllFlightNames2 = Serial.MyFlight.getAllFlightNames2();

    for (String z : AllFlightNames2) {

        listData.addElement(z);
    }

    flightList.setModel(listData);
    flightList.setAutoCreateRowSorter(true);
    flightList.toggleSortOrder();
    flightList.setSortOrder(SortOrder.ASCENDING);

    flightList.clearSelection();

    flightList.setSelectedIndex(0);
    if (Serial.MyFlight.FlightExist("Flight 1")) {
        plot.setDataset(0, Serial.MyFlight.GetFlightData("Flight 1"));
    }
    this.setCursor(Cursor.getDefaultCursor());
    return true;

}

From source file:kr.ac.kaist.swrc.jhannanum.demo.GUIDemo.java

/**
 * Returns the panel for the work flow./*  ww w .  j a  v  a2 s.  c  o m*/
 * 
 * @return the panel for the work flow
 */
private JComponent createWorkflow() {
    JPanel workflowPanel = new JPanel(new GridLayout(1, 3));

    listModelMajor2 = new DefaultListModel();
    listModelMajor3 = new DefaultListModel();
    listModelSupplement1 = new DefaultListModel();
    listModelSupplement2 = new DefaultListModel();
    listModelSupplement3 = new DefaultListModel();

    listPluginMajor2 = new JList(listModelMajor2);
    listPluginMajor3 = new JList(listModelMajor3);
    listPluginSupplement1 = new JList(listModelSupplement1);
    listPluginSupplement2 = new JList(listModelSupplement2);
    listPluginSupplement3 = new JList(listModelSupplement3);

    // phase1
    JPanel phasePanel = new JPanel(new GridLayout(1, 1));
    phasePanel.setBorder(BorderFactory.createTitledBorder("Phase1. Plain Text Processing"));
    JPanel listPanel = new JPanel(new GridLayout(1, 1));
    listPanel.setBorder(BorderFactory.createTitledBorder("Supplement Plug-in"));
    JScrollPane scroll = new JScrollPane();
    scroll.setViewportView(listPluginSupplement1);
    listPanel.add(scroll);
    phasePanel.add(listPanel);
    workflowPanel.add(phasePanel);

    // phase2
    phasePanel = new JPanel(new GridLayout(1, 2));
    phasePanel.setBorder(BorderFactory.createTitledBorder("Phase2. Morphological Analysis"));
    listPanel = new JPanel(new GridLayout(1, 1));
    listPanel.setBorder(BorderFactory.createTitledBorder("Major Plug-in"));
    scroll = new JScrollPane();
    scroll.setViewportView(listPluginMajor2);
    listPanel.add(scroll);
    phasePanel.add(listPanel);

    listPanel = new JPanel(new GridLayout(1, 1));
    listPanel.setBorder(BorderFactory.createTitledBorder("Supplement Plug-in"));
    scroll = new JScrollPane();
    scroll.setViewportView(listPluginSupplement2);
    listPanel.add(scroll);
    phasePanel.add(listPanel);

    workflowPanel.add(phasePanel);

    // phase3
    phasePanel = new JPanel(new GridLayout(1, 2));
    phasePanel.setBorder(BorderFactory.createTitledBorder("Phase3. Part Of Speech Tagging"));
    listPanel = new JPanel(new GridLayout(1, 1));
    listPanel.setBorder(BorderFactory.createTitledBorder("Major Plug-in"));
    scroll = new JScrollPane();
    scroll.setViewportView(listPluginMajor3);
    listPanel.add(scroll);
    phasePanel.add(listPanel);

    listPanel = new JPanel(new GridLayout(1, 1));
    listPanel.setBorder(BorderFactory.createTitledBorder("Supplement Plug-in"));
    scroll = new JScrollPane();
    scroll.setViewportView(listPluginSupplement3);
    listPanel.add(scroll);
    phasePanel.add(listPanel);

    workflowPanel.add(phasePanel);

    /////////////////////////////////////////////////////////////////////////////////////

    JPanel controlPanel = new JPanel(new GridLayout(4, 1));
    controlPanel.setBorder(BorderFactory.createTitledBorder("Workflow Control"));
    buttonActivate = new JButton("Activate the workflow");
    buttonAnalysis = new JButton("Analyze Text");
    buttonReset = new JButton("Close the workflow");

    JPanel threadPanel = new JPanel(new GridLayout(1, 1));
    radioMultiThread = new JRadioButton("Mutli-thread Mode", true);
    radioSingleThread = new JRadioButton("Single-thread Mode", false);
    threadPanel.setBorder(BorderFactory.createTitledBorder("Thread Mode"));
    threadPanel.add(radioMultiThread);
    threadPanel.add(radioSingleThread);
    ButtonGroup groupThread = new ButtonGroup();
    groupThread.add(radioMultiThread);
    groupThread.add(radioSingleThread);

    controlPanel.add(threadPanel);
    controlPanel.add(buttonActivate);
    controlPanel.add(buttonAnalysis);
    controlPanel.add(buttonReset);

    buttonAnalysis.setEnabled(false);
    buttonReset.setEnabled(false);

    /////////////////////////////////////////////////////////////////////////////////////

    JPanel pluginInfoPanel = new JPanel(new GridLayout(1, 1));
    pluginInfoPanel.setBorder(BorderFactory.createTitledBorder("Plug-in Information"));
    areaPluginInfo = new JTextArea();
    areaPluginInfo.setLineWrap(true);
    scroll = new JScrollPane();
    scroll.setViewportView(areaPluginInfo);
    pluginInfoPanel.add(scroll);

    JPanel infoPanel = new JPanel(new GridLayout(1, 2));
    infoPanel.add(pluginInfoPanel);
    infoPanel.add(controlPanel);

    JPanel panel = new JPanel(new GridLayout(2, 1));
    workflowPanel.setBorder(BorderFactory.createTitledBorder("HanNanum Workflow"));
    panel.add(workflowPanel);
    panel.add(infoPanel);

    return panel;
}

From source file:ui.Interface.java

private void butSortSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butSortSelectActionPerformed
    if (txtNumbersSelect.getText().equals("")) {
        JOptionPane.showMessageDialog(this, "Please fill out the Empty fields!", "Sorting Algo Simulator v2.0",
                javax.swing.JOptionPane.ERROR_MESSAGE);
        return;//from  w  ww . j a  v a 2 s  .  co  m
    }
    try {
        ArrayList simulationSteps = new ArrayList();
        String numbers = txtNumbersSelect.getText();
        numbers = numbers.replaceAll("\\s+", " ");
        String parts[] = numbers.split(" ");
        int size = parts.length;
        SelectionSort selectionSort = new SelectionSort(size);

        int Numbers[] = new int[parts.length];
        for (int i = 0; i < parts.length; i++) {
            Numbers[i] = Integer.parseInt(parts[i]);
        }
        for (int i = 0; i < size; i++) {
            selectionSort.insert(Numbers[i]);
        }
        long startTime = System.nanoTime();
        simulationSteps = selectionSort.selectionSort();
        long endTime = System.nanoTime();
        SelectTimeDiff = (endTime - startTime);

        listSortingSelect.setModel(new DefaultListModel());
        Iterator it = simulationSteps.iterator();
        while (it.hasNext()) {
            ((DefaultListModel) listSortingSelect.getModel()).addElement(it.next());
        }

        String lastElement = simulationSteps.get(simulationSteps.size() - 1).toString();
        txtSortedSelect.setText(lastElement);
        txtTimeSelect.setText(String.valueOf(SelectTimeDiff));
        txtCountSelect.setText(String.valueOf(SelectInstructionCount));
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this,
                "Error : Pls recheck the Number Sequence.. Sorry! non Numeric Characters are not allowed here",
                "Sorting Algo Simulator v2.0", javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
}

From source file:gtu._work.ui.RegexDirReplacer.java

private void scheduleExecuteActionPerformed(ActionEvent evt) {
    try {//w ww .j  a v a2s .co  m
        DefaultListModel model = (DefaultListModel) srcList.getModel();
        DefaultListModel rmodel = new DefaultListModel();
        DefaultListModel pmodel = (DefaultListModel) templateList.getModel();

        errMsg = new StringBuilder();
        successMsg = new StringBuilder();

        String replaceText = null;
        String bakupReplaceText = null;

        File newFile = null;
        File oldFile = null;
        OldNewFile oldNewFile = null;
        for (int ii = 0; ii < model.getSize(); ii++) {
            oldFile = (File) model.getElementAt(ii);
            replaceText = FileUtil.loadFromFile(oldFile, getCharset());
            bakupReplaceText = replaceText.toString();

            for (int jj = 0; jj < pmodel.getSize(); jj++) {
                Entry<Object, Object> entry = (Entry<Object, Object>) pmodel.getElementAt(jj);
                replaceText = replacer((String) entry.getKey(), (String) entry.getValue(), replaceText,
                        oldFile);
            }

            if (!bakupReplaceText.equals(replaceText)) {
                newFile = new File(oldFile.getParent(), oldFile.getName() + ".replace");
                FileUtil.saveToFile(newFile, replaceText, getCharset());
                successMsg.append(newFile.getName() + "\n");
                oldNewFile = new OldNewFile();
                oldNewFile.oldFile = oldFile;
                oldNewFile.newFile = newFile;
                rmodel.addElement(oldNewFile);
            }
        }

        newRepList.setModel(rmodel);
        JOptionPaneUtil.newInstance().iconInformationMessage()
                .showMessageDialog(String.format(MESSAGE, successMsg, errMsg), getTitle());
    } catch (Exception ex) {
        JCommonUtil.handleException(ex);
    }
}

From source file:cis_690_report.DynamicReporter.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    jTextField1.setText("");
    JFileChooser choose = new JFileChooser();
    choose.showOpenDialog(null);//from www  .  j a v  a 2  s .  co  m
    f = choose.getSelectedFile();
    String path = f.getAbsolutePath();
    jTextField1.setText(path);
    jPanel2.setVisible(true);

    header = new String[120];
    for (int x = 0; x < 120; x++) {
        header[x] = "";
    }
    String line = "";
    BufferedReader br2 = null;
    try {
        br2 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(DynamicReporter.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {

        while ((line = br2.readLine()) != null) {

            // use comma as separator

            String Bull[] = line.split(",");
            //  System.out.println(Bull.length);
            if (number_of_rows == 0) {
                for (int i = 0; i < Bull.length; i++) {
                    header[i] = Bull[i];
                }
            }

            number_of_rows++;

        }

    } catch (IOException ex) {
        Logger.getLogger(DynamicReporter.class.getName()).log(Level.SEVERE, null, ex);
    }
    Bulls = new String[number_of_rows - 1];
    for (int x = 0; x < Bulls.length; x++) {
        Bulls[x] = "";
    }

    BufferedReader br3 = null;
    try {
        br3 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(DynamicReporter.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        int k = 0;
        while ((line = br3.readLine()) != null) {

            // use comma as separator

            String Bull[] = line.split(",");
            //  System.out.println(Bull.length);
            if (k != 0) {
                if (!Bull[2].equals("")) {
                    Bulls[k - 1] += Bull[2] + ("(Brand) ");
                }
                if (!Bull[6].equals("")) {
                    Bulls[k - 1] += Bull[6] + ("(RFID) ");
                }
                if (!Bull[7].equals("")) {
                    Bulls[k - 1] += Bull[7] + ("(Tag) ");
                }
                if (!Bull[8].equals("")) {
                    Bulls[k - 1] += Bull[8] + ("(Tattoo) ");
                }
                if (!Bull[9].equals("")) {
                    Bulls[k - 1] += Bull[9] + ("(Other) ");
                }
                Bulls[k - 1] += ":" + k;

            }
            k++;
        }

    } catch (IOException ex) {
        Logger.getLogger(DynamicReporter.class.getName()).log(Level.SEVERE, null, ex);
    }

    for (int y = 0; y < Bulls.length; y++) {
        System.out.print(Bulls[y]);
    }

    DefaultListModel dlm = new DefaultListModel();
    for (int y = 0; y < header.length; y++) {
        dlm.addElement(header[y] + ": " + y);
    }
    jList1.setModel(dlm);
    jPanel1.setVisible(false);
}

From source file:edu.ku.brc.specify.config.init.secwiz.UserPanel.java

/**
 * @param isInitial//w  w w  .  ja  v a 2  s . c o m
 */
private void loadData(final boolean isInitial) {
    label.setText("");

    String hostName = properties.getProperty("hostName");
    String dbUserName = properties.getProperty("dbUserName");
    String dbPassword = properties.getProperty("dbPassword");

    int index = 0;
    List<String> dbNamesList = masterPanel.getDbNamesForMaster();
    List<String> otherNamesList = masterPanel.getDbNameList();

    if (dbNamesList == null || dbNamesList.size() == 0) {
        return;
    }

    //dbNamesList.clear();
    //otherNamesList.clear();
    //dbNamesList.add("testfish");

    Vector<String> items = new Vector<String>(dbNamesList);
    Collections.sort(items);

    if (!isInitial) {
        index = dbList.getSelectedIndex();
        if (index == -1) {
            return;
        }
    }

    databaseName = isInitial ? items.get(0) : (String) dbList.getSelectedValue();

    DBMSUserMgr mgr = DBMSUserMgr.getInstance();
    do {
        if (mgr.connect(dbUserName, dbPassword, hostName, databaseName)) {
            if (isInitial) {
                HashSet<String> dbNameHashSet = new HashSet<String>();
                DefaultListModel model = new DefaultListModel();
                for (String nm : items) {
                    model.addElement(nm);
                    dbNameHashSet.add(nm);
                }
                dbList.setModel(model);

                model = new DefaultListModel();
                for (String nm : otherNamesList) {
                    if (!dbNameHashSet.contains(nm)) {
                        model.addElement(nm);
                    }
                }
                otherDBList.setModel(model);
            }

            label.setText(getFormattedResStr("MSTR_USR_DB", databaseName));

            if (!mgr.doesDBHaveTable(databaseName, "specifyuser")) {
                items.remove(0);
                databaseName = isInitial ? items.get(0) : (String) dbList.getSelectedValue();
                continue;
            }

            Vector<UserData> userDataList = new Vector<UserData>();
            String sql = "SELECT SpecifyUserId, Name, Password, EMail FROM specifyuser";
            Vector<Object[]> data = BasicSQLUtils.query(mgr.getConnection(), sql);

            for (Object[] c : data) {
                UserData ud = new UserData((Integer) c[0], (String) c[1], (String) c[2], "(On user's machine)",
                        (String) c[3]);
                userDataList.add(ud);

                sql = String.format(
                        "SELECT LastName, FirstName, EMail FROM agent WHERE SpecifyUserID = %d ORDER BY TimestampModified, TimestampCreated LIMIT 0,1",
                        ud.getId());
                Vector<Object[]> uData = BasicSQLUtils.query(mgr.getConnection(), sql);
                if (uData.size() > 0) {
                    Object[] d = uData.get(0);
                    ud.setLastName((String) d[0]);
                    ud.setFirstName((String) d[1]);

                    String email = (String) d[2];
                    if (StringUtils.isNotEmpty(email) && StringUtils.isEmpty(ud.getEmail())) {
                        ud.setEmail(email);
                    }
                } else {
                    // error
                }
            }
            mgr.close();
            userModel.setUserData(userDataList);
            UIHelper.calcColumnWidths(userTable);

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    Window window = getTopWindow();
                    Insets screenInsets = Toolkit.getDefaultToolkit()
                            .getScreenInsets(window.getGraphicsConfiguration());
                    Rectangle screenRect = window.getGraphicsConfiguration().getBounds();

                    screenRect.height -= screenInsets.top + screenInsets.bottom;
                    screenRect.width -= screenInsets.left + screenInsets.right;

                    Rectangle rect = window.getBounds();
                    Dimension size = window.getPreferredSize();

                    // Make sure the window isn't larger than the screen
                    size.width = Math.min(size.width, screenRect.width);
                    size.height = Math.min(size.height, screenRect.height);

                    if (size.height > rect.height || size.width > rect.width) {
                        window.setBounds(rect.x, rect.y, size.width, size.height);
                        UIHelper.centerWindow(getTopWindow());

                    }
                }
            });

            if (isInitial && items.size() > 0) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        dbList.setSelectedIndex(0);
                    }
                });
            }

            break;
        } else if (items.size() > 1) {
            items.remove(0);
            databaseName = isInitial ? items.get(0) : (String) dbList.getSelectedValue();
        } else {
            break;
        }

    } while (true);

}