import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import eu.etaxonomy.cdm.common.CdmUtils;
import eu.etaxonomy.taxeditor.preference.Resources;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
/**
- * <p>
- * TextWithLabelElement class.
- * </p>
- *
* @author n.hoffmann
* @version $Id: $
*/
protected Text text;
private Label label;
- /** Constant <code>MAX_HEIGHT=0</code> */
+ private final boolean isMultiLine;
+
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.
- * @wbp.parser.entryPoint
- */
+ protected TextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, boolean isMultiLine) {
+ super(formFactory, parentElement);
+ this.isMultiLine = isMultiLine;
+ }
+
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);
+ }
+
+ protected TextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
+ String initialText, Integer textHeight, Integer textLimit, boolean isMultiLine, int style) {
super(formFactory, parentElement);
- if (labelString != null) {
- label = formFactory.createLabel(getLayoutComposite(), CdmUtils.Nz(labelString), SWT.NULL);
- addControl(label);
- label.setLayoutData(LayoutConstants.LEFT());
- }
+ this.isMultiLine = isMultiLine;
+
+ initLabel(formFactory, labelString, isMultiLine, getLayoutComposite());
+
+ 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;
combinedStyle = combinedStyle | SWT.WRAP;
}
- text = formFactory.createText(getLayoutComposite(), "", combinedStyle);
+ text = formFactory.createText(layoutComposite, "", 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;
}
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));
+ }
+ else{
+ label.setLayoutData(LayoutConstants.LEFT());
+ }
+ }
+ }
+
/**
* Get the text of this composites text composite
*
}
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events
- * .ModifyEvent)
- */
/** {@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));
}
+ @Override
+ public boolean isEnabled() {
+ return text.isEnabled();
+ }
+
/** {@inheritDoc} */
@Override
public void setIrrelevant(boolean irrelevant) {
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);
}
+
}