ref #7189 Connect dialog resizable and allowing for automatic size calculation
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 20 May 2020 13:24:00 +0000 (15:24 +0200)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 20 May 2020 13:24:00 +0000 (15:24 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java

index 04d10da40892ee166a34f697c189cdbe082d436d..cef9c78bf11060b895388a26d86fad24f87b8d9d 100644 (file)
@@ -147,9 +147,9 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
     private StyledText styledTxtMessage;
 
 
-    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 = 50;
     private Label lblEditorVersion;
     private Text txtEditorVersion;
@@ -205,6 +205,8 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         populateCdmServerCombo();
         shlConnect.open();
         shlConnect.layout();
+        Point newSize = shlConnect.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+        shlConnect.setSize(newSize);
 
         xpndblcmpstAdvanced.setExpanded(false);
 
@@ -225,9 +227,9 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
      * Create contents of the dialog.
      */
     private void createContents() {
-        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 = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE);
+        //shlConnect.setMinimumSize(new Point(MIN_WIDTH, MIN_HEIGHT));
+        // shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
         shlConnect.setText(Messages.RemotingLoginDialog_LABEL_CONNECT);
         shlConnect.setLayout(new FillLayout(SWT.HORIZONTAL));
 
@@ -236,7 +238,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
 
         Composite cdmServerComposite = new Composite(remotingComposite, SWT.NONE);
         GridData gd_cdmServerComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
-        gd_cdmServerComposite.heightHint = 68;
+        // gd_cdmServerComposite.heightHint = 68;
         cdmServerComposite.setLayoutData(gd_cdmServerComposite);
         cdmServerComposite.setLayout(new GridLayout(4, false));
 
@@ -254,7 +256,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
             }
         });
         GridData gd_comboCdmServer = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
-        gd_comboCdmServer.widthHint = 150;
+        //gd_comboCdmServer.widthHint = 150;
         comboCdmServer.setLayoutData(gd_comboCdmServer);
         comboCdmServer.select(0);
 
@@ -262,7 +264,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         txtCdmServerStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
         txtCdmServerStatus.setEditable(false);
         GridData gd_txtCdmServerStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
-        gd_txtCdmServerStatus.widthHint = 100;
+        //gd_txtCdmServerStatus.widthHint = 100;
 
         txtCdmServerStatus.setLayoutData(gd_txtCdmServerStatus);
 
@@ -278,7 +280,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
 
         Label lblCdmInstance = new Label(cdmServerComposite, SWT.NONE);
         GridData gd_lblCdmInstance = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
-        gd_lblCdmInstance.heightHint = 30;
+        //gd_lblCdmInstance.heightHint = 30;
         lblCdmInstance.setLayoutData(gd_lblCdmInstance);
         lblCdmInstance.setText(Messages.RemotingLoginDialog_LABEL_CDM_INSTANCE);
         lblCdmInstance.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
@@ -291,7 +293,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
             }
         });
         GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
-        gd_comboCdmInstance.widthHint = 150;
+        //gd_comboCdmInstance.widthHint = 150;
         comboCdmInstance.setLayoutData(gd_comboCdmInstance);
         comboCdmInstance.select(0);
 
@@ -299,7 +301,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         txtCdmInstanceStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
         txtCdmInstanceStatus.setEditable(false);
         GridData gd_txtCdmInstanceStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
-        gd_txtCdmInstanceStatus.widthHint = 100;
+        //gd_txtCdmInstanceStatus.widthHint = 100;
         txtCdmInstanceStatus.setLayoutData(gd_txtCdmInstanceStatus);
 
         btnCdmInstanceRefresh = new Button(cdmServerComposite, SWT.FLAT);
@@ -310,15 +312,15 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
             }
         });
         GridData gd_btnCdmInstanceRefresh = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
-        gd_btnCdmInstanceRefresh.widthHint = 110;
-        gd_btnCdmInstanceRefresh.heightHint = 30;
+//        gd_btnCdmInstanceRefresh.widthHint = 110;
+//        gd_btnCdmInstanceRefresh.heightHint = 30;
         btnCdmInstanceRefresh.setLayoutData(gd_btnCdmInstanceRefresh);
         btnCdmInstanceRefresh.setText(Messages.RemotingLoginDialog_LABEL_REFRESH);
 
         loginComposite = new Composite(remotingComposite, SWT.NONE);
         GridData gd_loginComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
-        gd_loginComposite.widthHint = 487;
-        gd_loginComposite.heightHint = 70;
+//        gd_loginComposite.widthHint = 487;
+//        gd_loginComposite.heightHint = 70;
         loginComposite.setLayoutData(gd_loginComposite);
         GridLayout gl_loginComposite = new GridLayout(6, false);
         gl_loginComposite.marginTop = 5;
