use of org.talend.daikon.NamedThing in project tdi-studio-se by Talend.
the class DynamicComposite method resetParameters.
public List<ElementParameter> resetParameters() {
final List<ElementParameter> newParameters = new ArrayList<>();
List<ElementParameter> currentParameters = (List<ElementParameter>) element.getElementParameters();
List<ElementParameter> parameters = new ArrayList<>();
ComponentService componentService = internalService.getComponentService();
Connection theConnection = null;
if (connectionItem != null) {
theConnection = connectionItem.getConnection();
}
Properties properties = null;
PropertyValueEvaluator evaluator = null;
if (element instanceof FakeElement) {
properties = form.getProperties();
evaluator = new MetadataContextPropertyValueEvaluator(theConnection);
currentParameters.clear();
} else {
properties = ((INode) element).getComponentProperties();
evaluator = new ComponentContextPropertyValueEvaluator((INode) element);
}
if (properties instanceof ComponentProperties) {
if (form != null) {
properties.setValueEvaluator(evaluator);
properties.refreshLayout(form);
}
// For context display.
properties.setValueEvaluator(null);
boolean isInitializing = false;
if (element instanceof INode) {
INode node = (INode) element;
IComponent component = node.getComponent();
if (component instanceof AbstractBasicComponent) {
isInitializing = ((AbstractBasicComponent) component).isInitializing();
}
}
parameters = ComponentsUtils.getParametersFromForm(element, isInitializing, section, (ComponentProperties) properties, form);
addUpdateParameterIfNotExist(parameters);
properties.setValueEvaluator(evaluator);
}
for (ElementParameter parameter : parameters) {
if (parameter instanceof GenericElementParameter) {
GenericElementParameter genericElementParameter = (GenericElementParameter) parameter;
genericElementParameter.setComponentService(componentService);
genericElementParameter.setDrivedByForm(drivedByForm);
genericElementParameter.callBeforePresent();
genericElementParameter.removePropertyChangeListener(this);
genericElementParameter.addPropertyChangeListener(this);
if (wizardPropertyChangeListener != null && IGenericConstants.NAME_PROPERTY.equals(parameter.getName())) {
genericElementParameter.addPropertyChangeListener(wizardPropertyChangeListener);
}
if (EParameterFieldType.SCHEMA_REFERENCE.equals(genericElementParameter.getFieldType())) {
if (genericElementParameter.getChildParameters().size() == 0) {
IElementParameter schemaParameter = element.getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE, section);
genericElementParameter.getChildParameters().putAll(schemaParameter.getChildParameters());
}
} else if (EParameterFieldType.NAME_SELECTION_AREA.equals(genericElementParameter.getFieldType()) && theConnection != null) {
List<NamedThing> values = new ArrayList<>();
List<MetadataTable> metadataTables = SchemaUtils.getMetadataTables(theConnection, SubContainer.class);
List<String> tableLabels = new ArrayList<>();
for (MetadataTable metaTable : metadataTables) {
tableLabels.add(metaTable.getLabel());
}
List<NamedThing> possibleValues = ComponentsUtils.getFormalPossibleValues(genericElementParameter);
for (NamedThing possibleValue : possibleValues) {
if (tableLabels.contains(possibleValue.getName())) {
values.add(possibleValue);
}
}
genericElementParameter.setValue(values);
}
if (properties != null && isRepository(element)) {
String repositoryValue = genericElementParameter.getRepositoryValue();
if (genericElementParameter.isShow(currentParameters) && (repositoryValue != null) && (!genericElementParameter.getName().equals(EParameterName.PROPERTY_TYPE.getName())) && genericElementParameter.getCategory() == section) {
org.talend.daikon.properties.property.Property property = properties.getValuedProperty(genericElementParameter.getName());
if (property != null && property.getTaggedValue(IGenericConstants.REPOSITORY_VALUE) != null) {
genericElementParameter.setRepositoryValueUsed(true);
genericElementParameter.setReadOnly(true);
}
}
}
}
}
boolean added = false;
for (ElementParameter currentParameter : currentParameters) {
if (EParameterName.UPDATE_COMPONENTS.getName().equals(currentParameter.getName())) {
currentParameter.setValue(true);
}
if (currentParameter.isSerialized() && currentParameter.getCategory().equals(section)) {
if (!added) {
newParameters.addAll(parameters);
added = true;
}
continue;
}
newParameters.add(currentParameter);
}
if (element instanceof FakeElement) {
newParameters.addAll(reverseParameters(parameters));
}
element.setElementParameters(newParameters);
return newParameters;
}
use of org.talend.daikon.NamedThing in project tdi-studio-se by Talend.
the class GenericUIBuilder method createWidgetUIByWidgetType.
private void createWidgetUIByWidgetType(Composite parent, Widget widget) {
NamedThing property = getProperty(widget);
if (property == null) {
return;
}
String displayName = property.getDisplayName();
String widgetType = widget.getWidgetType();
if (widgetType == null) {
return;
}
if (Widget.BUTTON_WIDGET_TYPE.equals(widgetType)) {
Button btn = new Button(parent, SWT.PUSH);
btn.setText(displayName);
}
}
use of org.talend.daikon.NamedThing 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()));
}
}
use of org.talend.daikon.NamedThing in project components by Talend.
the class CommonTestUtils method checkAllConnector.
private static void checkAllConnector(FixedConnectorsComponentProperties fccp, ErrorCollector collector, Set<PropertyPathConnector> allConnectors) {
for (PropertyPathConnector connector : allConnectors) {
NamedThing property = fccp.getProperty(connector.getPropertyPath());
collector.checkThat(property, notNullValue());
collector.checkThat(property, anyOf(instanceOf(Property.class), instanceOf(SchemaProperties.class)));
}
}
use of org.talend.daikon.NamedThing in project components by Talend.
the class FullExampleProperties method setupProperties.
@Override
public void setupProperties() {
super.setupProperties();
// setup multipleSelectionProp
ArrayList<NamedThing> multipleSelectableList = new ArrayList<NamedThing>();
multipleSelectableList.add(new SimpleNamedThing("foo"));
multipleSelectableList.add(new SimpleNamedThing("bar"));
multipleSelectableList.add(new SimpleNamedThing("foobar"));
multipleSelectionProp.setPossibleValues(multipleSelectableList);
// $NON-NLS-1$
schema.setValue(SchemaBuilder.builder().record("EmptyRecord").fields().endRecord());
}
Aggregations