List of usage examples for javax.swing SwingWorker execute
public final void execute()
From source file:net.openbyte.gui.WorkFrame.java
private void menuItem3ActionPerformed(ActionEvent e) { if (this.api == ModificationAPI.BUKKIT) { showBukkitIncompatibleFeature(); return;//from w w w. j a v a 2 s . co m } System.out.println("Building modification JAR."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { GradleConnector.newConnector().forProjectDirectory(workDirectory).connect().newBuild() .forTasks("build").run(); return null; } }; if (this.api == ModificationAPI.MCP) { // recompile and reobfuscate worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { if (System.getProperty("os.name").startsWith("Windows")) { Runtime.getRuntime().exec("cmd /c recompile.bat", null, workDirectory); Runtime.getRuntime().exec("cmd /c reobfuscate.bat", null, workDirectory); return null; } try { CommandLine recompile = CommandLine.parse("python " + new File(new File(workDirectory, "runtime"), "recompile.py").getAbsolutePath() + " $@"); CommandLine reobfuscate = CommandLine.parse("python " + new File(new File(workDirectory, "runtime"), "reobfuscate.py").getAbsolutePath() + " $@"); File recompilePy = new File(new File(workDirectory, "runtime"), "recompile.py"); File reobfuscatePy = new File(new File(workDirectory, "runtime"), "reobfuscate.py"); CommandLine authRecompile = CommandLine.parse("chmod 755 " + recompilePy.getAbsolutePath()); CommandLine authReobfuscate = CommandLine .parse("chmod 755 " + reobfuscatePy.getAbsolutePath()); DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(workDirectory); executor.execute(authRecompile); executor.execute(authReobfuscate); executor.execute(recompile); executor.execute(reobfuscate); System.out.println("Finished building modification JAR."); } catch (Exception e) { e.printStackTrace(); } return null; } }; } worker.execute(); }
From source file:co.edu.unal.pos.gui.PosHadoopJFrame.java
private void startMapReduceJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startMapReduceJButtonActionPerformed SwingWorker<Void, Void> swingWorker = new SwingWorker<Void, Void>() { @Override//from w ww . j a va 2s. c o m protected Void doInBackground() throws Exception { disableGUI(); String id = StringUtils.trimToNull(productIdJTextField.getText()); String description = StringUtils.trimToNull(productDescriptionJTextField.getText()); Integer year = getIntegerValue(yearJTextField); IntegerFilterOperator yearOperator = getIntegerFilterOperator(yearOperatorJComboBox); Integer month = getIntegerValue(monthJTextField); IntegerFilterOperator monthOperator = getIntegerFilterOperator(monthOperatorJComboBox); Integer day = getIntegerValue(dayJTextField); IntegerFilterOperator dayOperator = getIntegerFilterOperator(dayOperatorJComboBox); SaleFactFilter saleFactFilter = new SaleFactFilter(id, description, year, yearOperator, month, monthOperator, day, dayOperator); JobRunner.getInstance().runJob(getAggregationLevel(), saleFactFilter); List<SaleFact> saleFacts = ReaderClient.getInstance().getSaleFacts(); String[][] mapReduceResults = new String[saleFacts.size()][MAP_REDUCE_RESULTS_COLUMNS_NAMES.length]; for (int i = 0; i < saleFacts.size(); i++) { SaleFact saleFact = saleFacts.get(i); mapReduceResults[i][0] = saleFact.getTimeDimension().getYear() != null ? String.valueOf(saleFact.getTimeDimension().getYear()) : ""; mapReduceResults[i][1] = saleFact.getTimeDimension().getMonth() != null ? String.valueOf(saleFact.getTimeDimension().getMonth()) : ""; mapReduceResults[i][2] = saleFact.getTimeDimension().getDay() != null ? String.valueOf(saleFact.getTimeDimension().getDay()) : ""; mapReduceResults[i][3] = String.valueOf(saleFact.getProductQuantity()); mapReduceResults[i][4] = currencyFormatter.format(saleFact.getPrice()); mapReduceResults[i][5] = saleFact.getProductDimension().getId(); mapReduceResults[i][6] = saleFact.getProductDimension().getDescription(); } mapReduceResultsTableDataModel.setDataVector(mapReduceResults, MAP_REDUCE_RESULTS_COLUMNS_NAMES); enableGUI(); return null; } }; swingWorker.execute(); }
From source file:es.emergya.ui.plugins.admin.aux1.SummaryAction.java
@Override public void actionPerformed(ActionEvent e) { // Utilizamos un lock sobre el objeto para evitar abrir varias fichas // del mismo objeto ya que las acciones a realizar se lanzan en un // SwingWorker // sobre el que no tenemos garantizado el instante de ejecucin, lo que // puede hacer que se llame varias veces a getSummaryDialog(). synchronized (this) { if (abriendo) { if (log.isTraceEnabled()) { log.trace("Ya hay otra ventana " + this.getClass().getName() + " abrindose..."); }// w w w .j ava 2 s . c o m return; } abriendo = true; } SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { try { if (d == null || !d.isShowing()) { d = getSummaryDialog(); } if (d != null) { d.pack(); int x; int y; Container myParent = window.getPluginContainer().getDetachedTab(0); Point topLeft = myParent.getLocationOnScreen(); Dimension parentSize = myParent.getSize(); Dimension mySize = d.getSize(); if (parentSize.width > mySize.width) { x = ((parentSize.width - mySize.width) / 2) + topLeft.x; } else { x = topLeft.x; } if (parentSize.height > mySize.height) { y = ((parentSize.height - mySize.height) / 2) + topLeft.y; } else { y = topLeft.y; } d.setLocation(x, y); } else { log.error("No pude abrir la ficha por un motivo desconocido"); } return null; } catch (Throwable t) { log.error("Error al abrir la ficha", t); return null; } } @Override protected void done() { if (d != null) { d.setVisible(true); d.setExtendedState(JFrame.NORMAL); d.setAlwaysOnTop(true); d.requestFocus(); } abriendo = false; if (log.isTraceEnabled()) { log.info("Swingworker " + this.getClass().getName() + " finalizado. Abriendo = false"); } } }; sw.execute(); }
From source file:edu.ku.brc.specify.dbsupport.cleanuptools.AgentCleanupProcessor.java
/** * /* w w w .j a v a 2s . com*/ */ private void processNextAgent(final FindItemInfo fii) { SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() { private boolean doSkip = false; @Override protected Object doInBackground() throws Exception { if (outputRows[0].length() > 0) { tblWriter.logObjRowVAlign(outputRows, "top"); } for (StringBuilder sb : outputRows) { sb.setLength(0); } updCnt = 0; outputRows[0].append(getAgentStr(fii.getId())); for (Integer agentID : fii.getDuplicateIds()) { if (outputRows[1].length() > 0) outputRows[1].append("<BR>"); outputRows[1].append(getAgentStr(agentID)); } if (isGroupOK(fii) && isRolesOK(fii) && isCollectorsOK(fii) && isFundingAgentOK(fii) && isVariantOK(fii)) { if (usedIds == null || !usedIds.contains(fii.getId())) { int numLeft = fii.cleanDuplicateIds(usedIds); if (numLeft > 0) { checkForAddrs(fii); // this calls doMergeOfAgents } else { doMergeOfAgents(fii); } } else { doMergeOfAgents(fii); } } else { doSkip = true; } currIndex++; return null; } @Override protected void done() { prgDlg.setOverall(currIndex); if (doSkip) { if (hasMoreAgents()) { nextAgent(); } else { doComplete(); } } } }; worker.execute(); }
From source file:edu.ku.brc.specify.config.init.secwiz.SpecifyDBSecurityWizard.java
/** * //from w ww .ja v a 2 s . c o m */ 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:edu.ku.brc.specify.tasks.ReportsBaseTask.java
/** * Prints a JTable's model as a Grid Report. * /* ww w . ja va 2 s .c o m*/ * @param cmdAction the command holding the actual JTable object */ protected void printGrid(final CommandAction cmdAction) { String pageTitle = cmdAction.getProperty("gridtitle").toString(); final PageSetupDlg pageSetup = new PageSetupDlg(); pageSetup.createUI(); pageSetup.setPageTitle(pageTitle); pageSetup.setVisible(true); if (pageSetup.isCancelled()) { return; } SwingWorker<Integer, Integer> backupWorker = new SwingWorker<Integer, Integer>() { protected Exception excpt = null; /* (non-Javadoc) * @see javax.swing.SwingWorker#doInBackground() */ @Override protected Integer doInBackground() throws Exception { JTable table = (JTable) cmdAction.getProperty("jtable"); if (table != null) { try { LabelsPane labelsPane = new LabelsPane(name, ReportsBaseTask.this, null); DynamicReport dr = buildReport(table.getModel(), pageSetup); JRDataSource ds = new JRTableModelDataSource(table.getModel()); JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dr, new ClassicLayoutManager(), ds); labelsPane.reportFinished(jp); SubPaneMgr.getInstance().addPane(labelsPane); } catch (Exception ex) { excpt = ex; ex.printStackTrace(); } } return null; } @Override protected void done() { super.done(); UIRegistry.getStatusBar().setProgressDone(PRINT_GRID); UIRegistry.clearSimpleGlassPaneMsg(); if (excpt != null) { UIRegistry.getStatusBar().setErrorMessage(getResourceString("REP_ERR_GRDRPT"), excpt); } } }; final JStatusBar statusBar = UIRegistry.getStatusBar(); statusBar.setIndeterminate(PRINT_GRID, true); UIRegistry.writeSimpleGlassPaneMsg( getLocalizedMessage("REP_GRID_RPT", cmdAction.getProperty("gridtitle").toString()), 24); backupWorker.execute(); }
From source file:ca.uviccscu.lp.server.main.MainFrame.java
@Deprecated public static void setupTablePopupOld() { JMenuItem menuItem = new JMenuItem("Start"); menuItem.addActionListener(new ActionListener() { @Override//from w w w .j a v a2 s.c om public void actionPerformed(final ActionEvent e) { /* lockInterface(); l.trace(e.paramString()); int row = jTable1.rowAtPoint(new Point(Shared.guiLastTablePopupX, Shared.guiLastTablePopupY)); String game = (String) jTable1.getModel().getValueAt(row, 0); l.trace("Popup action! 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(Utils.concatenatePaths(new String[]{Shared.workingDirectory, Shared.torrentStoreSubDirectory})); try { TOTorrent t = TrackerManager.createNewTorrent(g, tp, new ProgressListener(game)); TrackerManager.getCore().addTorrentToTracker(t, tp.getAbsolutePath(), g.getAbsolutePath()); } catch (Exception ex) { l.error("Torrent create failed: " + game, ex); } } else if (status == 1||status == 2) { l.error("Game torrent already created"); } else { l.error("Game has been run already"); } unlockInterface(); * */ SwingWorker worker = new SwingWorker<Void, Void>() { @Override public Void doInBackground() { MainFrame.lockInterface(); l.trace(e.paramString()); int row = jTable1 .rowAtPoint(new Point(Shared.guiLastTablePopupX, Shared.guiLastTablePopupY)); String game = (String) jTable1.getModel().getValueAt(row, 0); l.trace("Popup start action! 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(Shared.workingDirectory + Shared.torrentStoreSubDirectory + "\\" + GamelistStorage.getGame(game).gameName + ".torrent"); try { MainFrame.setReportingActive(); TOTorrent t = TrackerManager.createNewTorrent(g, tp, new HashingProgressListener(game)); TrackerManager.getCore().addTorrentToTracker(t, tp.getAbsolutePath(), g.getAbsolutePath()); GamelistStorage.getGame(game).gameStatus = 1; MainFrame.setReportingIdle(); } catch (Exception ex) { l.error("Torrent create failed: " + game, ex); } } else if (status == 1 || status == 2) { l.error("Game torrent already created"); } else if (status == 4) { TrackerManager.getCore() .resumeTorrentSeeding(GamelistStorage.getGame(game).gameTorrent); TrackerManager.getCore() .resumeTorrentTracking(GamelistStorage.getGame(game).gameTorrent); } else { l.error("Game has been started already"); } return null; } @Override public void done() { MainFrame.updateProgressBar(-1, 0, 100000, "Idle", true, true); MainFrame.updateProgressBar(-1, 0, 100000, "Idle", false, true); MainFrame.updateTask("Idle...", true); MainFrame.unlockInterface(); } }; worker.execute(); } }); popupMenu.add(menuItem); JMenuItem menuItem2 = new JMenuItem("Stop"); menuItem2.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { SwingWorker worker = new SwingWorker<Void, Void>() { @Override public Void doInBackground() { MainFrame.lockInterface(); l.trace(e.paramString()); int row = jTable1 .rowAtPoint(new Point(Shared.guiLastTablePopupX, Shared.guiLastTablePopupY)); String game = (String) jTable1.getModel().getValueAt(row, 0); l.trace("Popup stop action! row: " + row + " and name " + game); Game g = GamelistStorage.getGame(game); int status = g.gameStatus; if (status == 3) { try { TrackerManager.getCore() .pauseTorrentSeeding(GamelistStorage.getGame(game).gameTorrent); TrackerManager.getCore() .pauseTorrentTracking(GamelistStorage.getGame(game).gameTorrent); g.gameStatus = 4; } catch (Exception ex) { l.error("Torrent create failed: " + game, ex); } } else if (status == 1 || status == 2) { l.error("Game torrent already created"); } else { l.error("Game has been started already"); } return null; } @Override public void done() { MainFrame.updateProgressBar(-1, 0, 100000, "Idle", true, true); MainFrame.updateProgressBar(-1, 0, 100000, "Idle", false, true); MainFrame.updateTask("Idle...", true); MainFrame.unlockInterface(); } }; worker.execute(); } }); //menuItem.addActionListener(new ActionAdapter(this)); popupMenu.add(menuItem2); MouseListener popupListener = new PopupListener(); jTable1.addMouseListener(popupListener); }
From source file:fi.hoski.remote.ui.Admin.java
private JMenuItem menuItemSync() { JMenuItem syncItem = new JMenuItem(); TextUtil.populate(syncItem, "SYNCHRONIZE"); ActionListener syncAction = new ActionListener() { @Override/*from ww w . j a va 2s . c om*/ public void actionPerformed(ActionEvent e) { SwingWorker task = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { Progress progress = new UIProgress(frame, TextUtil.getText("SYNCHRONIZE")); progress.setNote(""); try { dss.synchronize(progress); } catch (Throwable ex) { progress.close(); ex.printStackTrace(); JOptionPane.showMessageDialog(frame, ex.getMessage()); } return null; } }; task.execute(); } }; syncAction = createActionListener(frame, syncAction); syncItem.addActionListener(syncAction); return syncItem; }
From source file:de.cismet.cids.custom.objecteditors.utils.VermessungUmleitungPanel.java
/** * DOCUMENT ME!// w w w .j a v a2 s . c o m */ 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.mirth.connect.client.ui.browsers.message.MessageBrowser.java
public void viewAttachment() { try {/*from w ww . j av a2s. c o m*/ 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) { } }