*/
package eu.etaxonomy.taxeditor.ui.dialog;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.commons.lang.StringUtils;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
private final static String STATUS_NO_INSTANCES = "No Instances Found";
private final static String STATUS_ERROR = "Error";
private final static String STATUS_REMOTING_NOT_ACTIVATED = "Remoting not activated";
+ private final static String STATUS_NOT_COMPATIBLE = "Not Compatible";
+
+ private final static String MESG_COMPATIBLE_EDITOR_OLD = "Please update the Taxonomic Editor (Help->Check for Updates) or choose a compatible cdm-server";
+ private final static String MESG_COMPATIBLE_SERVER_OLD = "Please update the chosen cdm-server or choose a compatible cdm-server";
+
private final static String STORE_PREFERENCES_NODE = "eu.etaxonomy.taxeditor.store";
private final static String LOGIN_NODE = "login";
private final int MIN_WIDTH = 530;
private final int MIN_HEIGHT = 220;
- private final int MIN_EXP_HEIGHT = 350;
+ private final int MIN_EXP_HEIGHT = 380;
private final int MESSAGE_HEIGHT = 25;
private Label lblEditorVersion;
private Text txtEditorVersion;
readPrefLastServerInstance();
}
+ setEditorInfo();
populateCdmServerCombo();
shlConnect.open();
shlConnect.layout();
lblServerVersion = new Label(compAdvanced, SWT.CENTER);
lblServerVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- lblServerVersion.setText("Server Version :");
+ lblServerVersion.setText("Server Cdmlib Version :");
lblServerVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
txtServerVersion = new Text(compAdvanced, SWT.BORDER);
- txtServerVersion.setEnabled(false);
txtServerVersion.setEditable(false);
txtServerVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
new Label(compAdvanced, SWT.NONE);
lblEditorVersion = new Label(compAdvanced, SWT.CENTER);
lblEditorVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- lblEditorVersion.setText("Editor Version :");
+ lblEditorVersion.setText("Editor Cdmlib Version :");
lblEditorVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
txtEditorVersion = new Text(compAdvanced, SWT.BORDER);
- txtEditorVersion.setEnabled(false);
txtEditorVersion.setEditable(false);
txtEditorVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(compAdvanced, SWT.NONE);
lblServerCDMVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
txtServerCDMVersion = new Text(compAdvanced, SWT.BORDER);
- txtServerCDMVersion.setEnabled(false);
txtServerCDMVersion.setEditable(false);
txtServerCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(compAdvanced, SWT.NONE);
lblEditorCDMVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
txtEditorCDMVersion = new Text(compAdvanced, SWT.BORDER);
- txtEditorCDMVersion.setEnabled(false);
txtEditorCDMVersion.setEditable(false);
txtEditorCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
private void checkSelectedCdmServer() {
- txtCdmInstanceStatus.setText("");
- txtPort.setEditable(false);
- txtPort.setEnabled(false);
+ clearOnServerChange();
emptyCredentials();
if(selectedCsii != null) {
if(selectedCsii.pingServer()) {
txtCdmServerStatus.setText(STATUS_AVAILABLE);
populateCdmInstanceCombo(true);
+ txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion());
+ txtServerVersion.setToolTipText(generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified()));
} else {
txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
comboCdmInstance.setEnabled(false);
btnConnect.setEnabled(false);
txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
+ txtCdmInstanceStatus.setToolTipText("");
Job job = new Job("Retrieve Server Instances") {
@Override
}
});
}
- } catch (CDMServerException e) {
+ } catch (final CDMServerException e) {
MessagingUtils.warn(getClass(), e);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- txtCdmInstanceStatus.setText(STATUS_REMOTING_NOT_ACTIVATED);
+ txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
+ txtCdmInstanceStatus.setToolTipText(e.getMessage());
comboCdmInstance.setEnabled(false);
btnConnect.setEnabled(false);
}
private void refreshCdmInstance() {
txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
+ clearOnInstanceChange();
updateSelectedCdmInstance();
checkSelectedCdmInstance();
}
}
private void checkSelectedCdmInstance() {
+ boolean available = false;
+ String status = STATUS_NOT_AVAILABLE;
+ String message = null;
+
if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
try {
if(selectedCsii.pingInstance(selectedCdmInstance, getPort())) {
- txtCdmInstanceStatus.setText(STATUS_AVAILABLE);
- btnConnect.setEnabled(true);
+ status = STATUS_AVAILABLE;
+ available = true;
} else {
- txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
- btnConnect.setEnabled(false);
+ status = STATUS_NOT_AVAILABLE;
+ available = false;
+ }
+
+ if(available) {
+ txtServerCDMVersion.setText(selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort()).getDbSchemaVersion());
+ int compareDbSchemaVersion = selectedCsii.compareDbSchemaVersion(selectedCdmInstance, getPort());
+ int compareCdmlibServicesVersion = selectedCsii.compareCdmlibServicesVersion();
+
+ if(compareDbSchemaVersion > 0 || compareCdmlibServicesVersion > 0) {
+ status = STATUS_NOT_COMPATIBLE;
+ available = false;
+ message = MESG_COMPATIBLE_EDITOR_OLD;
+ } else if(compareDbSchemaVersion < 0 || compareCdmlibServicesVersion < 0) {
+ status = STATUS_NOT_COMPATIBLE;
+ available = false;
+ message = MESG_COMPATIBLE_SERVER_OLD;
+ } else {
+ status = STATUS_AVAILABLE;
+ available = true;
+ message = "";
+ }
+
+
}
+
} catch (Exception e) {
- txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
txtCdmInstanceStatus.setToolTipText(e.getMessage());
+ } finally {
+ btnConnect.setEnabled(available);
+ txtCdmInstanceStatus.setText(status);
+ if(!StringUtils.isBlank(message)) {
+ setMessage(message);
+ }
}
+
}
}
styledTxtMessage.setText(message);
styledTxtMessage.setVisible(true);
((GridData)styledTxtMessage.getLayoutData()).exclude = false;
- shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT+MESSAGE_HEIGHT);
- shlConnect.setMinimumSize(MIN_WIDTH, MIN_HEIGHT+MESSAGE_HEIGHT);
+ shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
+ shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
} else {
styledTxtMessage.setText("");
styledTxtMessage.setVisible(false);
((GridData)styledTxtMessage.getLayoutData()).exclude = true;
- shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
- shlConnect.setMinimumSize(MIN_WIDTH, MIN_HEIGHT);
+ shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage());
+ shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage());
}
remotingComposite.layout();
}
+ private int getHeightWithoutMessage() {
+ if(xpndblcmpstAdvanced.isExpanded()) {
+ return MIN_EXP_HEIGHT;
+ } else {
+ return MIN_HEIGHT;
+ }
+ }
public void hide(boolean isHidden) {
}
});
}
+
+ private String generateLastModifiedTooltip(String cdmlibLastModified) {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z");
+ Date cdmlibLastModifiedDate;
+ String cdmlibLastModifiedTimestamp = "";
+
+ cdmlibLastModifiedDate = new Date(Long.valueOf(cdmlibLastModified));
+ cdmlibLastModifiedTimestamp = sdf.format(cdmlibLastModifiedDate);
+
+ return "last modified : " + cdmlibLastModifiedTimestamp;
+ }
+
+ private void setEditorInfo() {
+ txtEditorCDMVersion.setText(CdmMetaData.getDbSchemaVersion());
+ txtEditorVersion.setText(CdmApplicationState.getCdmlibVersion());
+ txtEditorVersion.setToolTipText(generateLastModifiedTooltip(CdmApplicationState.getCdmlibLastModified()));
+ }
+
+ private void clearOnServerChange() {
+ setMessage("");
+ txtServerCDMVersion.setText("");
+ txtServerVersion.setText("");
+ txtServerVersion.setToolTipText("");
+ txtServerCDMVersion.setText("");
+ txtPort.setEditable(false);
+ txtPort.setEnabled(false);
+ }
+
+ private void clearOnInstanceChange() {
+ setMessage("");
+ txtServerCDMVersion.setText("");
+ }
+
+ private void updateOnServerChange(String serverVersion, String serverVersionTooltip) {
+
+ }
+
}