editorApplicationContext : reverted stand-alone app context conf
authorCherian Mathew <c.mathew@bgbm.org>
Tue, 27 Jan 2015 09:37:13 +0000 (09:37 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Tue, 27 Jan 2015 09:37:13 +0000 (09:37 +0000)
RemotingLoginDialog : updated dialog with server fetch

.gitattributes
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java
eu.etaxonomy.taxeditor.store/src/main/resources/eu/etaxonomy/cdm/editorApplicationContext.xml [new file with mode: 0644]

index 32246ba8f6fe236142f2379f306139dfe8f52f18..067401bb3c34de55260a48764d8798cdb201dd01 100644 (file)
@@ -1821,6 +1821,7 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/supplemen
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/supplementaldata/SupplementalDataViewer.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/org/eclipse/wb/swt/ResourceManager.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/org/eclipse/wb/swt/SWTResourceManager.java -text
+eu.etaxonomy.taxeditor.store/src/main/resources/eu/etaxonomy/cdm/editorApplicationContext.xml -text
 eu.etaxonomy.taxeditor.store/src/main/resources/log4j.properties -text
 eu.etaxonomy.taxeditor.store/src/test/java/eu/etaxonomy/taxeditor/store/NameProtectTitleCacheTest.java -text
 eu.etaxonomy.taxeditor.store/src/test/java/eu/etaxonomy/taxeditor/store/operations/AbstractTaxeditorOperationTestBase.java -text
index b9d4e631b48c541d59a8e13bf5fb51e4dcf2a559..e9d59d1a53cdf1bbe8c28de0ced3d80c7f92c077 100644 (file)
@@ -13,6 +13,10 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.MouseAdapter;
 import org.eclipse.swt.events.MouseEvent;
@@ -33,7 +37,9 @@ import org.eclipse.wb.swt.SWTResourceManager;
 
 import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.remoting.source.CdmServerInstanceInfo;
+import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
+import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
+import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo.CdmInstanceInfo;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -44,26 +50,25 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
 public class RemotingLoginDialog extends Dialog {
 
     protected Object result;
-    protected Shell shlLogin;
-    private Text txtUsername;
-    private Text txtPassword;
+    protected Shell shlConnect;
     private Text txtPort;
     private Text txtCdmServerStatus;
     private Text txtCdmInstanceStatus;
     private Combo comboCdmServer;
     private Combo comboCdmInstance;
-    private Button btnLogin;
+    private Button btnConnect;
 
-    private final Map<String, CdmServerInstanceInfo> csiiMap = new HashMap<String, CdmServerInstanceInfo>();
+    private final Map<String, CdmServerInfo> csiiMap = new HashMap<String, CdmServerInfo>();
 
     private final String STATUS_AVAILABLE = "Available";
     private final String STATUS_NOT_AVAILABLE = "Not Available";
     private final String STATUS_RETRIEVING = "Retrieving ...";
     private final String STATUS_CHECKING_AVAILABILITY = "Checking ...";
     private final String STATUS_NO_INSTANCES = "No Instances Found";
+    private final String STATUS_ERROR = "Error";
 
-    private CdmServerInstanceInfo selectedCsii;
-    private String selectedCdmInstance;
+    private CdmServerInfo selectedCsii;
+    private CdmInstanceInfo selectedCdmInstance;
 
 
     /**
@@ -83,12 +88,12 @@ public class RemotingLoginDialog extends Dialog {
     public Object open() {
         createContents();
         populateCdmServerCombo();
-        shlLogin.open();
-        shlLogin.layout();
+        shlConnect.open();
+        shlConnect.layout();
 
         Display display = getParent().getDisplay();
 
-        while (!shlLogin.isDisposed()) {
+        while (!shlConnect.isDisposed()) {
             if (!display.readAndDispatch()) {
                 display.sleep();
             }
@@ -101,12 +106,12 @@ public class RemotingLoginDialog extends Dialog {
      * Create contents of the dialog.
      */
     private void createContents() {
-        shlLogin = new Shell(getParent(), getStyle());
-        shlLogin.setSize(490, 292);
-        shlLogin.setText("Login");
-        shlLogin.setLayout(new FillLayout(SWT.HORIZONTAL));
+        shlConnect = new Shell(getParent(), getStyle());
+        shlConnect.setSize(490, 157);
+        shlConnect.setText("Connect");
+        shlConnect.setLayout(new FillLayout(SWT.HORIZONTAL));
 
-        Composite composite = new Composite(shlLogin, SWT.NONE);
+        Composite composite = new Composite(shlConnect, SWT.NONE);
         FillLayout fl_composite = new FillLayout(SWT.VERTICAL);
         fl_composite.spacing = 5;
         composite.setLayout(fl_composite);
@@ -142,7 +147,7 @@ public class RemotingLoginDialog extends Dialog {
         lblPortSeparator.setText(" :  ");
 
         txtPort = new Text(cdmServerComposite, SWT.BORDER);
-        GridData gd_txtPort = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+        GridData gd_txtPort = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
         gd_txtPort.widthHint = 50;
         txtPort.setLayoutData(gd_txtPort);
 
@@ -150,7 +155,7 @@ public class RemotingLoginDialog extends Dialog {
         txtCdmServerStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
         txtCdmServerStatus.setEditable(false);
         GridData gd_txtCdmServerStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
-        gd_txtCdmServerStatus.widthHint = 50;
+        gd_txtCdmServerStatus.widthHint = 100;
         txtCdmServerStatus.setLayoutData(gd_txtCdmServerStatus);
 
         Label lblCdmInstance = new Label(cdmServerComposite, SWT.NONE);
@@ -164,68 +169,41 @@ public class RemotingLoginDialog extends Dialog {
         comboCdmInstance.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
+                updateSelectedCdmInstance();
                 checkSelectedCdmServerInstance();
             }
         });
-        GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1);
+        GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
         gd_comboCdmInstance.widthHint = 150;
         comboCdmInstance.setLayoutData(gd_comboCdmInstance);
         comboCdmInstance.select(0);
 
-        txtCdmInstanceStatus = new Text(cdmServerComposite, SWT.BORDER);
-        txtCdmInstanceStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
-        txtCdmInstanceStatus.setEditable(false);
-        GridData gd_txtCdmInstanceStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
-        gd_txtCdmInstanceStatus.widthHint = 50;
-        txtCdmInstanceStatus.setLayoutData(gd_txtCdmInstanceStatus);
-        new Label(cdmServerComposite, SWT.NONE);
-
         Button btnRefresh = new Button(cdmServerComposite, SWT.FLAT);
-        GridData gd_btnRefresh = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
+        GridData gd_btnRefresh = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
         gd_btnRefresh.widthHint = 110;
         gd_btnRefresh.heightHint = 30;
         btnRefresh.setLayoutData(gd_btnRefresh);
         btnRefresh.setText("Refresh");
-        new Label(cdmServerComposite, SWT.NONE);
-        new Label(cdmServerComposite, SWT.NONE);
-        new Label(cdmServerComposite, SWT.NONE);
-        new Label(cdmServerComposite, SWT.NONE);
-        new Label(cdmServerComposite, SWT.NONE);
-        new Label(cdmServerComposite, SWT.NONE);
-
-        Label lblUsername = new Label(cdmServerComposite, SWT.NONE);
-        lblUsername.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
-        lblUsername.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
-        lblUsername.setText("Username : ");
-
-        txtUsername = new Text(cdmServerComposite, SWT.BORDER);
-        txtUsername.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
-        new Label(cdmServerComposite, SWT.NONE);
-
-        Label lblPassword = new Label(cdmServerComposite, SWT.NONE);
-        lblPassword.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
-        lblPassword.setText("Password : ");
-        lblPassword.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
 
-        txtPassword = new Text(cdmServerComposite, SWT.BORDER | SWT.PASSWORD);
-        txtPassword.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
-        new Label(cdmServerComposite, SWT.NONE);
+        txtCdmInstanceStatus = new Text(cdmServerComposite, SWT.BORDER);
+        txtCdmInstanceStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
+        txtCdmInstanceStatus.setEditable(false);
+        GridData gd_txtCdmInstanceStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
+        gd_txtCdmInstanceStatus.widthHint = 100;
+        txtCdmInstanceStatus.setLayoutData(gd_txtCdmInstanceStatus);
         new Label(cdmServerComposite, SWT.NONE);
 
-        btnLogin = new Button(cdmServerComposite, SWT.FLAT);
-        btnLogin.addMouseListener(new MouseAdapter() {
+        btnConnect = new Button(cdmServerComposite, SWT.FLAT);
+        btnConnect.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseUp(MouseEvent e) {
-                login();
+                connect();
             }
         });
-        GridData gd_btnLogin = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
-        gd_btnLogin.heightHint = 30;
-        btnLogin.setLayoutData(gd_btnLogin);
-        btnLogin.setText("Login");
-        new Label(cdmServerComposite, SWT.NONE);
-        new Label(cdmServerComposite, SWT.NONE);
-        new Label(cdmServerComposite, SWT.NONE);
+        GridData gd_btnConnect = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
+        gd_btnConnect.heightHint = 30;
+        btnConnect.setLayoutData(gd_btnConnect);
+        btnConnect.setText("Connect");
         new Label(cdmServerComposite, SWT.NONE);
         new Label(cdmServerComposite, SWT.NONE);
         new Label(cdmServerComposite, SWT.NONE);
@@ -233,14 +211,26 @@ public class RemotingLoginDialog extends Dialog {
     }
 
     private void populateCdmServerCombo() {
-        for(CdmServerInstanceInfo csii : CdmServerInstanceInfo.getCdmServers()) {
-            csiiMap.put(csii.getName(), csii);
-            comboCdmServer.add(csii.getName());
-        }
-        comboCdmServer.select(0);
-        updateSelectedCdmServer();
-        updatePort();
-        checkSelectedCdmServer();
+        Job job = new Job("Retrieve Server Instances") {
+            @Override
+            protected IStatus run(IProgressMonitor monitor) {
+                Display.getDefault().asyncExec(new Runnable() {
+                    @Override
+                    public void run() {
+                        for(CdmServerInfo csii : CdmServerInfo.getCdmServers()) {
+                            csiiMap.put(csii.getName(), csii);
+                            comboCdmServer.add(csii.getName());
+                        }
+                        comboCdmServer.select(0);
+                        updateSelectedCdmServer();
+                        updatePort();
+                        checkSelectedCdmServer();
+                    }
+                });
+                return Status.OK_STATUS;
+            }
+        };
+        job.schedule();
     }
 
 
@@ -271,41 +261,77 @@ public class RemotingLoginDialog extends Dialog {
         }
     }
 
+    private void updateSelectedCdmInstance() {
+        int selIndex = comboCdmInstance.getSelectionIndex();
+        if(selIndex != -1) {
+            selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
+        }
+    }
+
     private void populateCdmInstanceCombo(final boolean forceRefresh) {
         comboCdmInstance.removeAll();
         comboCdmInstance.setEnabled(false);
+        btnConnect.setEnabled(false);
         txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
+        Job job = new Job("Retrieve Server Instances") {
+            @Override
+            protected IStatus run(IProgressMonitor monitor) {
+                try {
+                    if(selectedCsii != null) {
+                        if(forceRefresh) {
+                            selectedCsii.refreshInstances();
+                        }
+                        final List<CdmInstanceInfo> instances = selectedCsii.getInstances();
+                        Display.getDefault().asyncExec(new Runnable() {
+                            @Override
+                            public void run() {
+                                if(!instances.isEmpty()) {
+                                    for(CdmInstanceInfo cdmInstance : instances) {
+                                        comboCdmInstance.add(cdmInstance.getName());
+                                    }
+                                    comboCdmInstance.select(0);
+                                    updateSelectedCdmInstance();
+                                    checkSelectedCdmServerInstance();
+                                    comboCdmInstance.setEnabled(true);
+                                } else {
+                                    txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES);
+                                    btnConnect.setEnabled(false);
+                                }
+                            }
+                        });
+                    }
+                } catch (CDMServerException e) {
+                    MessagingUtils.warn(getClass(), e);
+                    Display.getDefault().asyncExec(new Runnable() {
+                        @Override
+                        public void run() {
+                            txtCdmInstanceStatus.setText(STATUS_ERROR);
+                            comboCdmInstance.setEnabled(false);
+                            btnConnect.setEnabled(false);
+                        }
+                    });
+
 
-        if(selectedCsii != null) {
-            if(forceRefresh) {
-                selectedCsii.refreshInstances();
-            }
-            List<String> instances = selectedCsii.getInstances();
-            if(!instances.isEmpty()) {
-                for(String cdmInstance : instances) {
-                    comboCdmInstance.add(cdmInstance);
                 }
-                comboCdmInstance.select(0);
-                checkSelectedCdmServerInstance();
-            } else {
-                txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES);
+                return Status.OK_STATUS;
             }
-        }
-        comboCdmInstance.setEnabled(true);
+        };
+
+        // Start the Job
+        job.schedule();
+
+
     }
 
     private void checkSelectedCdmServerInstance() {
         if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
-            int selInstanceIndex = comboCdmInstance.getSelectionIndex();
-            String instance = comboCdmInstance.getItem(selInstanceIndex);
-
             try {
-                if(selectedCsii.pingInstance(instance)) {
+                if(selectedCsii.pingInstance(selectedCdmInstance)) {
                     txtCdmInstanceStatus.setText(STATUS_AVAILABLE);
-                    btnLogin.setEnabled(true);
+                    btnConnect.setEnabled(true);
                 } else {
                     txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
-                    btnLogin.setEnabled(false);
+                    btnConnect.setEnabled(false);
                 }
             } catch (Exception e) {
                 txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
@@ -315,7 +341,7 @@ public class RemotingLoginDialog extends Dialog {
 
     }
 
-    private void login() {
+    private void connect() {
         if(CdmStore.isConnecting()){
             MessagingUtils.warningDialog("Already connecting", this, "You are currently connecting to a different CDM Instance already.");
             return;
@@ -326,15 +352,14 @@ public class RemotingLoginDialog extends Dialog {
 
         try {
             checkSelectedCdmServerInstance();
-            CdmDataSourceRepository.changeDataSource(selectedCsii.getCdmRemoteSource(instance));
+            CdmDataSourceRepository.changeDataSource(selectedCsii.getCdmRemoteSource(selectedCdmInstance));
 
         } catch (Exception e) {
             // Do not expect anything to go wrong at this point, so we throw a runtime exception
             // if any problems
             throw new RuntimeException(e);
         }
-
-        //boolean result = CdmStore.getLoginManager().authenticate(txtUsername.getText(), txtPassword.getText());
+        shlConnect.dispose();
     }
 
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/resources/eu/etaxonomy/cdm/editorApplicationContext.xml b/eu.etaxonomy.taxeditor.store/src/main/resources/eu/etaxonomy/cdm/editorApplicationContext.xml
new file mode 100644 (file)
index 0000000..b402e67
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+  xmlns:context="http://www.springframework.org/schema/context"\r
+  xmlns:tx="http://www.springframework.org/schema/tx"\r
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
+    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd\r
+    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">\r
+\r
+  <!-- Local application context and term initializer -->\r
+  <import resource="classpath:/eu/etaxonomy/cdm/localApplicationContext.xml"/>\r
+  \r
+  <!-- Remote application context and term initializer -->\r
+  <!--  <import resource="classpath:/eu/etaxonomy/cdm/remotingApplicationContext.xml"/> -->\r
+  \r
+</beans>\r