Example usage for javax.swing SwingWorker SwingWorker

List of usage examples for javax.swing SwingWorker SwingWorker

Introduction

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

Prototype

public SwingWorker() 

Source Link

Document

Constructs this SwingWorker .

Usage

From source file:com.josescalia.tumblr.form.PreferenceForm.java

private void btnDeleteCacheActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteCacheActionPerformed
    frame = (MainFrame) this.getTopLevelAncestor();

    if (UIAlert.showConfirm(this, "Are you sure ?") == JOptionPane.OK_OPTION) {
        logger.info("deleting cache");

        //busy cursor and frame progress bar
        frame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
        frame.startProgressBar("Deleting");
        new SwingWorker<String, String>() {
            @Override/*from w w  w  .j  a  v a 2  s.c o  m*/
            protected String doInBackground() throws Exception {
                int successDeleteCount = 0;
                int failedDeleteCount = 0;
                for (File file : cacheFile.getFileList()) {
                    if (!file.getName().contains("ImageNotFound")) {
                        logger.info("deleting file " + file.getName());
                        if (file.delete()) {
                            successDeleteCount++;
                        } else {
                            failedDeleteCount++;
                        }
                    }
                }
                return "Done\n " + successDeleteCount + " cache file(s) deleted\n" + failedDeleteCount
                        + " cache  file(s) not deleted";
            }

            @Override
            protected void done() {
                try {
                    UIAlert.showInformation(null, get());
                    getCacheFileInfo();
                } catch (InterruptedException e) {
                    logger.error(e);
                } catch (ExecutionException e) {
                    logger.error(e);
                }
                frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                frame.stopProgressBar("");
            }
        }.execute();

    }

}

From source file:com.mirth.connect.client.ui.browsers.event.EventBrowser.java

private void countButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_countButtonActionPerformed
    final String workingId = parent.startWorking("Counting search result size...");
    filterButton.setEnabled(false);/*from w w w.j a  va  2s  .c om*/
    nextPageButton.setEnabled(false);
    previousPageButton.setEnabled(false);
    countButton.setEnabled(false);
    pageGoButton.setEnabled(false);
    final EventBrowser eventBrowser = this;

    if (worker != null && !worker.isDone()) {
        worker.cancel(true);
    }

    worker = new SwingWorker<Void, Void>() {
        private Exception e;

        public Void doInBackground() {
            try {
                events.setItemCount(parent.mirthClient.getEventCount(eventFilter));
            } catch (ClientException e) {
                if (e instanceof RequestAbortedException) {
                    // The client is no longer waiting for the count request
                } else {
                    parent.alertThrowable(parent, e);
                }
                cancel(true);
            }

            return null;
        }

        public void done() {
            if (!isCancelled()) {
                if (e != null) {
                    countButton.setEnabled(true);
                    parent.alertThrowable(eventBrowser, e);
                } else {
                    updatePagination();
                    countButton.setEnabled(false);
                }
                filterButton.setEnabled(true);
            }

            parent.stopWorking(workingId);
        }
    };

    worker.execute();
}

From source file:com.mirth.connect.client.ui.SettingsPanelServer.java

