ref #7189 improving & cleaning up size calculation of login dialog
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Mon, 25 May 2020 12:42:25 +0000 (14:42 +0200)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Mon, 25 May 2020 12:42:25 +0000 (14:42 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java

index cef9c78bf11060b895388a26d86fad24f87b8d9d..0487aa51a2cf1b25e4da37ec65ffc4d94de9aab2 100644 (file)
@@ -150,6 +150,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 MESSAGE_HEIGHT = 50;
     private Label lblEditorVersion;
     private Text txtEditorVersion;
@@ -203,10 +204,8 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
 
         setEditorInfo();
         populateCdmServerCombo();
+        shlConnect.pack(true);
         shlConnect.open();
-        shlConnect.layout();
-        Point newSize = shlConnect.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
-        shlConnect.setSize(newSize);
 
         xpndblcmpstAdvanced.setExpanded(false);
 
@@ -228,8 +227,6 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
      */
     private void createContents() {
         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));
 
@@ -238,7 +235,6 @@ 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;
         cdmServerComposite.setLayoutData(gd_cdmServerComposite);
         cdmServerComposite.setLayout(new GridLayout(4, false));
 
@@ -247,7 +243,13 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         lblCdmServer.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
         lblCdmServer.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
 
-        comboCdmServer = new Combo(cdmServerComposite, SWT.READ_ONLY);
+        comboCdmServer = new Combo(cdmServerComposite, SWT.READ_ONLY) {
+            @Override
+            public Point computeSize(final int wHint, final int hHint, final boolean changed) {
+                final Point preferredSize = super.computeSize(wHint, hHint, changed);
+                return new Point(Math.min(maxSize.x, preferredSize.x), Math.min(maxSize.y, preferredSize.y));
+            }
+        };
         comboCdmServer.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
@@ -256,7 +258,6 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
             }
         });
         GridData gd_comboCdmServer = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
-        //gd_comboCdmServer.widthHint = 150;
         comboCdmServer.setLayoutData(gd_comboCdmServer);
         comboCdmServer.select(0);
 
@@ -264,7 +265,6 @@ 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;
 
         txtCdmServerStatus.setLayoutData(gd_txtCdmServerStatus);
 
@@ -293,7 +293,6 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
             }
         });
         GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
-        //gd_comboCdmInstance.widthHint = 150;
         comboCdmInstance.setLayoutData(gd_comboCdmInstance);
         comboCdmInstance.select(0);
 
@@ -301,7 +300,6 @@ 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;
         txtCdmInstanceStatus.setLayoutData(gd_txtCdmInstanceStatus);
 
         btnCdmInstanceRefresh = new Button(cdmServerComposite, SWT.FLAT);
@@ -312,15 +310,11 @@ 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;
         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;
         loginComposite.setLayoutData(gd_loginComposite);
         GridLayout gl_loginComposite = new GridLayout(6, false);
         gl_loginComposite.marginTop = 5;
@@ -328,7 +322,6 @@ 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;
         lblLogin.setLayoutData(gd_lblLogin);
         lblLogin.setText(Messages.RemotingLoginDialog_LABEL_LOGIN_COLON);
         lblLogin.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
@@ -336,8 +329,6 @@ 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;
         txtLogin.setLayoutData(gd_txtLogin);
 
         lblPassword = new Label(loginComposite, SWT.CENTER);
@@ -348,8 +339,6 @@ 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;
         txtPassword.setLayoutData(gd_txtPassword);
         new Label(loginComposite, SWT.NONE);
         txtPassword.addKeyListener(new KeyAdapter() {
@@ -394,27 +383,16 @@ 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;
 
         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) {
-                if(e.getState()) {
-                    Point newSize = shlConnect.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
-                    shlConnect.setSize(newSize);
-                } else {
-                    Point newSize = shlConnect.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
-                    shlConnect.setSize(newSize);
-                }
-
+                shlConnect.pack(true);
             }
             @Override
             public void expansionStateChanging(ExpansionEvent e) {
@@ -429,14 +407,12 @@ 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.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;
         txtPort.setLayoutData(gd_txtPort);
 
         lblServerVersion = new Label(compAdvanced, SWT.CENTER);
@@ -465,8 +441,8 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         txtEditorVersion = new Text(compAdvanced, SWT.BORDER);
         txtEditorVersion.setEditable(false);
         txtEditorVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
-        new Label(compAdvanced, SWT.NONE);
-        new Label(compAdvanced, SWT.NONE);
+//        new Label(compAdvanced, SWT.NONE);
+//        new Label(compAdvanced, SWT.NONE);
 
         lblServerCDMVersion = new Label(compAdvanced, SWT.CENTER);
         lblServerCDMVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
@@ -476,8 +452,8 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
         txtServerCDMVersion = new Text(compAdvanced, SWT.BORDER);
         txtServerCDMVersion.setEditable(false);
         txtServerCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
-        new Label(compAdvanced, SWT.NONE);
-        new Label(compAdvanced, SWT.NONE);
+//        new Label(compAdvanced, SWT.NONE);
+//        new Label(compAdvanced, SWT.NONE);
 
         lblEditorCDMVersion = new Label(compAdvanced, SWT.CENTER);
         lblEditorCDMVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
@@ -863,6 +839,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
                     btnConnect.setEnabled(true);
                     btnConnect.setText("Create Schema");
                     btnConnect.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
+                    btnConnect.requestLayout();
                 }
              });
         } else {
@@ -1104,8 +1081,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
             styledTxtMessage.setVisible(true);
             ((GridData)styledTxtMessage.getLayoutData()).exclude = false;
 //            shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
-            Point newSize = shlConnect.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
-            shlConnect.setSize(newSize);
+            shlConnect.pack(true);
         } else {
             if (!styledTxtMessage.isDisposed()){
                 styledTxtMessage.setText(""); //$NON-NLS-1$
@@ -1113,9 +1089,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
                 ((GridData)styledTxtMessage.getLayoutData()).exclude = true;
             }
             if(!shlConnect.isDisposed()){
-//                shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage());
-                Point newSize = shlConnect.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
-                shlConnect.setSize(newSize);
+                shlConnect.pack(true);
             }
         }
         if (!remotingComposite.isDisposed()){