[MOBY-guts] biomoby commit

Martin Senger senger at dev.open-bio.org
Tue Nov 18 06:40:11 UTC 2008


senger
Tue Nov 18 01:40:11 EST 2008
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard
In directory dev.open-bio.org:/tmp/cvs-serv6073/src/main/org/biomoby/service/dashboard

Modified Files:
	DashboardConfig.java DashboardProperties.java 
	RegistryPanel.java 
Log Message:
allowing to limit the list of known registries in Dashboard
moby-live/Java/src/main/org/biomoby/service/dashboard DashboardConfig.java,1.1,1.2 DashboardProperties.java,1.28,1.29 RegistryPanel.java,1.30,1.31
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/DashboardConfig.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/DashboardConfig.java	2008/03/02 12:45:26	1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/DashboardConfig.java	2008/11/18 06:40:11	1.2
@@ -244,6 +244,34 @@
     }
 
     /**************************************************************************
+     * Almost the same functionality as {@link #getString getString}
+     * method. The different is the return value: this method allows
+     * to return several values of the same property. In the
+     * configuration file, a property can be repeated, or can have
+     * several comma-separated values. <p>
+     *
+     * By the way, the importance of a comma in a property value also
+     * means that any 'normal' (the one not meant as a value
+     * separator) commas in property values, must be escaped by
+     * backslashes. <p>
+     *
+     * @return all values of the given property, or - if such property
+     * does not exist - return a one-element array with the
+     * 'defaultValue' unless the 'defaultValue' is also null in which
+     * case return an empty array
+     **************************************************************************/
+    public static String[] getStrings (String key,
+				       String defaultValue) {
+	String[] values = get().getStringArray (key);
+	if (values.length > 0) return values;
+
+	if (defaultValue == null)
+	    return ArrayUtils.EMPTY_STRING_ARRAY;
+	else
+	    return new String[] { defaultValue };
+    }
+
+    /**************************************************************************
      * Get an integer value associated with the given configuration
      * key, or - if not found or not of integer value - get the given
      * default value. <p>

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/DashboardProperties.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/DashboardProperties.java	2008/05/14 20:37:10	1.28
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/DashboardProperties.java	2008/11/18 06:40:11	1.29
@@ -203,4 +203,23 @@
      */
     static final String DP_REGISTRY_CACHE_DIR = "registry.cache.dir";
 
+    /** A property name. Its value contains a name or a
+     * comma-separated list of names of BioMoby registries that will
+     * be displayed in the RegistryPanel. If this property is missing,
+     * the list is taken from the hard-coded known registries in the
+     * Java source file. <p>
+     *
+     * The names (values of this property) are equivalent to the
+     * 'synonym' attribute of the Registry class.
+     */
+    static final String DP_WANTED_REGISTRIES = "dashboard.wanted.registries";
+
+    /** A property name. Its value contains a name (synonym) of a
+     * default BioMoby registry. By default, the default registry is
+     * taken either from the first element in {@link
+     * #DP_WANTED_REGISTRIES} or from
+     * <tt>Registries.DEFAULT_REGISTRY_SYNONYM</tt>.
+     */
+    static final String DP_DEFAULT_REGISTRY = "dashboard.default.registry";
+
 }

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/RegistryPanel.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/RegistryPanel.java	2008/03/02 16:19:15	1.30
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/RegistryPanel.java	2008/11/18 06:40:11	1.31
@@ -38,6 +38,8 @@
 import java.awt.event.ItemListener;
 
 import java.io.File;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * A panel displaying contents of a Biomoby registry. It also select
@@ -421,10 +423,10 @@
         showReg.setToolTipText ("Each time you select a registry, an info appears in console window");
 
 	final Registries regs = RegistriesList.getInstance();
-        JComboBox regList = new JComboBox (regs.list());
+        JComboBox regList = new JComboBox (getOnlyWantedRegistries (regs.list()));
         regList.setToolTipText ("A selection will fill text fields below");
-	regList.setSelectedItem (getPrefValue (DP_REGISTRY_SYNONYM,
-					       Registries.DEFAULT_REGISTRY_SYNONYM));
+	final String defaultRegistry = getDefaultRegistrySynonym();
+	regList.setSelectedItem (getPrefValue (DP_REGISTRY_SYNONYM, defaultRegistry));
 	regList.addActionListener (new ActionListener() {
 		public void actionPerformed (ActionEvent e) {
 		    String contents =  (String)((JComboBox)e.getSource()).getSelectedItem();
@@ -434,9 +436,9 @@
 			theReg = regs.get (contents);
 		    } catch (MobyException ee) {
 			try {
-			    theReg = regs.get (null);
+			    theReg = regs.get (defaultRegistry);
 			} catch (MobyException ee2) {
-			    log.error ("List of registries does not contain a default registry.");
+			    log.error ("List of registries does not contain the default registry.");
 			}
 		    }
 		    if (theReg != null) {
@@ -458,6 +460,69 @@
     }
 
     /**************************************************************************
+     * Filter the given list of known registry by an optional
+     * properties. Return the filtered result, or the same list if
+     * there is no relevant property. Check if the wanted registries
+     * are also registered ones and ignore (with warning) those that
+     * are not.
+     **************************************************************************/
+    protected static String[] getOnlyWantedRegistries (String[] regs) {
+	String[] wantedRegs = DashboardConfig.getStrings (DP_WANTED_REGISTRIES, null);
+
+ 	if (wantedRegs.length == 0)
+ 	    return regs;
+
+	// check if all of the wanted registries are also known ones
+	List<String> registeredAndWanted = new ArrayList<String>();
+	for (String wantedReg: wantedRegs) {
+	    boolean found = false;
+	    for (String knownReg: regs) {
+		if (wantedReg.equals (knownReg)) {
+		    found = true;
+		    break;
+		}
+	    }
+	    if (found) {
+		registeredAndWanted.add (wantedReg);
+	    } else {
+		log.warn ("An unknown registry synonym found in the property " +
+			  DP_WANTED_REGISTRIES + ": " + wantedReg);
+	    }
+	}
+	if (registeredAndWanted.size() > 0) {
+	    return registeredAndWanted.toArray (new String[] {});
+	} else {
+	    return regs;
+	}
+    }
+
+    /**************************************************************************
+     * Return a synonym of the default registry. It is retrieved (in
+     * this order):
+     *
+     * - from the property DP_DEFAULT_REGISTRY;
+     * - from Registries.DEFAULT_REGISTRY_SYNONYM.
+     *
+     * Log warning if the returned default registry is not in the list
+     * of wanted registries.
+     **************************************************************************/
+    protected static String getDefaultRegistrySynonym() {
+
+	String defaultReg = DashboardConfig.getString (DP_DEFAULT_REGISTRY, null);
+	if (defaultReg == null)
+	    defaultReg = Registries.DEFAULT_REGISTRY_SYNONYM;
+
+	String[] wantedRegs =
+	    getOnlyWantedRegistries (RegistriesList.getInstance().list());
+	for (String wantedReg: wantedRegs) {
+	    if (defaultReg.equals (wantedReg))
+		return defaultReg;
+	}
+	log.warn ("Default registry '" + defaultReg + "' is not found in wanted registries.");
+	return defaultReg;
+    }
+
+    /**************************************************************************
      * Panel for registry.
      **************************************************************************/
     protected JPanel getRegistryLocation() {




More information about the MOBY-guts mailing list