List of usage examples for javax.swing SwingWorker SwingWorker
public SwingWorker()
From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java
private void saveEmpInfo(final boolean showInfoMsg) { showWaitPanel("?......"); new SwingWorker<Employee, Void>() { @Override// www . j ava 2 s .c o m protected Employee doInBackground() throws Exception { Employee employee = initEmpFromUi(); if (StringUtils.isEmpty(employee.getId())) { return HrmBiz.getInstance().insertEmp(employee); } else { return HrmBiz.getInstance().updateEmp(employee); } } @Override protected void done() { try { hideWaitPanel(); employee = get(); updateData(); if (showInfoMsg) { showInfoMsg("??!"); } } catch (Exception e) { hideWaitPanel(); showErrorMsg(e); } } }.execute(); }
From source file:au.org.ala.delta.intkey.Intkey.java
/** * Load the Desktop in the background. We do this because * Desktop.getDesktop() can be very slow *///from w w w. ja v a2 s .c o m private void loadDesktopInBackground() { _desktopWorker = new SwingWorker<Desktop, Void>() { protected Desktop doInBackground() { if (Desktop.isDesktopSupported()) { return Desktop.getDesktop(); } else { return null; } } }; _desktopWorker.execute(); }
From source file:com.t3.client.AppActions.java
private static void doSaveCampaign(final Campaign campaign, final File file, final Observer callback) { TabletopTool.getFrame()//w w w . j a v a 2 s.co m .showFilledGlassPane(new StaticMessageDialog(I18N.getText("msg.info.campaignSaving"))); new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { if (AppState.isSaving()) { return "Campaign currently being auto-saved. Try again later."; // string error message } try { AppState.setIsSaving(true); TabletopTool.getAutoSaveManager().pause(); long start = System.currentTimeMillis(); PersistenceUtil.saveCampaign(campaign, file); AppMenuBar.getMruManager().addMRUCampaign(AppState.getCampaignFile()); TabletopTool.getFrame().setStatusMessage(I18N.getString("msg.info.campaignSaved")); // Minimum display time so people can see the message try { Thread.sleep(Math.max(0, 500 - (System.currentTimeMillis() - start))); } catch (InterruptedException e) { // Nothing to do } return null; // 'null' means everything worked; no errors } catch (IOException ioe) { TabletopTool.showError("msg.error.failedSaveCampaign", ioe); } catch (Throwable t) { TabletopTool.showError("msg.error.failedSaveCampaign", t); } finally { AppState.setIsSaving(false); TabletopTool.getAutoSaveManager().restart(); } return "Failed due to exception"; // string error message } @Override protected void done() { TabletopTool.getFrame().hideGlassPane(); Object obj = null; try { obj = get(); if (obj instanceof String) TabletopTool.showWarning((String) obj); } catch (Exception e) { TabletopTool.showError("Exception during SwingWorker.get()?", e); } if (callback != null) { callback.update(null, obj); } } }.execute(); }
From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java
private void queryHistory() { new SwingWorker<List<EmployeeHistory>, Void>() { @Override//from w w w . ja v a 2s .c o m protected List<EmployeeHistory> doInBackground() throws Exception { EmployeeHistory empHistory = new EmployeeHistory(); empHistory.setEmpId(uiId.getText()); if (uiHistoryType.getSelectedIndex() > 0) { empHistory.setType(uiHistoryType.getSelectedItem().toString()); } empHistory.setOperator(uiHistoryOperator.getText()); return HrmBiz.getInstance().getEmpHistory(empHistory); } @Override protected void done() { try { List<EmployeeHistory> empHistory = get(); if (empHistory != null) { historyModel.setData(empHistory); } } catch (Exception e) { showErrorMsg(e); } } }.execute(); }
From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java
private void querySuspend() { new SwingWorker<List<EmployeeSuspend>, Void>() { @Override//from w w w .j ava2s.c o m protected List<EmployeeSuspend> doInBackground() throws Exception { EmployeeSuspend employeeSuspend = new EmployeeSuspend(); employeeSuspend.setEmpId(uiId.getText()); return HrmBiz.getInstance().getEmpSuspend(employeeSuspend); } @Override protected void done() { try { List<EmployeeSuspend> empSuspend = get(); if (empSuspend != null) { suspendModel.setData(empSuspend); uiEmpSuspend.packAll(); } } catch (Exception e) { showErrorMsg(e); } } }.execute(); }
From source file:com.xilinx.virtex7.MainScreen.java
private JPanel testPanelItems2() { 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-2:")); t3_o1 = new JCheckBox("Loopback"); if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV) t3_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) t3_o1.setToolTipText("This loops back software generated raw Ethernet frames at 10G PHY"); t3_o1.setSelected(true);//from ww w .j a v a 2 s. c o m t3_o1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) { t3_o1.setSelected(true); return; } if (t3_o1.isSelected()) { // disable others test3_option = DriverInfo.ENABLE_LOOPBACK; t3_o2.setSelected(false); t3_o3.setSelected(false); } else { if (!t3_o2.isSelected() && !t3_o3.isSelected()) { test3_option = DriverInfo.CHECKER; t3_o2.setSelected(true); } } } }); //b1.setSelected(true); t3_o2 = new JCheckBox("HW Checker"); if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV) t3_o2.setToolTipText( "This enables Checker in hardware at DMA user interface verifying traffic generated by software"); t3_o2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (t3_o2.isSelected()) { // disable others test3_option = DriverInfo.CHECKER; t3_o1.setSelected(false); //t2_o3.setSelected(false); if (t3_o3.isSelected()) test3_option = DriverInfo.CHECKER_GEN; } else { if (t3_o3.isSelected()) test3_option = DriverInfo.GENERATOR; else { test3_option = DriverInfo.ENABLE_LOOPBACK; t3_o1.setSelected(true); } } } }); //b2.setEnabled(false); t3_o3 = new JCheckBox("HW Generator"); if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV) t3_o3.setToolTipText("This enables traffic generator in hardware at the DMA user interface"); t3_o3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (t3_o3.isSelected()) { // disable others test3_option = DriverInfo.GENERATOR; t3_o1.setSelected(false); //t2_o2.setSelected(false); if (t3_o2.isSelected()) test3_option = DriverInfo.CHECKER_GEN; } else { if (t3_o2.isSelected()) test3_option = DriverInfo.CHECKER; else { test3_option = DriverInfo.ENABLE_LOOPBACK; t3_o1.setSelected(true); } } } }); //b3.setEnabled(false); JPanel ip = new JPanel(); ip.setLayout(new BoxLayout(ip, BoxLayout.PAGE_AXIS)); ip.add(t3_o1); ip.add(t3_o2); ip.add(t3_o3); panel.add(ip); panel.add(new JLabel("Packet Size (bytes):")); t3_psize = new JTextField("32768", 5); panel.add(t3_psize); s3test = new JButton("Start"); //s3test.setEnabled(false); s3test.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.phy2 == LED_ON && lstats.phy3 == 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.phy2 == LED_OFF || lstats.phy3 == 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.phy2 == LED_OFF || lstats.phy3 == LED_OFF)) { JOptionPane.showMessageDialog(null, "10G-PHY link is down. Test cannot be started", "Error", JOptionPane.ERROR_MESSAGE); return; } } if (s3test.getText().equals("Start")) { int psize = 0; dataMismatch4 = errcnt2 = false; try { psize = Integer.parseInt(t3_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(2, test3_option, psize); t3_o1.setEnabled(false); t3_o2.setEnabled(false); t3_o3.setEnabled(false); t3_psize.setEnabled(false); s3test.setText("Stop"); testStarted2 = true; updateLog("[Test Started for Data Path-2]", logStatus); } else if (s3test.getText().equals("Stop")) { // Disable button to avoid multiple clicks s3test.setEnabled(false); SwingWorker worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { try { stopTest3(); } catch (Exception e) { e.printStackTrace(); } return null; } }; worker.execute(); } } }); panel.add(s3test); if ((mode == LandingPage.APPLICATION_MODE) || (mode == LandingPage.APPLICATION_MODE_P2P)) { t3_o1.setSelected(false); t3_o2.setSelected(false); t3_o3.setSelected(false); t3_o1.setEnabled(false); t3_o2.setEnabled(false); t3_o3.setEnabled(false); t3_psize.setEnabled(false); t3_psize.setText(""); s3test.setEnabled(false); } return panel; }
From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java
private void queryJobAdjustment() { new SwingWorker<List<JobAdjustment>, Void>() { @Override/*from w ww .j a v a2 s .c o m*/ protected List<JobAdjustment> doInBackground() throws Exception { return HrmBiz.getInstance().getJobAdjustmentByEmp(uiId.getText()); } @Override protected void done() { try { List<JobAdjustment> empHistory = get(); if (empHistory != null) { jobAdjustmentModel.setData(empHistory); } } catch (Exception e) { showErrorMsg(e); } } }.execute(); }
From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java
protected void uiFindPraisePunishActionPerformed(ActionEvent evt) { if (StringUtils.isEmpty(employee.getId())) { return;/* w w w .j av a 2 s.c o m*/ } new SwingWorker<List<PraisePunish>, Void>() { @Override protected List<PraisePunish> doInBackground() throws Exception { Map<String, String> map = new HashMap<String, String>(); map.put("empId", employee.getId()); map.put("dateStart", uiPraisePunishDateStart.getText()); map.put("dateEnd", uiPraisePunishDateEnd.getText()); if (uiPraisePunishType.getSelectedIndex() != 0) { map.put("ppType", uiPraisePunishType.getSelectedItem().toString()); } return HrmBiz.getInstance().getPraisePunish(map); } @Override protected void done() { try { List<PraisePunish> pps = get(); if (pps != null) { praisePunishModel.setPps(pps); } } catch (Exception e) { hideWaitPanel(); } } }.execute(); }
From source file:com.mirth.connect.client.ui.Frame.java
public void registerUser(final User user) { final String workingId = startWorking("Registering user..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { try { ConnectServiceUtil.registerUser(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, user, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES); } catch (ClientException e) { // ignore errors connecting to update/stats server }//from www. ja v a 2 s . co m return null; } public void done() { stopWorking(workingId); } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.Frame.java
public void sendUsageStatistics() { UpdateSettings updateSettings = null; try {/*from w w w . j av a2 s . c o m*/ updateSettings = mirthClient.getUpdateSettings(); } catch (Exception e) { } if (updateSettings != null && updateSettings.getStatsEnabled()) { final String workingId = startWorking("Sending usage statistics..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { try { String usageData = mirthClient.getUsageData(getClientStats()); if (usageData != null) { boolean isSent = ConnectServiceUtil.sendStatistics(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, false, usageData, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES); if (isSent) { UpdateSettings settings = new UpdateSettings(); settings.setLastStatsTime(System.currentTimeMillis()); mirthClient.setUpdateSettings(settings); } } } catch (ClientException e) { // ignore errors connecting to update/stats server } return null; } public void done() { stopWorking(workingId); } }; worker.execute(); } }