Search in sources :

Example 6 with ComponentService

use of org.talend.components.api.service.ComponentService in project tdi-studio-se by Talend.

the class ComponentsUtilsTest method testLoadComponents.

@Test
public void testLoadComponents() {
    ComponentService componentService = ComponentsUtils.getComponentService();
    Set<ComponentDefinition> componentDefinitions = componentService.getAllComponents();
    Set<IComponent> coms = ComponentsFactoryProvider.getInstance().getComponents();
    List<IComponent> comList = new ArrayList<IComponent>();
    for (ComponentDefinition componentDefinition : componentDefinitions) {
        for (IComponent com : coms) {
            if (com.getName().equals(componentDefinition.getName())) {
                comList.add(com);
                break;
            }
        }
    }
    coms.removeAll(comList);
    ComponentsUtils.loadComponents(componentService);
    coms = ComponentsFactoryProvider.getInstance().getComponents();
    for (ComponentDefinition componentDefinition : componentDefinitions) {
        if (!componentDefinition.getName().equals("tJIRAInput")) {
            continue;
        }
        for (IComponent com : coms) {
            if (com.getName().equals(componentDefinition.getName())) {
                assertFalse("Component loaded: " + componentDefinition.getName(), true);
            }
        }
    }
}
Also used : IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) ComponentService(org.talend.components.api.service.ComponentService) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Test(org.junit.Test)

Example 7 with ComponentService

use of org.talend.components.api.service.ComponentService in project tdi-studio-se by Talend.

the class GenericElementParameterTest method before.

@Before
public void before() {
    ComponentService componentService = ComponentsUtils.getComponentService();
    //$NON-NLS-1$
    TestProperties props = (TestProperties) new TestProperties("test").init();
    Form form = props.getForm(Form.MAIN);
    //$NON-NLS-1$ //$NON-NLS-2$
    IComponent component = ComponentsFactoryProvider.getInstance().get("tSalesforceConnection", "DI");
    INode node = new Node(component, new Process(new FakePropertyImpl()));
    parameter = new GenericElementParameter(node, props, form, form.getWidget(props.userId), componentService);
}
Also used : TestProperties(org.talend.designer.core.generic.utils.TestProperties) INode(org.talend.core.model.process.INode) FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) Form(org.talend.daikon.properties.presentation.Form) IComponent(org.talend.core.model.components.IComponent) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) Process(org.talend.designer.core.ui.editor.process.Process) ComponentService(org.talend.components.api.service.ComponentService) Before(org.junit.Before)

Example 8 with ComponentService

use of org.talend.components.api.service.ComponentService in project tdi-studio-se by Talend.

the class ComponentsUtils method getComponentService.

public static ComponentService getComponentService() {
    ComponentService compService = null;
    BundleContext bundleContext = FrameworkUtil.getBundle(ComponentsUtils.class).getBundleContext();
    ServiceReference<ComponentService> compServiceRef = bundleContext.getServiceReference(ComponentService.class);
    if (compServiceRef != null) {
        compService = bundleContext.getService(compServiceRef);
    }
    return compService;
}
Also used : ComponentService(org.talend.components.api.service.ComponentService) BundleContext(org.osgi.framework.BundleContext)

Example 9 with ComponentService

use of org.talend.components.api.service.ComponentService in project tdi-studio-se by Talend.

the class Component method getWizardDefinition.

private ComponentWizardDefinition getWizardDefinition(ComponentProperties componentProperties) {
    ComponentWizardDefinition definition = null;
    if (componentProperties == null) {
        return null;
    }
    ComponentService service = ComponentsUtils.getComponentService();
    List<ComponentWizard> componentWizards = service.getComponentWizardsForProperties(componentProperties, null);
    for (ComponentWizard componentWizard : componentWizards) {
        definition = componentWizard.getDefinition();
        // Can we ensure it is the same wizard with metadata connection wizard by this way?
        if (definition.isTopLevel()) {
            return definition;
        }
    }
    List<NamedThing> namedThings = componentProperties.getProperties();
    for (NamedThing namedThing : namedThings) {
        if (namedThing instanceof ComponentProperties) {
            definition = getWizardDefinition((ComponentProperties) namedThing);
            if (definition != null && definition.isTopLevel()) {
                return definition;
            }
        }
    }
    return null;
}
Also used : ComponentWizard(org.talend.components.api.wizard.ComponentWizard) ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentWizardDefinition(org.talend.components.api.wizard.ComponentWizardDefinition) ComponentService(org.talend.components.api.service.ComponentService) NamedThing(org.talend.daikon.NamedThing)

Example 10 with ComponentService

use of org.talend.components.api.service.ComponentService 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;
}
Also used : INode(org.talend.core.model.process.INode) ComponentProperties(org.talend.components.api.properties.ComponentProperties) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) PropertyValueEvaluator(org.talend.daikon.properties.property.PropertyValueEvaluator) ComponentContextPropertyValueEvaluator(org.talend.designer.core.generic.context.ComponentContextPropertyValueEvaluator) MetadataContextPropertyValueEvaluator(org.talend.metadata.managment.ui.wizard.context.MetadataContextPropertyValueEvaluator) IElementParameterEventProperties(org.talend.designer.core.generic.constants.IElementParameterEventProperties) IContextEventProperties(org.talend.designer.core.generic.constants.IContextEventProperties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) Properties(org.talend.daikon.properties.Properties) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ArrayList(java.util.ArrayList) ComponentService(org.talend.components.api.service.ComponentService) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) MetadataContextPropertyValueEvaluator(org.talend.metadata.managment.ui.wizard.context.MetadataContextPropertyValueEvaluator) NamedThing(org.talend.daikon.NamedThing) FakeElement(org.talend.designer.core.model.FakeElement) SubContainer(org.talend.repository.generic.model.genericMetadata.SubContainer) AbstractBasicComponent(org.talend.designer.core.model.components.AbstractBasicComponent) ComponentContextPropertyValueEvaluator(org.talend.designer.core.generic.context.ComponentContextPropertyValueEvaluator)

Aggregations

ComponentService (org.talend.components.api.service.ComponentService)11 ComponentProperties (org.talend.components.api.properties.ComponentProperties)7 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)4 NamedThing (org.talend.daikon.NamedThing)4 GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)4 ArrayList (java.util.ArrayList)3 IComponent (org.talend.core.model.components.IComponent)3 Connection (org.talend.core.model.metadata.builder.connection.Connection)3 Form (org.talend.daikon.properties.presentation.Form)3 GenericConnectionItem (org.talend.repository.generic.model.genericMetadata.GenericConnectionItem)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 Path (org.eclipse.core.runtime.Path)2 Test (org.junit.Test)2 BundleContext (org.osgi.framework.BundleContext)2 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)2 IElementParameter (org.talend.core.model.process.IElementParameter)2 INode (org.talend.core.model.process.INode)2 ConnectionItem (org.talend.core.model.properties.ConnectionItem)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2