From 82dd347146ade7d78f042d471ad8d4dedb189b43 Mon Sep 17 00:00:00 2001 From: Cherian Mathew Date: Tue, 27 Jan 2015 09:37:13 +0000 Subject: [PATCH] editorApplicationContext : reverted stand-alone app context conf RemotingLoginDialog : updated dialog with server fetch --- .gitattributes | 1 + .../ui/dialog/RemotingLoginDialog.java | 211 ++++++++++-------- .../cdm/editorApplicationContext.xml | 16 ++ 3 files changed, 135 insertions(+), 93 deletions(-) create mode 100644 eu.etaxonomy.taxeditor.store/src/main/resources/eu/etaxonomy/cdm/editorApplicationContext.xml diff --git a/.gitattributes b/.gitattributes index 32246ba8f..067401bb3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java index b9d4e631b..e9d59d1a5 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java @@ -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 csiiMap = new HashMap(); + private final Map csiiMap = new HashMap(); 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 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 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 index 000000000..b402e6728 --- /dev/null +++ b/eu.etaxonomy.taxeditor.store/src/main/resources/eu/etaxonomy/cdm/editorApplicationContext.xml @@ -0,0 +1,16 @@ + + + + + + + + + + -- 2.34.1