[MOBY-guts] biomoby commit

Martin Senger senger at pub.open-bio.org
Wed Oct 12 11:17:59 UTC 2005


senger
Wed Oct 12 07:17:59 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard
In directory pub.open-bio.org:/tmp/cvs-serv13525/src/main/org/biomoby/service/dashboard

Modified Files:
	AbstractPanel.java CommonTree.java NOTES PropertyChannel.java 
	RegistryModel.java RegistryPanel.java 
Added Files:
	DataTypesTree.java JProgressBarWithCancel.java 
Log Message:


moby-live/Java/src/main/org/biomoby/service/dashboard DataTypesTree.java,NONE,1.1 JProgressBarWithCancel.java,NONE,1.1 AbstractPanel.java,1.6,1.7 CommonTree.java,1.2,1.3 NOTES,1.7,1.8 PropertyChannel.java,1.1,1.2 RegistryModel.java,1.3,1.4 RegistryPanel.java,1.8,1.9
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/AbstractPanel.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/AbstractPanel.java	2005/09/24 17:51:51	1.6
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/AbstractPanel.java	2005/10/12 11:17:59	1.7
@@ -16,15 +16,19 @@
 
 import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JScrollPane;
 import javax.swing.Icon;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JTextField;
+import javax.swing.JTextArea;
 import javax.swing.JComboBox;
+import javax.swing.JOptionPane;
 import javax.swing.JFileChooser;
 import javax.swing.AbstractButton;
 import javax.swing.BorderFactory;
 import javax.swing.JComponent;
+import javax.swing.SwingConstants;
 import javax.swing.border.Border;
 import javax.swing.border.TitledBorder;
 import javax.swing.border.CompoundBorder;
@@ -34,6 +38,7 @@
 import javax.swing.filechooser.FileFilter;
 import javax.swing.text.html.HTMLDocument;
 
+import java.awt.Component;
 import java.awt.GridBagLayout;
 import java.awt.GridBagConstraints;
 import java.awt.Insets;
@@ -84,9 +89,13 @@
     protected Icon panelIcon;
     protected JComponent pComponent;
     protected static Icon confirmIcon;
+    protected static Icon warningIcon;
 
     // re-use "style" components
     protected static final Insets BREATH_TOP = new Insets (10,0,0,0);
+    protected static final Font MSG_AREA_FONT = new Font ("Courier", Font.PLAIN, 10);
+    protected static final Font TITLE_FONT = new Font ("Serif", Font.BOLD, 20);
+    protected static final Color TITLE_FGCOLOR = new Color (12, 55, 241);
 
     //
     protected PropertyChannel propertyChannel;
@@ -117,8 +126,8 @@
      **************************************************************************/
     public JLabel getTitle() {
 	JLabel title = new JLabel (getName(), getIcon(), JLabel.CENTER);
-	title.setFont (new Font ("Serif", Font.BOLD, 20));
-	title.setForeground (new Color (12, 55, 241));
+	title.setFont (TITLE_FONT);
+	title.setForeground (TITLE_FGCOLOR);
 	return title;
     }
 
@@ -269,12 +278,19 @@
     }
 
     /*********************************************************************
-     * Create a text field (possibly with an 'initValue' with history
-     * taken from given 'preferenceNode'. If 'evenName' is not null
-     * (which means that the contens of this text filed may be of
-     * interest of someone outside), add an action event that will
-     * update the shared property storage (a global variable
-     * 'propertyChannel') when the text field changes its value.
+     * Create a text field (possibly with an 'initValue') with its
+     * history taken from given 'preferenceNode'. <p>
+     *
+     * If 'initValue' is an empty string, the text field starts with
+     * an empty initial value. If the 'initValue' is null, the text
+     * field starts filled with the last time used value (stored in
+     * and taken from the 'preference node'). <p>
+     *
+     * If 'evenName' is not null (which means that the contens of this
+     * text filed may be of interest of someone outside), add an
+     * action event that will update the shared property storage
+     * (which is in a global variable 'propertyChannel') when the text
+     * field changes its value.
      ********************************************************************/
     protected JTextFieldWithHistory createText (String initValue,
 						String preferenceNode,
@@ -335,4 +351,46 @@
         return SwingUtils.confirm (null, msg, confirmIcon);
     }
 
