[MOBY-guts] biomoby commit

Eddie Kawas kawas at dev.open-bio.org
Wed Jun 4 16:03:04 UTC 2008


kawas
Wed Jun  4 12:03:04 EDT 2008
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard
In directory dev.open-bio.org:/tmp/cvs-serv1758/src/main/org/biomoby/service/dashboard

Modified Files:
	PerlMoSeSPanel.java 
Log Message:
* no longer use the perl moses version from the cvs; require that user has installed module MOSES::MOBY from cpan (or from cvs) first.
some ui changes
* removed sync panel. from now on sync is done in the back ground
* removed the editor tab and moved it to a toolbar on the editor pane
* removed the panels tab pane
* moved the console window to be below the editor pane and always visible
moby-live/Java/src/main/org/biomoby/service/dashboard PerlMoSeSPanel.java,1.9,1.10
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/PerlMoSeSPanel.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/PerlMoSeSPanel.java	2008/06/02 22:29:29	1.9
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/PerlMoSeSPanel.java	2008/06/04 16:03:04	1.10
@@ -3,7 +3,6 @@
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Event;
-import java.awt.FlowLayout;
 import java.awt.Font;
 import java.awt.GraphicsEnvironment;
 import java.awt.GridBagLayout;
@@ -30,6 +29,7 @@
 import javax.swing.AbstractButton;
 import javax.swing.BorderFactory;
 import javax.swing.Box;
+import javax.swing.BoxLayout;
 import javax.swing.ButtonGroup;
 import javax.swing.Icon;
 import javax.swing.JButton;
@@ -43,8 +43,8 @@
 import javax.swing.JRadioButton;
 import javax.swing.JScrollPane;
 import javax.swing.JSplitPane;
-import javax.swing.JTabbedPane;
 import javax.swing.JTextPane;
+import javax.swing.JToolBar;
 import javax.swing.KeyStroke;
 import javax.swing.SwingConstants;
 import javax.swing.border.Border;
@@ -59,6 +59,9 @@
 
 import org.apache.commons.io.FilenameUtils;
 import org.biomoby.shared.MobyException;
+import org.biomoby.shared.event.NotificationEvent;
+import org.biomoby.shared.event.NotificationListener;
+import org.biomoby.shared.event.Notifier;
 import org.tulsoft.tools.gui.JTextFieldWithHistory;
 import org.tulsoft.tools.gui.SwingUtils;
 
@@ -83,12 +86,6 @@
     // boolean do we generate soap services
     static String PM_SOAP = "perl-moses-soap";
 
-    // boolean: do we update the service cache
-    static String PM_UPDATE_SERVICE_CACHE = "perl-moses-update-service-cache";
-
-    // boolean: do we update the datatype cache
-    static String PM_UPDATE_DATATYPE_CACHE = "perl-moses-update-datatype-cache";
-
     // boolean: are we currently updating the datatype cache
     static String PM_SYNC_DATATYPES = "perl-moses-sync-datatypes";
 
@@ -143,13 +140,13 @@
 
     private JLabel aSelectedCount, sSelectedCount, currentlyEditing;
 
-    private JButton editorSaveButton, editorCloseButton, editorOpenButton, scriptsBtn, generateBtn, syncBtn;
+    private JButton editorSaveButton, editorCloseButton, editorOpenButton, scriptsBtn, generateBtn;
 
     // are we enabling moses actions
     private boolean enable_moses_actions = true;
 
     // is the user running windows
-    private boolean is_windows_pc = false, not_installed = false;
+    private boolean is_windows_pc = false;
 
     private Icon openFileIcon, openFileIconDis, closeFileIcon,
     		 closeFileIconDis, saveFileIcon, saveFileIconDis, 
@@ -159,6 +156,14 @@
     
     private JComboBox fonts;
     
