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;
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;
/**
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;
/**
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();
}
* 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);
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);
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);
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);
}
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();
}
}
}
+ 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);
}
- 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;
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();
}