@@ -326,7 +328,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
 
         lblLogin = new Label(loginComposite, SWT.CENTER);
         GridData gd_lblLogin = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
-        gd_lblLogin.widthHint = 50;
+//        gd_lblLogin.widthHint = 50;
         lblLogin.setLayoutData(gd_lblLogin);
         lblLogin.setText(Messages.RemotingLoginDialog_LABEL_LOGIN_COLON);
         lblLogin.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
@@ -334,8 +336,8 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         txtLogin = new Text(loginComposite, SWT.BORDER);
         GridData gd_txtLogin = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
         gd_txtLogin.minimumWidth = 80;
-        gd_txtLogin.widthHint = 80;
-        gd_txtLogin.heightHint = 15;
+//        gd_txtLogin.widthHint = 80;
+//        gd_txtLogin.heightHint = 15;
         txtLogin.setLayoutData(gd_txtLogin);
 
         lblPassword = new Label(loginComposite, SWT.CENTER);
@@ -346,8 +348,8 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         txtPassword = new Text(loginComposite, SWT.BORDER | SWT.PASSWORD);
         GridData gd_txtPassword = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
         gd_txtPassword.minimumWidth = 80;
-        gd_txtPassword.widthHint = 80;
-        gd_txtPassword.heightHint = 15;
+//        gd_txtPassword.widthHint = 80;
+//        gd_txtPassword.heightHint = 15;
         txtPassword.setLayoutData(gd_txtPassword);
         new Label(loginComposite, SWT.NONE);
         txtPassword.addKeyListener(new KeyAdapter() {
@@ -392,23 +394,25 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         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;
+        // 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;
+        // gd_xpndblcmpstAdvanced.heightHint = 19;
+        // gd_xpndblcmpstAdvanced.widthHint = MIN_WIDTH - 10;
         xpndblcmpstAdvanced.setLayoutData(gd_xpndblcmpstAdvanced);
         xpndblcmpstAdvanced.addExpansionListener(new IExpansionListener() {
             @Override
             public void expansionStateChanged(ExpansionEvent e) {
                 if(e.getState()) {
-                    shlConnect.setSize(MIN_WIDTH, MIN_EXP_HEIGHT);
+                    Point newSize = shlConnect.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+                    shlConnect.setSize(newSize);
                 } else {
-                    shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
+                    Point newSize = shlConnect.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+                    shlConnect.setSize(newSize);
                 }
 
             }
@@ -425,14 +429,14 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
 
         lblPort = new Label(compAdvanced, SWT.CENTER);
         lblPort.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
-        lblPort.setSize(0, 0);
+        //lblPort.setSize(0, 0);
         lblPort.setText(Messages.RemotingLoginDialog_LABEL_PORT);
         lblPort.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
 
         txtPort = new Text(compAdvanced, SWT.BORDER);
         GridData gd_txtPort = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
         gd_txtPort.minimumWidth = 50;
-        gd_txtPort.widthHint = 50;
+        // gd_txtPort.widthHint = 50;
         txtPort.setLayoutData(gd_txtPort);
 
         lblServerVersion = new Label(compAdvanced, SWT.CENTER);
@@ -484,6 +488,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         txtEditorCDMVersion.setEditable(false);
         txtEditorCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
 
+
     }
 
        private void connectButtonPressed() {
@@ -1098,8 +1103,9 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
             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);
+//            shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
+            Point newSize = shlConnect.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+            shlConnect.setSize(newSize);
         } else {
             if (!styledTxtMessage.isDisposed()){
                 styledTxtMessage.setText(""); //$NON-NLS-1$
@@ -1107,8 +1113,9 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
                 ((GridData)styledTxtMessage.getLayoutData()).exclude = true;
             }
             if(!shlConnect.isDisposed()){
-                shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage());
-                shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage());
+//                shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage());
+                Point newSize = shlConnect.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+                shlConnect.setSize(newSize);
             }
         }
         if (!remotingComposite.isDisposed()){
@@ -1116,13 +1123,13 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         }
     }
 
-    private int getHeightWithoutMessage() {
-        if(xpndblcmpstAdvanced.isExpanded()) {
-            return MIN_EXP_HEIGHT;
-        } else {
-            return MIN_HEIGHT;
-        }
-    }
+//    private int getHeightWithoutMessage() {
+//        if(xpndblcmpstAdvanced.isExpanded()) {
+//            return MIN_EXP_HEIGHT;
+//        } else {
+//            return MIN_HEIGHT;
+//        }
+//    }
 
 
     public void hide(boolean isHidden) {