/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/
package eu.esdihumboldt.hale.ui.common.editors;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import eu.esdihumboldt.hale.common.align.model.ParameterValue;
import eu.esdihumboldt.hale.ui.common.AttributeEditor;
/**
* Simple attribute editor for string values.
*
* @author Simon Templer
* @partner 01 / Fraunhofer Institute for Computer Graphics Research
*/
public class StringEditor extends AbstractAttributeEditor<String> {
private final Text text;
/**
* Create a string attribute editor.
*
* @param parent the parent composite
*/
public StringEditor(Composite parent) {
text = new Text(parent, SWT.BORDER | SWT.SINGLE);
text.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
fireValueChanged(VALUE, null, text.getText());
}
});
}
/**
* @see AttributeEditor#getAsText()
*/
@Override
public String getAsText() {
return getValue();
}
/**
* @see AttributeEditor#getControl()
*/
@Override
public Control getControl() {
return text;
}
/**
* @see AttributeEditor#getValue()
*/
@Override
public String getValue() {
return text.getText();
}
/**
* @see AttributeEditor#setAsText(String)
*/
@Override
public void setAsText(String text) {
setValue(text);
}
/**
* @see AttributeEditor#setValue(Object)
*/
@Override
public void setValue(String value) {
if (value == null) {
// can't handle null value
text.setText("");
}
text.setText(value);
}
/**
* @see AttributeEditor#isValid()
*/
@Override
public boolean isValid() {
return true;
}
/**
* @see eu.esdihumboldt.hale.ui.common.AttributeEditor#getValueType()
*/
@Override
public String getValueType() {
return ParameterValue.DEFAULT_TYPE;
}
}