Search in sources :

Example 1 with SimpleNamedThing

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);
}
Also used : SimpleNamedThing(org.talend.daikon.SimpleNamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) NamedThing(org.talend.daikon.NamedThing) Test(org.junit.Test)

Example 2 with SimpleNamedThing

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;
}
Also used : SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) Property(org.talend.daikon.properties.property.Property) SchemaProperty(org.talend.daikon.properties.property.SchemaProperty)

Example 3 with SimpleNamedThing

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()));
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) Form(org.talend.daikon.properties.presentation.Form) Element(org.talend.core.model.process.Element) FakeElement(org.talend.designer.core.model.FakeElement) Widget(org.talend.daikon.properties.presentation.Widget) ArrayList(java.util.ArrayList) StringProperty(org.talend.daikon.properties.property.StringProperty) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) FakeElement(org.talend.designer.core.model.FakeElement) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) ComponentService(org.talend.components.api.service.ComponentService) StringProperty(org.talend.daikon.properties.property.StringProperty) Property(org.talend.daikon.properties.property.Property) Test(org.junit.Test)

Aggregations

NamedThing (org.talend.daikon.NamedThing)3 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Property (org.talend.daikon.properties.property.Property)2 ComponentProperties (org.talend.components.api.properties.ComponentProperties)1 ComponentService (org.talend.components.api.service.ComponentService)1 Element (org.talend.core.model.process.Element)1 Form (org.talend.daikon.properties.presentation.Form)1 Widget (org.talend.daikon.properties.presentation.Widget)1 SchemaProperty (org.talend.daikon.properties.property.SchemaProperty)1 StringProperty (org.talend.daikon.properties.property.StringProperty)1 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)1 FakeElement (org.talend.designer.core.model.FakeElement)1