List of usage examples for javax.swing SwingWorker execute
public final void execute()
From source file:com.anrisoftware.prefdialog.miscswing.docks.dockingframes.core.DockingFramesDock.java
private void doLoadLayout(String name, InputStream stream, PropertyChangeListener... listeners) throws LayoutInterruptedException, LayoutLoadingException { try {//from w ww .j a va 2s. c om SwingWorker<InputStream, InputStream> worker = loadFactory.create(layoutListeners, this, name, control, stream); for (PropertyChangeListener l : listeners) { worker.addPropertyChangeListener(l); } worker.execute(); worker.get(); } catch (InterruptedException e) { throw new LayoutInterruptedException(name, e); } catch (ExecutionException e) { throw new LayoutLoadingException(name, e.getCause()); } }
From source file:com.anrisoftware.prefdialog.miscswing.docks.dockingframes.core.DockingFramesDock.java
private void doSaveLayout(String name, OutputStream stream, PropertyChangeListener... listeners) throws LayoutException { try {/*www. j a v a 2s .co m*/ SwingWorker<OutputStream, OutputStream> worker = saveFactory.create(layoutListeners, this, name, control, stream); for (PropertyChangeListener l : listeners) { worker.addPropertyChangeListener(l); } worker.execute(); worker.get(); } catch (ExecutionException e) { throw new LayoutSavingException(name, e.getCause()); } catch (InterruptedException e) { throw new LayoutInterruptedException(name, e); } }
From source file:co.edu.unal.pos.gui.PosHadoopJFrame.java
private void startEtlJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startEtlJButtonActionPerformed SwingWorker<Void, Void> swingWorker = new co.edu.unal.pos.hadoop.SwingWorker(this); swingWorker.execute(); }
From source file:de.wusel.partyplayer.gui.PartyPlayer.java
private void play(final SongWrapper song) { SwingWorker worker = new SwingWorker() { @Override/*w w w .j a v a2 s . c o m*/ protected Object doInBackground() throws Exception { if (player.isPlaying()) { return null; } player.play(song); return null; } }; worker.execute(); }
From source file:es.emergya.cliente.scheduler.jobs.UpdateAdminJob.java
@SuppressWarnings("unchecked") @Override/* w w w. j a va2s .c o m*/ public void run() { try { for (final PluginListener o : (List<PluginListener>) Collections.synchronizedList(updatables)) try { if (!(o instanceof Option) || ((Option) o).needsUpdating()) { SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { PluginEventHandler.fireChange(o); return null; } @Override protected void done() { super.done(); o.refresh(null); } }; sw.execute(); } } catch (Throwable t) { log.error("Error al actualizar " + o.toString() + " debido a " + t.toString()); } } catch (Throwable e) { log.fatal("Error al ejecutar la actualizacin de adminjob " + e.toString(), e); } }
From source file:net.openbyte.gui.CreateProjectFrame.java
private void button1ActionPerformed(ActionEvent e) { if (!(Launch.nameToSolution.get(textField1.getText()) == null)) { JOptionPane.showMessageDialog(this, "Project has already been created.", "Error", JOptionPane.ERROR_MESSAGE); return;// w w w . jav a 2 s . c o m } ModificationAPI modificationAPI = ModificationAPI.MINECRAFT_FORGE; String apiName = (String) comboBox1.getSelectedItem(); if (apiName.equals("MCP")) { modificationAPI = ModificationAPI.MCP; } if (apiName.equals("Bukkit")) { modificationAPI = ModificationAPI.BUKKIT; } MinecraftVersion minecraftVersion = MinecraftVersion.BOUNTIFUL_UPDATE; if (((String) comboBox2.getSelectedItem()).equals("1.7.10")) { minecraftVersion = MinecraftVersion.THE_UPDATE_THAT_CHANGED_THE_WORLD; } if (modificationAPI == ModificationAPI.MCP) { minecraftVersion = MinecraftVersion.COMBAT_UPDATE; String version = (String) comboBox2.getSelectedItem(); if (version.equals("1.8.9")) { minecraftVersion = MinecraftVersion.BOUNTIFUL_UPDATE; } if (version.equals("1.7.10")) { minecraftVersion = MinecraftVersion.THE_UPDATE_THAT_CHANGED_THE_WORLD; } } if (modificationAPI == ModificationAPI.BUKKIT) { minecraftVersion = MinecraftVersion.COMBAT_UPDATE; } this.version = minecraftVersion; this.api = modificationAPI; setVisible(false); //JOptionPane.showMessageDialog(this, "We're working on setting up the project. When we are ready, a window will show up.", "Working on project creation", JOptionPane.INFORMATION_MESSAGE); this.projectName = textField1.getText(); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { doOperations(); return null; } }; monitor.setMillisToPopup(0); monitor.setMillisToDecideToPopup(0); monitor.setProgress(1); worker.execute(); if (monitor.isCanceled()) { projectFolder.delete(); new File(Files.WORKSPACE_DIRECTORY, projectName + ".openproj").delete(); return; } }
From source file:edu.ku.brc.specify.ui.AttachmentIconMapper.java
/** * Sends notification on GUI thread//w ww.j a v a 2 s . c om * @param listener * @param imgIcon */ private ImageIcon notifyListener(final ChangeListener listener, final ImageIcon imgIcon) { if (listener != null) { SwingWorker<Boolean, Boolean> worker = new SwingWorker<Boolean, Boolean>() { @Override protected Boolean doInBackground() throws Exception { try { Thread.sleep(100); } catch (Exception ex) { } return null; } @Override protected void done() { listener.stateChanged(new ChangeEvent(imgIcon)); } }; worker.execute(); } return imgIcon; }
From source file:com.mirth.connect.client.ui.SettingsPanelMap.java
public boolean doSave() { final Map<String, ConfigurationProperty> configurationMap = new HashMap<String, ConfigurationProperty>(); RefreshTableModel model = (RefreshTableModel) configurationMapTable.getModel(); for (int i = 0; i < model.getRowCount(); i++) { String key = (String) model.getValueAt(i, 0); String value = (String) model.getValueAt(i, 1); String comment = (String) model.getValueAt(i, 2); if (StringUtils.isNotBlank(key)) { configurationMap.put(key, new ConfigurationProperty(value, comment)); } else {/*from w w w . j a v a 2s .c o m*/ if (StringUtils.isNotBlank(value) || StringUtils.isNotBlank(comment)) { getFrame().alertWarning(this, "Blank keys are not allowed."); return false; } } } final String workingId = getFrame().startWorking("Saving " + getTabName() + " settings..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { try { getFrame().mirthClient.setConfigurationMap(configurationMap); } catch (ClientException e) { getFrame().alertThrowable(getFrame(), e); } return null; } @Override public void done() { setSaveEnabled(false); getFrame().stopWorking(workingId); } }; worker.execute(); return true; }
From source file:commonline.query.gui.action.ClearDatabaseAction.java
public void actionPerformed(ActionEvent actionEvent) { if (JOptionPane.showConfirmDialog(parent, "Are you sure you want to clear the databases?", "Clear DB", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION) { SwingWorker worker = new SwingWorker<Void, Void>() { protected Void doInBackground() throws Exception { for (RecordParserDataSource dataSource : dataSources) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); for (RecordLayoutTableInfo tableInfo : dataSource.getTableInfos()) { try { jdbcTemplate.execute("delete from " + tableInfo.getTableName()); } catch (Exception err) { throw new RuntimeException("Problem clearing table:" + tableInfo.getTableName() + ", in DB:" + dataSource.getUrl(), err); }/*from w w w . j ava 2 s . c om*/ } } return null; } }; worker.execute(); } }
From source file:com.aw.swing.mvp.action.ActionManager.java
public void executeAction(final Action action) { atBeginningOfAction(action);//from w ww. ja v a 2 s .com AWActionTipPainter.instance().hideTipWindow(); if (action instanceof RoundTransitionAction) { ((RoundTransitionAction) action).setTransitionStoppedWithException(false); } GridProviderManager gridProviderManager = action.getPst().getGridProviderMgr(); gridProviderManager.removeEditors(); try { action.checkBasicConditions(); } catch (FlowBreakSilentlyException ex) { logger.info("Exit flow method silently"); return; } catch (AWException ex) { logger.error("AW Exception:", ex); if (action instanceof RoundTransitionAction) { ((RoundTransitionAction) action).setTransitionStoppedWithException(true); } PainterMessages.paintException(ex); return; } String confirmMsg = action.getConfirmMsg(); if (StringUtils.hasText(confirmMsg)) { boolean isCancelAction = action instanceof CancelAction; boolean isFindPst = action.getPst() instanceof FindPresenter; boolean isModeReadOnly = ViewMode.MODE_READONLY.equals(action.getPst().getViewMode()); boolean isShowCancelMsgConfirmation = action.getPst().isShowCancelMsgConfirmation(); if (!isCancelAction || (isShowCancelMsgConfirmation && !isModeReadOnly && !isFindPst)) { if (!MsgDisplayer.showConfirmMessage(confirmMsg)) { logger.debug( "The action:<" + action.toString() + ">will not be executed because was not confirmed"); return; } } } try { action.checkConditions(); AWInputVerifier.getInstance().disable(); Presenter pst = action.getPst(); if (action.execBinding) { pst.setValuesToBean(); } if (action.execValidation) { pst.validate(); } } catch (AWException ex) { if (action instanceof RoundTransitionAction) { ((RoundTransitionAction) action).setTransitionStoppedWithException(true); } if (ex instanceof FlowBreakSilentlyException) { return; } logger.error("AW Exception:", ex); PainterMessages.paintException(ex); return; } finally { AWInputVerifier.getInstance().enable(); } if (action.useMessageBlocker) { try { if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeAndWait(new Runnable() { public void run() { ProcessMsgBlocker.instance().showMessage("Procesando ..."); } }); } else { ProcessMsgBlocker.instance().showMessage("Procesando ..."); } } catch (Throwable e) { e.printStackTrace(); } SwingWorker swingWorker = new SwingWorker() { protected Object doInBackground() throws Exception { executeActionInternal(action); return null; } protected void done() { ProcessMsgBlocker.instance().removeMessage(); action.afterExecute(); } }; swingWorker.execute(); } else { executeActionInternal(action); action.afterExecute(); } }