JAL-1060 - prototype GUI with traffic light coding for JABAWS urls that were fine...
authorjprocter <jprocter@compbio.dundee.ac.uk>
Wed, 28 Mar 2012 13:30:23 +0000 (14:30 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Wed, 28 Mar 2012 13:30:23 +0000 (14:30 +0100)
src/jalview/gui/WsPreferences.java
src/jalview/jbgui/GWsPreferences.java

index 8a09df8..7104fa9 100644 (file)
  */
 package jalview.gui;
 
+import jalview.bin.Cache;
+import jalview.jbgui.GWsPreferences;
+import jalview.ws.jws2.Jws2Discoverer;
+import jalview.ws.rest.RestServiceDescription;
+
 import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.net.URL;
 import java.util.Vector;
 
-import javax.swing.JCheckBox;
 import javax.swing.JLabel;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
+import javax.swing.JTable;
 import javax.swing.JTextField;
-
-import jalview.bin.Cache;
-import jalview.jbgui.GWsPreferences;
-import jalview.ws.rest.RestServiceDescription;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableCellRenderer;
 
 public class WsPreferences extends GWsPreferences
 {
 
+
   public WsPreferences()
   {
     super();
     initFromPreferences();
   }
 
-  Vector<String> wsUrls, oldUrls,rsbsUrls,oldRsbsUrls;
+  Vector<String> wsUrls, oldUrls, rsbsUrls, oldRsbsUrls;
 
   private boolean needWsMenuUpdate;
 
@@ -62,6 +69,8 @@ public class WsPreferences extends GWsPreferences
       oldUrls = null;
       wsUrls = new Vector<String>();
     }
+    wsList.setDefaultRenderer(Integer.class, new JabaWSStatusRenderer());
+    wsList.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
     updateList();
     rsbsUrls = jalview.ws.rest.RestClient.getRsbsDescriptions();
     if (rsbsUrls != null)
@@ -101,11 +110,109 @@ public class WsPreferences extends GWsPreferences
 
   };
 
-  private void updateList()
+  private void updateList() {
+    Object tdat[][] = new Object[wsUrls.size()][2];
+    int r=0;
+    for (String url : wsUrls)
+    {
+      int status = Jws2Discoverer.getDiscoverer().getServerStatusFor(url);
+      tdat[r][1]=new Integer(status);
+      tdat[r++][0]=url;
+    }
+    
+    wsList.setModel(new WsUrlTableModel(tdat));
+    wsList.getColumn("Status").setMinWidth(10);
+  }
+  private class JabaWSStatusRenderer extends JPanel implements TableCellRenderer
   {
-    wsList.setListData(wsUrls);
+    public JabaWSStatusRenderer()
+    {
+      setOpaque(true);
+      setMinimumSize(new Dimension(10,10));
+//      setText(" ");
+      
+    }
+    /**
+     * render an Integer reflecting service status as a colour and symbol
+     */
+
+    @Override
+    public Component getTableCellRendererComponent(JTable arg0,
+            Object status, boolean isSelected, boolean hasFocus, int row, int column)
+    {
+      Color c;
+      String t=new String("");
+      switch (((Integer) status).intValue())
+      {
+      case 1:
+//        cb.setSelected(true);
+        //cb.setBackground(
+        c=Color.green;
+        break;
+      case 0:
+//        cb.setSelected(true);
+//        cb.setBackground(
+        c=Color.lightGray;
+        break;
+      case -1:
+        //cb.setSelected(false);
+        //cb.setBackground(
+        c=Color.red;
+        break;
+      default:
+        //cb.setSelected(false);
+        //cb.setBackground(
+        c=Color.orange;
+      }
+      setBackground(c);
+      //setText(t);
+      return this;
+      
+    }
+
   }
