ref #7981: implement aggregation configuration wizard
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / RemotingLoginDialog.java
index 0b6143b00d5a39d08695a28002a87b4b78e40d82..004a26e2f656ec53caa5b831cf24105cddc3781c 100644 (file)
@@ -61,6 +61,7 @@ import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
 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.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;
 import eu.etaxonomy.taxeditor.l10n.Messages;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
@@ -148,7 +149,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
     private final int MIN_WIDTH = 530;
     private final int MIN_HEIGHT = 220;
     private final int MIN_EXP_HEIGHT = 380;
     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;
     private Label lblEditorVersion;
     private Text txtEditorVersion;
     private Label lblServerCDMVersion;
@@ -209,8 +210,10 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         Display display = getParent().getDisplay();
 
         while (!shlConnect.isDisposed()) {
         Display display = getParent().getDisplay();
 
         while (!shlConnect.isDisposed()) {
-            if (!display.readAndDispatch()) {
-                display.sleep();
+            if (!display.isDisposed()){
+                if (!display.readAndDispatch()) {
+                    display.sleep();
+                }
             }
         }
 
             }
         }
 
@@ -221,7 +224,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
      * Create contents of the dialog.
      */
     private void createContents() {
      * 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);
         shlConnect.setMinimumSize(new Point(MIN_WIDTH, MIN_HEIGHT));
         shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
         shlConnect.setText(Messages.RemotingLoginDialog_LABEL_CONNECT);
@@ -259,6 +262,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         txtCdmServerStatus.setEditable(false);
         GridData gd_txtCdmServerStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
         gd_txtCdmServerStatus.widthHint = 100;
         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);
         txtCdmServerStatus.setLayoutData(gd_txtCdmServerStatus);
 
         btnCdmServerRefresh = new Button(cdmServerComposite, SWT.NONE);
@@ -382,15 +386,20 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         styledTxtMessage.setSelectionForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
         styledTxtMessage.setDoubleClickEnabled(false);
         styledTxtMessage.setEditable(false);
         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;
         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;
         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
         xpndblcmpstAdvanced.setLayoutData(gd_xpndblcmpstAdvanced);
         xpndblcmpstAdvanced.addExpansionListener(new IExpansionListener() {
             @Override
@@ -481,7 +490,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
                        startManagedServer();
                } else {
                        connect();
                        startManagedServer();
                } else {
                        connect();
-                       if (CdmStore.isActive()){
+                       if (CdmStore.isActive() && CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_REMOTING)){
                            PreferencesUtil.setNomenclaturalCodePreferences();
                        }
 
                            PreferencesUtil.setNomenclaturalCodePreferences();
                        }
 
@@ -600,6 +609,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
                         disableCdmInstanceControls("", ""); //$NON-NLS-1$ //$NON-NLS-2$
                     }
                 } catch (CDMServerException | IOException e) {
                         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);
                     MessagingUtils.warningDialog(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, this,
                             Messages.RemotingLoginDialog_CONNECTION_FAILED_MESSAGE);
                     logger.warn(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, e);
@@ -699,7 +709,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         if(selIndex != -1) {
             selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
 
         if(selIndex != -1) {
             selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
 
-            if(loadLoginPrefs && !isDevRemoteSource) {
+            if(loadLoginPrefs) {
                 readPrefCredentials();
             }
         }
                 readPrefCredentials();
             }
         }
@@ -984,11 +994,11 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
     }
 
     private String getUsernamePrefKey() {
     }
 
     private String getUsernamePrefKey() {
-        return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + USERNAME_SUFFIX;
+        return selectedCsii.toString(selectedCdmInstance.getName(), isDevRemoteSource?getPort():-1) + USERNAME_SUFFIX;
     }
 
     private String getPasswordPrefKey() {
     }
 
     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) {
     }
 
     private boolean validateLogin(ICdmRemoteSource remoteSource) {
@@ -1029,23 +1039,29 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
 
     public void setMessage(String message) {
         if(message != null && !message.isEmpty()) {
 
     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(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() {
     }
 
     private int getHeightWithoutMessage() {
@@ -1058,13 +1074,17 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
 
 
     public void hide(boolean isHidden) {
 
 
     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() {
         }
     }
     public void dispose() {
-        if(shlConnect != null && shlConnect.getDisplay() != null) {
-            shlConnect.dispose();
+        if (!shlConnect.isDisposed()){
+            if(shlConnect != null && shlConnect.getDisplay() != null) {
+                shlConnect.dispose();
+            }
         }
     }
 
         }
     }
 
@@ -1072,11 +1092,11 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         Display.getDefault().asyncExec(new Runnable() {
             @Override
             public void run() {
         Display.getDefault().asyncExec(new Runnable() {
             @Override
             public void run() {
-                if(!isDevRemoteSource) {
+                if(selectedCdmInstance!=null){
                     if(isRememberMe()) {
                         persistPrefCredentials();
                     }else{
                     if(isRememberMe()) {
                         persistPrefCredentials();
                     }else{
-                       removePrefCredentials();
+                        removePrefCredentials();
                     }
                     persistPrefLastServerInstance();
                 }
                     }
                     persistPrefLastServerInstance();
                 }