List of usage examples for javax.swing SwingWorker SwingWorker
public SwingWorker()
From source file:edu.ku.brc.specify.config.init.secwiz.SpecifyDBSecurityWizard.java
/** * //from w ww . jav a 2 s . c om */ public void configureDatabase() { setupLoginPrefs(); if (SpecifyDBSecurityWizard.this.listener != null) { SpecifyDBSecurityWizard.this.listener.hide(); } SwingWorker<Integer, Integer> worker = new SwingWorker<Integer, Integer>() { protected boolean isOK = false; /* (non-Javadoc) * @see javax.swing.SwingWorker#doInBackground() */ @Override protected Integer doInBackground() throws Exception { try { String dbName = props.getProperty("dbName"); String hostName = props.getProperty("hostName"); DatabaseDriverInfo driverInfo = (DatabaseDriverInfo) props.get("driverObj"); String connStr = driverInfo.getConnectionStr(DatabaseDriverInfo.ConnectionType.Create, hostName, dbName); if (connStr == null) { connStr = driverInfo.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open, hostName, dbName); } String saUserName = props.getProperty("saUserName"); // Master Username String saPassword = props.getProperty("saPassword"); // Master Password BuildSampleDatabase bsd = new BuildSampleDatabase(); progressFrame = bsd.createProgressFrame(getResourceString("CREATE_DIV")); progressFrame.adjustProgressFrame(); progressFrame.setProcessPercent(true); progressFrame.setOverall(0, 12); UIRegistry.pushWindow(progressFrame); UIHelper.centerAndShow(progressFrame); if (!UIHelper.tryLogin(driverInfo.getDriverClassName(), driverInfo.getDialectClassName(), dbName, connStr, saUserName, saPassword)) { isOK = false; return null; } } catch (Exception ex) { //edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SpecifyDBSetupWizard.class, ex); ex.printStackTrace(); } return null; } /* (non-Javadoc) * @see javax.swing.SwingWorker#done() */ @Override protected void done() { if (isOK) { if (UIRegistry.isMobile()) { DBConnection.setCopiedToMachineDisk(true); } HibernateUtil.shutdown(); DBConnection.shutdown(); } if (listener != null) { listener.hide(); listener.finished(); } } }; worker.execute(); }
From source file:sk.uniza.fri.pds.spotreba.energie.gui.MainGui.java
private void typeAndCatMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_typeAndCatMenuItemActionPerformed final StatistikaTypuKategorieParams params = new StatistikaTypuKategorieParams(); int option = showUniversalInputDialog(params, "tatistika poda typu a kategrie"); if (option == JOptionPane.OK_OPTION) { new SwingWorker<List, RuntimeException>() { @Override//from w ww .j a v a2s . c om protected List doInBackground() throws Exception { try { return SeHistoriaService.getInstance().getTypeAndCategoryStatistics(params); } catch (RuntimeException e) { publish(e); return null; } } @Override protected void done() { try { List data = get(); showJTable(StatistikaTypuKategorie.class, data); } catch (InterruptedException | ExecutionException ex) { Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex); } } @Override protected void process(List<RuntimeException> chunks) { if (chunks.size() > 0) { showException("Chyba", chunks.get(0)); } } }.execute(); } }
From source file:com.mirth.connect.client.ui.NotificationDialog.java
private void doSave() { final Properties personPreferences = new Properties(); if (!StringUtils.equals(checkForNotifications, Boolean.toString(checkForNotificationsSetting))) { personPreferences.put("checkForNotifications", Boolean.toString(checkForNotificationsSetting)); }// w ww . j a v a 2 s.c om if (!StringUtils.equals(showNotificationPopup, Boolean.toString(notificationCheckBox.isSelected()))) { personPreferences.put("showNotificationPopup", Boolean.toString(notificationCheckBox.isSelected())); } Set<Integer> currentArchivedNotifications = notificationModel.getArchivedNotifications(); if (!archivedNotifications.equals(currentArchivedNotifications)) { personPreferences.put("archivedNotifications", ObjectXMLSerializer.getInstance().serialize(currentArchivedNotifications)); } if (!personPreferences.isEmpty()) { final String workingId = parent.startWorking("Saving notifications settings..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { try { parent.mirthClient.setUserPreferences(parent.getCurrentUser(parent).getId(), personPreferences); } catch (ClientException e) { parent.alertThrowable(parent, e); } return null; } @Override public void done() { parent.stopWorking(workingId); } }; worker.execute(); } parent.updateNotificationTaskName(unarchivedCount); this.dispose(); }
From source file:de.cismet.cids.custom.objecteditors.utils.VermessungUmleitungPanel.java
/** * DOCUMENT ME!/*from www . j a v a 2s . c om*/ */ private void deleteFile() { final SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() { @Override protected Boolean doInBackground() throws Exception { if (initError) { return false; } final String filename = createFilename(); final File f = File.createTempFile(filename, ".txt"); return webDavHelper.deleteFileFromWebDAV(filename + ".txt", createDirName(), getConnectionContext()); } @Override protected void done() { try { if (!get()) { final org.jdesktop.swingx.error.ErrorInfo ei = new ErrorInfo( org.openide.util.NbBundle.getMessage(VermessungUmleitungPanel.class, "VermessungUmleitungPanel.errorDialog.title"), org.openide.util.NbBundle.getMessage(VermessungUmleitungPanel.class, "VermessungUmleitungPanel.errorDialog.delete.message"), null, null, null, Level.ALL, null); JXErrorPane.showDialog( StaticSwingTools.getParentFrameIfNotNull(VermessungUmleitungPanel.this), ei); editor.handleEscapePressed(); if (escapeText != null) { tfName.setText(escapeText); } else { tfName.setText(""); } } else { editor.handleUmleitungDeleted(); } } catch (InterruptedException ex) { LOG.error("Deleting link file worker was interrupted", ex); } catch (ExecutionException ex) { LOG.error("Error in deleting link file worker", ex); final org.jdesktop.swingx.error.ErrorInfo ei = new ErrorInfo( org.openide.util.NbBundle.getMessage(VermessungUmleitungPanel.class, "VermessungUmleitungPanell.errorDialog.title"), org.openide.util.NbBundle.getMessage(VermessungUmleitungPanel.class, "VermessungUmleitungPanel.errorDialog.delete.message"), ex.getMessage(), null, ex, Level.ALL, null); JXErrorPane.showDialog(StaticSwingTools.getParentFrameIfNotNull(VermessungUmleitungPanel.this), ei); } } }; worker.execute(); }
From source file:com.josescalia.tumblr.app.MainFrame.java
private void executeMenu(final String beanName) { mainPanel.setCursor(new Cursor(Cursor.WAIT_CURSOR)); progressBar.setIndeterminate(true);//from w ww . j a v a2 s . co m new SwingWorker<BaseForm, BaseForm>() { @Override protected BaseForm doInBackground() throws Exception { return (BaseForm) context.getBean(beanName); } @Override protected void done() { BaseForm frm; try { removePanelFromMain(); frm = get(); frm.showForm(); frm.setVisible(true); mainPanel.setLayout(new BorderLayout()); mainPanel.add(frm); mainPanel.validate(); } catch (InterruptedException ex) { logger.error(ex.getMessage()); UIAlert.showError(mainPanel, "No Such Form Defined"); } catch (ExecutionException ex) { logger.error(ex.getMessage()); UIAlert.showError(mainPanel, "Something wrong with the system"); } progressBar.setIndeterminate(false); mainPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } }.execute(); //this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); }
From source file:edu.ku.brc.specify.config.init.MasterUserPanel.java
/** * // ww w . j av a2s. c o m */ protected void createMasterUser() { String saUsrNm = ((JTextField) comps.get("saUserName")).getText(); if (StringUtils.isNotEmpty(saUsrNm) && saUsrNm.equalsIgnoreCase("root")) { UIRegistry.showLocalizedError("MASTER_NO_ROOT"); ((JTextField) comps.get("saUserName")).setText(""); return; } if (!checkPermsForMasterUserCreation()) { return; } if (isOK == null || !isOK) { progressBar.setIndeterminate(true); progressBar.setVisible(true); setUIEnabled(false); label.setText(UIRegistry.getResourceString("CONN_DB")); createMUBtn.setVisible(false); SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { MasterUserPanel.this.label.setForeground(Color.BLACK); isOK = false; if (!isEmbedded) { DBMSUserMgr mgr = DBMSUserMgr.getInstance(); String dbUserName = properties.getProperty("dbUserName"); String dbPassword = properties.getProperty("dbPassword"); String dbName = properties.getProperty("dbName"); String hostName = properties.getProperty("hostName"); String saUserName = ((JTextField) comps.get("saUserName")).getText(); String saPassword = ((JTextField) comps.get("saPassword")).getText(); if (mgr.connectToDBMS(dbUserName, dbPassword, hostName)) { if (mgr.doesUserExists(saUserName)) { if (!mgr.setPermissions(saUserName, dbName, DBMSUserMgr.PERM_ALL_BASIC)) { errorKey = "ERR_SET_PERM"; } else { isOK = true; } } if (!mgr.doesUserExists(saUserName)) { firePropertyChange(propName, 0, 1); isOK = mgr.createUser(saUserName, saPassword, dbName, DBMSUserMgr.PERM_ALL_BASIC); if (!isOK) { errorKey = "ERR_CRE_MASTER"; } else { isOK = true; } } } else { errorKey = "NO_CONN_ROOT"; isOK = false; } if (mgr != null) { mgr.close(); } } else { isOK = true; } return null; } /* (non-Javadoc) * @see javax.swing.SwingWorker#done() */ @Override protected void done() { super.done(); progressBar.setIndeterminate(false); progressBar.setVisible(false); setUIEnabled(true); updateBtnUI(); createMUBtn.setVisible(!isOK); if (isOK) { setUIEnabled(false); label.setText(UIRegistry.getResourceString("MASTER_CREATED")); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { nextBtn.doClick(); } }); } else { label.setText(UIRegistry.getResourceString(errorKey)); UIRegistry.showLocalizedError(errorKey); } } }; worker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if (propName.equals(evt.getPropertyName())) { MasterUserPanel.this.label.setText(UIRegistry.getLocalizedMessage("CREATE_MASTER")); } } }); worker.execute(); } }
From source file:com.mirth.connect.client.ui.SettingsPanelServer.java
public void doBackup() { if (isSaveEnabled()) { int option = JOptionPane.showConfirmDialog(this, "Would you like to save the settings first?"); if (option == JOptionPane.YES_OPTION) { if (!doSave()) { return; }/*from ww w . ja va 2s. c o m*/ } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) { return; } } final String backupDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); final File exportFile = getFrame().createFileForExport(backupDate.substring(0, 10) + " Mirth Backup.xml", "XML"); if (exportFile != null) { final String workingId = getFrame().startWorking("Exporting server config..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { ServerConfiguration configuration = null; try { configuration = getFrame().mirthClient.getServerConfiguration(); } catch (ClientException e) { getFrame().alertThrowable(SettingsPanelServer.this, e); return null; } // Update resource names for (Channel channel : configuration.getChannels()) { getFrame().updateResourceNames(channel, configuration.getResourceProperties().getList()); } configuration.setDate(backupDate); String backupXML = ObjectXMLSerializer.getInstance().serialize(configuration); getFrame().exportFile(backupXML, exportFile, "Server Configuration"); return null; } public void done() { getFrame().stopWorking(workingId); } }; worker.execute(); } }
From source file:es.emergya.ui.gis.ControlPanel.java
public void setAvaliableResources(Collection<Object> res) { avaliableResources = new Vector<Object>(res); Collections.sort(avaliableResources, comparator); SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { @Override//www . ja va 2 s. co m protected Object doInBackground() throws Exception { return null; } @Override protected void done() { super.done(); // actualizamos la lista if (!isComboResourcesShowing) { Object selected = resources.getSelectedItem(); resources.removeAllItems(); for (Object o : avaliableResources) { resources.addItem(o); } resources.setSelectedItem(selected); } if (!isComboResourcesShowing) resources.updateUI(); } }; sw.execute(); }
From source file:it.illinois.adsc.ema.softgrid.monitoring.ui.SPMainFrame.java
public void startIEDs(final String caseFilePath) { runButton.setEnabled(false);// www .j ava 2s . c o m clearButton.setEnabled(true); serverStatus = 0; setTitle("SoftGrid Monitor"); SwingWorker iedWorker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { System.out.println("Starting IED initialization...!"); resultTabbedPane.add(logAreaScrollPane, "IED Log"); queryScrolPane.getViewport().add(queryTextArea, null); messageHandler.addLogMessage("Initialize Power World...DONE"); messageHandler.addLogMessage("Initialize COM interface...DONE"); messageHandler.addLogMessage("Initialize IED interfaces...DONE"); messageHandler.addLogMessage("Starting IED Servers.........!(This may take few seconds)"); it.illinois.adsc.ema.control.conf.generator.ConfigGenerator.generateConfigXml(ConfigUtil.SCL_PATH, ConfigUtil.CONFIG_PEROPERTY_FILE, ConfigUtil.IP); messageHandler.addLogMessage("Generating SCL files...!"); SclGenerator.generateSCLFiles(); messageHandler.addLogMessage("SCL files generated."); String[] args = { "-f", ConfigUtil.CONFIG_PEROPERTY_FILE, ConfigUtil.SERVER_TYPE, "local" }; mainTabbedPane.add(altertScrolPane, "Transient Monitor"); monitorButton.setVisible(true); SoftGridController.setIEDLogEventListener(SPMainFrame.this); executeMonitorQuery(); startPython(); System.out.println("All Init Operations are executed...!"); SoftGridController.initiate(args); try { dataFileWriter = new BufferedWriter(new FileWriter(new File(ConfigUtil.EXP_DATA_FILE))); } catch (IOException e) { e.printStackTrace(); } return null; } }; iedWorker.execute(); startMonitor(); }
From source file:edu.ku.brc.af.core.db.MySQLBackupService.java
/** * @param newFilePath//from w w w . java2 s . co m * @param isMonthly */ public void doCompareBeforeRestore(final String restoreFilePath, final SimpleGlassPane glassPane) { SwingWorker<Integer, Integer> backupWorker = new SwingWorker<Integer, Integer>() { protected Vector<Object[]> rowData = null; /* (non-Javadoc) * @see javax.swing.SwingWorker#doInBackground() */ @Override protected Integer doInBackground() throws Exception { rowData = doCompare(MySQLBackupService.this.getTableNames(), restoreFilePath); return null; } @Override protected void done() { super.done(); if (rowData != null && rowData.size() > 0) { UIRegistry.getStatusBar().setProgressDone(STATUSBAR_NAME); BackupCompareDlg dlg = new BackupCompareDlg(rowData); dlg.setVisible(true); if (!dlg.isCancelled()) { doActualRestore(restoreFilePath, glassPane); } else { UIRegistry.clearSimpleGlassPaneMsg(); } } else { doActualRestore(restoreFilePath, glassPane); } } }; backupWorker.execute(); }