import java.util.Map;
import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.service.IUserService;
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
import eu.etaxonomy.taxeditor.l10n.Messages;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
*/
public class RemotingLoginDialog extends Dialog implements ICDMServerError {
- /**
- *
- */
- private static final String DEFAULT_PASS = "00000";
- /**
- *
- */
- private static final String DEFAULT_USER = "admin";
+ private Logger logger = Logger.getLogger(getClass());
+
+ private static final String DEFAULT_PASS = "00000"; //$NON-NLS-1$
+ private static final String DEFAULT_USER = "admin"; //$NON-NLS-1$
private static final String UBUNTU = "Ubuntu"; //$NON-NLS-1$
protected Object result;
protected Shell shlConnect;
private final int MIN_WIDTH = 530;
private final int MIN_HEIGHT = 220;
private final int MIN_EXP_HEIGHT = 380;
- private final int MESSAGE_HEIGHT = 25;
+ private final int MESSAGE_HEIGHT = 50;
private Label lblEditorVersion;
private Text txtEditorVersion;
private Label lblServerCDMVersion;
Display display = getParent().getDisplay();
while (!shlConnect.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
+ if (!display.isDisposed()){
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
}
}
* Create contents of the dialog.
*/
private void createContents() {
- shlConnect = new Shell(getParent(), SWT.DIALOG_TRIM);
+ shlConnect = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shlConnect.setMinimumSize(new Point(MIN_WIDTH, MIN_HEIGHT));
shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
shlConnect.setText(Messages.RemotingLoginDialog_LABEL_CONNECT);
txtCdmServerStatus.setEditable(false);
GridData gd_txtCdmServerStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_txtCdmServerStatus.widthHint = 100;
+
txtCdmServerStatus.setLayoutData(gd_txtCdmServerStatus);
btnCdmServerRefresh = new Button(cdmServerComposite, SWT.NONE);
styledTxtMessage.setSelectionForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
styledTxtMessage.setDoubleClickEnabled(false);
styledTxtMessage.setEditable(false);
+ styledTxtMessage.setWordWrap(true);
+
GridData gd_styledTxtMessage = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
gd_styledTxtMessage.exclude = true;
gd_styledTxtMessage.minimumHeight = MESSAGE_HEIGHT;
gd_styledTxtMessage.heightHint = MESSAGE_HEIGHT;
+ gd_styledTxtMessage.widthHint = MIN_WIDTH - 5;
+
styledTxtMessage.setLayoutData(gd_styledTxtMessage);
xpndblcmpstAdvanced = new ExpandableComposite(remotingComposite, SWT.NONE, ExpandableComposite.TWISTIE);
GridData gd_xpndblcmpstAdvanced = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
gd_xpndblcmpstAdvanced.heightHint = 19;
+ gd_xpndblcmpstAdvanced.widthHint = MIN_WIDTH - 10;
xpndblcmpstAdvanced.setLayoutData(gd_xpndblcmpstAdvanced);
xpndblcmpstAdvanced.addExpansionListener(new IExpansionListener() {
@Override
startManagedServer();
} else {
connect();
- if (CdmStore.isActive()){
+ if (CdmStore.isActive() && CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_REMOTING)){
PreferencesUtil.setNomenclaturalCodePreferences();
}
txtPort.setEditable(true);
txtPort.setEnabled(true);
}
- if(selectedCsii.pingServer()) {
- txtCdmServerStatus.setText(STATUS_AVAILABLE);
- populateCdmInstanceCombo(true);
- String serverVersionTimestamp = generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified());
- txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion() + ":" + serverVersionTimestamp); //$NON-NLS-1$
- } else {
+ try {
+ if(selectedCsii.pingServer()) {
+ txtCdmServerStatus.setText(STATUS_AVAILABLE);
+ populateCdmInstanceCombo(true);
+ String serverVersionTimestamp = generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified());
+ txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion() + ":" + serverVersionTimestamp); //$NON-NLS-1$
+ } else {
+ txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
+ comboCdmInstance.removeAll();
+ disableCdmInstanceControls("", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ } catch (CDMServerException | IOException e) {
txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
- comboCdmInstance.removeAll();
- disableCdmInstanceControls("", "");
+ MessagingUtils.warningDialog(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, this,
+ Messages.RemotingLoginDialog_CONNECTION_FAILED_MESSAGE);
+ logger.warn(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, e);
}
}
updatePort();
if(selIndex != -1) {
selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
- if(loadLoginPrefs && !isDevRemoteSource) {
+ if(loadLoginPrefs) {
readPrefCredentials();
}
}
int compareDbSchemaVersion = selectedCsii.compareDbSchemaVersion(selectedCdmInstance, getPort());
int compareCdmlibServicesVersion = 0;
boolean disableServicesApiTimestampCheck =
- PreferencesUtil.getPreferenceStore().getBoolean((IPreferenceKeys.DISABLE_SERVICES_API_TIMESTAMP_CHECK));
+ PreferencesUtil.getBooleanValue((IPreferenceKeys.DISABLE_SERVICES_API_TIMESTAMP_CHECK));
if(!disableServicesApiTimestampCheck) {
compareCdmlibServicesVersion = selectedCsii.compareCdmlibServicesVersion();
}
}
private String getUsernamePrefKey() {
- return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + USERNAME_SUFFIX;
+ return selectedCsii.toString(selectedCdmInstance.getName(), isDevRemoteSource?getPort():-1) + USERNAME_SUFFIX;
}
private String getPasswordPrefKey() {
- return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + PASSWORD_SUFFIX;
+ return selectedCsii.toString(selectedCdmInstance.getName(), isDevRemoteSource?getPort():-1) + PASSWORD_SUFFIX;
}
private boolean validateLogin(ICdmRemoteSource remoteSource) {
public void setMessage(String message) {
if(message != null && !message.isEmpty()) {
- if(message.length() > 60) {
- styledTxtMessage.setToolTipText(message);
- message = message.substring(0, 60) + "..."; //$NON-NLS-1$
- }
+// if(message.length() > 50) {
+// styledTxtMessage.setToolTipText(message);
+// message = message.substring(0,50) + "..."; //$NON-NLS-1$
+// }
styledTxtMessage.setText(message);
styledTxtMessage.setVisible(true);
((GridData)styledTxtMessage.getLayoutData()).exclude = false;
shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
} else {
- styledTxtMessage.setText(""); //$NON-NLS-1$
- styledTxtMessage.setVisible(false);
- ((GridData)styledTxtMessage.getLayoutData()).exclude = true;
- shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage());
- shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage());
+ if (!styledTxtMessage.isDisposed()){
+ styledTxtMessage.setText(""); //$NON-NLS-1$
+ styledTxtMessage.setVisible(false);
+ ((GridData)styledTxtMessage.getLayoutData()).exclude = true;
+ }
+ if(!shlConnect.isDisposed()){
+ shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage());
+ shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage());
+ }
+ }
+ if (!remotingComposite.isDisposed()){
+ remotingComposite.layout();
}
- remotingComposite.layout();
}
private int getHeightWithoutMessage() {
public void hide(boolean isHidden) {
- if(shlConnect != null && shlConnect.getDisplay() != null) {
- shlConnect.setVisible(!isHidden);
+ if (!shlConnect.isDisposed()){
+ if(shlConnect != null && shlConnect.getDisplay() != null) {
+ shlConnect.setVisible(!isHidden);
+ }
}
}
public void dispose() {
- if(shlConnect != null && shlConnect.getDisplay() != null) {
- shlConnect.dispose();
+ if (!shlConnect.isDisposed()){
+ if(shlConnect != null && shlConnect.getDisplay() != null) {
+ shlConnect.dispose();
+ }
}
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- if(!isDevRemoteSource) {
+ if(selectedCdmInstance!=null){
if(isRememberMe()) {
persistPrefCredentials();
}else{
- removePrefCredentials();
+ removePrefCredentials();
}
persistPrefLastServerInstance();
}