+    /*********************************************************************
+     * Display an error message.
+     ********************************************************************/
+    public static void error (Object msg) {
+	if (warningIcon == null)
+	    warningIcon = SwingUtils.createIcon ("images/warningButton.gif",
+						 Dashboard.class);
+	JOptionPane.showMessageDialog (null, msg, "Error message",
+				       JOptionPane.PLAIN_MESSAGE, warningIcon);
+    }
+
+    /*********************************************************************
+     * Display an error message. Construct the message from
+     * 'prologue', some intermediate title, and a text area filled
+     * from the exception 'e'.
+     ********************************************************************/
+    public static void error (String prologue, Exception e) {
+
+	// slightly format message prologue
+	// TBD: HTML escape
+	prologue = prologue + "The actual error is:\n\n";
+	if (! prologue.startsWith ("<html")) {
+	    prologue = "<html>" + prologue + "</html>";
+	    prologue = prologue.replaceAll ("\n", "<br>\n");
+	}
+
+	// slightly format the error message
+	// TBD: make it (or part of it) red
+	String msg = e.getMessage();
+
+	JTextArea area = new JTextArea (15, 50);
+	area.setEditable (false);
+	area.setFont (MSG_AREA_FONT);	
+	area.setText (msg);
+	area.setCaretPosition (0);
+
+	JPanel p = new JPanel (new GridBagLayout());
+ 	SwingUtils.addComponent (p, new JLabel (prologue),  0, 0, 1, 1, NONE, NWEST, 0.0, 0.0);
+ 	SwingUtils.addComponent (p, new JScrollPane (area), 0, 1, 1, 1, BOTH, NWEST, 1.0, 1.0);
+	error (p);
+    }
+
 }

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/CommonTree.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/CommonTree.java	2005/09/24 17:51:51	1.2
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/CommonTree.java	2005/10/12 11:17:59	1.3
@@ -45,9 +45,7 @@
 
 /**
  * A common JTree re-used (and always slightly modified) by all
- * Dashboard trees. <p>
- *
- * WORK IN PROGRESS. <p>
+ * Biomoby registry trees. <p>
  *
  * @author <A HREF="mailto:martin.senger at gmail.com">Martin Senger</A>
  * @version $Id$
@@ -55,6 +53,8 @@
 public class CommonTree
     extends JTree {
 
+    final static String RELOAD = "Reload";
+
     // some shared constants
     final static protected int SORTED_BY_NAME      = 0;
     final static protected int SORTED_BY_AUTHORITY = 1;
@@ -186,13 +186,23 @@
 			expand();
 		    }
 		}));
+
 	popup.add
-	    (new JMenuItem (new AbstractAction ("Collaps all nodes") {
+	    (new JMenuItem (new AbstractAction ("Collapse all nodes") {
 		    public void actionPerformed (ActionEvent e) {
 			collapse();
 		    }
 		}));
 
+	popup.addSeparator();
+
+	popup.add
+	    (new JMenuItem (new AbstractAction (RELOAD) {
+		    public void actionPerformed (ActionEvent e) {
+			reload();
+		    }
+		}));
+
 	// add listener to this tree to bring up popup menus
 	MouseListener popupListener = new PopupListener();
 	addMouseListener (popupListener);
@@ -208,7 +218,22 @@
 	private void maybeShowPopup (MouseEvent e) {
 	    if (e.isPopupTrigger() && popup.isEnabled()) {
 		popup.show (e.getComponent(),
-			    e.getX(), e.getY());
+			e.getX(), e.getY());
+	    }
+	}
+    }
+
+    /*********************************************************************
+     * Enable/disable the whole popup except the 'Reload' option (that
+     * one remains enabled always).
+     ********************************************************************/
+    protected void setEnabledPopup (boolean enabled) {
+	synchronized (popup) {
+	    Component[] components = popup.getComponents();
+	    for (int i = 0; i < components.length; i++) {
+		if ( components[i] instanceof JMenuItem &&
+		     ! ((JMenuItem)components[i]).getText().equals (RELOAD) )
+		    ((JMenuItem)components[i]).setEnabled (enabled);
 	    }
 	}
     }