private void testEmailButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_testEmailButtonActionPerformed
    resetInvalidSettings();//from  w  ww.  ja v  a 2s  .com
    ServerSettings serverSettings = getServerSettings();
    StringBuilder invalidFields = new StringBuilder();

    if (StringUtils.isBlank(serverSettings.getSmtpHost())) {
        smtpHostField.setBackground(UIConstants.INVALID_COLOR);
        invalidFields.append("\"SMTP Host\" is required\n");
    }

    if (StringUtils.isBlank(serverSettings.getSmtpPort())) {
        smtpPortField.setBackground(UIConstants.INVALID_COLOR);
        invalidFields.append("\"SMTP Port\" is required\n");
    }

    if (StringUtils.isBlank(serverSettings.getSmtpTimeout())) {
        smtpTimeoutField.setBackground(UIConstants.INVALID_COLOR);
        invalidFields.append("\"Send Timeout\" is required\n");
    }

    if (StringUtils.isBlank(serverSettings.getSmtpFrom())) {
        defaultFromAddressField.setBackground(UIConstants.INVALID_COLOR);
        invalidFields.append("\"Default From Address\" is required\n");
    }

    if (serverSettings.getSmtpAuth()) {
        if (StringUtils.isBlank(serverSettings.getSmtpUsername())) {
            usernameField.setBackground(UIConstants.INVALID_COLOR);
            invalidFields.append("\"Username\" is required\n");
        }

        if (StringUtils.isBlank(serverSettings.getSmtpPassword())) {
            passwordField.setBackground(UIConstants.INVALID_COLOR);
            invalidFields.append("\"Password\" is required\n");
        }
    }

    String errors = invalidFields.toString();
    if (StringUtils.isNotBlank(errors)) {
        PlatformUI.MIRTH_FRAME.alertCustomError(PlatformUI.MIRTH_FRAME, errors,
                "Please fix the following errors before sending a test email:");
        return;
    }

    String sendToEmail = (String) JOptionPane.showInputDialog(PlatformUI.MIRTH_FRAME, "Send test email to:",
            "Send Test Email", JOptionPane.INFORMATION_MESSAGE, null, null, serverSettings.getSmtpFrom());

    if (StringUtils.isNotBlank(sendToEmail)) {
        try {
            new InternetAddress(sendToEmail).validate();
        } catch (Exception error) {
            PlatformUI.MIRTH_FRAME.alertWarning(PlatformUI.MIRTH_FRAME,
                    "The Send To Address is invalid: " + error.getMessage());
            return;
        }

        final Properties properties = new Properties();
        properties.put("port", serverSettings.getSmtpPort());
        properties.put("encryption", serverSettings.getSmtpSecure());
        properties.put("host", serverSettings.getSmtpHost());
        properties.put("timeout", serverSettings.getSmtpTimeout());
        properties.put("authentication", String.valueOf(serverSettings.getSmtpAuth()));
        properties.put("username", serverSettings.getSmtpUsername());
        properties.put("password", serverSettings.getSmtpPassword());
        properties.put("toAddress", sendToEmail);
        properties.put("fromAddress", serverSettings.getSmtpFrom());

        final String workingId = PlatformUI.MIRTH_FRAME.startWorking("Sending test email...");

        SwingWorker worker = new SwingWorker<Void, Void>() {

            public Void doInBackground() {

                try {
                    ConnectionTestResponse response = (ConnectionTestResponse) PlatformUI.MIRTH_FRAME.mirthClient
                            .sendTestEmail(properties);

                    if (response == null) {
                        PlatformUI.MIRTH_FRAME.alertError(PlatformUI.MIRTH_FRAME, "Failed to send email.");
                    } else if (response.getType().equals(ConnectionTestResponse.Type.SUCCESS)) {
                        PlatformUI.MIRTH_FRAME.alertInformation(PlatformUI.MIRTH_FRAME, response.getMessage());
                    } else {
                        PlatformUI.MIRTH_FRAME.alertWarning(PlatformUI.MIRTH_FRAME, response.getMessage());
                    }

                    return null;
                } catch (Exception e) {
                    PlatformUI.MIRTH_FRAME.alertThrowable(PlatformUI.MIRTH_FRAME, e);
                    return null;
                }
            }

            public void done() {
                PlatformUI.MIRTH_FRAME.stopWorking(workingId);
            }
        };

        worker.execute();
    }
}

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/* w ww .j  av  a 2 s  .com*/
                    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:edu.ku.brc.ui.UIRegistry.java

/**
 * Fades screen and writes message to screen
 * @param localizedMsg the already localized message
 * @param milliseconds the number of milliseconds to pause showing the message
 * @param textColor the color of the text
 * @param pointSize the point size to draw the text
 * @param yTextPos set the the 'y' position of the text
 *//*from w  w  w.  j av  a2 s . c  o  m*/
public static void writeTimedSimpleGlassPaneMsg(final String localizedMsg, final Integer milliseconds,
        final Color textColor, final Integer pointSize, final boolean doHideOnClick, final Integer yTextPos) {
    final SimpleGlassPane sgp = UIRegistry.writeSimpleGlassPaneMsg(localizedMsg,
            pointSize == null ? STD_FONT_SIZE : pointSize);
    if (sgp != null) {
        sgp.setTextColor(textColor);
        sgp.setHideOnClick(doHideOnClick);
        sgp.setTextYPos(yTextPos);
    }

    SwingWorker<Integer, Integer> msgWorker = new SwingWorker<Integer, Integer>() {
        /* (non-Javadoc)
         * @see javax.swing.SwingWorker#doInBackground()
         */
        @Override
        protected Integer doInBackground() throws Exception {
            try {
                Thread.sleep(milliseconds != null ? milliseconds : STD_WAIT_TIME);

            } catch (Exception ex) {
                ex.printStackTrace();
            }

            return null;
        }

        @Override
        protected void done() {
            super.done();

            if (sgp != null) {
                sgp.setTextColor(null);
            }

            UIRegistry.clearSimpleGlassPaneMsg();

            if (textColor == Color.RED) {
                getStatusBar().setErrorMessage(localizedMsg);
            } else {
                displayStatusBarText(localizedMsg);
            }
        }
    };

    msgWorker.execute();
}

