Revision d4d342a1
Added by Cherian Mathew over 8 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.ui.dialog; |
11 | 11 |
|
12 |
import java.text.SimpleDateFormat; |
|
13 |
import java.util.Date; |
|
12 | 14 |
import java.util.HashMap; |
13 | 15 |
import java.util.List; |
14 | 16 |
import java.util.Map; |
15 | 17 |
|
18 |
import org.apache.commons.lang.StringUtils; |
|
16 | 19 |
import org.eclipse.core.runtime.IProgressMonitor; |
17 | 20 |
import org.eclipse.core.runtime.IStatus; |
18 | 21 |
import org.eclipse.core.runtime.Status; |
... | ... | |
44 | 47 |
import org.osgi.service.prefs.BackingStoreException; |
45 | 48 |
import org.osgi.service.prefs.Preferences; |
46 | 49 |
|
50 |
import eu.etaxonomy.cdm.api.application.CdmApplicationState; |
|
51 |
import eu.etaxonomy.cdm.model.metadata.CdmMetaData; |
|
47 | 52 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
48 | 53 |
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException; |
49 | 54 |
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource; |
... | ... | |
76 | 81 |
private final static String STATUS_NO_INSTANCES = "No Instances Found"; |
77 | 82 |
private final static String STATUS_ERROR = "Error"; |
78 | 83 |
private final static String STATUS_REMOTING_NOT_ACTIVATED = "Remoting not activated"; |
84 |
private final static String STATUS_NOT_COMPATIBLE = "Not Compatible"; |
|
85 |
|
|
86 |
private final static String MESG_COMPATIBLE_EDITOR_OLD = "Please update the Taxonomic Editor (Help->Check for Updates) or choose a compatible cdm-server"; |
|
87 |
private final static String MESG_COMPATIBLE_SERVER_OLD = "Please update the chosen cdm-server or choose a compatible cdm-server"; |
|
88 |
|
|
79 | 89 |
private final static String STORE_PREFERENCES_NODE = "eu.etaxonomy.taxeditor.store"; |
80 | 90 |
|
81 | 91 |
private final static String LOGIN_NODE = "login"; |
... | ... | |
108 | 118 |
|
109 | 119 |
private final int MIN_WIDTH = 530; |
110 | 120 |
private final int MIN_HEIGHT = 220; |
111 |
private final int MIN_EXP_HEIGHT = 350;
|
|
121 |
private final int MIN_EXP_HEIGHT = 380;
|
|
112 | 122 |
private final int MESSAGE_HEIGHT = 25; |
113 | 123 |
private Label lblEditorVersion; |
114 | 124 |
private Text txtEditorVersion; |
... | ... | |
163 | 173 |
readPrefLastServerInstance(); |
164 | 174 |
} |
165 | 175 |
|
176 |
setEditorInfo(); |
|
166 | 177 |
populateCdmServerCombo(); |
167 | 178 |
shlConnect.open(); |
168 | 179 |
shlConnect.layout(); |
... | ... | |
385 | 396 |
|
386 | 397 |
lblServerVersion = new Label(compAdvanced, SWT.CENTER); |
387 | 398 |
lblServerVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
388 |
lblServerVersion.setText("Server Version :"); |
|
399 |
lblServerVersion.setText("Server Cdmlib Version :");
|
|
389 | 400 |
lblServerVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL)); |
390 | 401 |
|
391 | 402 |
txtServerVersion = new Text(compAdvanced, SWT.BORDER); |
392 |
txtServerVersion.setEnabled(false); |
|
393 | 403 |
txtServerVersion.setEditable(false); |
394 | 404 |
txtServerVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); |
395 | 405 |
new Label(compAdvanced, SWT.NONE); |
... | ... | |
397 | 407 |
|
398 | 408 |
lblEditorVersion = new Label(compAdvanced, SWT.CENTER); |
399 | 409 |
lblEditorVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
400 |
lblEditorVersion.setText("Editor Version :"); |
|
410 |
lblEditorVersion.setText("Editor Cdmlib Version :");
|
|
401 | 411 |
lblEditorVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL)); |
402 | 412 |
|
403 | 413 |
txtEditorVersion = new Text(compAdvanced, SWT.BORDER); |
404 |
txtEditorVersion.setEnabled(false); |
|
405 | 414 |
txtEditorVersion.setEditable(false); |
406 | 415 |
txtEditorVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); |
407 | 416 |
new Label(compAdvanced, SWT.NONE); |
... | ... | |
413 | 422 |
lblServerCDMVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL)); |
414 | 423 |
|
415 | 424 |
txtServerCDMVersion = new Text(compAdvanced, SWT.BORDER); |
416 |
txtServerCDMVersion.setEnabled(false); |
|
417 | 425 |
txtServerCDMVersion.setEditable(false); |
418 | 426 |
txtServerCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); |
419 | 427 |
new Label(compAdvanced, SWT.NONE); |
... | ... | |
425 | 433 |
lblEditorCDMVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL)); |
426 | 434 |
|
427 | 435 |
txtEditorCDMVersion = new Text(compAdvanced, SWT.BORDER); |
428 |
txtEditorCDMVersion.setEnabled(false); |
|
429 | 436 |
txtEditorCDMVersion.setEditable(false); |
430 | 437 |
txtEditorCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); |
431 | 438 |
|
... | ... | |
511 | 518 |
|
512 | 519 |
private void checkSelectedCdmServer() { |
513 | 520 |
|
514 |
txtCdmInstanceStatus.setText(""); |
|
515 |
txtPort.setEditable(false); |
|
516 |
txtPort.setEnabled(false); |
|
521 |
clearOnServerChange(); |
|
517 | 522 |
emptyCredentials(); |
518 | 523 |
|
519 | 524 |
if(selectedCsii != null) { |
... | ... | |
524 | 529 |
if(selectedCsii.pingServer()) { |
525 | 530 |
txtCdmServerStatus.setText(STATUS_AVAILABLE); |
526 | 531 |
populateCdmInstanceCombo(true); |
532 |
txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion()); |
|
533 |
txtServerVersion.setToolTipText(generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified())); |
|
527 | 534 |
|
528 | 535 |
} else { |
529 | 536 |
txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE); |
... | ... | |
538 | 545 |
comboCdmInstance.setEnabled(false); |
539 | 546 |
btnConnect.setEnabled(false); |
540 | 547 |
txtCdmInstanceStatus.setText(STATUS_RETRIEVING); |
548 |
txtCdmInstanceStatus.setToolTipText(""); |
|
541 | 549 |
|
542 | 550 |
Job job = new Job("Retrieve Server Instances") { |
543 | 551 |
@Override |
... | ... | |
579 | 587 |
} |
580 | 588 |
}); |
581 | 589 |
} |
582 |
} catch (CDMServerException e) { |
|
590 |
} catch (final CDMServerException e) {
|
|
583 | 591 |
MessagingUtils.warn(getClass(), e); |
584 | 592 |
Display.getDefault().asyncExec(new Runnable() { |
585 | 593 |
@Override |
586 | 594 |
public void run() { |
587 |
txtCdmInstanceStatus.setText(STATUS_REMOTING_NOT_ACTIVATED); |
|
595 |
txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE); |
|
596 |
txtCdmInstanceStatus.setToolTipText(e.getMessage()); |
|
588 | 597 |
comboCdmInstance.setEnabled(false); |
589 | 598 |
btnConnect.setEnabled(false); |
590 | 599 |
} |
... | ... | |
603 | 612 |
|
604 | 613 |
private void refreshCdmInstance() { |
605 | 614 |
txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY); |
615 |
clearOnInstanceChange(); |
|
606 | 616 |
updateSelectedCdmInstance(); |
607 | 617 |
checkSelectedCdmInstance(); |
608 | 618 |
} |
... | ... | |
618 | 628 |
} |
619 | 629 |
|
620 | 630 |
private void checkSelectedCdmInstance() { |
631 |
boolean available = false; |
|
632 |
String status = STATUS_NOT_AVAILABLE; |
|
633 |
String message = null; |
|
634 |
|
|
621 | 635 |
if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) { |
622 | 636 |
try { |
623 | 637 |
if(selectedCsii.pingInstance(selectedCdmInstance, getPort())) { |
624 |
txtCdmInstanceStatus.setText(STATUS_AVAILABLE);
|
|
625 |
btnConnect.setEnabled(true);
|
|
638 |
status = STATUS_AVAILABLE;
|
|
639 |
available = true;
|
|
626 | 640 |
} else { |
627 |
txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE); |
|
628 |
btnConnect.setEnabled(false); |
|
641 |
status = STATUS_NOT_AVAILABLE; |
|
642 |
available = false; |
|
643 |
} |
|
644 |
|
|
645 |
if(available) { |
|
646 |
txtServerCDMVersion.setText(selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort()).getDbSchemaVersion()); |
|
647 |
int compareDbSchemaVersion = selectedCsii.compareDbSchemaVersion(selectedCdmInstance, getPort()); |
|
648 |
int compareCdmlibServicesVersion = selectedCsii.compareCdmlibServicesVersion(); |
|
649 |
|
|
650 |
if(compareDbSchemaVersion > 0 || compareCdmlibServicesVersion > 0) { |
|
651 |
status = STATUS_NOT_COMPATIBLE; |
|
652 |
available = false; |
|
653 |
message = MESG_COMPATIBLE_EDITOR_OLD; |
|
654 |
} else if(compareDbSchemaVersion < 0 || compareCdmlibServicesVersion < 0) { |
|
655 |
status = STATUS_NOT_COMPATIBLE; |
|
656 |
available = false; |
|
657 |
message = MESG_COMPATIBLE_SERVER_OLD; |
|
658 |
} else { |
|
659 |
status = STATUS_AVAILABLE; |
|
660 |
available = true; |
|
661 |
message = ""; |
|
662 |
} |
|
663 |
|
|
664 |
|
|
629 | 665 |
} |
666 |
|
|
630 | 667 |
} catch (Exception e) { |
631 |
txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE); |
|
632 | 668 |
txtCdmInstanceStatus.setToolTipText(e.getMessage()); |
669 |
} finally { |
|
670 |
btnConnect.setEnabled(available); |
|
671 |
txtCdmInstanceStatus.setText(status); |
|
672 |
if(!StringUtils.isBlank(message)) { |
|
673 |
setMessage(message); |
|
674 |
} |
|
633 | 675 |
} |
676 |
|
|
634 | 677 |
} |
635 | 678 |
|
636 | 679 |
} |
... | ... | |
751 | 794 |
styledTxtMessage.setText(message); |
752 | 795 |
styledTxtMessage.setVisible(true); |
753 | 796 |
((GridData)styledTxtMessage.getLayoutData()).exclude = false; |
754 |
shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT+MESSAGE_HEIGHT);
|
|
755 |
shlConnect.setMinimumSize(MIN_WIDTH, MIN_HEIGHT+MESSAGE_HEIGHT);
|
|
797 |
shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
|
|
798 |
shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
|
|
756 | 799 |
} else { |
757 | 800 |
styledTxtMessage.setText(""); |
758 | 801 |
styledTxtMessage.setVisible(false); |
759 | 802 |
((GridData)styledTxtMessage.getLayoutData()).exclude = true; |
760 |
shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
|
|
761 |
shlConnect.setMinimumSize(MIN_WIDTH, MIN_HEIGHT);
|
|
803 |
shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage());
|
|
804 |
shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage());
|
|
762 | 805 |
} |
763 | 806 |
remotingComposite.layout(); |
764 | 807 |
} |
765 | 808 |
|
809 |
private int getHeightWithoutMessage() { |
|
810 |
if(xpndblcmpstAdvanced.isExpanded()) { |
|
811 |
return MIN_EXP_HEIGHT; |
|
812 |
} else { |
|
813 |
return MIN_HEIGHT; |
|
814 |
} |
|
815 |
} |
|
766 | 816 |
|
767 | 817 |
|
768 | 818 |
public void hide(boolean isHidden) { |
... | ... | |
790 | 840 |
} |
791 | 841 |
}); |
792 | 842 |
} |
843 |
|
|
844 |
private String generateLastModifiedTooltip(String cdmlibLastModified) { |
|
845 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z"); |
|
846 |
Date cdmlibLastModifiedDate; |
|
847 |
String cdmlibLastModifiedTimestamp = ""; |
|
848 |
|
|
849 |
cdmlibLastModifiedDate = new Date(Long.valueOf(cdmlibLastModified)); |
|
850 |
cdmlibLastModifiedTimestamp = sdf.format(cdmlibLastModifiedDate); |
|
851 |
|
|
852 |
return "last modified : " + cdmlibLastModifiedTimestamp; |
|
853 |
} |
|
854 |
|
|
855 |
private void setEditorInfo() { |
|
856 |
txtEditorCDMVersion.setText(CdmMetaData.getDbSchemaVersion()); |
|
857 |
txtEditorVersion.setText(CdmApplicationState.getCdmlibVersion()); |
|
858 |
txtEditorVersion.setToolTipText(generateLastModifiedTooltip(CdmApplicationState.getCdmlibLastModified())); |
|
859 |
} |
|
860 |
|
|
861 |
private void clearOnServerChange() { |
|
862 |
setMessage(""); |
|
863 |
txtServerCDMVersion.setText(""); |
|
864 |
txtServerVersion.setText(""); |
|
865 |
txtServerVersion.setToolTipText(""); |
|
866 |
txtServerCDMVersion.setText(""); |
|
867 |
txtPort.setEditable(false); |
|
868 |
txtPort.setEnabled(false); |
|
869 |
} |
|
870 |
|
|
871 |
private void clearOnInstanceChange() { |
|
872 |
setMessage(""); |
|
873 |
txtServerCDMVersion.setText(""); |
|
874 |
} |
|
875 |
|
|
876 |
private void updateOnServerChange(String serverVersion, String serverVersionTooltip) { |
|
877 |
|
|
878 |
} |
|
879 |
|
|
793 | 880 |
} |
Also available in: Unified diff
#5302 Add cdm version and services version check