Split up control creation of TextWithLabelElement
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 25 Aug 2015 06:05:51 +0000 (08:05 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 25 Aug 2015 06:05:51 +0000 (08:05 +0200)
 - this fixes layout problems when inserting a separate button for
opening links

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TextWithLabelElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java

index efe1877..039b54c 100644 (file)
@@ -60,22 +60,13 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
 
         this.isMultiLine = isMultiLine;
 
-        init(formFactory, labelString, initialText, textHeight, textLimit, isMultiLine, style, getLayoutComposite());
-    }
+        initLabel(formFactory, labelString, isMultiLine, getLayoutComposite());
 
-    protected void init(CdmFormFactory formFactory, String labelString, String initialText, Integer textHeight,
-            Integer textLimit, boolean isMultiLine, int style, Composite layoutComposite) {
-        if (labelString != null) {
-            label = formFactory.createLabel(layoutComposite, CdmUtils.Nz(labelString), SWT.NULL);
-            addControl(label);
-            if(isMultiLine){
-                label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
-            }
-            else{
-                label.setLayoutData(LayoutConstants.LEFT());
-            }
-        }
+        initText(formFactory, initialText, textHeight, textLimit, isMultiLine, style, getLayoutComposite());
+    }
 
+    protected void initText(CdmFormFactory formFactory, String initialText, Integer textHeight, Integer textLimit,
+            boolean isMultiLine, int style, Composite layoutComposite) {
         int scrollStyle = textHeight == null ? SWT.NULL : (SWT.V_SCROLL | SWT.MULTI);
 
         int combinedStyle = style | SWT.BORDER | scrollStyle;
@@ -128,6 +119,19 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
         setText(initialText);
     }
 
+    protected void initLabel(CdmFormFactory formFactory, String labelString, boolean isMultiLine, Composite layoutComposite) {
+        if (labelString != null) {
+            label = formFactory.createLabel(layoutComposite, CdmUtils.Nz(labelString), SWT.NULL);
+            addControl(label);
+            if(isMultiLine){
+                label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+            }
+            else{
+                label.setLayoutData(LayoutConstants.LEFT());
+            }
+        }
+    }
+
     /**
      * Get the text of this composites text composite
      *
index 4f5bcde..a329e87 100644 (file)
@@ -22,7 +22,6 @@ import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Layout;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.forms.widgets.TableWrapLayout;
@@ -40,27 +39,19 @@ public class UriWithLabelElement extends TextWithLabelElement {
 
     private final Label labelException;
     private final Button btnOpenBrowser;
-    private static final int NUM_COLUMNS = 3;
 
        protected UriWithLabelElement(CdmFormFactory formFactory,
                        ICdmFormElement parentElement, String labelString,
                        URI initialUri, Integer textHeight, int style) {
                super(formFactory, parentElement, false);
 
-               Layout parentLayout = getLayoutComposite().getLayout();
-               int parentNumColumns = 2;
-               if(parentLayout instanceof TableWrapLayout){
-                   parentNumColumns = ((TableWrapLayout)parentLayout).numColumns;
-               }
-        Composite layoutComposite = formFactory.createComposite(getLayoutComposite());
-        addControl(layoutComposite);
-
-        layoutComposite.setLayout(LayoutConstants.LAYOUT(3, false));
-        layoutComposite.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(parentNumColumns, 1));
+        initLabel(formFactory, labelString, false, getLayoutComposite());
 
-        init(formFactory, labelString, null, textHeight, null, false, style, layoutComposite);
+        Composite textAndButton = formFactory.createComposite(getLayoutComposite(), style);
+        textAndButton.setLayout(LayoutConstants.LAYOUT(2, false));
+        textAndButton.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
 
-               btnOpenBrowser = formFactory.createButton(layoutComposite, "", SWT.NONE);
+               btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE);
                btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.ADD_CHILD_TAXON_ICON));
                btnOpenBrowser.setToolTipText("Open in external browser");
                btnOpenBrowser.addSelectionListener(new SelectionAdapter() {
@@ -85,8 +76,14 @@ public class UriWithLabelElement extends TextWithLabelElement {
         });
                btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT());
 
-               labelException = formFactory.createLabel(layoutComposite, "", SWT.WRAP);
-               labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(NUM_COLUMNS, 1));
+               initLabel(formFactory, labelString, false, textAndButton);
+
+               labelException = formFactory.createLabel(getLayoutComposite(), "", SWT.WRAP);
+               int numColumns = AbstractFormSection.DEFAULT_NUM_COLUMNS;
+               if(getLayoutComposite().getLayout() instanceof TableWrapLayout){
+                   numColumns = ((TableWrapLayout)getLayoutComposite().getLayout()).numColumns;
+               }
+        labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(numColumns, 1));
                addControl(labelException);
                setUri(initialUri);
        }