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;
import eu.etaxonomy.taxeditor.preference.Resources;
/**
- * <p>
- * TextWithLabelElement class.
- * </p>
- *
* @author n.hoffmann
* @version $Id: $
*/
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) {
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;
}
else{
layoutData = LayoutConstants.FILL();
- layoutData.grabHorizontal = true;
}
if (textHeight != null && textHeight > 0) {
(layoutData).heightHint = textHeight;
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());
}
/**
}
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events
- * .ModifyEvent)
- */
/** {@inheritDoc} */
@Override
public void modifyText(ModifyEvent e) {
text.setForeground(getColor(symbolicName));
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled()
- */
@Override
public boolean isEnabled() {
return text.isEnabled();
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);
}