Adds async refresh of server
authorCherian Mathew <c.mathew@bgbm.org>
Thu, 26 Nov 2015 14:18:51 +0000 (15:18 +0100)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 26 Nov 2015 14:18:51 +0000 (15:18 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java

index b8cca7c..a462990 100644 (file)
@@ -233,7 +233,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 refreshCdmServer();
-                updatePort();
+
             }
         });
         GridData gd_comboCdmServer = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
@@ -487,11 +487,6 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
                         CdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
                         if(devRemoteSource != null) {
                             isDevRemoteSource = true;
-                        }
-                        refreshCdmServer();
-                        updatePort();
-
-                        if(devRemoteSource != null) {
                             String username = System.getProperty("cdm.server.dev.username");
                             String password = System.getProperty("cdm.server.dev.password");
                             if(username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
@@ -499,6 +494,8 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
                                 txtPassword.setText(password);
                                 CdmStore.connect(devRemoteSource, RemotingLoginDialog.this);
                             }
+                        } else {
+                            refreshCdmServer();
                         }
                     }
                 });
@@ -510,9 +507,15 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
 
 
     private void refreshCdmServer() {
-        txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
-        updateSelectedCdmServer();
-        checkSelectedCdmServer();
+        Display.getDefault().asyncExec(new Runnable() {
+            @Override
+            public void run() {
+                txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
+                updateSelectedCdmServer();
+                checkSelectedCdmServer();
+                updatePort();
+            }
+        });
     }
 
     private void updateSelectedCdmServer() {
@@ -564,6 +567,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
             } else {
                 txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
                 comboCdmInstance.removeAll();
+                disableCdmInstanceControls("", "");
             }
         }
     }
@@ -620,10 +624,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
                     Display.getDefault().asyncExec(new Runnable() {
                         @Override
                         public void run() {
-                            txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
-                            txtCdmInstanceStatus.setToolTipText(e.getMessage());
-                            comboCdmInstance.setEnabled(false);
-                            btnConnect.setEnabled(false);
+                            disableCdmInstanceControls(STATUS_NOT_AVAILABLE, e.getMessage());
                         }
                     });
                 }
@@ -635,10 +636,15 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
             // Start the Job
             serverJob.schedule();
         }
+    }
 
+    private void disableCdmInstanceControls(String cdmInstanceStatus, String tooltip) {
+        txtCdmInstanceStatus.setText(cdmInstanceStatus);
+        txtCdmInstanceStatus.setToolTipText(tooltip);
+        comboCdmInstance.setEnabled(false);
+        btnConnect.setEnabled(false);
 
     }
-
     private void refreshCdmInstance() {
         txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
         clearOnInstanceChange();
@@ -689,14 +695,6 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
                 CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName());
     }
 
-    private boolean isActiveCdmInstanceRunningInManagedServer() {
-        return CdmStore.getManagedServer() != null &&
-                CdmStore.getManagedServer().isAlive() &&
-                CdmStore.isActive() &&
-                CdmServerInfo.NAME_LOCALHOST_MGD.equals(CdmStore.getActiveCdmSource().getName());
-    }
-
-
     private void startManagedServer() {
         if(isManagedServerRunning()) {
             if(CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName())) {