You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2011/12/19 19:15:36 UTC

svn commit: r1220880 - in /incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya: appwrapper/DescriptorEditorDialog.java appwrapper/HostDescriptionDialog.java registrybrowser/nodes/HostDescriptionNode.java

Author: samindaw
Date: Mon Dec 19 18:15:36 2011
New Revision: 1220880

URL: http://svn.apache.org/viewvc?rev=1220880&view=rev
Log:
https://issues.apache.org/jira/browse/AIRAVATA-235
fixed for host descs

Modified:
    incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/appwrapper/DescriptorEditorDialog.java
    incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/appwrapper/HostDescriptionDialog.java
    incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/registrybrowser/nodes/HostDescriptionNode.java

Modified: incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/appwrapper/DescriptorEditorDialog.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/appwrapper/DescriptorEditorDialog.java?rev=1220880&r1=1220879&r2=1220880&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/appwrapper/DescriptorEditorDialog.java (original)
+++ incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/appwrapper/DescriptorEditorDialog.java Mon Dec 19 18:15:36 2011
@@ -187,6 +187,12 @@ public class DescriptorEditorDialog exte
     private void editDescriptor() {
     	switch (descriptorType){
 	    	case HOST:
+	    		HostDescription h = (HostDescription) getSelected();
+	    		HostDescriptionDialog hostDescriptionDialog = new HostDescriptionDialog(engine,false,h);
+	    		hostDescriptionDialog.open();
+	    		if (hostDescriptionDialog.isHostCreated()) {
+					loadDescriptors();
+				}
 	    		break;
 	    	case SERVICE:
 	    		ServiceDescription d = (ServiceDescription) getSelected();

Modified: incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/appwrapper/HostDescriptionDialog.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/appwrapper/HostDescriptionDialog.java?rev=1220880&r1=1220879&r2=1220880&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/appwrapper/HostDescriptionDialog.java (original)
+++ incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/appwrapper/HostDescriptionDialog.java Mon Dec 19 18:15:36 2011
@@ -21,6 +21,20 @@
 
 package org.apache.airavata.xbaya.appwrapper;
 
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+
 import org.apache.airavata.common.utils.SwingUtil;
 import org.apache.airavata.commons.gfac.type.HostDescription;
 import org.apache.airavata.registry.api.Registry;
@@ -32,19 +46,10 @@ import org.apache.airavata.xbaya.gui.Gri
 import org.apache.airavata.xbaya.gui.XBayaLabel;
 import org.apache.airavata.xbaya.gui.XBayaTextField;
 
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-
 public class HostDescriptionDialog extends JDialog {
 
 	private static final long serialVersionUID = -2910634296292034085L;
 
-	private XBayaEngine engine;
-
     private XBayaTextField hostIdTextField;
 
     private XBayaTextField hostAddressTextField;
@@ -83,9 +88,25 @@ public class HostDescriptionDialog exten
      * @param engine XBaya workflow engine
      */
     public HostDescriptionDialog(XBayaEngine engine, boolean newHost, HostDescription originalHostDescription) {
-        this.engine = engine;
         setNewHost(newHost);
         setOriginalHostDescription(originalHostDescription);
+        addWindowListener(new WindowAdapter() {
+            @Override
+            public void windowOpened(WindowEvent arg0) {
+                if (isNewHost()) {
+					String baseName = "Host";
+					int i = 1;
+					String defaultName = baseName + i;
+					try {
+						while (getRegistry().getServiceDescription(defaultName) != null) {
+							defaultName = baseName + (++i);
+						}
+					} catch (Exception e) {
+					}
+					hostIdTextField.setText(defaultName);
+				}
+            }
+        });
         setRegistry(engine.getConfiguration().getJcrComponentRegistry().getRegistry());
         initGUI();
     }
@@ -138,8 +159,12 @@ public class HostDescriptionDialog exten
     	setBounds(100, 100, 400, 280);
     	setModal(true);
         setLocationRelativeTo(null);
-        setTitle("New Host Description");
-        this.hostIdTextField = new XBayaTextField();
+        if (isNewHost()) {
+			setTitle("New Host Description");
+		}else{
+			setTitle("Update Host Description: "+getOriginalHostDescription().getType().getHostName());
+		}
+		this.hostIdTextField = new XBayaTextField();
         this.hostAddressTextField = new XBayaTextField();
         this.globusGateKeeperTextField = new XBayaTextField();
         this.GridFTPTextField = new XBayaTextField();
@@ -158,12 +183,13 @@ public class HostDescriptionDialog exten
         hostIdTextField.getSwingComponent().addKeyListener(new KeyAdapter() {
             @Override
             public void keyReleased(KeyEvent e) {
-                try {
-                    validateDialog();
-                    setError(null);
-                } catch (Exception e1) {
-                    setError(e1.getMessage());
-                }
+            	updateDialogStatus();
+            }
+        });
+        hostAddressTextField.getSwingComponent().addKeyListener(new KeyAdapter() {
+            @Override
+            public void keyReleased(KeyEvent e) {
+            	updateDialogStatus();
             }
         });
         GridPanel infoPanel1 = new GridPanel();
@@ -192,8 +218,11 @@ public class HostDescriptionDialog exten
         lblError = new JLabel();
         lblError.setForeground(Color.RED);
         buttonPanel.add(lblError);
-        okButton = new JButton("OK");
-        okButton.addActionListener(new ActionListener() {
+        okButton = new JButton("Save");
+        if (!isNewHost()) {
+			okButton.setText("Update");
+		}
+		okButton.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 ok();
             }
@@ -240,11 +269,14 @@ public class HostDescriptionDialog exten
     	HostDescriptionType t = getOriginalHostDescription().getType();
     	hostIdTextField.setText(t.getHostName());
 		hostAddressTextField.setText(t.getHostAddress());
-		if (t instanceof GlobusHostType){
+		boolean isGlobus = t instanceof GlobusHostType;
+		chkGobusHost.setSelected(isGlobus);
+		if (isGlobus){
 			globusGateKeeperTextField.setText(arrayToString(((GlobusHostType) t).getGlobusGateKeeperEndPointArray()));
 			GridFTPTextField.setText(arrayToString(((GlobusHostType) t).getGridFTPEndPointArray()));
 		}
 		hostIdTextField.setEditable(isNewHost());
+		updateGlobusHostTypeAndControls();
 	}
     
     public String getHostId() {
@@ -266,22 +298,26 @@ public class HostDescriptionDialog exten
     }
 
     private void validateDialog() throws Exception {
-        okButton.setEnabled(true);
-        if (this.hostIdTextField.getText() == null ||  this.hostIdTextField.getText().trim().equals("")) {
-            throw new Exception("Id of the host cannot be empty!!!");
-        }
-
-        HostDescription hostDescription2 = null;
-        try {
-            hostDescription2 = getRegistry().getHostDescription(this.hostIdTextField.getText());
-        } catch (RegistryException e) {
-            throw e;
-        }
-        if (hostDescription2 != null) {
-            throw new Exception("Host descriptor with the given id already exists!!!");
-        }
-
-        if (getHostLocation() == null || getHostLocation().trim().equals("")) {
+        if (isNewHost()) {
+			String hostName = this.hostIdTextField.getText();
+			if (hostName == null
+					|| hostName.trim().equals("")) {
+				throw new Exception("Id of the host cannot be empty!!!");
+			}
+			HostDescription hostDescription2 = null;
+			try {
+				hostDescription2 = getRegistry().getHostDescription(
+						hostName);
+			} catch (RegistryException e) {
+				throw e;
+			}
+			if (hostDescription2 != null) {
+				throw new Exception(
+						"Host descriptor with the given id already exists!!!");
+			}
+		}
+        String hostAddress = this.hostAddressTextField.getText();
+		if (hostAddress == null || hostAddress.trim().equals("")) {
             throw new Exception("Host location/ip cannot be empty!!!");
         }
     }

Modified: incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/registrybrowser/nodes/HostDescriptionNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/registrybrowser/nodes/HostDescriptionNode.java?rev=1220880&r1=1220879&r2=1220880&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/registrybrowser/nodes/HostDescriptionNode.java (original)
+++ incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/registrybrowser/nodes/HostDescriptionNode.java Mon Dec 19 18:15:36 2011
@@ -25,12 +25,12 @@ import java.util.Arrays;
 import java.util.List;
 
 import javax.swing.Icon;
-import javax.swing.JOptionPane;
 import javax.swing.JTree;
 import javax.swing.tree.TreeNode;
 
 import org.apache.airavata.commons.gfac.type.HostDescription;
 import org.apache.airavata.registry.api.exception.RegistryException;
+import org.apache.airavata.xbaya.appwrapper.HostDescriptionDialog;
 import org.apache.airavata.xbaya.registrybrowser.menu.AbstractBrowserActionItem;
 import org.apache.airavata.xbaya.registrybrowser.menu.DeleteAction;
 import org.apache.airavata.xbaya.registrybrowser.menu.EditAction;
@@ -73,22 +73,36 @@ public class HostDescriptionNode extends
 
     public boolean triggerAction(JTree tree, String action) throws Exception {
         if (action.equals(DeleteAction.ID)) {
-            deleteHostDescription(tree);
-            return true;
+        	return deleteHostDescription(tree);
         } else if (action.equals(EditAction.ID)) {
-            JOptionPane.showMessageDialog(null, "TODO");
-            return true;
+            return editHostDescription(tree);
         }
         return super.triggerAction(tree, action);
     }
+    
+    @Override
+    public String getDefaultAction() {
+    	return EditAction.ID;
+    }
+    
+	private boolean editHostDescription(JTree tree) {
+		HostDescriptionDialog hostDescriptionDialog = new HostDescriptionDialog(getXBayaEngine(),false,getHostDescription());
+		hostDescriptionDialog.open();
+		if (hostDescriptionDialog.isHostCreated()) {
+		    refresh();
+		    reloadTreeNode(tree, this);
+		}
+		return true;
+	}
 
-    private void deleteHostDescription(JTree tree) throws RegistryException {
+    private boolean deleteHostDescription(JTree tree) throws RegistryException {
         if (askQuestion("Host description", "Are you sure that you want to remove the host description \""
                 + getHostDescription().getType().getHostName() + "\"?")) {
             getRegistry().deleteHostDescription(getHostDescription().getType().getHostName());
             ((AbstractAiravataTreeNode) getParent()).refresh();
             reloadTreeNode(tree, getParent());
         }
+        return true;
     }
 
     @Override
@@ -96,7 +110,7 @@ public class HostDescriptionNode extends
         if (action.getID().equals(DeleteAction.ID)) {
             return "Remove";
         } else if (action.getID().equals(EditAction.ID)) {
-            return "Edit";
+            return "View/Edit";
         }
         return action.getDefaultCaption();
     }