import eu.etaxonomy.cdm.common.CdmUtils;
import eu.etaxonomy.taxeditor.preference.Resources;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
/**
* <p>
protected Text text;
private Label label;
+ 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, String labelString,
+ String initialText, Integer textHeight, int style) {
+ this(formFactory, parentElement, labelString, initialText, textHeight, null, false, style);
+ }
+
+ protected TextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
+ String initialText, Integer textHeight, boolean isMultiLine, int style) {
+ this(formFactory, parentElement, labelString, initialText, textHeight, null, isMultiLine, style);
+ }
+
+ protected TextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
+ String initialText, Integer textHeight, Integer textLimit, int style) {
+ this(formFactory, parentElement, labelString, initialText, textHeight, textLimit, false, style);
+ }
+
/**
* <p>
* Constructor for TextWithLabelElement.
* 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, int style) {
+ String initialText, Integer textHeight, Integer textLimit, boolean isMultiLine, int style) {
super(formFactory, parentElement);
+ this.isMultiLine = isMultiLine;
+
if (labelString != null) {
label = formFactory.createLabel(getLayoutComposite(), CdmUtils.Nz(labelString), SWT.NULL);
addControl(label);
- label.setLayoutData(LayoutConstants.LEFT());
+ if(isMultiLine){
+ label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ }
+ else{
+ label.setLayoutData(LayoutConstants.LEFT());
+ }
}
int scrollStyle = textHeight == null ? SWT.NULL : (SWT.V_SCROLL | SWT.MULTI);
}
text = formFactory.createText(getLayoutComposite(), "", combinedStyle);
+ text.setTextLimit(textLimit!=null?textLimit:Text.LIMIT);
addControl(text);
});
}
- TableWrapData layoutData = LayoutConstants.FILL();
+ TableWrapData layoutData;
+ if(isMultiLine){
+ layoutData = LayoutConstants.FILL_HORIZONTALLY(2, 1);
+ }
+ else{
+ layoutData = LayoutConstants.FILL();
+ }
if (textHeight != null && textHeight > 0) {
(layoutData).heightHint = textHeight;
}
/** {@inheritDoc} */
@Override
public void modifyText(ModifyEvent e) {
+ if(e.widget==text && !isMultiLine){
+ Text text = (Text) e.widget;
+ boolean hasControlCharacters = false;
+ String textString = text.getText();
+ int stringLength = textString.length();
+ for (int i = 0; i < stringLength; i++) {
+ if (Character.isISOControl(textString.charAt(i))) {
+ hasControlCharacters = true;
+ break;
+ }
+ }
+ if(hasControlCharacters){
+ //remove control character such as line breaks etc.
+ setText(text.getText().replaceAll("\\p{C}", new Character((char)9608).toString()));
+ }
+ }
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
}
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) {
public void setTextLimit(int limit) {
text.setTextLimit(limit);
}
+
}