Merge branch 'release/5.4.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / element / TextWithLabelElement.java
index 57092b726c31a456325d0903f934d431694e981e..22834daac24365cbf3e5227beab5a30d80455693 100644 (file)
@@ -9,6 +9,7 @@ import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
@@ -20,10 +21,6 @@ import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.taxeditor.preference.Resources;
 
 /**
- * <p>
- * TextWithLabelElement class.
- * </p>
- *
  * @author n.hoffmann
  * @version $Id: $
  */
@@ -35,9 +32,7 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
 
     private final boolean isMultiLine;
 
-    /** Constant <code>MAX_HEIGHT=0</code> */
     public static final int MAX_HEIGHT = 0;
-    /** Constant <code>SINGLE=-1</code> */
     public static final int SINGLE = -1;
 
     protected TextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, boolean isMultiLine) {
@@ -60,60 +55,19 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
         this(formFactory, parentElement, labelString, initialText, textHeight, textLimit, false, style);
     }
 
-    /**
-     * <p>
-     * Constructor for TextWithLabelElement.
-     * </p>
-     *
-     * @param formFactory
-     *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
-     *            object.
-     * @param parentElement
-     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
-     *            object.
-     * @param labelString
-     *            a {@link java.lang.String} object.
-     * @param initialText
-     *            a {@link java.lang.String} object.
-     * @param textHeight
-     *            a {@link java.lang.Integer} object.
-     *            @param textLimit max characters allowed to enter
-     * @param style
-     *            a int.
-     * @wbp.parser.entryPoint
-     */
     protected TextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
             String initialText, Integer textHeight, Integer textLimit, boolean isMultiLine, int style) {
         super(formFactory, parentElement);
 
         this.isMultiLine = isMultiLine;
 
-        init(formFactory, labelString, initialText, textHeight, textLimit, isMultiLine, style, getLayoutComposite());
-    }
+        initLabel(formFactory, labelString, isMultiLine, getLayoutComposite());
 
-    /**
-     * @param formFactory
-     * @param labelString
-     * @param initialText
-     * @param textHeight
-     * @param textLimit
-     * @param isMultiLine
-     * @param style
-     * @param layoutComposite
-     */
-    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;
@@ -154,7 +108,6 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
         }
         else{
             layoutData = LayoutConstants.FILL();
-            layoutData.grabHorizontal = true;
         }
         if (textHeight != null && textHeight > 0) {
             (layoutData).heightHint = textHeight;
@@ -167,13 +120,30 @@ 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));
+                ((TableWrapData)label.getLayoutData()).valign = TableWrapData.MIDDLE;
+            }
+            else{
+                label.setLayoutData(LayoutConstants.LEFT());
+                ((TableWrapData)label.getLayoutData()).valign = TableWrapData.MIDDLE;
+            }
+        }
+    }
+
     /**
      * Get the text of this composites text composite
      *
      * @return a {@link java.lang.String} object.
      */
     public String getText() {
-        return text.getText();
+
+      return CdmUtils.Nb(text.getText());
     }
 
     /**
@@ -196,13 +166,6 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
         }
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events
-     * .ModifyEvent)
-     */
     /** {@inheritDoc} */
     @Override
     public void modifyText(ModifyEvent e) {
@@ -233,9 +196,6 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
         text.setForeground(getColor(symbolicName));
     }
 
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled()
-     */
     @Override
     public boolean isEnabled() {
         return text.isEnabled();
@@ -263,36 +223,16 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
         setBackground(selected ? SELECTED : getPersistentBackground());
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#setFocus()
-     */
     /** {@inheritDoc} */
     @Override
     public void setFocus() {
         text.setFocus();
     }
 
-    /**
-     * <p>
-     * getMainControl
-     * </p>
-     *
-     * @return a {@link org.eclipse.swt.widgets.Control} object.
-     */
     public Control getMainControl() {
         return text;
     }
 
-    /**
-     * <p>
-     * setTextLimit
-     * </p>
-     *
-     * @param limit
-     *            a int.
-     */
     public void setTextLimit(int limit) {
         text.setTextLimit(limit);
     }