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 org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.service.IUserService;
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
-import eu.etaxonomy.taxeditor.Messages;
+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;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
*/
public class RemotingLoginDialog extends Dialog implements ICDMServerError {
+ 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 static String STATUS_RETRIEVING = Messages.RemotingLoginDialog_STATUS_RETRIEVING;
private final static String STATUS_CHECKING_AVAILABILITY = Messages.RemotingLoginDialog_STATUS_CHECKING;
private final static String STATUS_NO_INSTANCES = Messages.RemotingLoginDialog_STATUS_NO_INSTANCES_FOUND;
- private final static String STATUS_ERROR = Messages.RemotingLoginDialog_STATUS_ERROR;
- private final static String STATUS_REMOTING_NOT_ACTIVATED = Messages.RemotingLoginDialog_STATUS_REMOTING_NOT_ACTIVATED;
private final static String STATUS_NOT_COMPATIBLE = Messages.RemotingLoginDialog_STATUS_NOT_COMPATIBLE;
private final static String MESG_COMPATIBLE_EDITOR_OLD = Messages.RemotingLoginDialog_UPDATE_EDITOR;
private final static String LAST_SERVER_KEY = "lastServerKey"; //$NON-NLS-1$
private final static String LAST_INSTANCE_KEY = "lastInstanceKey"; //$NON-NLS-1$
- private final static String REFRESH_LABEL = Messages.RemotingLoginDialog_LABEL_REFRESH;
private Composite remotingComposite;
private CdmServerInfo selectedCsii;
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);
GridData gd_btnRememberMe = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
btnRememberMe.setLayoutData(gd_btnRememberMe);
btnRememberMe.setText(Messages.RemotingLoginDialog_LABEL_REMEMBER_ME);
- new Label(loginComposite, SWT.NONE);
- new Label(loginComposite, SWT.NONE);
- new Label(loginComposite, SWT.NONE);
- new Label(loginComposite, SWT.NONE);
+
+ Label lblDefaultLogin = new Label(loginComposite, SWT.NONE);
+ GridDataFactory.fillDefaults().span(4, 1).align(SWT.TRAIL, SWT.CENTER).applyTo(lblDefaultLogin);
+ lblDefaultLogin.setText(String.format(Messages.RemotingLoginDialog_DEFAULT_LOGIN, DEFAULT_USER, DEFAULT_PASS));
styledTxtMessage = new StyledText(remotingComposite, SWT.NONE);
styledTxtMessage.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
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
public void expansionStateChanged(ExpansionEvent e) {
- GridData gridData = (GridData) xpndblcmpstAdvanced.getLayoutData();
if(e.getState()) {
shlConnect.setSize(MIN_WIDTH, MIN_EXP_HEIGHT);
} else {
startManagedServer();
} else {
connect();
- if (CdmStore.isActive()){
+ if (CdmStore.isActive() && CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_REMOTING)){
PreferencesUtil.setNomenclaturalCodePreferences();
}
private void refreshCdmServer() {
- txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
- clearOnServerChange();
- emptyCredentials();
- updateSelectedCdmServer();
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- checkSelectedCdmServer();
- }
- });
-
+ try{
+ txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
+ clearOnServerChange();
+ emptyCredentials();
+ updateSelectedCdmServer();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ checkSelectedCdmServer();
+ }
+ });
+ }
+ catch(SWTException e){
+ //catch widget is disposed exception which may occurr if
+ //dialog is closed but the runnable tries to update
+ }
}
private void updateSelectedCdmServer() {
}
private void updatePort() {
- txtPort.setText("");
+ txtPort.setText(""); //$NON-NLS-1$
if(selectedCsii != null) {
int port = selectedCsii.getPort();
if(port == CdmServerInfo.NULL_PORT) {
}
private void checkSelectedCdmServer() {
- if(selectedCsii != null) {
- if(selectedCsii.isLocalhost()) {
- 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 {
- txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
- comboCdmInstance.removeAll();
- disableCdmInstanceControls("", "");
+ try{
+ if(selectedCsii != null) {
+ if(selectedCsii.isLocalhost()) {
+ txtPort.setEditable(true);
+ txtPort.setEnabled(true);
+ }
+ 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);
+ MessagingUtils.warningDialog(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, this,
+ Messages.RemotingLoginDialog_CONNECTION_FAILED_MESSAGE);
+ logger.warn(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, e);
+ }
}
+ updatePort();
+ }
+ catch(SWTException e){
+ //catch widget is disposed exception which may occurr if
+ //dialog is closed but the runnable tries to update
}
- updatePort();
}
comboCdmInstance.setEnabled(false);
btnConnect.setEnabled(false);
txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
- txtCdmInstanceStatus.setToolTipText("");
+ txtCdmInstanceStatus.setToolTipText(""); //$NON-NLS-1$
serverJob = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
@Override
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();
}
flushPreferences(credentialsPrefs);
}
+ private void removePrefCredentials() {
+ IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
+ Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
+ credentialsPrefs.put(getUsernamePrefKey(), txtLogin.getText());
+ credentialsPrefs.put(getPasswordPrefKey(), txtPassword.getText());
+ removePreferences(credentialsPrefs);
+ }
+ private void removePreferences(Preferences prefs) {
+ try {
+ prefs.removeNode();
+ } catch (BackingStoreException bse) {
+ setMessage(bse.getMessage());
+ }
+ }
private void flushPreferences(Preferences prefs) {
try {
prefs.flush();
}
}
+
+
private void readPrefCredentials() {
String username, password;
IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
}
private void emptyCredentials() {
- txtLogin.setText("");
- txtPassword.setText("");
+ txtLogin.setText(""); //$NON-NLS-1$
+ txtPassword.setText(""); //$NON-NLS-1$
}
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();
}
persistPrefLastServerInstance();
}