List of usage examples for javax.swing SwingWorker execute
public final void execute()
From source file:com.mirth.connect.client.ui.Frame.java
public void doPause() { final Set<DashboardStatus> selectedChannelStatuses = dashboardPanel.getSelectedChannelStatuses(); if (selectedChannelStatuses.size() == 0) { return;/*from w w w .j a v a2 s.c o m*/ } if (!getStatusesWithDependencies(selectedChannelStatuses, ChannelTask.PAUSE)) { return; } final String workingId = startWorking("Pausing channels..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { Set<String> channelIds = new HashSet<String>(); for (DashboardStatus dashboardStatus : selectedChannelStatuses) { channelIds.add(dashboardStatus.getChannelId()); } try { if (!channelIds.isEmpty()) { mirthClient.pauseChannels(channelIds); } } 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
private void doReprocess(final MessageFilter filter, final Integer selectedMetaDataId, final boolean showWarning) { final String workingId = startWorking("Retrieving Channels..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { if (channelPanel.getCachedChannelStatuses() == null || channelPanel.getCachedChannelStatuses().values().size() == 0) { channelPanel.retrieveChannels(); }/*from w ww . j ava 2s . c o m*/ return null; } public void done() { stopWorking(workingId); Map<Integer, String> destinationConnectors = new LinkedHashMap<Integer, String>(); destinationConnectors .putAll(dashboardPanel.getDestinationConnectorNames(messageBrowser.getChannelId())); new ReprocessMessagesDialog(messageBrowser.getChannelId(), filter, destinationConnectors, selectedMetaDataId, showWarning); } }; worker.execute(); }
From source file:gui_pack.MainGui.java
private void runTestsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runTestsButtonActionPerformed int rangeMin, rangeMax, spacing; int passing = 0; {// Beginning of input validation String errorTitle, errorMessage; //make sure at least one sort algorithm is selected if (!(insertionCheckBox.isSelected() || mergeCheckBox.isSelected() || quickCheckBox.isSelected() || selectionCheckBox.isSelected())) { errorTitle = "Selection Error"; errorMessage = "At least one sort algorithm (Insertion Sort, " + "Merge Sort, Quick Sort, or Selection Sort) must be selected."; JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.WARNING_MESSAGE); return; }//from ww w. ja v a 2s .co m //make sure at least one order is selected if (!(ascendingCheckBox.isSelected() || descendingCheckBox.isSelected() || randomCheckBox.isSelected())) { errorTitle = "Selection Error"; errorMessage = "At least one order (Ascending Order, Descending Order, or Random Order) " + "must be selected."; JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.WARNING_MESSAGE); return; } //make sure all the proper fields contain data try { rangeMin = Integer.parseInt(rangeMinField.getText()); rangeMax = Integer.parseInt(rangeMaxField.getText()); spacing = Integer.parseInt(spacingField.getText()); //for the multithreaded version of this program "iterations" cannot be a variable //this was left in to catch if the iteration field is left blank or has no value if (iterationField.isEnabled()) { Integer.parseInt(iterationField.getText()); } } catch (NumberFormatException arbitraryName) { errorTitle = "Input Error"; if (iterationField.isEnabled()) { errorMessage = "The size, intervals, and iterations fields must contain " + "integer values and only integer values."; } else { errorMessage = "The size and intervals fields must contain " + "integer values and only integer values."; } JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.WARNING_MESSAGE); return; } //make sure field data is appropriate if (rangeMin > rangeMax) { errorTitle = "Range Error"; errorMessage = "Minimum Size must be less than or equal to Maximum Size."; JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.WARNING_MESSAGE); return; } if (spacing < 1 || rangeMin < 1 || rangeMax < 1 || (iterationField.isEnabled() && Integer.parseInt(iterationField.getText()) < 1)) { errorTitle = "Value Error"; if (iterationField.isEnabled()) { errorMessage = "Intervals, sizes, and iterations must be in the positive domain. " + "Spacing, Range(min), Range(max), and Iterations must be greater than or" + " equal to one."; } else { errorMessage = "Intervals and sizes must be in the positive domain. " + "Spacing, Range(min) and Range(max) be greater than or" + " equal to one."; } JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.WARNING_MESSAGE); return; } if (!iterationField.isEnabled()) { passing = 0; } } // End of input validation //here's where we set up a loading bar in case the tests take a while JProgressBar loadBar = new JProgressBar(); JFrame loadFrame = new JFrame(); JLabel displayLabel1 = new JLabel(); loadBar.setIndeterminate(true); loadBar.setVisible(true); displayLabel1.setText("Running large tests, or many tests, using inefficient algorithms \n" + "may take a while. Please be patient."); loadFrame.setLayout(new FlowLayout()); loadFrame.add(loadBar); loadFrame.add(displayLabel1); loadFrame.setSize(600, 100); loadFrame.setTitle("Loading"); loadFrame.setVisible(true); //now we will leave this open until the tests are completed //now we can conduct the actual tests SwingWorker worker = new SwingWorker<XYSeriesCollection, Void>() { XYSeriesCollection results = new XYSeriesCollection(); @Override protected XYSeriesCollection doInBackground() { XYSeries insertSeries = new XYSeries("Insertion Sort"); XYSeries mergeSeries = new XYSeries("Merge Sort"); XYSeries quickSeries = new XYSeries("Quick Sort"); XYSeries selectSeries = new XYSeries("Selection Sort"); final boolean ascending = ascendingCheckBox.isSelected(); final boolean descending = descendingCheckBox.isSelected(); final boolean insertion = insertionCheckBox.isSelected(); final boolean merge = mergeCheckBox.isSelected(); final boolean quick = quickCheckBox.isSelected(); final boolean selection = selectionCheckBox.isSelected(); final int iterations = Integer.parseInt(iterationField.getText()); ListGenerator generator = new ListGenerator(); int[] list; for (int count = rangeMin; count <= rangeMax; count = count + spacing) { if (ascending) { list = generator.ascending(count); if (insertion) { insertSeries.add(count, insertionSort.sort(list)); } if (merge) { mergeSeries.add(count, mergeSort.sort(list)); } if (quick) { quickSeries.add(count, quickSort.sort(list)); } if (selection) { selectSeries.add(count, selectionSort.sort(list)); } } if (descending) { list = generator.descending(count); if (insertion) { insertSeries.add(count, insertionSort.sort(list)); } if (merge) { mergeSeries.add(count, mergeSort.sort(list)); } if (quick) { quickSeries.add(count, quickSort.sort(list)); } if (selection) { selectSeries.add(count, selectionSort.sort(list)); } } for (int iteration = 0; iteration < iterations; iteration++) { list = generator.random(count); if (insertion) { insertSeries.add(count, insertionSort.sort(list)); } if (merge) { mergeSeries.add(count, mergeSort.sort(list)); } if (quick) { quickSeries.add(count, quickSort.sort(list)); } if (selection) { selectSeries.add(count, selectionSort.sort(list)); } } } //now we aggregate the results if (insertion) { results.addSeries(insertSeries); } if (merge) { results.addSeries(mergeSeries); } if (quick) { results.addSeries(quickSeries); } if (selection) { results.addSeries(selectSeries); } return results; } @Override protected void done() { //finally, we display the results JFreeChart chart = ChartFactory.createScatterPlot("SortExplorer", // chart title "List Size", // x axis label "Number of Comparisons", // y axis label results, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); ChartFrame frame = new ChartFrame("First", chart); frame.pack(); frame.setVisible(true); loadFrame.setVisible(false); } }; //having set up the multithreading 'worker' we can finally conduct the //test worker.execute(); }
From source file:com.mirth.connect.client.ui.Frame.java
public void doRemoveAllEvents() { int option = JOptionPane.showConfirmDialog(this, "All events will be removed. Would you also like them to be\n" + "exported to a file on the server?"); if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) { return;//from w ww .j ava2 s .c o m } final boolean export = (option == JOptionPane.YES_OPTION); final String workingId = startWorking("Clearing events..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { private String exportPath = null; public Void doInBackground() { try { if (export) { exportPath = mirthClient.exportAndRemoveAllEvents(); } else { mirthClient.removeAllEvents(); } } catch (ClientException e) { alertThrowable(PlatformUI.MIRTH_FRAME, e); } return null; } public void done() { eventBrowser.runSearch(); if (exportPath != null) { alertInformation(PlatformUI.MIRTH_FRAME, "Events have been exported to the following server path:\n" + exportPath); } stopWorking(workingId); } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.Frame.java
public void doDeleteUser() { if (!alertOption(this, "Are you sure you want to delete this user?")) { return;//from w ww.ja va 2s.c om } final String workingId = startWorking("Deleting user..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { if (users.size() == 1) { alertWarning(PlatformUI.MIRTH_FRAME, "You must have at least one user account."); return null; } int userToDelete = userPanel.getUserIndex(); try { if (userToDelete != UIConstants.ERROR_CONSTANT) { mirthClient.removeUser(users.get(userToDelete).getId()); retrieveUsers(); } } catch (ClientException e) { alertThrowable(PlatformUI.MIRTH_FRAME, e); } return null; } public void done() { userPanel.updateUserTable(); userPanel.deselectRows(); stopWorking(workingId); } }; worker.execute(); }
From source file:es.emergya.ui.plugins.AdminPanel.java
/** * Cambia los datos que muestra la tabla al array que se le pase. * /* ww w .j a va 2 s .c o m*/ * Se aconseja que sean: * {@link Boolean} para valores si/no * * {@link AbstractAction} o subclases para botones * Numeros * * {@link String} para todo lo demas * * @param data */ public void setTableData(final Object[][] data) { final Object[][] newData = new Object[data.length][]; SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { private MyTableModel model; @Override protected Object doInBackground() throws Exception { if (data == null) { return null; } model = (MyTableModel) table.getModel(); synchronized (seleccion) { for (int i = 0; i < model.getRowCount(); i++) { if ((Boolean) model.getValueAt(i, 0)) { seleccion.add(model.getValueAt(i, columnToReselect)); } } } synchronized (seleccion) { for (int i = 0; i < data.length; i++) { newData[i] = new Object[data[0].length + 1]; newData[i][0] = new Boolean(Authentication.isAuthenticated() && seleccion.contains(data[i][columnToReselect - 1])); for (int j = 0; j < data[i].length; j++) { newData[i][j + 1] = data[i][j]; } } } return null; } protected void done() { model.updateRows(newData); if (!initialized) { table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); for (Integer i : colsWidth.keySet()) { try { final TableColumn column = table.getColumnModel().getColumn(i); final TableColumn filtro = filters.getColumnModel().getColumn(i); column.setPreferredWidth(colsWidth.get(i)); column.setMinWidth(colsWidth.get(i)); column.setMaxWidth(colsWidth.get(i)); filtro.setPreferredWidth(colsWidth.get(i)); filtro.setMinWidth(colsWidth.get(i)); filtro.setMaxWidth(colsWidth.get(i)); } catch (Throwable t) { log.error("Error al resizar las columnas: " + t); } } TableColumn col = table.getColumnModel().getColumn(0); TableColumn fil = filters.getColumnModel().getColumn(0); log.trace("Resizando CheckBox"); col.setMaxWidth(49); fil.setMaxWidth(49); int defaultWidth = 54; for (int i = 1; i < table.getColumnModel().getColumnCount() - 2; i++) { col = table.getColumnModel().getColumn(i); fil = filters.getColumnModel().getColumn(i); final Class<?> columnClass = ((MyTableModel) table.getModel()).getColumnClass(i); if (columnClass == JButton.class) { log.trace("Resizando JButton"); col.setMaxWidth(defaultWidth); fil.setMaxWidth(defaultWidth); } else if (columnClass == Boolean.class) { log.trace("Resizando CheckBox"); col.setMaxWidth(49); fil.setMaxWidth(49); } } if (getCanDelete()) { col = table.getColumnModel().getColumn(table.getColumnModel().getColumnCount() - 2); col.setMaxWidth(defaultWidth); col.setPreferredWidth(defaultWidth); col = table.getColumnModel().getColumn(table.getColumnModel().getColumnCount() - 1); col.setMaxWidth(defaultWidth); col.setPreferredWidth(defaultWidth); } else { col = table.getColumnModel().getColumn(table.getColumnModel().getColumnCount() - 1); col.setMaxWidth(defaultWidth * 2); col.setPreferredWidth(defaultWidth * 2); } int max = filters.getColumnModel().getColumnCount() - 1; filters.getColumnModel().getColumn(max).setMaxWidth(61); filters.getColumnModel().getColumn(max - 1).setMaxWidth(32); filters.getColumnModel().getColumn(max - 2).setMaxWidth(32); initialized = true; } } }; sw.execute(); }
From source file:com.mirth.connect.client.ui.Frame.java
public void doUninstallExtension() { final String workingId = startWorking("Uninstalling extension..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { private boolean success = true; public Void doInBackground() { String packageName = extensionsPanel.getSelectedExtension().getPath(); if (alertOkCancel(PlatformUI.MIRTH_FRAME, "Uninstalling this extension will remove all plugins and/or connectors\nin the following extension folder: " + packageName)) { try { mirthClient.uninstallExtension(packageName); } catch (ClientException e) { success = false;/* ww w .j av a 2 s .co m*/ alertThrowable(PlatformUI.MIRTH_FRAME, e); } } return null; } public void done() { if (success) { extensionsPanel.setRestartRequired(true); } stopWorking(workingId); } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.Frame.java
public void doShowMessages() { if (messageBrowser == null) { messageBrowser = new MessageBrowser(); }/*from www. ja v a2s . c o m*/ 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.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); }/*from www . ja v a 2 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); }/*from www. j av a 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(); } }