/**
- *
+ *
*/
package eu.etaxonomy.taxeditor.ui.element;
* <p>
* TextWithLabelElement class.
* </p>
- *
+ *
* @author n.hoffmann
* @version $Id: $
*/
-public class TextWithLabelElement extends AbstractCdmFormElement implements
- ModifyListener, IEnableableFormElement, ISelectable {
-
- protected Text text;
- private Label label;
-
- /** Constant <code>MAX_HEIGHT=0</code> */
- public static final int MAX_HEIGHT = 0;
- /** Constant <code>SINGLE=-1</code> */
- public static final int SINGLE = -1;
-
- /**
- * <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 style
- * a int.
- */
- protected TextWithLabelElement(CdmFormFactory formFactory,
- ICdmFormElement parentElement, String labelString,
- String initialText, Integer textHeight, int style) {
- super(formFactory, parentElement);
-
- if (labelString != null) {
- label = formFactory.createLabel(getLayoutComposite(),
- CdmUtils.Nz(labelString), SWT.NULL);
- addControl(label);
- label.setLayoutData(CdmFormFactory.LEFT());
- }
-
- int scrollStyle = textHeight == null ? SWT.NULL
- : (SWT.V_SCROLL | SWT.MULTI);
-
- int combinedStyle = style | SWT.BORDER | scrollStyle;
-
- //SWT.PASSWORD does not work when SWT.WRAP is set.
- if(style != SWT.PASSWORD){
- combinedStyle = combinedStyle | SWT.WRAP;
- }
-
- text = formFactory.createText(getLayoutComposite(), "", combinedStyle);
-
- addControl(text);
-
- // text.setWO
-
- if (textHeight == null) {
- text.addKeyListener(new KeyAdapter() {
- @Override
- public void keyPressed(KeyEvent e) {
- if (e.character == SWT.CR) {
- // Don't accept carriage returns as input when in single
- // line mode
- e.doit = false;
- } else if (e.character == SWT.TAB) {
- // traverse is not working for wrapped text widgets so
- // we reintroduce it here
- e.doit = false;
- TextWithLabelElement.this.text
- .traverse(SWT.TRAVERSE_TAB_NEXT);
- }
- }
- });
- }
-
- TableWrapData layoutData = CdmFormFactory.FILL();
- if (textHeight != null && textHeight > 0) {
- (layoutData).heightHint = textHeight;
- }
-
- text.setLayoutData(layoutData);
-
- text.addModifyListener(this);
-
- setText(initialText);
- }
-
- /**
- * Get the text of this composites text composite
- *
- * @return a {@link java.lang.String} object.
- */
- public String getText() {
- return text.getText();
- }
-
- /**
- * Set the text of this composites text composite
- *
- * @param string
- * a {@link java.lang.String} object.
- */
- public void setText(String string) {
- Listener[] listeners = text.getListeners(SWT.Modify);
-
- for (Listener listener : listeners) {
- text.removeListener(SWT.Modify, listener);
- }
-
- text.setText(CdmUtils.Nz(string));
-
- for (Listener listener : listeners) {
- text.addListener(SWT.Modify, listener);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events
- * .ModifyEvent)
- */
- /** {@inheritDoc} */
- public void modifyText(ModifyEvent e) {
- firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
- }
-
- /** {@inheritDoc} */
- public void setEnabled(boolean enabled) {
- text.setEnabled(enabled);
- String symbolicName = enabled ? Resources.COLOR_FONT_DEFAULT
- : Resources.COLOR_TEXT_DISABLED;
- text.setForeground(getColor(symbolicName));
- }
-
- /** {@inheritDoc} */
- public void setIrrelevant(boolean irrelevant) {
- String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT
- : Resources.COLOR_COMPOSITE_BACKGROUND;
-
- Color color = getColor(colorId);
- text.setBackground(color);
- }
-
- /** {@inheritDoc} */
- @Override
- public void setBackground(Color color) {
- if (label != null)
- label.setBackground(color);
- }
-
- @Override
- public void setSelected(boolean selected) {
- 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);
- }
+public class TextWithLabelElement extends AbstractCdmFormElement implements ModifyListener, IEnableableFormElement,
+ ISelectable {
+
+ protected Text text;
+ private Label label;
+
+ /** 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, String labelString,
+ String initialText, Integer textHeight, int style) {
+ this(formFactory, parentElement, labelString, initialText, textHeight, null, 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, int style) {
+ super(formFactory, parentElement);
+
+ if (labelString != null) {
+ label = formFactory.createLabel(getLayoutComposite(), CdmUtils.Nz(labelString), SWT.NULL);
+ addControl(label);
+ label.setLayoutData(LayoutConstants.LEFT());
+ }
+
+ int scrollStyle = textHeight == null ? SWT.NULL : (SWT.V_SCROLL | SWT.MULTI);
+
+ int combinedStyle = style | SWT.BORDER | scrollStyle;
+
+ // SWT.PASSWORD does not work when SWT.WRAP is set.
+ if (style != SWT.PASSWORD) {
+ combinedStyle = combinedStyle | SWT.WRAP;
+ }
+
+ text = formFactory.createText(getLayoutComposite(), "", combinedStyle);
+ text.setTextLimit(textLimit!=null?textLimit:Text.LIMIT);
+
+ addControl(text);
+
+ // text.setWO
+
+ if (textHeight == null) {
+ text.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if (e.character == SWT.CR) {
+ // Don't accept carriage returns as input when in single
+ // line mode
+ e.doit = false;
+ } else if (e.character == SWT.TAB) {
+ // traverse is not working for wrapped text widgets so
+ // we reintroduce it here
+ e.doit = false;
+ TextWithLabelElement.this.text.traverse(SWT.TRAVERSE_TAB_NEXT);
+ }
+ }
+ });
+ }
+
+ TableWrapData layoutData = LayoutConstants.FILL();
+ if (textHeight != null && textHeight > 0) {
+ (layoutData).heightHint = textHeight;
+ }
+
+ text.setLayoutData(layoutData);
+
+ text.addModifyListener(this);
+
+ setText(initialText);
+ }
+
+ /**
+ * Get the text of this composites text composite
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getText() {
+ return text.getText();
+ }
+
+ /**
+ * Set the text of this composites text composite
+ *
+ * @param string
+ * a {@link java.lang.String} object.
+ */
+ public void setText(String string) {
+ Listener[] listeners = text.getListeners(SWT.Modify);
+
+ for (Listener listener : listeners) {
+ text.removeListener(SWT.Modify, listener);
+ }
+
+ text.setText(CdmUtils.Nz(string));
+
+ for (Listener listener : listeners) {
+ text.addListener(SWT.Modify, listener);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events
+ * .ModifyEvent)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void modifyText(ModifyEvent e) {
+ firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setEnabled(boolean enabled) {
+ text.setEnabled(enabled);
+ String symbolicName = enabled ? Resources.COLOR_FONT_DEFAULT : Resources.COLOR_TEXT_DISABLED;
+ text.setForeground(getColor(symbolicName));
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled()
+ */
+ @Override
+ public boolean isEnabled() {
+ return text.isEnabled();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setIrrelevant(boolean irrelevant) {
+ String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT : Resources.COLOR_COMPOSITE_BACKGROUND;
+
+ Color color = getColor(colorId);
+ text.setBackground(color);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setBackground(Color color) {
+ if (label != null) {
+ label.setBackground(color);
+ }
+ }
+
+ @Override
+ public void setSelected(boolean selected) {
+ 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);
+ }
+
}