package jalview.gui;
-import jalview.bin.Cache;
-import jalview.util.MessageManager;
-import jalview.ws.WSDiscovererI;
-import jalview.ws.slivkaws.SlivkaWSDiscoverer;
-
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
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.CancellationException;
+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;
+import jalview.bin.Console;
+import jalview.util.MessageManager;
+import jalview.ws2.client.api.WebServiceDiscovererI;
+import jalview.ws2.client.slivka.SlivkaWSDiscoverer;
+
@SuppressWarnings("serial")
public class SlivkaPreferences extends JPanel
{
setPreferredSize(new Dimension(500, 450));
}
- WSDiscovererI discoverer;
+ WebServiceDiscovererI discoverer;
- private final ArrayList<String> urls = new ArrayList<>();
+ private final ArrayList<URL> urls = new ArrayList<>();
- private final ArrayList<Integer> statuses = new ArrayList<>();
+ private final Map<URL, Integer> statuses = new HashMap<>();
private final AbstractTableModel urlTableModel = new AbstractTableModel()
{
switch (columnIndex)
{
case 0:
- return urls.get(rowIndex);
+ return urls.get(rowIndex).toString();
case 1:
- return statuses.get(rowIndex);
+ return statuses.getOrDefault(urls.get(rowIndex), WebServiceDiscovererI.STATUS_UNKNOWN);
default:
throw new NoSuchElementException();
}
hasFocus, row, column);
switch ((Integer) value)
{
- case WSDiscovererI.STATUS_NO_SERVICES:
+ case WebServiceDiscovererI.STATUS_NO_SERVICES:
setForeground(Color.ORANGE);
break;
- case WSDiscovererI.STATUS_OK:
+ case WebServiceDiscovererI.STATUS_OK:
setForeground(Color.GREEN);
break;
- case WSDiscovererI.STATUS_INVALID:
+ case WebServiceDiscovererI.STATUS_INVALID:
setForeground(Color.RED);
break;
- case WSDiscovererI.STATUS_UNKNOWN:
+ case WebServiceDiscovererI.STATUS_UNKNOWN:
default:
setForeground(Color.LIGHT_GRAY);
}
JButton moveUrlDown = new JButton(
MessageManager.getString("action.move_down"));
- private String showEditUrlDialog(String oldUrl)
+ private URL showEditUrlDialog(String oldUrl)
{
- String input = (String) JOptionPane
+ String input = (String) JvOptionPane
.showInternalInputDialog(
- this,
+ this,
MessageManager.getString("label.url:"),
UIManager.getString("OptionPane.inputDialogTitle", MessageManager.getLocale()),
JOptionPane.QUESTION_MESSAGE,
}
try
{
- new URL(input);
+ return new URL(input);
} catch (MalformedURLException ex)
{
- JOptionPane.showMessageDialog(this,
- MessageManager.getString("label.invalid_url"), "Warning",
+ JvOptionPane.showInternalMessageDialog(this,
+ MessageManager.getString("label.invalid_url"),
+ UIManager.getString("OptionPane.messageDialogTitle",
+ MessageManager.getLocale()),
JOptionPane.WARNING_MESSAGE);
return null;
}
- return input;
}
// Button Action Listeners
private ActionListener newUrlAction = (ActionEvent e) -> {
- final String input = showEditUrlDialog("");
+ final URL input = showEditUrlDialog("");
if (input != null)
{
urls.add(input);
- statuses.add(discoverer.getServerStatusFor(input));
+ reloadStatusForUrl(input);
urlTableModel.fireTableRowsInserted(urls.size(), urls.size());
- discoverer.setServiceUrls(urls);
+ discoverer.setUrls(urls);
}
};
final int i = urlListTable.getSelectedRow();
if (i >= 0)
{
- final String input = showEditUrlDialog(urls.get(i));
+ final URL input = showEditUrlDialog(urls.get(i).toString());
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);
+ discoverer.setUrls(urls);
}
}
};
urls.remove(i);
statuses.remove(i);
urlTableModel.fireTableRowsDeleted(i, i);
- discoverer.setServiceUrls(urls);
+ discoverer.setUrls(urls);
}
};
private ActionListener moveUrlUpAction = (ActionEvent e) -> {
- int i = urlListTable.getSelectedRow();
+ final int i = urlListTable.getSelectedRow();
if (i > 0)
{
moveTableRow(i, i - 1);
- discoverer.setServiceUrls(urls);
+ discoverer.setUrls(urls);
}
};
private ActionListener moveUrlDownAction = (ActionEvent e) -> {
- int i = urlListTable.getSelectedRow();
+ final int i = urlListTable.getSelectedRow();
if (i >= 0 && i < urls.size() - 1)
{
moveTableRow(i, i + 1);
- discoverer.setServiceUrls(urls);
+ discoverer.setUrls(urls);
}
};
private void moveTableRow(int fromIndex, int toIndex)
{
- String url = urls.get(fromIndex);
+ URL 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);
+ Console.info("Requesting service reload");
+ discoverer.startDiscoverer().handle((services, exception) -> {
+ if (exception == null)
+ {
+ Console.info("Reloading done");
+ }
+ else if (exception instanceof CancellationException)
+ {
+ Console.info("Reloading cancelled");
+ }
+ else {
+ Console.error("Reloading failed", exception);
+ }
+ SwingUtilities.invokeLater(() -> progressBar.setVisible(false));
+ return null;
+ });
};
private ActionListener resetServicesAction = (ActionEvent e) -> {
- discoverer.setServiceUrls(null);
+ discoverer.setUrls(null);
urls.clear();
statuses.clear();
- urls.addAll(discoverer.getServiceUrls());
- for (String url : urls)
+ urls.addAll(discoverer.getUrls());
+ for (URL url : urls)
{
- statuses.add(discoverer.getServerStatusFor(url));
+ reloadStatusForUrl(url);
}
urlTableModel.fireTableDataChanged();
};
{
// Initial URLs loading
discoverer = SlivkaWSDiscoverer.getInstance();
- urls.addAll(discoverer.getServiceUrls());
- for (String url : urls)
+ urls.addAll(discoverer.getUrls());
+ for (URL url : urls)
{
- statuses.add(discoverer.getServerStatusFor(url));
+ reloadStatusForUrl(url);
}
}
+
+ private void reloadStatusForUrl(URL url)
+ {
+ CompletableFuture.supplyAsync(() -> discoverer.getStatusForUrl(url))
+ .thenAccept((status) -> {
+ statuses.put(url, status);
+ int row = urls.indexOf(url);
+ if (row >= 0)
+ urlTableModel.fireTableCellUpdated(row, 1);
+ });
+ }
}