[jbosstools-commits] JBoss Tools SVN: r24161 - in trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui: src/org/jboss/tools/internal/deltacloud/ui/wizards and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Aug 13 13:59:42 EDT 2010


Author: jjohnstn
Date: 2010-08-13 13:59:41 -0400 (Fri, 13 Aug 2010)
New Revision: 24161

Modified:
   trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
   trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnection.java
   trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionPage.java
Log:
2010-08-13  Jeff Johnston  <jjohnstn at redhat.com>

	* src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnection.java (performFinish): 
	(performTest): Pass url as String to DeltaCloudClient.
	* src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionPage.java (checkURL): Don't
	make synchronized as there is a special thread to run this now.  Also, append api to url
	automatically on behalf of the user.  Use Display threads when accessing any UI widgets.
	Enable the Test button if the URL is valid. 
	(createControl): Disable Test button by default.
	(CheckURLThread): New class based on Thread specifically for running checkURL. 
	(validate): Use new CheckURLThread class to check the url.



Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog	2010-08-13 17:41:20 UTC (rev 24160)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog	2010-08-13 17:59:41 UTC (rev 24161)
@@ -1,3 +1,15 @@
+2010-08-13  Jeff Johnston  <jjohnstn at redhat.com>
+
+	* src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnection.java (performFinish): 
+	(performTest): Pass url as String to DeltaCloudClient.
+	* src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionPage.java (checkURL): Don't
+	make synchronized as there is a special thread to run this now.  Also, append api to url
+	automatically on behalf of the user.  Use Display threads when accessing any UI widgets.
+	Enable the Test button if the URL is valid. 
+	(createControl): Disable Test button by default.
+	(CheckURLThread): New class based on Thread specifically for running checkURL. 
+	(validate): Use new CheckURLThread class to check the url.
+
 2010-08-12  Jeff Johnston  <jjohnstn at redhat.com>
 
 	* src/org/jboss/tools/deltacloud/ui/views/CVMessages.java (getFormattedString): New method.

Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnection.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnection.java	2010-08-13 17:41:20 UTC (rev 24160)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnection.java	2010-08-13 17:59:41 UTC (rev 24161)
@@ -44,7 +44,7 @@
 		String username = mainPage.getUsername();
 		String password = mainPage.getPassword();
 		try {
-			DeltaCloud newCloud = new DeltaCloud(name, new URL(url), username, password);
+			DeltaCloud newCloud = new DeltaCloud(name, url, username, password);
 			return newCloud.testConnection();
 		} catch (MalformedURLException e) {
 			Activator.log(e);
@@ -59,7 +59,7 @@
 		String username = mainPage.getUsername();
 		String password = mainPage.getPassword();
 		try {
-			DeltaCloud newCloud = new DeltaCloud(name, new URL(url), username, password);
+			DeltaCloud newCloud = new DeltaCloud(name, url, username, password);
 			DeltaCloudManager.getDefault().addCloud(newCloud);
 		} catch (MalformedURLException e) {
 			Activator.log(e);

Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionPage.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionPage.java	2010-08-13 17:41:20 UTC (rev 24160)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionPage.java	2010-08-13 17:59:41 UTC (rev 24161)
@@ -28,6 +28,7 @@
 import org.eclipse.swt.layout.FormLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Link;
@@ -80,6 +81,18 @@
 
 	private boolean urlValid;
 	
+	private class CheckURLThread extends Thread {
+		
+		@Override
+		public void run() {
+			try {
+				checkURL();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+	}
+	
 	private Listener linkListener = new Listener() {
 
 		public void handleEvent(Event event) {
@@ -159,21 +172,9 @@
 		
 		// Run check for valid DeltaCloud URL in separate thread
 		String urlValue = urlText.getText();
-		if (urlValue.endsWith("api")) {
-			ISafeRunnable runner = new ISafeRunnable() {
-
-				@Override
-				public void handleException(Throwable exception) {
-					setURLValid(false);
-				}
-
-				@Override
-				public void run() throws Exception {
-					// TODO Auto-generated method stub
-					checkURL();
-				}
-			};
-			SafeRunner.run(runner);
+		if (urlValue.length() > 5) {
+			CheckURLThread t = new CheckURLThread();
+			t.start();
 		} else if (urlValue.length() > 0){
 			typeText.setText(WizardMessages.getString(NONCLOUD_URL));
 			complete = false;
@@ -204,14 +205,22 @@
 	// Method to check the URL for validity as Delta-cloud API specifier.
 	// Since this is run in thread, it does not use the setErrorMessage()
 	// method and instead writes error messages to the typeText label.
-	private synchronized boolean checkURL() {
+	private boolean checkURL() {
 		boolean valid = false;
 		String oldurl = url;
-		url = urlText.getText();
+		Display.getDefault().syncExec(new Runnable() {
+
+			@Override
+			public void run() {
+				cloudType = typeText.getText();
+				url = urlText.getText();
+			}
+		});
+		String oldCloudType = cloudType;
 		if (url.length() > 0) {
 			if (!url.equals(oldurl)) {
 				try {
-					URL u = new URL(url + ".xml");
+					URL u = new URL(url + "/api.xml"); //$NON-NLS-1$
 					Object o = u.getContent();
 					if (o instanceof InputStream) {
 						String xml = "";
@@ -226,7 +235,7 @@
 								BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
 								while ((line = reader.readLine()) != null) 
 								{
-									sb.append(line).append("\n");	
+									sb.append(line).append("\n"); //$NON-NLS-1$
 								}
 								xml = sb.toString();
 							}
@@ -261,11 +270,22 @@
 					cloudType = WizardMessages.getString(NONCLOUD_URL);
 				} catch (SAXException e) {
 					cloudType = WizardMessages.getString(NONCLOUD_URL);
+				} catch (Exception e) {
+					cloudType = WizardMessages.getString(INVALID_URL);
 				}
 				setURLValid(valid);
 			}
-			if (!typeText.getText().equals(cloudType))
-				typeText.setText(cloudType);
+			if (!oldCloudType.equals(cloudType)) {
+				Display.getDefault().asyncExec(new Runnable() {
+
+					@Override
+					public void run() {
+						testButton.setEnabled(getURLValid());
+						typeText.setText(cloudType);
+					}
+					
+				});
+			}
 		}
 		return valid;
 	}
@@ -331,6 +351,7 @@
 		
 		testButton = new Button(container, SWT.NULL);
 		testButton.setText(WizardMessages.getString(TESTBUTTON_LABEL));
+		testButton.setEnabled(false);
 		testButton.addSelectionListener(buttonListener);
 		
 		Link ec2userLink = new Link(container, SWT.NULL);
@@ -372,7 +393,7 @@
 		
 		f = new FormData();
 		f.left = new FormAttachment(urlText, 0, SWT.LEFT);
-		f.top = new FormAttachment(urlText, 5);
+		f.top = new FormAttachment(urlText, 8);
 		f.right = new FormAttachment(100, 0);
 		typeText.setLayoutData(f);
 
@@ -382,7 +403,7 @@
 		
 		f = new FormData();
 		f.left = new FormAttachment(typeText, 0, SWT.LEFT);
-		f.top = new FormAttachment(typeText, 13);
+		f.top = new FormAttachment(typeText, 10);
 		f.right = new FormAttachment(100, -70);
 		usernameText.setLayoutData(f);
 		



More information about the jbosstools-commits mailing list