Split up control creation of TextWithLabelElement
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / element / UriWithLabelElement.java
index 4f5bcde7fbb96d30a6493450205ec6d4097b2ea9..a329e87ec1a9e9a8c2584de7fb73c9a0ee734f3c 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);
        }