List of usage examples for javax.swing SwingWorker SwingWorker
public SwingWorker()
From source file:com.mirth.connect.client.ui.Frame.java
public void doRefreshUser() { final String workingId = startWorking("Loading users..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { refreshUser();/*from www .j ava 2 s.c o m*/ return null; } public void done() { stopWorking(workingId); } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.Frame.java
public void deployChannel(final Set<String> selectedChannelIds) { if (CollectionUtils.isNotEmpty(selectedChannelIds)) { String plural = (selectedChannelIds.size() > 1) ? "s" : ""; final String workingId = startWorking("Deploying channel" + plural + "..."); dashboardPanel.deselectRows(false); doShowDashboard();//from w w w .j a va 2s. c o m SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { try { mirthClient.deployChannels(selectedChannelIds); } catch (ClientException e) { alertThrowable(PlatformUI.MIRTH_FRAME, e); } return null; } public void done() { stopWorking(workingId); doRefreshStatuses(true); } }; worker.execute(); } }
From source file:de.main.sessioncreator.DesktopApplication1View.java
private void btnWizardNext(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnWizardNext int selTab = wizardtabp.getSelectedIndex(); int maxTab = wizardtabp.getTabCount(); try {/*from w w w. ja va2 s.c o m*/ wizardbtnBack.setEnabled(true); wizardbtntopBack.setEnabled(true); wizardtabp.setSelectedIndex(selTab + 1); if (wizardtabp.getTitleAt(wizardtabp.getSelectedIndex()).contains("Charter")) { wizardChckBxNewCharter.addActionListener(new chckBxNewCharterListener()); swingHelper.setTab1EnableAt(wizardtabp, 1); progressBar.setVisible(true); progressBar.setIndeterminate(true); wizardbtnBack.setEnabled(false); wizardbtntopBack.setEnabled(false); wizardbtnNext.setEnabled(false); wizardbtntopNext.setEnabled(false); mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); wizardCmbxCharter.removeAllItems(); fileHelper.charterList.clear(); final File directory = new File(wizardTfPathTodo.getText()); worker = new SwingWorker<String, Void>() { @Override protected String doInBackground() { return getCharterBackgroundW(directory); } @Override protected void done() { try { if (!worker.get().contains("no")) { progressBar.setIndeterminate(false); progressBar.setVisible(false); wizardbtnBack.setEnabled(true); wizardbtntopBack.setEnabled(true); wizardbtnNext.setEnabled(true); wizardbtntopNext.setEnabled(true); int no = wizardCmbxCharter.getItemCount(); wizardLblChooseCharter.setText("Please select one of " + no + " Charter"); mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } else { progressBar.setIndeterminate(false); progressBar.setVisible(false); wizardbtnBack.setEnabled(true); wizardbtntopBack.setEnabled(true); wizardbtnNext.setEnabled(false); wizardbtntopNext.setEnabled(false); mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } catch (InterruptedException ex) { Logger.getLogger(DesktopApplication1View.class.getName()).log(Level.SEVERE, null, ex); } catch (ExecutionException ex) { Logger.getLogger(DesktopApplication1View.class.getName()).log(Level.SEVERE, null, ex); } } }; worker.execute(); } if (wizardtabp.getTitleAt(wizardtabp.getSelectedIndex()).contains("Areas")) { swingHelper.setTab1EnableAt(wizardtabp, 2); progressBar.setVisible(true); progressBar.setIndeterminate(true); wizardbtnBack.setEnabled(false); wizardbtntopBack.setEnabled(false); wizardbtnNext.setEnabled(false); wizardbtntopNext.setEnabled(false); wizardbtnAddAreas.setEnabled(false); if (wizardtaChoosenAreas.getDocument().getLength() == 0) { wizardbtnRemoveArea.setEnabled(false); } else { wizardbtnRemoveArea.setEnabled(true); } wizardtaChoosenAreas.getDocument().addDocumentListener(new choosenAreaListener()); wizardtabpAreas.removeAll(); final File coverageini = new File(wizardtfCoverageini.getText()); getAreasBacgroundW(coverageini); wizardbtnBack.setEnabled(true); wizardbtntopBack.setEnabled(true); wizardbtnNext.setEnabled(true); wizardbtntopNext.setEnabled(true); if (wizardChckBxNewCharter.isSelected()) { wizardbtnSaveTodo.setEnabled(true); } wizardbtnNext.setText("Create Testsession"); progressBar.setIndeterminate(false); progressBar.setVisible(false); if (!wizardChckBxNewCharter.isSelected()) { String todo = ChoosenCharter.substring(ChoosenCharter.indexOf("(" + wizardTfPathTodo.getText())) .replace("(", "").replace(")", ""); final File todocheckliste = new File(todo); String msg = "Import all Areas from the Todo-Session?"; fileHelper.getAreasChecklist(todocheckliste); fileHelper.areaChecklist.remove(0); if (!fileHelper.areaChecklist.get(0).isEmpty()) { if (JOptionPane.showConfirmDialog(wizardtabpAreas, msg, "Import?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == 0) { wizardtaChoosenAreas.setText(""); for (String s : fileHelper.areaChecklist) { wizardtaChoosenAreas.append(s + "\n"); } wizardtaChoosenAreas.setCaretPosition(0); } } } } if (wizardtabp.getTitleAt(wizardtabp.getSelectedIndex()).contains("Testsession")) { swingHelper.setTab1EnableAt(wizardtabp, 3); wizardbtnNext.setVisible(false); wizardbtntopNext.setEnabled(false); wizardbtnStart.addActionListener(new ButtonListenerStart()); wizardbtntopStart.addActionListener(new ButtonListenerStart()); wizardbtnStop.addActionListener(new ButtonListenerStop()); wizardbtntopStop.addActionListener(new ButtonListenerStop()); if (wizardChckBxNewCharter.isSelected()) { wizardtaCharterdynamic.setText(wizardtaNewCharter.getText().trim()); } else { wizardtaCharterdynamic.setText( ChoosenCharter.substring(0, ChoosenCharter.indexOf("(" + wizardTfPathTodo.getText()))); } statusMessageLabel.setText(""); wizardbtnStart.setVisible(true); wizardbtnStart.setEnabled(true); wizardbtntopStart.setEnabled(true); wizardbtnStop.setVisible(true); wizardbtnStop.setEnabled(false); wizardbtntopStop.setEnabled(false); final JPopupMenu popupMenu = new JPopupMenu(); final File coverageini = new File(wizardtfCoverageini.getText()); swingHelper.getAreastoPopupMenu(popupMenu, coverageini, new alBugsIssue()); popupListener2 = new PopupListener(popupMenu); wizardtaTestsessionAreas.addMouseListener(popupListener2); wizardtaTestsessionAreas.setText(wizardtaChoosenAreas.getText()); wizardtaTestsessionAreas.setCaretPosition(0); wizardtaCharterdynamic.setCaretPosition(0); if (wizardChckBxSecondTester.isSelected()) { TesterRealname = wizardCmbxTester.getSelectedItem().toString(); wizardtfNameOfTester.setText(TesterRealname.substring(4) + " " + wizardCmbxMoreTester.getSelectedItem().toString().substring(4)); } else { TesterRealname = wizardCmbxTester.getSelectedItem().toString(); wizardtfNameOfTester.setText(TesterRealname.substring(4)); } } if (wizardtabp.getSelectedIndex() == maxTab) { wizardbtnNext.setEnabled(false); wizardbtntopNext.setEnabled(false); } } catch (IndexOutOfBoundsException ex) { statusMessageLabel.setText(ex.getMessage()); } }
From source file:com.mirth.connect.client.ui.Frame.java
public void doUndeployChannel() { final Set<DashboardStatus> selectedChannelStatuses = dashboardPanel.getSelectedChannelStatuses(); if (selectedChannelStatuses.size() == 0) { return;//from w ww . j a v a 2 s . c o m } if (!getStatusesWithDependencies(selectedChannelStatuses, ChannelTask.UNDEPLOY)) { return; } dashboardPanel.deselectRows(false); String plural = (selectedChannelStatuses.size() > 1) ? "s" : ""; final String workingId = startWorking("Undeploying channel" + plural + "..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { try { Set<String> channelIds = new LinkedHashSet<String>(); for (DashboardStatus channelStatus : selectedChannelStatuses) { channelIds.add(channelStatus.getChannelId()); } mirthClient.undeployChannels(channelIds); } catch (ClientException e) { alertThrowable(PlatformUI.MIRTH_FRAME, e); } return null; } public void done() { stopWorking(workingId); doRefreshStatuses(true); } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.Frame.java
public void doSaveChannel() { final String workingId = startWorking("Saving channel..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { if (changesHaveBeenMade() || currentContentPage == channelEditPanel.transformerPane || currentContentPage == channelEditPanel.filterPane) { if (channelEditPanel.saveChanges()) { setSaveEnabled(false); }//from w w w .j ava 2 s. c o m return null; } else { return null; } } public void done() { stopWorking(workingId); } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.Frame.java
public void doShowMessages() { if (messageBrowser == null) { messageBrowser = new MessageBrowser(); }//w w w . j a va 2 s . c om String id = ""; String channelName = ""; boolean channelDeployed = true; Integer channelRevision = null; final List<Integer> metaDataIds = new ArrayList<Integer>(); if (currentContentPage == dashboardPanel) { List<DashboardStatus> selectedStatuses = dashboardPanel.getSelectedStatuses(); Set<DashboardStatus> selectedChannelStatuses = dashboardPanel.getSelectedChannelStatuses(); if (selectedStatuses.size() == 0) { return; } if (selectedChannelStatuses.size() > 1) { JOptionPane.showMessageDialog(Frame.this, "This operation can only be performed on a single channel."); return; } for (DashboardStatus status : selectedStatuses) { metaDataIds.add(status.getMetaDataId()); } id = selectedStatuses.get(0).getChannelId(); channelName = selectedChannelStatuses.iterator().next().getName(); channelRevision = 0; } else if (currentContentPage == channelPanel) { Channel selectedChannel = channelPanel.getSelectedChannels().get(0); metaDataIds.add(null); id = selectedChannel.getId(); channelName = selectedChannel.getName(); channelRevision = selectedChannel.getRevision(); channelDeployed = false; for (DashboardStatus dashStatus : status) { if (dashStatus.getChannelId().equals(id)) { channelDeployed = true; } } } setBold(viewPane, -1); setPanelName("Channel Messages - " + channelName); setCurrentContentPage(messageBrowser); setFocus(messageTasks); final String channelId = id; final boolean isChannelDeployed = channelDeployed; final String workingId = startWorking("Retrieving channel metadata..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { Map<Integer, String> connectors; List<MetaDataColumn> metaDataColumns; public Void doInBackground() { try { connectors = mirthClient.getConnectorNames(channelId); metaDataColumns = mirthClient.getMetaDataColumns(channelId); } catch (ClientException e) { alertThrowable(PlatformUI.MIRTH_FRAME, e); } return null; } public void done() { stopWorking(workingId); if (connectors == null || metaDataColumns == null) { alertError(PlatformUI.MIRTH_FRAME, "Could not retrieve metadata for channel."); } else { messageBrowser.loadChannel(channelId, connectors, metaDataColumns, metaDataIds, isChannelDeployed); } } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowser.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);// w ww. j av a 2s . c o m nextPageButton.setEnabled(false); previousPageButton.setEnabled(false); countButton.setEnabled(false); pageGoButton.setEnabled(false); final MessageBrowser messageBrowser = this; if (worker != null && !worker.isDone()) { worker.cancel(true); } worker = new SwingWorker<Void, Void>() { private Exception e; public Void doInBackground() { try { messages.setItemCount(parent.mirthClient.getMessageCount(channelId, messageFilter)); } 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(messageBrowser, e); } else { updatePagination(); countButton.setEnabled(false); } filterButton.setEnabled(true); } parent.stopWorking(workingId); } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.Frame.java
public void clearStats(List<DashboardStatus> statusesToClear, final boolean deleteReceived, final boolean deleteFiltered, final boolean deleteSent, final boolean deleteErrored) { final String workingId = startWorking("Clearing statistics..."); Map<String, List<Integer>> channelConnectorMap = new HashMap<String, List<Integer>>(); for (DashboardStatus status : statusesToClear) { String channelId = status.getChannelId(); Integer metaDataId = status.getMetaDataId(); List<Integer> metaDataIds = channelConnectorMap.get(channelId); if (metaDataIds == null) { metaDataIds = new ArrayList<Integer>(); channelConnectorMap.put(channelId, metaDataIds); }//from ww w.j a v a 2 s . c o m metaDataIds.add(metaDataId); } final Map<String, List<Integer>> channelConnectorMapFinal = channelConnectorMap; SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { try { mirthClient.clearStatistics(channelConnectorMapFinal, deleteReceived, deleteFiltered, deleteSent, deleteErrored); } catch (ClientException e) { alertThrowable(PlatformUI.MIRTH_FRAME, e); } return null; } public void done() { doRefreshStatuses(true); stopWorking(workingId); } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.Frame.java
public void doRemoveFilteredMessages() { if (alertOption(this, "<html>Are you sure you would like to remove all currently filtered messages (including QUEUED) in this channel?<br>Channel must be stopped for unfinished messages to be removed.<br><font size='1'><br></font>WARNING: Removing a Source message will remove all of its destinations.</html>")) { final String workingId = startWorking("Removing messages..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { try { mirthClient.removeMessages(messageBrowser.getChannelId(), messageBrowser.getMessageFilter()); } catch (ClientException e) { if (e instanceof RequestAbortedException) { // The client is no longer waiting for the delete request } else { alertThrowable(PlatformUI.MIRTH_FRAME, e); }// www.j a v a2 s . c o m } return null; } public void done() { if (currentContentPage == dashboardPanel) { doRefreshStatuses(true); } else if (currentContentPage == messageBrowser) { messageBrowser.refresh(1, true); } stopWorking(workingId); } }; worker.execute(); } }
From source file:com.mirth.connect.client.ui.Frame.java
public void doRemoveMessage() { final Integer metaDataId = messageBrowser.getSelectedMetaDataId(); final Long messageId = messageBrowser.getSelectedMessageId(); final String channelId = messageBrowser.getChannelId(); if (alertOption(this, "<html>Are you sure you would like to remove the selected message?<br>Channel must be stopped for an unfinished message to be removed.<br><font size='1'><br></font>WARNING: Removing a Source message will remove all of its destinations.</html>")) { final String workingId = startWorking("Removing message..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { try { MessageFilter filter = new MessageFilter(); filter.setMinMessageId(messageId); filter.setMaxMessageId(messageId); List<Integer> metaDataIds = new ArrayList<Integer>(); metaDataIds.add(metaDataId); filter.setIncludedMetaDataIds(metaDataIds); mirthClient.removeMessages(channelId, filter); } catch (ClientException e) { alertThrowable(PlatformUI.MIRTH_FRAME, e); }//w w w . j a va 2s . c o m return null; } public void done() { if (currentContentPage == dashboardPanel) { doRefreshStatuses(true); } else if (currentContentPage == messageBrowser) { messageBrowser.refresh(null, false); } stopWorking(workingId); } }; worker.execute(); } }