+    /*
+     * The following strings are error messages that perl-moses produces when a 
+     * cache needs to be created and updates fail
+     */
+    private String SERVICE_CACHE_DOESNT_EXIST = "Please create a services cache first!";
+    
+    private String DATATYPE_CACHE_DOESNT_EXIST = "Please create a datatype cache first!";
+    
     /**
      * Default constructor: set the image, and determines 
      * whether or not we are using windows
@@ -174,36 +179,7 @@
 	
 	// set up some default values
 	if (!enable_moses_actions){
-	    File dir = AntModel.createFileName(
-		    new String[]{
-			    System.getProperty ("user.dir"), 
-			    "..", 
-			    "Perl",
-			    "MOSES-MOBY"}
-	    );
 	    String s = "";
-	    if (dir.exists() && dir.isDirectory()) {
-		File f = new File(dir, "lib");
-		// here, we set all values or none of them
-		if (f.exists() && f.isDirectory()) {
-		    s = getPrefValue(PM_PERL_LIB_1, "");
-		    if (s.equals("")) {
-		        // never has been set - set it to cvs path
-		        setPrefValue(PM_PERL_LIB_1, f.getPath());
-		    }
-		    // ignore PM_PERL_LIB_2
-		    f = new File(dir, "bin");
-		    if (f.exists() && f.isDirectory()) {
-			f = new File(f, "scripts");
-			if (f.exists() && f.isDirectory()) {
-			    s = getPrefValue(PM_SCRIPTS_INSTALL_DIR, "");
-			    if (s.equals("")) {
-				setPrefValue(PM_SCRIPTS_INSTALL_DIR, f.getPath());
-			    }
-			}
-		    }
-		}
-	    }
 	    // this value can be set irregardless of the others
 	    s = getPrefValue(PM_PERL_INSTALL_DIR, "");
 	    if (s.equals(""))
@@ -342,8 +318,8 @@
 		    return;
 		}
 		if (e.getPropertyName().equals(PM_INFORMATION)) {
-		    JOptionPane.showMessageDialog(null, e.getNewValue(),
-			    "Information", JOptionPane.INFORMATION_MESSAGE);
+		   /* JOptionPane.showMessageDialog(null, e.getNewValue(),
+			    "Information", JOptionPane.INFORMATION_MESSAGE);*/
 		    console.setText("Information:" + e.getNewValue().toString()
 			    + "\n");
 		    return;
@@ -361,11 +337,28 @@
 		    doCloseFile();
 		    return;
 		}
-
 	    }
 	});
+	
 	registryModel = createRegistryModel();
-
+	registryModel.addNotificationListener(new NotificationListener() {
+	    public void notified(NotificationEvent e) {
+		if (e.getType() == Notifier.AUTHORITIES_UPDATED) {
+		    if (enable_moses_actions && !getPropertyChannel().getBoolean(PM_SYNC_SERVICES, false)) {
+			getPropertyChannel().put(PM_SYNC_SERVICES, true);
+			onUpdateServiceCache();
+			return;
+		    }
+		}
+		
+		if (enable_moses_actions && e.getType() == Notifier.DATA_TYPES_UPDATED) {
+		    if (!getPropertyChannel().getBoolean(PM_SYNC_DATATYPES, false)) {
+			getPropertyChannel().put(PM_SYNC_DATATYPES, true);
+		    	onUpdateDatatypeCache();
+		    	return;
+		    }
+		}
+	    }});
 	if (pComponent != null)
 	    return pComponent;
 	pComponent = new JPanel(new GridBagLayout(), true);
@@ -400,6 +393,9 @@
 	
     }
 