@@ -242,6 +267,14 @@
     }
 
     /*********************************************************************
+     * Does nothing here - it is supposed to be overwritten bya
+     * concrete tree.
+     ********************************************************************/
+    protected void reload() {
+	System.out.println ("Invoking a reload.");
+    }
+
+    /*********************************************************************
      * Search underlying objects and highligh nodes corresponding to
      * the found objects. But it does nothing here - it is supposed to
      * be overwritten by a concrete tree.
@@ -292,4 +325,11 @@
 	}
     }
 
+    /*********************************************************************
+     * Display an error message.
+     ********************************************************************/
+    protected static void error (String prologue, Exception e) {
+	AbstractPanel.error (prologue, e);
+    }
+
 }

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/NOTES,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/NOTES	2005/09/25 09:07:22	1.7
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/NOTES	2005/10/12 11:17:59	1.8
@@ -98,7 +98,6 @@
 
 ----
 
-* error messages (dialog window, or a text-area window/save button, something on sterrr?)
 ? logging (LogPanel and/or usual logging to a file?)
 * communication with StatusBar (incl. progress bar, cancel button)
 * disabling things during a long-time operation
@@ -136,6 +135,14 @@
 * BUG: not sure why so many (repeated) changes from the actionlistener
 in JFieldTextWithHistory
 
+? select a part of an error message and highlight it in red?
+
+? HELP (in a Dashboard Menu)
+  - helps from panels
+  - About
+    - credits
+    - add dynamically a URL from dashboard.properties...
+
 TODO with views:
 ----------------
 * change onMethods() to be protected or even private...
@@ -169,6 +176,12 @@
 ? improve API javadoc of all these Central*Impl
 ? start to work on/think of the RDF-based cache 
 
+General options (available from the menu)
+---------------
+* export/import user preferences
+* set-up what panels are wanted
+* language ( => use proper ResourceBundler...)
+
 Registry panel
 --------------
 
@@ -204,3 +217,5 @@
 - RDF resources
 - Log panel
 - Configure a new Dashboard
+
+- Debugging panel (with a Memory Panel embedded; replacing current two pannels)

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/PropertyChannel.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/PropertyChannel.java	2005/09/24 17:51:51	1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/PropertyChannel.java	2005/10/12 11:17:59	1.2
@@ -29,9 +29,9 @@
  * </ul><p>
  *
  * Obviously, there are some properties that do not make sense to be
- * stored here: the short-lived properties, such as log messages, or
- * progress bar change events. Such messages can be delivered in an
- * ordinary way via property change listeners. <p>
+ * stored here: the short-lived properties, such as progress bar
+ * change events. Such messages can be delivered in an ordinary way
+ * via property change listeners. <p>
  *
  * The panels/models are sending here properties by calling method
  * <tt>put</tt>. If we find, in the future, that sending properties
@@ -40,7 +40,7 @@
  * see any advantage of it. <p>
  *
  * Property names are of no interest for this class, but it is good to
- * remind that the they should be defined in the class {@link
+ * remind that they should be defined in the class {@link
  * DashboardProperties}. <p>
 
  * @author <A HREF="mailto:martin.senger at gmail.com">Martin Senger</A>

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/RegistryModel.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/RegistryModel.java	2005/09/25 09:07:22	1.3
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/RegistryModel.java	2005/10/12 11:17:59	1.4
@@ -52,14 +52,27 @@
 	super (support);
     }
 
