use of org.talend.daikon.SimpleNamedThing in project tdi-studio-se by Talend.
the class WidgetFieldTypeMappingReaderTest method testGetFieldType.
@Test
public void testGetFieldType() {
//$NON-NLS-1$//$NON-NLS-2$
NamedThing nameAndLabel = new SimpleNamedThing("testName", "testLabel");
//$NON-NLS-1$
Assert.assertEquals("testName", nameAndLabel.getName());
//$NON-NLS-1$
Assert.assertEquals("testLabel", nameAndLabel.getDisplayName());
Assert.assertNull(nameAndLabel.getTitle());
WidgetFieldTypeMappingReader mappingReader = WidgetFieldTypeMappingReader.getInstance();
//$NON-NLS-1$//$NON-NLS-2$
String fieldType = mappingReader.getFieldType("widget.type.default", nameAndLabel, "java.lang.String");
//$NON-NLS-1$
Assert.assertEquals("TEXT", fieldType);
//$NON-NLS-1$
fieldType = mappingReader.getFieldType("widget.type.default", nameAndLabel, null);
//$NON-NLS-1$
Assert.assertEquals("LABEL", fieldType);
//$NON-NLS-1$//$NON-NLS-2$
fieldType = mappingReader.getFieldType("widget.type.hidden.text", nameAndLabel, "widget.type.hidden.text");
//$NON-NLS-1$
Assert.assertEquals("HIDDEN_TEXT", fieldType);
}
use of org.talend.daikon.SimpleNamedThing in project tdi-studio-se by Talend.
the class ComponentsUtils method getFormalPossibleValues.
/**
* Get formal possible values of the <code>param</code>. Every possible value will be {@link NamedThing} type.
*
* @param param
* @return
*/
public static List<NamedThing> getFormalPossibleValues(GenericElementParameter param) {
List<NamedThing> nals = new ArrayList<>();
if (param == null) {
return nals;
}
List<?> possibleValues = param.getPossibleValues();
if (possibleValues != null) {
for (Object object : possibleValues) {
if (object instanceof NamedThing) {
nals.add((NamedThing) object);
} else if (object instanceof String) {
String name = (String) object;
Property property = param.getProperty();
if (property != null) {
NamedThing nl = new SimpleNamedThing(name, property.getPossibleValuesDisplayName(name));
nals.add(nl);
}
}
}
}
return nals;
}
use of org.talend.daikon.SimpleNamedThing in project tdi-studio-se by Talend.
the class ComponentsUtilsTest method testGetFormalPossibleValues.
@Test
public void testGetFormalPossibleValues() {
ComponentService componentService = ComponentsUtils.getComponentService();
//$NON-NLS-1$
ComponentProperties props = (ComponentProperties) new TestProperties("test").init();
Form form = props.getForm(Form.MAIN);
Element element = new FakeElement(form.getName());
Widget testWidget = null;
Property testProperty = null;
Collection<Widget> widgets = form.getWidgets();
Iterator<Widget> widgetsIterator = widgets.iterator();
while (widgetsIterator.hasNext()) {
Widget widget = widgetsIterator.next();
NamedThing content = widget.getContent();
if (content instanceof Property) {
testWidget = widget;
testProperty = (Property) content;
break;
}
}
assertNotNull(testWidget);
assertNotNull(testProperty);
// Test NamedThing type
List<NamedThing> namedThings = new ArrayList<>();
namedThings.add(new SimpleNamedThing("p1", "Test P1"));
namedThings.add(new SimpleNamedThing("p2", "Test P2"));
namedThings.add(new SimpleNamedThing("p3", "Test P3"));
testProperty.setPossibleValues(namedThings);
GenericElementParameter param = new GenericElementParameter(element, props, form, testWidget, componentService);
param.setPossibleValues(testProperty.getPossibleValues());
List<NamedThing> possibleValues = ComponentsUtils.getFormalPossibleValues(param);
assertEquals(3, possibleValues.size());
namedThings.retainAll(possibleValues);
assertEquals(3, namedThings.size());
// Test Integer type which is not support yet
List<Integer> ints = new ArrayList<>();
ints.add(1);
ints.add(2);
ints.add(3);
testProperty.setPossibleValues(ints);
param = new GenericElementParameter(element, props, form, testWidget, componentService);
param.setPossibleValues(testProperty.getPossibleValues());
possibleValues = ComponentsUtils.getFormalPossibleValues(param);
assertEquals(0, possibleValues.size());
// Test StringProperty
testWidget = null;
StringProperty testStringProperty = null;
widgetsIterator = widgets.iterator();
while (widgetsIterator.hasNext()) {
Widget widget = widgetsIterator.next();
NamedThing content = widget.getContent();
if (content instanceof StringProperty) {
testWidget = widget;
testStringProperty = (StringProperty) content;
break;
}
}
assertNotNull(testWidget);
assertNotNull(testStringProperty);
testStringProperty.setPossibleNamedThingValues(namedThings);
param = new GenericElementParameter(element, props, form, testWidget, componentService);
param.setPossibleValues(testStringProperty.getPossibleValues());
possibleValues = ComponentsUtils.getFormalPossibleValues(param);
assertEquals(3, possibleValues.size());
List<String> pvNames = new ArrayList<>();
for (NamedThing pv : possibleValues) {
pvNames.add(pv.getName());
}
for (NamedThing nt : namedThings) {
assertTrue(pvNames.contains(nt.getName()));
}
}
Aggregations