+    private final PropertyChannel getPropertyChannel() {
+	return this.propertyChannel;
+    }
     private JPanel getMoSeSPanel() {
 	
 	JPanel p = new JPanel (new GridBagLayout());
@@ -410,7 +406,7 @@
 	JPanel sPanel = createTitledPanel("Local User Config");
 	if (!enable_moses_actions) {
 	       scriptsBtn = createButton(
-		    "Test user config",
+		    "Confirm values are correct",
 		    "Check whether or not your local user config is correct",
 		    KeyEvent.VK_R, new ActionListener() {
 			public void actionPerformed(ActionEvent e) {
@@ -424,11 +420,16 @@
 				    user_check_install();
 				    if (enable_moses_actions) {
 					// we are good to go! enable buttons
-					syncBtn.setEnabled(enable_moses_actions);
-					generateBtn.setEnabled(enable_moses_actions);
-					scriptsBtn.setEnabled(!enable_moses_actions);
 					propertyChannel.fire(PM_INFORMATION, "Your local configuration was successful!");
-					
+					if (enable_moses_actions && !getPropertyChannel().getBoolean(PM_SYNC_SERVICES, false)) {
+					    getPropertyChannel().put(PM_SYNC_SERVICES, true);
+					    onUpdateServiceCache();
+					}
+					if (!getPropertyChannel().getBoolean(PM_SYNC_DATATYPES, false)) {
+					    getPropertyChannel().put(PM_SYNC_DATATYPES, true);
+					    onUpdateDatatypeCache();
+					}
+					scriptsBtn.setEnabled(!enable_moses_actions);
 				    } else {
 					// alert them that this directory didnt
 					// contain anything useful
@@ -486,7 +487,6 @@
 			    return;
 			}
 			generateBtn.setEnabled(false);
-			syncBtn.setEnabled(false);
 			propertyChannel.fire(DP_STATUS_MSG,
 				"Processing MoSeS skeletons...");
 			if (propertyChannel
@@ -519,120 +519,11 @@
 	SwingUtils.addComponent(bPanel, genSoap,      0, 2, 2, 1, NONE, NWEST, 0.0, 0.0);
 	SwingUtils.addComponent(bPanel, generateBtn,  0, 3, 2, 1, HORI, NWEST, 0.0, 0.0);
 
-	JPanel uPanel = createTitledPanel("Utilities");
-	JCheckBox syncServices = createActionBox("Synchronize Services",
-		PM_UPDATE_SERVICE_CACHE);
-	JCheckBox syncDatatypes = createActionBox("Synchronize Datatypes",
-		PM_UPDATE_DATATYPE_CACHE);
-
-	syncBtn = createButton("Synchronize",
-		"Synchronize the Perl-MoSeS caches with Dashboard\'s cache",
-		KeyEvent.VK_Z, new ActionListener() {
-		    public void actionPerformed(ActionEvent e) {
-			boolean syncData = propertyChannel.getBoolean(
-				PM_UPDATE_DATATYPE_CACHE, false);
-			boolean syncServices = propertyChannel.getBoolean(
-				PM_UPDATE_SERVICE_CACHE, false);
-
-			if (syncData || syncServices) {
-			    generateBtn.setEnabled(false);
-			    syncBtn.setEnabled(false);
-			    if (syncData) {
-				propertyChannel.put(PM_SYNC_DATATYPES, true);
-				onUpdateDatatypeCache();
-			    }
-			    if (syncServices) {
-				propertyChannel.put(PM_SYNC_SERVICES, true);
-				onUpdateServiceCache();
-			    }
-			}
-		    }
-		});
-	syncBtn.setEnabled(enable_moses_actions);
-	
-	SwingUtils.addComponent(uPanel, syncServices,  0, 0, 1, 1, NONE, NWEST, 0.0, 0.0);
-	SwingUtils.addComponent(uPanel, syncDatatypes, 0, 1, 1, 1, NONE, NWEST, 0.0, 0.0);
-	SwingUtils.addComponent(uPanel, syncBtn,       0, 2, 1, 1, HORI, NWEST, 0.0, 0.0);
-
-	JPanel ePanel = createTitledPanel("Editor");
-	
-	editorOpenButton = new JButton("Open", openFileIcon);
-	editorOpenButton.setIcon(openFileIcon);
-	editorOpenButton.setDisabledIcon(openFileIconDis);
-	editorOpenButton.setVerticalTextPosition(AbstractButton.BOTTOM);
-	editorOpenButton.setHorizontalTextPosition(AbstractButton.CENTER);
-	editorOpenButton.addActionListener(new ActionListener() {
-	    public void actionPerformed(ActionEvent e) {
-		String path = propertyChannel.getString(PM_FILE_LAST_DIRECTORY);
-		JFileChooser openFile;
-		// provide a history
-		if (path == null)
-		    openFile = new JFileChooser();
-		else 
-		    openFile = new JFileChooser(path);
-		
-		openFile.setDialogTitle("Open a Perl-MoSeS impl file");
-		openFile.setApproveButtonText("Open script");
-		openFile.setFileSelectionMode(JFileChooser.FILES_ONLY);
-		openFile.addChoosableFileFilter(new FileFilter() {
-		    @Override
-		    public boolean accept(File f) {
-			if (f.isDirectory())
-			    return true;
-			String extension = FilenameUtils.getExtension(f.getName());
-			return ("pm".equalsIgnoreCase(extension)
-				|| "pl".equalsIgnoreCase(extension) 
-				|| "cgi".equalsIgnoreCase(extension));
-		    }
-		    @Override
-		    public String getDescription() {
-			return "Perl files";
-		    }
-		});
-		int doOpen = openFile.showOpenDialog(null);
-		if (doOpen == JFileChooser.APPROVE_OPTION) {
-		    propertyChannel.fire(PM_FILE_ACTION_OPEN, openFile.getSelectedFile().getPath());
-		}
-	    }
-	});
-	
-	editorSaveButton = new JButton("Save", saveFileIcon);
-	editorSaveButton.setIcon(saveFileIcon);
-	editorSaveButton.setDisabledIcon(saveFileIconDis);
-	editorSaveButton.setVerticalTextPosition(AbstractButton.BOTTOM);
-	editorSaveButton.setHorizontalTextPosition(AbstractButton.CENTER);
-	editorSaveButton.addActionListener(new ActionListener() {
-	    public void actionPerformed(ActionEvent e) {
-		propertyChannel.fire(PM_FILE_ACTION_SAVE, "");
-	    }
-	});
-
-	editorCloseButton = new JButton("Close", closeFileIcon);
-	editorCloseButton.setIcon(closeFileIcon);
-	editorCloseButton.setDisabledIcon(closeFileIconDis);
-	editorCloseButton.setVerticalTextPosition(AbstractButton.BOTTOM);
-	editorCloseButton.setHorizontalTextPosition(AbstractButton.CENTER);
-	editorCloseButton.addActionListener(new ActionListener() {
-	    public void actionPerformed(ActionEvent e) {
-		propertyChannel.fire(PM_FILE_ACTION_CLOSE, "");
-	    }
-	});
-	// initially open is enabled, close and save are not
-	editorOpenButton.setEnabled(true);
-	editorCloseButton.setEnabled(false);
-	editorSaveButton.setEnabled(false);
-			
-	SwingUtils.addComponent(ePanel, editorOpenButton,  0, 0, 1, 1, NONE, NWEST, 0.0, 0.0);
-	SwingUtils.addComponent(ePanel, editorSaveButton,  1, 0, 1, 1, NONE, NWEST, 0.0, 0.0);
-	SwingUtils.addComponent(ePanel, editorCloseButton, 2, 0, 1, 1, NONE, NWEST, 0.0, 0.0);	
-
 	// add to the main panel
 	int count = 0;
 	if (!enable_moses_actions)
 	    SwingUtils.addComponent(p, sPanel, 0, count++, 2, 1, HORI, NWEST, 0.0, 0.0);    
 	SwingUtils.addComponent(p, bPanel, 0, count++,     2, 1, HORI, NWEST, 0.0, 0.0);
-	SwingUtils.addComponent(p, uPanel, 0, count++,     2, 1, HORI, NWEST, 0.0, 0.0);
-	SwingUtils.addComponent(p, ePanel, 0, count++,     2, 1, HORI, NWEST, 0.0, 0.0);
 		
 	return p;
 
@@ -698,7 +589,7 @@
 	Border blackline = BorderFactory.createLineBorder(Color.black);
 	CompoundBorder compoundBorder = BorderFactory.createCompoundBorder(
 		BorderFactory.createTitledBorder(blackline,
-			"Perl-MoSeS: Impl Editor"), BorderFactory
+			"Perl-MoSeS: Editor"), BorderFactory
 			.createEmptyBorder(5, 5, 5, 5));
 	p.setBorder(compoundBorder);
 	
@@ -744,7 +635,8 @@
     }
     private JComponent getFontChooser() {
 	JLabel label = new JLabel("Font:");
-	JPanel panel = new JPanel(new FlowLayout());
+	JToolBar toolbar = new JToolBar("Editor");
+	toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
 	
 	// get all the fonts available
 	GraphicsEnvironment env =
@@ -783,7 +675,7 @@
 	    }
 	    
 	});
-	
+	fonts.setPreferredSize(fonts.getMinimumSize());
 	// create a zoom in button
 	JButton zoomInButton = AbstractPanel.createButton
 	    ("",
@@ -814,13 +706,89 @@
 	zoomOutButton.setDisabledIcon (zoomOutIconDis);
 	SwingUtils.compact (zoomOutButton);
 	
-	// add the font chooser and zoom buttons to the panel
-	panel.add(label);
-	panel.add(fonts);
-	panel.add(zoomInButton);
-	panel.add(zoomOutButton);
-	panel.add(Box.createHorizontalGlue());
-	return panel;
+	//JPanel ePanel = createTitledPanel("File");
+	
+	editorOpenButton = new JButton("Open", openFileIcon);
+	editorOpenButton.setIcon(openFileIcon);
+	editorOpenButton.setDisabledIcon(openFileIconDis);
+	editorOpenButton.setVerticalTextPosition(AbstractButton.BOTTOM);
+	editorOpenButton.setHorizontalTextPosition(AbstractButton.CENTER);
+	editorOpenButton.addActionListener(new ActionListener() {
+	    public void actionPerformed(ActionEvent e) {
+		String path = propertyChannel.getString(PM_FILE_LAST_DIRECTORY);
+		JFileChooser openFile;
+		// provide a history
+		if (path == null)
+		    openFile = new JFileChooser();
+		else 
+		    openFile = new JFileChooser(path);
+		
+		openFile.setDialogTitle("Open a Perl Scrip:");
+		openFile.setApproveButtonText("Open script");
+		openFile.setFileSelectionMode(JFileChooser.FILES_ONLY);
+		openFile.addChoosableFileFilter(new FileFilter() {
+		    @Override
+		    public boolean accept(File f) {
+			if (f.isDirectory())
+			    return true;
+			String extension = FilenameUtils.getExtension(f.getName());
+			return ("pm".equalsIgnoreCase(extension)
+				|| "pl".equalsIgnoreCase(extension) 
+				|| "cgi".equalsIgnoreCase(extension));
+		    }
+		    @Override
+		    public String getDescription() {
+			return "Perl scripts";
+		    }
+		});
+		int doOpen = openFile.showOpenDialog(null);
+		if (doOpen == JFileChooser.APPROVE_OPTION) {
+		    propertyChannel.fire(PM_FILE_ACTION_OPEN, openFile.getSelectedFile().getPath());
+		}
+	    }
+	});
+	
+	editorSaveButton = new JButton("Save", saveFileIcon);
+	editorSaveButton.setIcon(saveFileIcon);
+	editorSaveButton.setDisabledIcon(saveFileIconDis);
+	editorSaveButton.setVerticalTextPosition(AbstractButton.BOTTOM);
+	editorSaveButton.setHorizontalTextPosition(AbstractButton.CENTER);
+	editorSaveButton.addActionListener(new ActionListener() {
+	    public void actionPerformed(ActionEvent e) {
+		propertyChannel.fire(PM_FILE_ACTION_SAVE, "");
+	    }
+	});
+
+	editorCloseButton = new JButton("Close", closeFileIcon);
+	editorCloseButton.setIcon(closeFileIcon);
+	editorCloseButton.setDisabledIcon(closeFileIconDis);
+	editorCloseButton.setVerticalTextPosition(AbstractButton.BOTTOM);
+	editorCloseButton.setHorizontalTextPosition(AbstractButton.CENTER);
+	editorCloseButton.addActionListener(new ActionListener() {
+	    public void actionPerformed(ActionEvent e) {
+		propertyChannel.fire(PM_FILE_ACTION_CLOSE, "");
+	    }
+	});
+	// initially open is enabled, close and save are not
+	editorOpenButton.setEnabled(true);
+	editorCloseButton.setEnabled(false);
+	editorSaveButton.setEnabled(false);
+			
+	// add the font chooser, file and zoom buttons to the panel
+	toolbar.add(editorOpenButton);
+	toolbar.add(editorSaveButton);
+	toolbar.add(editorCloseButton);
+	toolbar.addSeparator();
+	toolbar.add(label);
+	toolbar.addSeparator();
+	toolbar.add(fonts);
+	toolbar.addSeparator();
+	toolbar.add(zoomInButton);
+	toolbar.add(zoomOutButton);
+	toolbar.add(Box.createGlue());
+	Box b = Box.createHorizontalBox();
+	SwingUtils.addComponent(b, toolbar,          0, 0, 1, 1, NONE, WEST, 0.0, 0.0);
+	return b;
     }
 
     private JRadioButton createHowToButton (String title, String howTo) {
@@ -891,49 +859,63 @@
     private void onUpdateDatatypeCache() {
 	final SwingWorker worker = new SwingWorker() {
 	    MobyException exception = null;
-
+	    boolean updateFailed = false;
+	    
 	    public Object construct() {
+		generateBtn.setEnabled(false);
 		propertyChannel.fire(DP_STATUS_MSG,
 			"Synchronizing Perl-MoSeS Datatype Cache...");
 		console.setEnabledAppendMode(false);
 		ArrayList<String> command = new ArrayList<String>();
 		// update the moses cache first ...
 		Process p;
+		StringBuffer inputstream = new StringBuffer();
+		StringBuffer errorstream = new StringBuffer();
 		try {
-		    // empty the command list
-		    command = new ArrayList<String>();
-		    command.addAll(generatePerlPrefix());
-		    String s = (command.size() > 0 ? command.remove(command.size()-1) : "") ;
-		    
-		    // construct the command
-		    command.add(is_windows_pc ?  "moses-generate-datatypes.bat"
-			    : s + "moses-generate-datatypes.pl");
-		    command.add("-R");
-		    command
-			    .add(propertyChannel
-				    .getString(DashboardProperties.DP_REGISTRY_ENDPOINT));
-		    command.add("-f");
-		    // place command into com
-		    String[] com = command.toArray(new String[] {});
-
-		    // execute the command
-		    p = Runtime.getRuntime().exec(com);
-		    BufferedReader br = new BufferedReader(
-			    new InputStreamReader(p.getInputStream()));
-		    String line = null;
-		    while ((line = br.readLine()) != null) {
-			console.setText(line
-				+ System.getProperty("line.separator"));
+		    for (int x = 0; x < 2; x++) {
+        		    inputstream = new StringBuffer();
+        		    errorstream = new StringBuffer();
+        		    // empty the command list
+        		    command = new ArrayList<String>();
+        		    command.addAll(generatePerlPrefix());
+        		    String s = (command.size() > 0 ? command.remove(command.size()-1) : "") ;
+        		    
+        		    // construct the command
+        		    command.add(is_windows_pc ?  "moses-generate-datatypes.bat"
+        			    : s + "moses-generate-datatypes.pl");
+        		    command.add("-R");
+        		    command
+        			    .add(propertyChannel
+        				    .getString(DashboardProperties.DP_REGISTRY_ENDPOINT));
+        		    command.add(updateFailed ? "-f" : "-u");
+        		    // place command into com
+        		    String[] com = command.toArray(new String[] {});
+        
+        		    // execute the command
+        		    p = Runtime.getRuntime().exec(com);
+        		    BufferedReader br = new BufferedReader(
+        			    new InputStreamReader(p.getInputStream()));
+        		    String line = null;
+        		    while ((line = br.readLine()) != null) {
+        			inputstream.append(line
+        				+ System.getProperty("line.separator"));
+        		    }
+        		    BufferedReader errorBr = new BufferedReader(
+        			    new InputStreamReader(p.getErrorStream()));
+        		    line = null;
+        		    while ((line = errorBr.readLine()) != null) {
+        			errorstream.append(line
+        				+ System.getProperty("line.separator"));
+        		    }
+        		    p.waitFor();
+        		    if (
+        			    inputstream.toString().indexOf(DATATYPE_CACHE_DOESNT_EXIST) > 0 || 
+        			    errorstream.toString().indexOf(DATATYPE_CACHE_DOESNT_EXIST) > 0) {
+        			updateFailed = true;
+        		    } else {
+        			break;
+        		    }
 		    }
-		    BufferedReader errorBr = new BufferedReader(
-			    new InputStreamReader(p.getErrorStream()));
-		    line = null;
-		    while ((line = errorBr.readLine()) != null) {
-			console.setText(line
-				+ System.getProperty("line.separator"));
-		    }
-		    p.waitFor();
-
 		} catch (IOException ioe) {
 		    exception = new MobyException(
 			    "There was a problem synchronizing the datatype cache(x001):\n" + ioe.getMessage(),
@@ -943,6 +925,8 @@
 			    "There was a problem synchronizing the datatype cache(x002)\n: + ie.getMessage()",
 			    ie);
 		}
+		console.setText(inputstream.toString());
+		console.setText(errorstream.toString());
 		return null; // not used here
 	    }
 
@@ -959,7 +943,6 @@
 				
 		if (!(propertyChannel.getBoolean(PM_SYNC_DATATYPES, false) || propertyChannel
 			.getBoolean(PM_SYNC_SERVICES, false))) {
-		    syncBtn.setEnabled(true);
 		    generateBtn.setEnabled(true);
 		}
 		
@@ -971,48 +954,62 @@
     private void onUpdateServiceCache() {
 	final SwingWorker worker = new SwingWorker() {
 	    MobyException exception = null;
-
+	    boolean updateFailed = false;
+	    
 	    public Object construct() {
 		propertyChannel.fire(DP_STATUS_MSG,
 			"Synchronizing Perl-MoSeS Service Cache...");
+		generateBtn.setEnabled(false);
 		console.setEnabledAppendMode(false);
 		ArrayList<String> command = new ArrayList<String>();
 		// update the moses cache first ...
 		Process p;
+		StringBuffer inputstream = new StringBuffer();
+		StringBuffer errorstream = new StringBuffer();
 		try {
-		    // empty the command list
-		    command = new ArrayList<String>();
-		    command.addAll(generatePerlPrefix());
-		    String s = (command.size() > 0 ? command.remove(command.size()-1) : "") ;
-		    // construct the command
-		    command.add(is_windows_pc ?  "moses-generate-services.bat"
-			    : s +  "moses-generate-services.pl");
-		    command.add("-R");
-		    command
-			    .add(propertyChannel
-				    .getString(DashboardProperties.DP_REGISTRY_ENDPOINT));
-		    command.add("-f");
-		    // place command into com
-		    String[] com = command.toArray(new String[] {});
-
-		    // execute the command
-		    p = Runtime.getRuntime().exec(com);
-		    BufferedReader br = new BufferedReader(
-			    new InputStreamReader(p.getInputStream()));
-		    String line = null;
-		    while ((line = br.readLine()) != null) {
-			console.setText(line
-				+ System.getProperty("line.separator"));
-		    }
-		    BufferedReader errorBr = new BufferedReader(
-			    new InputStreamReader(p.getErrorStream()));
-		    line = null;
-		    while ((line = errorBr.readLine()) != null) {
-			console.setText(line
-				+ System.getProperty("line.separator"));
+		    for (int x = 0; x < 2; x++) {
+        		    inputstream = new StringBuffer();
+        		    errorstream = new StringBuffer();
+        		    // empty the command list
+        		    command = new ArrayList<String>();
+        		    command.addAll(generatePerlPrefix());
+        		    String s = (command.size() > 0 ? command.remove(command.size()-1) : "") ;
+        		    // construct the command
+        		    command.add(is_windows_pc ?  "moses-generate-services.bat"
+        			    : s +  "moses-generate-services.pl");
+        		    command.add("-R");
+        		    command
+        			    .add(propertyChannel
+        				    .getString(DashboardProperties.DP_REGISTRY_ENDPOINT));
+        		    command.add(updateFailed ? "-f" : "-u");
+        		    // place command into com
+        		    String[] com = command.toArray(new String[] {});
+        
+        		    // execute the command
+        		    p = Runtime.getRuntime().exec(com);
+        		    BufferedReader br = new BufferedReader(
+        			    new InputStreamReader(p.getInputStream()));
+        		    String line = null;
+        		    while ((line = br.readLine()) != null) {
+        			inputstream.append(line
+        				+ System.getProperty("line.separator"));
+        		    }
+        		    BufferedReader errorBr = new BufferedReader(
+        			    new InputStreamReader(p.getErrorStream()));
+        		    line = null;
+        		    while ((line = errorBr.readLine()) != null) {
+        			errorstream.append(line
+        				+ System.getProperty("line.separator"));
+        		    }
+        		    p.waitFor();
+        		    if (
+        			    inputstream.toString().indexOf(SERVICE_CACHE_DOESNT_EXIST) > 0 || 
+        			    errorstream.toString().indexOf(SERVICE_CACHE_DOESNT_EXIST) > 0) {
+        			updateFailed = true;
+        		    } else {
+        			break;
+        		    }
 		    }
-		    p.waitFor();
-
 		} catch (IOException ioe) {
 		    exception = new MobyException(
 			    "There was a problem synchronizing the service cache(x001):\n" + ioe.getMessage(),
@@ -1022,6 +1019,8 @@
 			    "There was a problem synchronizing the service cache(x002):\n" + ie.getMessage(),
 			    ie);
 		}
+		console.setText(inputstream.toString());
+		console.setText(errorstream.toString());
 		return null; // not used here
 	    }
 
@@ -1038,7 +1037,6 @@
 			propertyChannel.getBoolean(PM_SYNC_DATATYPES, false) 
 			|| 
 			propertyChannel.getBoolean(PM_SYNC_SERVICES, false))) {
-		    syncBtn.setEnabled(true);
 		    generateBtn.setEnabled(true);
 		}
 	    }
@@ -1125,14 +1123,9 @@
 		    propertyChannel
 			    .fire(DP_STATUS_MSG,
 				    "Generating Perl-MoSeS service skeletons complete!");
-		    JOptionPane.showMessageDialog(null,
-			        "Processing of selected service completed!\n" +
-		    		"Please check the 'console' to ensure that the service\n" +
-		    		"skeletons were generated correctly.", "Completed", JOptionPane.INFORMATION_MESSAGE);
-		    if (!(propertyChannel.getBoolean(PM_SYNC_DATATYPES, false) || propertyChannel
-			    .getBoolean(PM_SYNC_SERVICES, false))) {
-			syncBtn.setEnabled(true);
-		    }
+		    propertyChannel.fire(PM_INFORMATION,
+			        "Processing of selected service completed! " +
+		    		"Any errors encountered should be reported above.");
 		}
 	    }
 	};
@@ -1225,14 +1218,9 @@
 		    propertyChannel
 			    .fire(DP_STATUS_MSG,
 				    "Generating Perl-MoSeS service skeletons complete!");
-		    JOptionPane.showMessageDialog(null,
-			        "Processing of selected service completed!\n" +
-		    		"Please check the 'console' to ensure that the service\n" +
-		    		"skeletons were generated correctly.", "Completed", JOptionPane.INFORMATION_MESSAGE);
-		    if (!(propertyChannel.getBoolean(PM_SYNC_DATATYPES, false) || propertyChannel
-			    .getBoolean(PM_SYNC_SERVICES, false))) {
-			syncBtn.setEnabled(true);
-		    }
+		    propertyChannel.fire(PM_INFORMATION,
+			        "Processing of selected service completed! " +
+		    		"Any errors encountered should be reported above.");
 		}
 	    }
 	};




More information about the MOBY-guts mailing list