+    /**************************************************************************
+     * Return an endpoint (a stringified URL) of a default Moby
+     * registry.
+     *************************************************************************/
+    public String getDefaultRegistryEndpoint() {
+	return CentralDigestCachedImpl.DEFAULT_ENDPOINT;
+    }
+
+    /**************************************************************************
+     * Return a namespace (a URI) used by a default Moby registry.
+     *************************************************************************/
+    public String getDefaultRegistryNamespace() {
+	return CentralDigestCachedImpl.DEFAULT_NAMESPACE;
+    }
+
     /*********************************************************************
      *
      ********************************************************************/
     public MobyDataType[] getDataTypesByNames()
 	throws MobyException {
-
-	if (worker == null)
-	    initWorker();
+	initWorker();
 
 	MobyDataType[] dataTypes = worker.getDataTypes();
  	java.util.Arrays.sort (dataTypes);
@@ -72,9 +85,7 @@
     public MobyDataType[] getDataTypesByAuthority()
 	throws MobyException {
 
-	if (worker == null)
-	    initWorker();
-
+	initWorker();
 	MobyDataType[] dataTypes = worker.getDataTypes();
 	java.util.Arrays.sort
 	    (dataTypes,
@@ -130,17 +141,40 @@
     /*********************************************************************
      *
      ********************************************************************/
-    protected void initWorker()
+    protected String getCacheDir() {
+	if (worker instanceof CentralDigestCachedImpl)
+	    return ((CentralDigestCachedImpl)worker).getCacheDir();
+	else
+	    return null;
+    }
+
+    /*********************************************************************
+     *
+     ********************************************************************/
+    protected synchronized void initWorker()
 	throws MobyException {
-	String registryURL = propertyChannel.getString (DP_REGISTRY_ENDPOINT);
-	String registryNS = propertyChannel.getString (DP_REGISTRY_NAMESPACE);
-//  	String cacheDir = propertyChannel.getString (DP_CACHE_DIR);
- 	String cacheDir = "/home/senger/jMoby/myCache";
-//  	cacheDir = null;
-
-	worker = new CentralDigestCachedImpl (registryURL,
-					      registryNS,
-					      cacheDir);
+	if (worker == null) {
+	    String registryURL = propertyChannel.getString (DP_REGISTRY_ENDPOINT);
+	    String registryNS = propertyChannel.getString (DP_REGISTRY_NAMESPACE);
+	    String cacheDir = propertyChannel.getString (DP_CACHE_DIR);
+	    //  	String cacheDir = "/home/senger/jMoby/myCache";
+	    //  	cacheDir = null;
+
+	    worker = new CentralDigestCachedImpl (registryURL,
+						  registryNS,
+						  cacheDir);
+	} else {
+	    String maybeNewRegistryURL = propertyChannel.getString (DP_REGISTRY_ENDPOINT);
+	    String maybeNewRegistryNS = propertyChannel.getString (DP_REGISTRY_NAMESPACE);
+	    String maybeNewCacheDir = propertyChannel.getString (DP_CACHE_DIR);
+	    if ( maybeNewRegistryURL.equals (worker.getRegistryEndpoint()) &&
+		 maybeNewRegistryNS.equals (worker.getRegistryNamespace()) &&
+		 maybeNewCacheDir.equals (getCacheDir()) )
+		return;
+	    worker = new CentralDigestCachedImpl (maybeNewRegistryURL,
+						  maybeNewRegistryNS,
+						  maybeNewCacheDir);
+	}
     }
 
 

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/RegistryPanel.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/RegistryPanel.java	2005/09/25 09:07:22	1.8
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/RegistryPanel.java	2005/10/12 11:17:59	1.9
@@ -77,6 +77,8 @@
     RegistryModel registryModel;
 
     // components that are used from more methods
+    JTextFieldWithHistory registryURL;
+    JTextFieldWithHistory registryNS;
     JFileChooserWithHistory cacheDir;
     JLabel labelCacheDir;
     CommonConsole console;
@@ -115,9 +117,19 @@
 
 	pComponent = new JPanel (new GridBagLayout(), true);
 
+	// registry and cache locations (this must be created before
+	// creating various ontology trees because the trees will need
+	// to know registry and cache locations)
+	JPanel regLocation = getRegistryLocation();
+	JPanel cacheLocation = getCacheLocation();
+
+	// console panel
+	console = new CommonConsole();
+	console.setAppendMode (false);
+
 	// ontology trees
 	ServicesTree servicesTree = new ServicesTree();
-	DataTypesTree dataTypesTree = new DataTypesTree();
+	DataTypesTree dataTypesTree = new DataTypesTree (registryModel, console);
 	dataTypesTree.update (CommonTree.SORTED_BY_NAME);
 	NamespacesTree namespacesTree = new NamespacesTree();
 
@@ -134,10 +146,6 @@
 	split2.setContinuousLayout (true);
 	split2.setOneTouchExpandable (true);
 
-	// console panel
-	console = new CommonConsole();
-	console.setAppendMode (false);
-
 	JSplitPane split3 = new JSplitPane (JSplitPane.VERTICAL_SPLIT,
 					    split2,
 					    console);
@@ -145,11 +153,6 @@
 	split3.setContinuousLayout (true);
 	split3.setOneTouchExpandable (true);
 
-
-	// registry and cache locations
-	JPanel regLocation = getRegistryLocation();
-	JPanel cacheLocation = getCacheLocation();
-
 	// put all together
  	SwingUtils.addComponent (pComponent, split3,                      0, 0, 1, 2, BOTH, NWEST, 1.0, 1.0);
  	SwingUtils.addComponent (pComponent, regLocation,                 1, 0, 1, 1, HORI, NWEST, 0.0, 0.0);
@@ -168,6 +171,8 @@
      *
      **************************************************************************/
     public void onDefaults() {
+	registryURL.setText (registryModel.getDefaultRegistryEndpoint());
+	registryNS.setText (registryModel.getDefaultRegistryNamespace());
     }
 
     /**************************************************************************
@@ -202,11 +207,9 @@
      **************************************************************************/
     protected JPanel getRegistryLocation() {
    	JLabel labelRegistryURL = new JLabel("Endpoint");
-	JTextFieldWithHistory registryURL =
-	    createText ("", "registryEndpoint", DP_REGISTRY_ENDPOINT);
+	registryURL = createText (null, "registryEndpoint", DP_REGISTRY_ENDPOINT);
    	JLabel labelRegistryNS = new JLabel("Namespace (URI)");
-	JTextFieldWithHistory registryNS =
-	    createText ("", "registryNamespace", DP_REGISTRY_NAMESPACE);
+	registryNS = createText (null, "registryNamespace", DP_REGISTRY_NAMESPACE);
 	JButton reloadAllButton =
 	    createButton (" Reload all ",
 			  "Reload all ontology trees from the Biomoby registry",
@@ -307,283 +310,6 @@
 	}
     }
 
-    /**************************************************************************
-     *
-     **************************************************************************/
-    class DataTypesTree extends CommonTree {
-	MobyDataType[] dataTypes = null;
-	int lastSorted = SORTED_BY_NAME;
-	boolean hideBadGuys = false;
-	boolean showMembers = false;
-	JCheckBoxMenuItem hideBox;
-
-	public DataTypesTree() {
-	    super ("DataTypes");
-	    createPopups ("Data Types Menu");
-	}
-
-	protected void createPopups (String title) {
-	    super.createPopups (title);
-	    popup.addSeparator();
-	    popup.add
-		(new JMenuItem (new AbstractAction ("Sort by names") {
-			public void actionPerformed (ActionEvent e) {
-			    update (lastSorted = SORTED_BY_NAME);
-			    hideBox.setEnabled (true);
-			}
-		    }));
-	    popup.add
-		(new JMenuItem (new AbstractAction ("Sort by authorities") {
-			public void actionPerformed (ActionEvent e) {
-			    update (lastSorted = SORTED_BY_AUTHORITY);
-			    hideBox.setEnabled (false);
-			}
-		    }));
-	    popup.addSeparator();
-
-	    JCheckBoxMenuItem showBox = new JCheckBoxMenuItem ("Show HAS/HASA members");
-	    showBox.addItemListener (new ItemListener() {
-		    public void itemStateChanged  (ItemEvent e) {
-			showMembers = (e.getStateChange() == ItemEvent.SELECTED);
-			update (lastSorted);
-		    }
-		});
-	    popup.add (showBox);
-
-	    hideBox = new JCheckBoxMenuItem ("Hide deprecated objects");
-	    hideBox.addItemListener (new ItemListener() {
-		    public void itemStateChanged  (ItemEvent e) {
-			hideBadGuys = (e.getStateChange() == ItemEvent.SELECTED);
-			if (hideBadGuys)
-			    removeBadGuys();
-			else
-			    update (lastSorted);
-		    }
-		});
-	    popup.add (hideBox);
-	}
-
-	void update (int howSorted) {
-	    popup.setEnabled (false);
-	    final int sorted = howSorted;
-	    final SwingWorker worker = new SwingWorker() {
-		    public Object construct() {
-			try {
-			    if (sorted == SORTED_BY_AUTHORITY)
-				dataTypes = registryModel.getDataTypesByAuthority();
-			    else
-				dataTypes = registryModel.getDataTypesByNames();
-			} catch (MobyException e) {
-			    // TBD: what to do here?
-			    System.err.println ("ERROR: " + e.getMessage());
-			}
-			return dataTypes;  // not used here
-		    }
-
-		    // runs on the event-dispatching thread.
-		    public void finished() {
-			if (dataTypes != null) {
-			    if (sorted == SORTED_BY_AUTHORITY)
-				onUpdateDataTreeByAuth (dataTypes);
-			    else
-				onUpdateDataTree (dataTypes);
-			    popup.setEnabled (true);
-			}
-		    }
-		};
-	    worker.start(); 
-	}
-
-	void onUpdateDataTree (MobyDataType[] dataTypes) {
-	    DefaultTreeModel tModel = (DefaultTreeModel)getModel();
-	    DefaultMutableTreeNode root = (DefaultMutableTreeNode)tModel.getRoot();
-	    root.removeAllChildren();   // does not harm if no children exist
-	    HashMap nodes = new HashMap (dataTypes.length);
-	    for (int i = 0; i < dataTypes.length; i++) {
-		String thisName = dataTypes[i].getName();
-		DefaultMutableTreeNode thisNode = (DefaultMutableTreeNode)nodes.get (thisName);
-		if (thisNode == null) {
-		    thisNode = new DefaultMutableTreeNode (new CommonNode (thisName));
-		    nodes.put (thisName, thisNode);
-		}
-		String[] parents = dataTypes[i].getParentNames();
-		if (parents.length == 0) {   // we have a top-level object
-		    root.add (thisNode);
-		} else {
-		    String parentName = parents[0];
-		    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)nodes.get (parentName);
-		    if (parentNode == null) {
-			parentNode = new DefaultMutableTreeNode (new CommonNode (parentName));
-			nodes.put (parentName, parentNode);
-		    }
-		    if (showMembers)
-			addMembers (thisNode, dataTypes[i]);
-		    parentNode.add (thisNode);
-		}
-	    }
-	    if (hideBadGuys)
-		removeBadGuys();
-	    else
-		tModel.reload();
-	}
-
-
-	void onUpdateDataTreeByAuth (MobyDataType[] dataTypes) {
-	    DefaultTreeModel tModel = (DefaultTreeModel)getModel();
-	    DefaultMutableTreeNode root = (DefaultMutableTreeNode)tModel.getRoot();
-	    root.removeAllChildren();   // does not harm if no children exist
-	    HashMap nodes = new HashMap (dataTypes.length);
-	    for (int i = 0; i < dataTypes.length; i++) {
-		String thisName = dataTypes[i].getName();
-		DefaultMutableTreeNode thisNode = (DefaultMutableTreeNode)nodes.get (thisName);
-		if (thisNode == null) {
-		    thisNode = new DefaultMutableTreeNode (new CommonNode (thisName));
-		    nodes.put (thisName, thisNode);
-		}
-		String authority = dataTypes[i].getAuthority();
-		if (UUtils.isEmpty (authority))
-		    authority = "<unknown>";
-		DefaultMutableTreeNode authNode = (DefaultMutableTreeNode)nodes.get (authority);
-		if (authNode == null) {
-		    authNode = new DefaultMutableTreeNode (new CommonNode (authority));
-		    nodes.put (authority, authNode);
-		    root.add (authNode);
-		}
-		if (showMembers)
-		    addMembers (thisNode, dataTypes[i]);
-		authNode.add (thisNode);
-	    }
-	    tModel.reload();
-	}
-
-	void removeBadGuys() {
-	    DefaultTreeModel tModel = (DefaultTreeModel)getModel();
-	    DefaultMutableTreeNode root = (DefaultMutableTreeNode)tModel.getRoot();
-	 
-	    Vector removeFromParent = new Vector();   // nodes that will be removed   
-	    Vector removeAllChildren = new Vector();  // nodes whose children will be removed
-	    for (Enumeration en = root.children(); en.hasMoreElements(); ) {
-		DefaultMutableTreeNode node = (DefaultMutableTreeNode)en.nextElement();
-		String value = ((CommonNode)node.getUserObject()).getValue();
-		if (value.equals ("Object")) {
-		    // primitive type should not have children
-		    for (Enumeration en2 = node.children(); en2.hasMoreElements(); ) {
-			DefaultMutableTreeNode node2 = (DefaultMutableTreeNode)en2.nextElement();
-			String value2 = ((CommonNode)node2.getUserObject()).getValue();
-			if (DataTypesGenerator.isPrimitiveType (value2))
-			    removeAllChildren.addElement (node2);
-		    }
-		} else {
-		    // only Object can be a root object
-		    removeFromParent.addElement (node);
-		}
-	    }
-	    for (Enumeration en = removeFromParent.elements(); en.hasMoreElements(); ) {
-		DefaultMutableTreeNode node = (DefaultMutableTreeNode)en.nextElement();
-		node.removeFromParent();
-	    }
-	    for (Enumeration en = removeAllChildren.elements(); en.hasMoreElements(); ) {
-		DefaultMutableTreeNode node = (DefaultMutableTreeNode)en.nextElement();
-		node.removeAllChildren();
-	    }
-	    tModel.reload();
-	}
-
-	void addMembers (DefaultMutableTreeNode node, MobyDataType dataType) {
-	    MobyRelationship[] rels = dataType.getChildren();
-	    for (int i = 0; i < rels.length; i++) {
-		String memberName = rels[i].getName();
-		String memberType = rels[i].getDataTypeName();
-		int memberRel = rels[i].getRelationshipType();
-		node.add (new DefaultMutableTreeNode (new MemberNode (rels[i])));
-	    }
-	}
-
-	/*********************************************************************
-	 * Search underlying objects and highligh nodes corresponding to
-	 * the found objects.
-	 ********************************************************************/
-	protected void search (String searchText) {
-	    final String regex = searchText;
-	    final SwingWorker worker = new SwingWorker() {
-		    HashSet found = new HashSet();
-		    public Object construct() {
-			try {
-			    if (UUtils.notEmpty (regex))
-				found = registryModel.find (regex);
-			} catch (MobyException e) {
-			    // TBD: what to do here?
-			    System.err.println ("ERROR: " + e.getMessage());
-			}
-			return found;  // not used here
-		    }
-
-		    // runs on the event-dispatching thread.
-		    public void finished() {
-			if (found != null)
-			    highlightAndJumpTo (found);
-		    }
-		};
-	    worker.start(); 
-	}
-
-	/*********************************************************************
-	 *
-	 ********************************************************************/
-	protected void selected (DefaultMutableTreeNode node) {
- 	    final CommonNode nodeObject = (CommonNode)node.getUserObject();
-	    final SwingWorker worker = new SwingWorker() {
-		    MobyDataType dataType;
-		    public Object construct() {
-			try {
-			    dataType = registryModel.getDataType (nodeObject.getValue());
-			} catch (MobyException e) {
-			    // TBD: what to do here?
-			    System.err.println ("ERROR: " + e.getMessage());
-			}
-			return dataType;  // not used here
-		    }
-
-		    // runs on the event-dispatching thread.
-		    public void finished() {
-			if (dataType != null)
-// 			    System.out.println (dataType);
-			    console.setText (dataType.toString());
-		    }
-		};
-	    worker.start(); 
-	}
-
-	class MemberNode extends CommonNode {
-	    MobyRelationship rel;
-	    public MemberNode (MobyRelationship rel) {
-		this.rel = rel;
-	    }
-	    public String getValue() {
-		return rel.getDataTypeName();
-	    }
-	    public String toString() {
-		String memberName = rel.getName();
-		String memberType = rel.getDataTypeName();
-		int memberRel = rel.getRelationshipType();
-		StringBuffer buf = new StringBuffer (100);
-		buf.append ("<html><b>");
-		buf.append (memberRel == Central.iHAS ? "HAS" : "HASA");
-		buf.append (": </b>");
-		buf.append (memberType);
-		if (UUtils.notEmpty (memberName)) {
-		    buf.append (" (<font color='blue'>");
-		    buf.append (memberName);
-		    buf.append ("</font>)");
-		}
-		return buf.toString();
-	    }
-	}
-
-
-    }
-
-
 
     /**************************************************************************
      *




More information about the MOBY-guts mailing list