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.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.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
+import jalview.bin.Cache;
+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 Map<String, Integer> statuses = new HashMap<>();
+ 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.getOrDefault(urls.get(rowIndex), WSDiscovererI.STATUS_UNKNOWN);
+ 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) JvOptionPane
.showInternalInputDialog(
}
try
{
- new URL(input);
+ return new URL(input);
} catch (MalformedURLException ex)
{
JvOptionPane.showInternalMessageDialog(this,
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);
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.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);
}
};
if (i > 0)
{
moveTableRow(i, i - 1);
- discoverer.setServiceUrls(urls);
+ discoverer.setUrls(urls);
}
};
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));
urls.set(toIndex, url);
private ActionListener refreshServicesAction = (ActionEvent e) -> {
progressBar.setVisible(true);
Cache.log.info("Requesting service reload");
- discoverer.startDiscoverer().handle((_discoverer, exception) -> {
+ discoverer.startDiscoverer().handle((services, exception) -> {
if (exception == null)
{
Cache.log.info("Reloading done");
}
- else
+ else if (exception instanceof CancellationException)
{
+ Cache.log.info("Reloading cancelled");
+ }
+ else {
Cache.log.error("Reloading failed", exception);
}
SwingUtilities.invokeLater(() -> progressBar.setVisible(false));
};
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)
{
reloadStatusForUrl(url);
}
{
// Initial URLs loading
discoverer = SlivkaWSDiscoverer.getInstance();
- urls.addAll(discoverer.getServiceUrls());
- for (String url : urls)
+ urls.addAll(discoverer.getUrls());
+ for (URL url : urls)
{
reloadStatusForUrl(url);
}
}
- private void reloadStatusForUrl(String url)
+ private void reloadStatusForUrl(URL url)
{
- CompletableFuture.supplyAsync(() -> discoverer.getServerStatusFor(url))
+ CompletableFuture.supplyAsync(() -> discoverer.getStatusForUrl(url))
.thenAccept((status) -> {
statuses.put(url, status);
int row = urls.indexOf(url);