+  private class WsUrlTableModel extends AbstractTableModel {
+    
+    private Object[][] data;
+    public WsUrlTableModel(Object[][] tdat)
+    {
+      this.data=tdat;
+    }
 
+    @Override
+    public int getColumnCount()
+    {
+      return 2;
+    }
+    @Override
+    public String getColumnName(int column)
+    {
+      if (column==1)
+      {
+        return "Status";
+      }
+      return "Service URL";
+    }
+    @Override
+    public int getRowCount()
+    {
+      if (data==null)
+      {
+        return 0;
+      }
+      return data.length;
+    }
+    @Override
+    public java.lang.Class<?> getColumnClass(int columnIndex) {
+      return getValueAt(0, columnIndex).getClass();
+    };
+    @Override
+    public Object getValueAt(int rowIndex, int columnIndex)
+    {
+      return data[rowIndex][columnIndex];
+    }
+    
+  }
   private void updateRsbsList()
   {
     sbrsList.setListData(rsbsUrls);
@@ -131,7 +238,7 @@ public class WsPreferences extends GWsPreferences
   @Override
   protected void deleteWsUrl_actionPerformed(ActionEvent e)
   {
-    int sel = wsList.getSelectedIndex();
+    int sel = wsList.getSelectedRow();
     if (sel > -1)
     {
       wsUrls.removeElementAt(sel);
@@ -149,7 +256,7 @@ public class WsPreferences extends GWsPreferences
   @Override
   protected void editWsUrl_actionPerformed(ActionEvent e)
   {
-    int sel = wsList.getSelectedIndex();
+    int sel = wsList.getSelectedRow();
     if (sel > -1)
     {
       String url = editUrl(wsUrls.elementAt(sel), "Edit JABAWS URL");
@@ -173,37 +280,44 @@ public class WsPreferences extends GWsPreferences
       }
     }
   }
+
   @Override
   protected void newSbrsUrl_actionPerformed(ActionEvent e)
   {
     RestServiceEditorPane rse = new RestServiceEditorPane();
     rse.showDialog("Add a new Simple Bioinformatics Rest Service");
     String rservice = rse.getEditedRestService();
-    if (rservice!=null && !rsbsUrls.contains(rservice))
+    if (rservice != null && !rsbsUrls.contains(rservice))
     {
       rsbsUrls.add(rservice);
       update++;
       updateRsbsList();
     }
   }
+
   @Override
   protected void editSbrsUrl_actionPerformed(ActionEvent e)
   {
     int sel = sbrsList.getSelectedIndex();
     if (sel > -1)
     {
-      RestServiceEditorPane rse = new RestServiceEditorPane(new RestServiceDescription(rsbsUrls.elementAt(sel)));
+      RestServiceEditorPane rse = new RestServiceEditorPane(
+              new RestServiceDescription(rsbsUrls.elementAt(sel)));
       rse.showDialog("Edit Simple Bioinformatics Rest Service entry");
       String rservice = rse.getEditedRestService();
-      if (rservice!=null)
+      if (rservice != null)
       {
         int present = rsbsUrls.indexOf(rservice);
-        if (present==-1) {
+        if (present == -1)
+        {
           update++;
-          rsbsUrls.setElementAt(rservice,sel);
+          rsbsUrls.setElementAt(rservice, sel);
           updateRsbsList();
-        } else {
-          if (present!=sel) {
+        }
+        else
+        {
+          if (present != sel)
+          {
             rsbsUrls.removeElementAt(sel);
             update++;
             updateRsbsList();
@@ -212,17 +326,21 @@ public class WsPreferences extends GWsPreferences
       }
     }
   }
-  
+
   void updateWsMenuConfig(boolean old)
   {
     if (old)
     {
-      if (oldUrls!=wsUrls || (wsUrls!=null && oldUrls!=null && !wsUrls.equals(oldUrls)))
+      if (oldUrls != wsUrls
+              || (wsUrls != null && oldUrls != null && !wsUrls
+                      .equals(oldUrls)))
       {
         update++;
       }
       wsUrls = (oldUrls == null) ? null : new Vector(oldUrls);
-      if (oldRsbsUrls!=rsbsUrls || (rsbsUrls!=null && oldRsbsUrls!=null && !oldRsbsUrls.equals(rsbsUrls)))
+      if (oldRsbsUrls != rsbsUrls
+              || (rsbsUrls != null && oldRsbsUrls != null && !oldRsbsUrls
+                      .equals(rsbsUrls)))
       {
         update++;
       }
@@ -249,9 +367,12 @@ public class WsPreferences extends GWsPreferences
             "WSMENU_BYTYPE",
             Boolean.valueOf(old ? oldIndexByType : indexByType.isSelected())
                     .toString());
-    
-    Cache.setProperty("SHOW_WSDISCOVERY_ERRORS",
-            Boolean.valueOf(old ? oldWsWarning : displayWsWarning.isSelected()).toString());
+
+    Cache.setProperty(
+            "SHOW_WSDISCOVERY_ERRORS",
+            Boolean.valueOf(
+                    old ? oldWsWarning : displayWsWarning.isSelected())
+                    .toString());
     updateServiceList();
     updateRsbsServiceList();
   }
@@ -266,14 +387,14 @@ public class WsPreferences extends GWsPreferences
   @Override
   protected void moveWsUrlDown_actionPerformed(ActionEvent e)
   {
-    int p = wsList.getSelectedIndex();
+    int p = wsList.getSelectedRow();
     if (p > -1 && p < wsUrls.size() - 1)
     {
       String t = wsUrls.get(p + 1);
       wsUrls.setElementAt(wsUrls.elementAt(p), p + 1);
       wsUrls.setElementAt(t, p);
       updateList();
-      wsList.setSelectedIndex(p + 1);
+      wsList.getSelectionModel().setSelectionInterval(p+1,p + 1);
       update++;
     }
   }
@@ -288,14 +409,14 @@ public class WsPreferences extends GWsPreferences
   @Override
   protected void moveWsUrlUp_actionPerformed(ActionEvent e)
   {
-    int p = wsList.getSelectedIndex();
+    int p = wsList.getSelectedRow();
     if (p > 0)
     {
       String t = wsUrls.get(p - 1);
       wsUrls.setElementAt(wsUrls.elementAt(p), p - 1);
       wsUrls.setElementAt(t, p);
       updateList();
-      wsList.setSelectedIndex(p - 1);
+      wsList.getSelectionModel().setSelectionInterval(p-1,p - 1);
       update++;
     }
   }
@@ -326,9 +447,9 @@ public class WsPreferences extends GWsPreferences
         // TODO: do a better job of checking that the url is a valid discovery
         // URL for web services.
         String tx = urltf.getText().trim();
-        while (tx.length()>0 && tx.lastIndexOf('/')==tx.length()-1)
+        while (tx.length() > 0 && tx.lastIndexOf('/') == tx.length() - 1)
         {
-          tx = tx.substring(0, tx.length()-1);
+          tx = tx.substring(0, tx.length() - 1);
         }
         foo = new URL(tx);
         valid = true;
@@ -384,7 +505,7 @@ public class WsPreferences extends GWsPreferences
     {
       if (!wsUrls.contains(url))
       {
-        int selind = wsList.getSelectedIndex();
+        int selind = wsList.getSelectedRow();
         if (selind > -1)
         {
           wsUrls.insertElementAt(url, selind);
@@ -446,6 +567,8 @@ public class WsPreferences extends GWsPreferences
             lastrefresh = update;
             Desktop.instance.startServiceDiscovery(true); // wait around for all
                                                           // threads to complete
+            updateList();
+
           }
           progressBar.setIndeterminate(false);
           progressBar.setVisible(false);
@@ -468,6 +591,7 @@ public class WsPreferences extends GWsPreferences
           {
             lastrefresh = update;
             Desktop.instance.startServiceDiscovery(true);
+            updateList();
           }
           Desktop.instance.setProgressBar(null, ct);
         }
@@ -493,12 +617,13 @@ public class WsPreferences extends GWsPreferences
   {
     jalview.ws.jws2.Jws2Discoverer.setServiceUrls(null);
     Vector nwsUrls = jalview.ws.jws2.Jws2Discoverer.getServiceUrls();
-    if (!wsUrls.equals(nwsUrls)) {
+    if (!wsUrls.equals(nwsUrls))
+    {
       update++;
     }
-    wsUrls=nwsUrls;
+    wsUrls = nwsUrls;
     updateList();
-    
+
     updateAndRefreshWsMenuConfig(true);
   }
 
index ad65bff..4e855af 100644 (file)
@@ -36,8 +36,8 @@ import javax.swing.JPanel;
 import javax.swing.JProgressBar;
 import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
+import javax.swing.JTable;
 import javax.swing.ListSelectionModel;
-import javax.swing.SwingConstants;
 import javax.swing.border.TitledBorder;
 
 /**
@@ -58,8 +58,9 @@ public class GWsPreferences extends JPanel
 
   protected JButton deleteSbrsUrl = new JButton();
 
-  protected JList wsList = new JList();
-
+  // Web service status and url table
+  protected JTable wsList=new JTable();
+  
   protected TitledBorder wsListTitleBorder = new TitledBorder(
           "Web Service Discovery URLS");
 
@@ -288,11 +289,12 @@ public class GWsPreferences extends JPanel
     progressBar.setString("");
     wsListUrlPanel.setBorder(BorderFactory.createEtchedBorder());
     wsListUrlPanel.setLayout(new BorderLayout());
-    // wsListUrlPanel.setPreferredSize(new Dimension(482,202));
     wsListPane.setBorder(BorderFactory.createEtchedBorder());
     wsListPane.getViewport().add(wsList);
-    // wsListPane.setPreferredSize(new Dimension(380, 80));
+    wsList.setPreferredSize(new Dimension(482,202));
+    wsListPane.setPreferredSize(new Dimension(380, 80));
     wsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+    wsList.setColumnSelectionAllowed(false);
     wsList.addMouseListener(new MouseListener()
     {
 
@@ -325,13 +327,11 @@ public class GWsPreferences extends JPanel
       }
 
     });
-    // wsListButtons.setPreferredSize(new Dimension(480, 60));
     wsListButtons.setLayout(new FlowLayout());
-    // wsListButtons.add(moveWsUrlUp);
-    // wsListButtons.add(moveWsUrlDown);
     wsListButtons.add(newWsUrl);
     wsListButtons.add(editWsUrl);
     wsListButtons.add(deleteWsUrl);
+    wsListButtons.setMinimumSize(new Dimension(350,80));
     wsListNavButs.setSize(new Dimension(80, 80));
     wsListNavButs.setPreferredSize(new Dimension(80, 80));
     wsListNavButs.setLayout(new FlowLayout());
@@ -348,7 +348,6 @@ public class GWsPreferences extends JPanel
     srbsListUrlPanel.setLayout(new BorderLayout());
     srbsListPane.setBorder(BorderFactory.createEtchedBorder());
     srbsListPane.getViewport().add(sbrsList);
-    //srbsListPane.setMinimumSize(new Dimension(380, 80));
     sbrsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     sbrsList.addMouseListener(new MouseListener()
     {