import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
import java.util.NoSuchElementException;
+import java.util.concurrent.CompletableFuture;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;
+import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
private final ArrayList<String> urls = new ArrayList<>();
- private final ArrayList<Integer> statuses = new ArrayList<>();
+ private final Map<String, Integer> statuses = new HashMap<>();
private final AbstractTableModel urlTableModel = new AbstractTableModel()
{
case 0:
return urls.get(rowIndex);
case 1:
- return statuses.get(rowIndex);
+ return statuses.getOrDefault(urls.get(rowIndex), WSDiscovererI.STATUS_UNKNOWN);
default:
throw new NoSuchElementException();
}
{
String input = (String) JvOptionPane
.showInternalInputDialog(
- this,
+ this,
MessageManager.getString("label.url:"),
UIManager.getString("OptionPane.inputDialogTitle", MessageManager.getLocale()),
JOptionPane.QUESTION_MESSAGE,
if (input != null)
{
urls.add(input);
- statuses.add(discoverer.getServerStatusFor(input));
+ reloadStatusForUrl(input);
urlTableModel.fireTableRowsInserted(urls.size(), urls.size());
discoverer.setServiceUrls(urls);
}
if (input != null)
{
urls.set(i, input);
- statuses.set(i, discoverer.getServerStatusFor(input));
+ statuses.remove(input);
+ reloadStatusForUrl(input);
urlTableModel.fireTableRowsUpdated(i, i);
discoverer.setServiceUrls(urls);
}
String url = urls.get(fromIndex);
int status = statuses.get(fromIndex);
urls.set(fromIndex, urls.get(toIndex));
- statuses.set(fromIndex, statuses.get(toIndex));
urls.set(toIndex, url);
- statuses.set(toIndex, status);
if (urlListTable.getSelectedRow() == fromIndex)
{
urlListTable.setRowSelectionInterval(toIndex, toIndex);
// Discoverer buttons action listeners
private ActionListener refreshServicesAction = (ActionEvent e) -> {
- new Thread(() -> {
- progressBar.setVisible(true);
- Cache.log.info("Requesting service reload");
- Desktop.instance.startServiceDiscovery(discoverer, true);
- Cache.log.info("Reloading done");
- progressBar.setVisible(false);
- }).start();
+ progressBar.setVisible(true);
+ Cache.log.info("Requesting service reload");
+ discoverer.startDiscoverer().handle((_discoverer, exception) -> {
+ if (exception == null)
+ {
+ Cache.log.info("Reloading done");
+ }
+ else
+ {
+ Cache.log.error("Reloading failed", exception);
+ }
+ SwingUtilities.invokeLater(() -> progressBar.setVisible(false));
+ return null;
+ });
};
private ActionListener resetServicesAction = (ActionEvent e) -> {
urls.addAll(discoverer.getServiceUrls());
for (String url : urls)
{
- statuses.add(discoverer.getServerStatusFor(url));
+ reloadStatusForUrl(url);
}
urlTableModel.fireTableDataChanged();
};
urls.addAll(discoverer.getServiceUrls());
for (String url : urls)
{
- statuses.add(discoverer.getServerStatusFor(url));
+ reloadStatusForUrl(url);
}
}
+
+ private void reloadStatusForUrl(String url)
+ {
+ CompletableFuture.supplyAsync(() -> discoverer.getServerStatusFor(url))
+ .thenAccept((status) -> {
+ statuses.put(url, status);
+ int row = urls.indexOf(url);
+ if (row >= 0)
+ urlTableModel.fireTableCellUpdated(row, 1);
+ });
+ }
}