From source file:com.xilinx.virtex7.MainScreen.java

private JPanel testPanelItems() {
    //JPanel panel1 = new JPanel();

    JPanel panel = new JPanel();

    panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

    panel.add(new JLabel("Data Path-0:"));
    t1_o1 = new JCheckBox("Loopback");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t1_o1.setToolTipText("This loops back software generated traffic in hardware");
    else if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV)
        t1_o1.setToolTipText("This loops back software generated raw Ethernet frames at 10G PHY");

    t1_o1.setSelected(true);//w  ww  .j a v a  2 s  .co  m
    t1_o1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {
                t1_o1.setSelected(true);
                return;
            }
            if (t1_o1.isSelected()) {
                // disable others
                test1_option = DriverInfo.ENABLE_LOOPBACK;
                t1_o2.setSelected(false);
                t1_o3.setSelected(false);
            } else {
                if (!t1_o2.isSelected() && !t1_o3.isSelected()) {
                    test1_option = DriverInfo.CHECKER;
                    t1_o2.setSelected(true);
                }
            }
        }
    });
    //b1.setSelected(true);
    t1_o2 = new JCheckBox("HW Checker");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t1_o2.setToolTipText("This enables Checker in hardware verifying traffic generated by software");
    t1_o2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (t1_o2.isSelected()) {
                // disable others
                test1_option = DriverInfo.CHECKER;
                t1_o1.setSelected(false);
                //t1_o3.setSelected(false);
                if (t1_o3.isSelected())
                    test1_option = DriverInfo.CHECKER_GEN;
            } else {
                if (t1_o3.isSelected())
                    test1_option = DriverInfo.GENERATOR;
                else {
                    test1_option = DriverInfo.ENABLE_LOOPBACK;
                    t1_o1.setSelected(true);
                }

            }
        }
    });
    //b2.setEnabled(false);
    t1_o3 = new JCheckBox("HW Generator");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t1_o3.setToolTipText("This enables traffic generator in hardware");
    t1_o3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (t1_o3.isSelected()) {
                // disable others
                test1_option = DriverInfo.GENERATOR;
                t1_o1.setSelected(false);
                //t1_o2.setSelected(false);
                if (t1_o2.isSelected())
                    test1_option = DriverInfo.CHECKER_GEN;
            } else {
                if (t1_o2.isSelected())
                    test1_option = DriverInfo.CHECKER;
                else {
                    test1_option = DriverInfo.ENABLE_LOOPBACK;
                    t1_o1.setSelected(true);
                }
            }
        }
    });
    //b3.setEnabled(false);
    JPanel ip = new JPanel();
    ip.setLayout(new BoxLayout(ip, BoxLayout.PAGE_AXIS));
    ip.add(t1_o1);
    ip.add(t1_o2);
    ip.add(t1_o3);
    panel.add(ip);
    panel.add(new JLabel("Packet Size (bytes):"));
    t1_psize = new JTextField("32768", 5);

    panel.add(t1_psize);
    startTest = new JButton("Start");
    startTest.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            //Check for led status and start the test
            if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {
                if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF
                        && (lstats.phy0 == LED_ON && lstats.phy1 == LED_ON)) {
                    JOptionPane.showMessageDialog(null, "DDR3 is not calibrated. Test cannot be started",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF
                        && (lstats.phy0 == LED_OFF || lstats.phy1 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null,
                            "DDR3 is not calibrated and 10G-PHY link is down. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (lstats.ddrCalib1 == LED_ON && lstats.ddrCalib2 == LED_ON
                        && (lstats.phy0 == LED_OFF || lstats.phy1 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null, "10G-PHY link is down. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }

            if (startTest.getText().equals("Start")) {
                // checking condition for DDR3 SODIMM
                if (t1_o1.isSelected() && !(lstats.ddrCalib1 == LED_ON && lstats.ddrCalib2 == LED_ON)) {
                    if (lstats.ddrCalib1 == LED_OFF || lstats.ddrCalib2 == LED_OFF) {
                        JOptionPane.showMessageDialog(null,
                                "DDR3 SODIMM is not calibrated. Test cannot be started", "Error",
                                JOptionPane.ERROR_MESSAGE);
                    }
                    return;
                } else if (t1_o2.isSelected() && (lstats.ddrCalib1 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null,
                            "DDR3 SODIMM-A is not calibrated. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (t1_o3.isSelected() && (lstats.ddrCalib2 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null,
                            "DDR3 SODIMM-B is not calibrated. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                int psize = 0;
                dataMismatch0 = errcnt0 = false;
                try {
                    psize = Integer.parseInt(t1_psize.getText());
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "Only Natural numbers are allowed", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if (psize < minpkt0 || psize > maxpkt0) {
                    JOptionPane.showMessageDialog(null,
                            "Packet size must be within " + minpkt0 + " to " + maxpkt0 + " bytes", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                di.startTest(0, test1_option, psize);
                // disable components
                t1_o1.setEnabled(false);
                t1_o2.setEnabled(false);
                t1_o3.setEnabled(false);
                t1_psize.setEnabled(false);
                startTest.setText("Stop");
                testStarted = true;
                updateLog("[Test Started for Data Path-0]", logStatus);
            } else if (startTest.getText().equals("Stop")) {
                startTest.setEnabled(false);
                SwingWorker worker = new SwingWorker<Void, Void>() {

                    @Override
                    protected Void doInBackground() throws Exception {
                        try {
                            stopTest1();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return null;
                    }

                };
                worker.execute();
            }
        }
    });
    panel.add(startTest);
    if ((mode == LandingPage.APPLICATION_MODE) || (mode == LandingPage.APPLICATION_MODE_P2P)) {
        t1_o1.setSelected(false);
        t1_o2.setSelected(false);
        t1_o3.setSelected(false);
        t1_o1.setEnabled(false);
        t1_o2.setEnabled(false);
        t1_o3.setEnabled(false);
        t1_psize.setEnabled(false);
        t1_psize.setText("");
        startTest.setEnabled(false);
    }
    //panel1.add(panel);
    return panel;
}

From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java

private void initData(final String id) {
    showWaitPanel("?......");
    new SwingWorker<Employee, Void>() {

        @Override/*from  ww  w. j  av  a 2 s.co m*/
        protected Employee doInBackground() throws Exception {
            if (StringUtils.isEmpty(id)) {
                return Employee.createNewEmployee();
            } else {
                return HrmBiz.getInstance().getEmployee(id);
            }
        }

        @Override
        protected void done() {
            try {
                employee = get();
                uiEntryDate.setCalendar(Calendar.getInstance());
                uiId.setText(employee.getId());
                uiName.setText(employee.getName());
                uiNamePy.setText(employee.getNamePy());
                if (StringUtils.isNotEmpty(employee.getState())) {
                    uiState.setSelectedItem(employee.getState());
                    switch (employee.getState()) {
                    case Employee.STATE_LEAVE:
                    case Employee.STATE_RETIRE:
                    case Employee.STATE_DELETE:
                        uiInfoTab.setSelectedIndex(1);
                        break;
                    case Employee.STATE_SUSPEND:
                        uiInfoTab.setSelectedIndex(2);
                        break;
                    case Employee.STATE_PROBATION:
                    case Employee.STATE_CONTRACT:
                    default:
                        break;
                    }
                }
                uiTimeCardLeaveCertify.setText(employee.getTimeCard());
                uiIdCard.setText(employee.getIdCard());
                uiBirthday.setText(employee.getBirthday());
                uiAge.setText(employee.getAge().toString());
                uiGender.setText(employee.getGender());
                if (StringUtils.isNotEmpty(employee.getMaritalStatus())) {
                    uiMarital.setSelectedItem(employee.getMaritalStatus());
                }
                uiContact.setText(employee.getContact());
                if (StringUtils.isNotEmpty(employee.getCensus())) {
                    uiCensus.setSelectedItem(employee.getCensus());
                }
                uiCensusAddress.setText(employee.getCensusAddress());

                // ?
                if (employee.getEmployeePhoto() != null && employee.getEmployeePhoto().getPhoto() != null
                        && employee.getEmployeePhoto().getPhoto().length > 0) {
                    EmployeePhoto photo = employee.getEmployeePhoto();
                    uiPhoto.putClientProperty("photo", employee.getEmployeePhoto().getPhoto());
                    try {
                        File imageFile = new File(
                                System.getProperty("user.dir") + "/temp/" + employee.getId() + ".png");
                        FileImageOutputStream fios = new FileImageOutputStream(imageFile);
                        fios.write(photo.getPhoto());
                        fios.flush();
                        fios.close();
                        uiPhoto.putClientProperty("path", imageFile.getPath());
                        uiPhoto.setImage(imageFile.getPath());
                    } catch (Exception e) {
                        showErrorMsg(e);
                    }
                } else {
                    uiPhoto.setImage("resource/image/default_emp_photo.png", true);
                }

                uiAddress.setText(employee.getAddress());
                if (StringUtils.isNotEmpty(employee.getCensusProvince())) {
                    uiResidencePermit.setSelectedItem(employee.getCensusProvince());
                }
                if (StringUtils.isNotEmpty(employee.getSuspendNote())) {
                    uiFactory.setSelectedItem(employee.getSuspendNote());
                }
                if (StringUtils.isNotEmpty(employee.getDept())) {
                    uiDept.setText(employee.getDept());
                }
                if (StringUtils.isNotEmpty(employee.getJob())) {
                    uiJob.setText(employee.getJob());
                }
                if (StringUtils.isNotEmpty(employee.getSuspendStart())) {
                    uiDdg.setSelectedItem(employee.getSuspendStart());
                }
                if (StringUtils.isNotEmpty(employee.getEntryDate())) {
                    uiEntryDate.setDate(Utils.dateFromStr(employee.getEntryDate()));
                }
                uiWorkAge.setText(UtilsClient.convertWorkAgeToStr(employee.getWorkAge()));
                if (StringUtils.isNotEmpty(employee.getProbationDate())) {
                    uiProbation.setDate(Utils.dateFromStr(employee.getProbationDate()));
                }
                if (StringUtils.isNotEmpty(employee.getExpirationDate())) {
                    uiExpiration.setText(employee.getExpirationDate());
                }
                if (StringUtils.isNotEmpty(employee.getDegree())) {
                    uiDegree.setSelectedItem(employee.getDegree());
                }
                uiSchool.setText(employee.getSchool());
                uiMajor.setText(employee.getMajor());
                uiWorkExperience.setText(employee.getWorkExperience());
                //               uiSuspendEnd.setText(employee.getSuspendEnd());
                uiSocialCard.setText(employee.getSocialCard());
                uiHousingCard.setText(employee.getHousingCard());
                uiBankCard.setText(employee.getBankCard());
                uiNote.setText(employee.getNote());
                uiPerformance.setText(employee.getCensusCity());
                uiPhoneShort.setText(employee.getPhoneShort());
                if (StringUtils.isNotEmpty(employee.getLeaveDate())) {
                    uiLeaveDate.setDate(Utils.dateFromStr(employee.getLeaveDate()));
                }

                if (StringUtils.isNotEmpty(employee.getSocialEndDate())) {
                    uiSocialEndDate.setText(employee.getSocialEndDate());
                }
                if (StringUtils.isNotEmpty(employee.getHousingEndDate())) {
                    uiHousingEndDate.setText(employee.getHousingEndDate());
                }
                uiLeaveType.setSelectedItem(employee.getLeaveType());
                uiLeaveReason.setText(employee.getLeaveReason());
                if (StringUtils.isNotEmpty(employee.getJobTitle())) {
                    uiGuide.setText(employee.getJobTitle());
                }
                hideWaitPanel();
            } catch (Exception e) {
                hideWaitPanel();
                showErrorMsg(e);
            }

        }

    }.execute();
}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowser.java

public void viewAttachment() {
    try {/*from   w  ww .  j  a  va2 s  .  c  om*/
        final String attachmentId = getSelectedAttachmentId();
        final Long messageId = getSelectedMessageId();
        final String attachType = (String) attachmentTable.getModel()
                .getValueAt(attachmentTable.convertRowIndexToModel(attachmentTable.getSelectedRow()), 1);
        final AttachmentViewer attachmentViewer = getAttachmentViewer(attachType);
        if (attachmentViewer != null) {

            final String workingId = parent.startWorking("Loading " + attachType + " viewer...");

            SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

                public Void doInBackground() {
                    attachmentViewer.viewAttachments(channelId, messageId, attachmentId);
                    return null;
                }

                public void done() {
                    parent.stopWorking(workingId);
                }
            };
            worker.execute();
        } else {
            parent.alertInformation(this, "No Attachment Viewer plugin installed for type: " + attachType);
        }
    } catch (Exception e) {
    }
}

From source file:com.xilinx.virtex7.MainScreen.java

private JPanel testPanelItems1() {
    JPanel panel = new JPanel();
    panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    /*panel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder("Test Parameters-1"),
                BorderFactory.createEmptyBorder()));*/
    float w = (float) ((float) width * 0.4);
    //panel.setPreferredSize(new Dimension((int)w, 100));
    panel.add(new JLabel("Data Path-1:"));
    t2_o1 = new JCheckBox("Loopback");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t2_o1.setToolTipText("This loops back software generated traffic at DMA user interface");
    else if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV)
        t2_o1.setToolTipText("This loops back software generated raw Ethernet frames at 10G PHY");

    t2_o1.setSelected(true);//www . j  av  a 2s .co  m
    t2_o1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {
                t2_o1.setSelected(true);
                return;
            }
            if (t2_o1.isSelected()) {
                // disable others
                test2_option = DriverInfo.ENABLE_LOOPBACK;
                t2_o2.setSelected(false);
                t2_o3.setSelected(false);
            } else {
                if (!t2_o2.isSelected() && !t2_o3.isSelected()) {
                    test2_option = DriverInfo.CHECKER;
                    t2_o2.setSelected(true);
                }
            }
        }
    });
    //b1.setSelected(true);
    t2_o2 = new JCheckBox("HW Checker");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t2_o2.setToolTipText(
                "This enables Checker in hardware at DMA user interface verifying traffic generated by software");
    t2_o2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (t2_o2.isSelected()) {
                // disable others
                test2_option = DriverInfo.CHECKER;
                t2_o1.setSelected(false);
                //t2_o3.setSelected(false);
                if (t2_o3.isSelected())
                    test2_option = DriverInfo.CHECKER_GEN;
            } else {
                if (t2_o3.isSelected())
                    test2_option = DriverInfo.GENERATOR;
                else {
                    test2_option = DriverInfo.ENABLE_LOOPBACK;
                    t2_o1.setSelected(true);
                }
            }
        }
    });
    //b2.setEnabled(false);
    t2_o3 = new JCheckBox("HW Generator");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t2_o3.setToolTipText("This enables traffic generator in hardware at the DMA user interface");
    t2_o3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (t2_o3.isSelected()) {
                // disable others
                test2_option = DriverInfo.GENERATOR;
                t2_o1.setSelected(false);
                //t2_o2.setSelected(false);
                if (t2_o2.isSelected())
                    test2_option = DriverInfo.CHECKER_GEN;
            } else {
                if (t2_o2.isSelected())
                    test2_option = DriverInfo.CHECKER;
                else {
                    test2_option = DriverInfo.ENABLE_LOOPBACK;
                    t2_o1.setSelected(true);
                }
            }
        }
    });
    //b3.setEnabled(false);
    JPanel ip = new JPanel();
    ip.setLayout(new BoxLayout(ip, BoxLayout.PAGE_AXIS));
    ip.add(t2_o1);
    ip.add(t2_o2);
    ip.add(t2_o3);
    panel.add(ip);
    panel.add(new JLabel("Packet Size (bytes):"));
    t2_psize = new JTextField("32768", 5);
    panel.add(t2_psize);
    stest = new JButton("Start");
    if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {

    } else
        stest.setEnabled(false);
    stest.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            //Check for led status and start the test
            if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {
                if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF
                        && (lstats.phy0 == LED_ON && lstats.phy1 == LED_ON)) {
                    JOptionPane.showMessageDialog(null, "DDR3 is not calibrated. Test cannot be started",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF
                        && (lstats.phy0 == LED_OFF || lstats.phy1 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null,
                            "DDR3 is not calibrated and 10G-PHY link is down. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (lstats.ddrCalib1 == LED_ON && lstats.ddrCalib2 == LED_ON
                        && (lstats.phy0 == LED_OFF || lstats.phy1 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null, "10G-PHY link is down. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }

            if (stest.getText().equals("Start")) {
                int psize = 0;
                dataMismatch2 = errcnt1 = false;
                try {
                    psize = Integer.parseInt(t2_psize.getText());
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "Only Natural numbers are allowed", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if (psize < minpkt1 || psize > maxpkt1) {
                    JOptionPane.showMessageDialog(null,
                            "Packet size must be within " + minpkt1 + " to " + maxpkt1 + " bytes", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                di.startTest(1, test2_option, psize);
                t2_o1.setEnabled(false);
                t2_o2.setEnabled(false);
                t2_o3.setEnabled(false);
                t2_psize.setEnabled(false);
                stest.setText("Stop");
                testStarted1 = true;
                updateLog("[Test Started for Data Path-1]", logStatus);

            } else if (stest.getText().equals("Stop")) {
                // Disable button to avoid multiple clicks
                stest.setEnabled(false);
                SwingWorker worker = new SwingWorker<Void, Void>() {

                    @Override
                    protected Void doInBackground() throws Exception {
                        try {
                            stopTest2();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return null;
                    }

                };
                worker.execute();
            }
        }
    });
    panel.add(stest);
    if ((mode == LandingPage.APPLICATION_MODE) || (mode == LandingPage.APPLICATION_MODE_P2P)) {
        t2_o1.setSelected(false);
        t2_o2.setSelected(false);
        t2_o3.setSelected(false);
        t2_o1.setEnabled(false);
        t2_o2.setEnabled(false);
        t2_o3.setEnabled(false);
        t2_psize.setEnabled(false);
        t2_psize.setText("");
        stest.setEnabled(false);
    }
    return panel;
}

From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java

protected void uiSaveActionPerformed(final boolean showInfoMsg) {
    try {//from   w w w .j  av a  2  s .  com
        // 
        if (StringUtils.isEmpty(uiName.getText())) {
            throw new Exception("???!");
        }
        if (StringUtils.isEmpty(uiNamePy.getText())) {
            uiNamePy.setText(PinyinUtil.getPinpin(uiName.getText()));
        }
        if (uiState.getSelectedIndex() == 0) {
            throw new Exception("??!");
        }
        if (StringUtils.isEmpty(uiIdCard.getText())) {
            throw new Exception("??!");
        }
        if (uiContact.getText().length() != 0 && uiContact.getText().length() != 11) {
            throw new Exception("??11?!");
        }
        switch (uiState.getSelectedItem().toString()) {
        case "":
            throw new Exception("??!");
        case Employee.STATE_LEAVE:
            if (uiLeaveDate.getCalendar() == null) {
                throw new Exception("??!");
            }
            if (StringUtils.isEmpty(uiLeaveType.getSelectedItem().toString())) {
                throw new Exception("??!");
            }
            break;
        case Employee.STATE_DELETE:
            if (uiLeaveDate.getCalendar() == null) {
                throw new Exception("?!");
            }
            break;
        case Employee.STATE_RETIRE:
            if (uiLeaveDate.getCalendar() == null) {
                throw new Exception("?!");
            }
            break;
        default:
            break;
        }
        if (StringUtils.isEmpty(uiDept.getText())) {
            throw new Exception("?!");
        }
        if (StringUtils.isEmpty(uiJob.getText())) {
            throw new Exception("??!");
        }
    } catch (Exception e) {
        showErrorMsg(e);
        return;
    }
    showWaitPanel("?......");
    new SwingWorker<String, Void>() {

        @Override
        protected String doInBackground() throws Exception {
            Employee employee = initEmpFromUi();
            return checkEmployeeInfo(employee);
        }

        @Override
        protected void done() {
            try {
                String info = get();
                hideWaitPanel();
                if (info == null) {
                    saveEmpInfo(showInfoMsg);
                } else {
                    int operation = JOptionPane.showConfirmDialog(InfoEmployee.this,
                            "<html>" + info + "<br/>???</html>", APP_NAME,
                            JOptionPane.YES_NO_OPTION);
                    if (operation == JOptionPane.YES_OPTION) {
                        saveEmpInfo(showInfoMsg);
                    }
                }
            } catch (Exception e) {
                hideWaitPanel();
                showErrorMsg(e);
            }
        }
    }.execute();
}