Search in sources :

Example 26 with ElementParameter

use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.

the class Component method addViewParameters.

public void addViewParameters(final List<ElementParameter> listParam, INode node) {
    ElementParameter param;
    IPreferenceStore localComponentProviderStore = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
        IComponentsLocalProviderService service = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
        if (service != null) {
            localComponentProviderStore = service.getPreferenceStore();
        }
    }
    String formatId = getNodeFormatIdWithoutFormatType(getName(), getTranslatedFamilyName());
    param = new ElementParameter(node);
    param.setName(EParameterName.LABEL.getName());
    param.setDisplayName(EParameterName.LABEL.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.VIEW);
    param.setNumRow(1);
    param.setReadOnly(false);
    param.setRequired(false);
    param.setShow(true);
    if (formatId != null) {
        if (localComponentProviderStore != null) {
            String label = localComponentProviderStore.getString(IComponentsLocalProviderService.PREFERENCE_TYPE_LABEL);
            if (!"".equals(label)) {
                //$NON-NLS-1$
                param.setValue(label);
            }
        }
    } else {
        // in case label/format is not set in the preferences.
        String label = DesignerPlugin.getDefault().getPreferenceStore().getString(TalendDesignerPrefConstants.DEFAULT_LABEL);
        if (!"".equals(label)) {
            //$NON-NLS-1$
            param.setValue(label);
        }
    }
    param.setDefaultValue(param.getValue());
    listParam.add(param);
    param = new ElementParameter(node);
    param.setName(EParameterName.HINT.getName());
    param.setDisplayName(EParameterName.HINT.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.VIEW);
    param.setNumRow(2);
    param.setReadOnly(false);
    param.setRequired(false);
    param.setShow(true);
    if (formatId != null) {
        if (localComponentProviderStore != null) {
            String label = localComponentProviderStore.getString(IComponentsLocalProviderService.PREFERENCE_TYPE_HINT);
            if (!"".equals(label)) {
                //$NON-NLS-1$
                param.setValue(label);
            }
        }
    } else {
        // in case hint/format is not set in the preferences.
        String label = DesignerPlugin.getDefault().getPreferenceStore().getString(TalendDesignerPrefConstants.DEFAULT_HINT);
        if (!"".equals(label)) {
            //$NON-NLS-1$
            param.setValue(label);
        }
    }
    param.setDefaultValue(param.getValue());
    listParam.add(param);
    param = new ElementParameter(node);
    param.setName(EParameterName.CONNECTION_FORMAT.getName());
    param.setDisplayName(EParameterName.CONNECTION_FORMAT.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.VIEW);
    param.setNumRow(3);
    param.setReadOnly(false);
    param.setRequired(false);
    param.setShow(true);
    if (formatId != null) {
        if (localComponentProviderStore != null) {
            String label = localComponentProviderStore.getString(IComponentsLocalProviderService.PREFERENCE_TYPE_CONNECTION);
            if (!"".equals(label)) {
                //$NON-NLS-1$
                param.setValue(label);
            }
        }
    }
    param.setDefaultValue(param.getValue());
    listParam.add(param);
}
Also used : IComponentsLocalProviderService(org.talend.core.ui.services.IComponentsLocalProviderService) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 27 with ElementParameter

use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.

the class Component method addDocParameters.

private void addDocParameters(final List<ElementParameter> listParam, INode node) {
    ElementParameter param = new ElementParameter(node);
    param.setName(EParameterName.INFORMATION.getName());
    param.setValue(new Boolean(false));
    param.setDisplayName(EParameterName.INFORMATION.getDisplayName());
    param.setFieldType(EParameterFieldType.CHECK);
    param.setCategory(EComponentCategory.DOC);
    param.setNumRow(1);
    param.setReadOnly(false);
    param.setRequired(false);
    param.setShow(true);
    param.setDefaultValue(param.getValue());
    listParam.add(param);
    param = new ElementParameter(node);
    param.setName(EParameterName.COMMENT.getName());
    //$NON-NLS-1$
    param.setValue("");
    param.setDisplayName(EParameterName.COMMENT.getDisplayName());
    param.setFieldType(EParameterFieldType.MEMO);
    param.setNbLines(10);
    param.setCategory(EComponentCategory.DOC);
    param.setNumRow(2);
    param.setReadOnly(false);
    param.setRequired(false);
    param.setShow(true);
    param.setDefaultValue(param.getValue());
    listParam.add(param);
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter)

Example 28 with ElementParameter

use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.

the class DynamicComposite method reverseParameters.

private List<ElementParameter> reverseParameters(List<ElementParameter> parameters) {
    List<ElementParameter> reversedParameters = new ArrayList<>();
    Map<Integer, List<ElementParameter>> paramMap = new LinkedHashMap<>();
    for (ElementParameter parameter : parameters) {
        int numRow = parameter.getNumRow();
        List<ElementParameter> params = paramMap.get(numRow);
        if (params == null) {
            params = new ArrayList<>();
            paramMap.put(numRow, params);
        }
        params.add(parameter);
    }
    Set<Entry<Integer, List<ElementParameter>>> paramEntrySet = paramMap.entrySet();
    Iterator<Entry<Integer, List<ElementParameter>>> paramIterator = paramEntrySet.iterator();
    while (paramIterator.hasNext()) {
        Entry<Integer, List<ElementParameter>> paramEntry = paramIterator.next();
        List<ElementParameter> params = paramEntry.getValue();
        if (params != null && params.size() > 1) {
            Collections.reverse(params);
        }
        reversedParameters.addAll(params);
    }
    return reversedParameters;
}
Also used : ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) Entry(java.util.Map.Entry) List(java.util.List) ArrayList(java.util.ArrayList)

Example 29 with ElementParameter

use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.

the class AbstractFakeComponent method createElementParameters.

@Override
public List<? extends IElementParameter> createElementParameters(INode node) {
    List<ElementParameter> listParam = new ArrayList<ElementParameter>();
    ElementParameter param;
    param = new ElementParameter(node);
    param.setName(EParameterName.UNIQUE_NAME.getName());
    //$NON-NLS-1$
    param.setValue("");
    param.setDisplayName(EParameterName.UNIQUE_NAME.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.ADVANCED);
    param.setNumRow(1);
    param.setReadOnly(true);
    param.setShow(false);
    listParam.add(param);
    param = new ElementParameter(node);
    param.setName(EParameterName.STARTABLE.getName());
    param.setValue(Boolean.TRUE);
    param.setDisplayName(EParameterName.STARTABLE.getDisplayName());
    param.setFieldType(EParameterFieldType.CHECK);
    param.setCategory(EComponentCategory.ADVANCED);
    param.setNumRow(5);
    param.setReadOnly(true);
    param.setRequired(false);
    param.setShow(false);
    listParam.add(param);
    param = new ElementParameter(node);
    param.setName(EParameterName.ACTIVATE.getName());
    param.setValue(new Boolean(true));
    param.setDisplayName(EParameterName.ACTIVATE.getDisplayName());
    param.setFieldType(EParameterFieldType.CHECK);
    param.setCategory(EComponentCategory.TECHNICAL);
    param.setNumRow(5);
    param.setReadOnly(false);
    param.setRequired(false);
    param.setShow(true);
    listParam.add(param);
    param = new ElementParameter(node);
    //$NON-NLS-1$
    param.setName("PROPERTY");
    param.setCategory(EComponentCategory.BASIC);
    param.setDisplayName(EParameterName.PROPERTY_TYPE.getDisplayName());
    param.setFieldType(EParameterFieldType.PROPERTY_TYPE);
    //$NON-NLS-1$
    param.setValue("");
    param.setNumRow(1);
    param.setShow(true);
    ElementParameter propertyChildParam = new ElementParameter(node);
    propertyChildParam.setCategory(EComponentCategory.BASIC);
    propertyChildParam.setName(EParameterName.PROPERTY_TYPE.getName());
    propertyChildParam.setDisplayName(EParameterName.PROPERTY_TYPE.getDisplayName());
    propertyChildParam.setListItemsDisplayName(new String[] { EmfComponent.TEXT_BUILTIN, EmfComponent.TEXT_REPOSITORY });
    propertyChildParam.setListItemsDisplayCodeName(new String[] { EmfComponent.BUILTIN, EmfComponent.REPOSITORY });
    propertyChildParam.setListItemsValue(new String[] { EmfComponent.BUILTIN, EmfComponent.REPOSITORY });
    propertyChildParam.setValue(EmfComponent.BUILTIN);
    propertyChildParam.setNumRow(param.getNumRow());
    propertyChildParam.setFieldType(EParameterFieldType.TECHNICAL);
    propertyChildParam.setShow(false);
    //$NON-NLS-1$ //$NON-NLS-2$
    propertyChildParam.setShowIf(param.getName() + " =='" + EmfComponent.REPOSITORY + "'");
    propertyChildParam.setReadOnly(param.isReadOnly());
    propertyChildParam.setNotShowIf(param.getNotShowIf());
    propertyChildParam.setSerialized(true);
    propertyChildParam.setParentParameter(param);
    propertyChildParam = new ElementParameter(node);
    propertyChildParam.setCategory(EComponentCategory.BASIC);
    propertyChildParam.setName(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
    propertyChildParam.setDisplayName(EParameterName.REPOSITORY_PROPERTY_TYPE.getDisplayName());
    propertyChildParam.setListItemsDisplayName(new String[] {});
    propertyChildParam.setListItemsValue(new String[] {});
    propertyChildParam.setNumRow(param.getNumRow());
    propertyChildParam.setFieldType(EParameterFieldType.TECHNICAL);
    //$NON-NLS-1$
    propertyChildParam.setValue("");
    propertyChildParam.setShow(false);
    propertyChildParam.setRequired(true);
    propertyChildParam.setReadOnly(param.isReadOnly());
    //$NON-NLS-1$//$NON-NLS-2$
    propertyChildParam.setShowIf(param.getName() + " =='" + EmfComponent.REPOSITORY + "'");
    propertyChildParam.setNotShowIf(param.getNotShowIf());
    propertyChildParam.setSerialized(true);
    propertyChildParam.setParentParameter(param);
    listParam.add(param);
    for (INodeConnector connector : createConnectors(node)) {
        if (!connector.getDefaultConnectionType().hasConnectionCategory(IConnectionCategory.DATA)) {
            continue;
        }
        String context = connector.getName();
        ElementParameter parentParam = new ElementParameter(node);
        parentParam.setName(EParameterName.NOT_SYNCHRONIZED_SCHEMA.getName());
        parentParam.setDisplayName(EParameterName.SCHEMA_TYPE.getDisplayName());
        parentParam.setFieldType(EParameterFieldType.SCHEMA_TYPE);
        parentParam.setCategory(EComponentCategory.BASIC);
        parentParam.setNumRow(1);
        parentParam.setReadOnly(false);
        parentParam.setShow(false);
        parentParam.setContext(context);
        listParam.add(parentParam);
        ElementParameter newParam = new ElementParameter(node);
        newParam.setCategory(EComponentCategory.BASIC);
        newParam.setName(EParameterName.SCHEMA_TYPE.getName());
        newParam.setDisplayName(EParameterName.SCHEMA_TYPE.getDisplayName());
        newParam.setListItemsDisplayName(new String[] { EmfComponent.TEXT_BUILTIN, EmfComponent.TEXT_REPOSITORY });
        newParam.setListItemsDisplayCodeName(new String[] { EmfComponent.BUILTIN, EmfComponent.REPOSITORY });
        newParam.setListItemsValue(new String[] { EmfComponent.BUILTIN, EmfComponent.REPOSITORY });
        newParam.setValue(EmfComponent.BUILTIN);
        newParam.setNumRow(1);
        newParam.setFieldType(EParameterFieldType.TECHNICAL);
        newParam.setShow(true);
        newParam.setReadOnly(true);
        newParam.setContext(context);
        newParam.setParentParameter(parentParam);
        newParam = new ElementParameter(node);
        newParam.setCategory(EComponentCategory.BASIC);
        newParam.setName(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
        newParam.setDisplayName(EParameterName.REPOSITORY_SCHEMA_TYPE.getDisplayName());
        newParam.setListItemsDisplayName(new String[] {});
        newParam.setListItemsValue(new String[] {});
        newParam.setNumRow(1);
        newParam.setFieldType(EParameterFieldType.TECHNICAL);
        //$NON-NLS-1$
        newParam.setValue("");
        newParam.setShow(false);
        newParam.setRequired(true);
        newParam.setContext(context);
        newParam.setParentParameter(parentParam);
    }
    return listParam;
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ArrayList(java.util.ArrayList) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 30 with ElementParameter

use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.

the class QueryGuessCommandTest method generateNewQuery.

@Test
public void generateNewQuery() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    connection = ConnectionFactory.eINSTANCE.createConnection();
    node = Mockito.mock(INode.class);
    connection.setContextMode(true);
    TdTable table = RelationalFactory.eINSTANCE.createTdTable();
    table.setName("tableName");
    table.setLabel("tableLabel");
    TdColumn column1 = RelationalFactory.eINSTANCE.createTdColumn();
    column1.setId("ID1");
    column1.setName("cName1");
    TdColumn column2 = RelationalFactory.eINSTANCE.createTdColumn();
    column2.setId("ID2");
    column2.setName("cName2");
    table.getColumns().add(column1);
    table.getColumns().add(column2);
    metadataTable = ConvertionHelper.convert(table);
    ElementParameter parameter = new ElementParameter(node);
    parameter.setName("DBTABLE");
    parameter.setValue(table.getName());
    Mockito.when(node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName())).thenReturn("REPOSITORY");
    Mockito.when(node.getElementParameterFromField(EParameterFieldType.DBTABLE)).thenReturn(parameter);
    String schema = "schema";
    // add test for PostgreSQL
    String dbType = EDatabaseTypeName.PSQL.getDisplayName();
    QueryGuessCommand command = new QueryGuessCommand(node, metadataTable, schema, dbType, connection);
    Method method = command.getClass().getDeclaredMethod("generateNewQuery");
    method.setAccessible(true);
    String queryString = (String) method.invoke(command);
    Assert.assertNotNull(queryString);
    Assert.assertTrue(queryString.contains(schema));
    Assert.assertTrue(queryString.contains(metadataTable.getTableName()));
    Assert.assertTrue(queryString.contains("cName1"));
    Assert.assertTrue(queryString.contains("cName2"));
    // add test for MySQL
    dbType = EDatabaseTypeName.MYSQL.getDisplayName();
    command = new QueryGuessCommand(node, metadataTable, schema, dbType, connection);
    method = command.getClass().getDeclaredMethod("generateNewQuery");
    method.setAccessible(true);
    queryString = (String) method.invoke(command);
    Assert.assertNotNull(queryString);
    Assert.assertFalse(queryString.contains(schema));
    Assert.assertTrue(queryString.contains(metadataTable.getTableName()));
    Assert.assertTrue(queryString.contains("cName1"));
    Assert.assertTrue(queryString.contains("cName2"));
}
Also used : INode(org.talend.core.model.process.INode) ElementParameter(org.talend.designer.core.model.components.ElementParameter) TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

ElementParameter (org.talend.designer.core.model.components.ElementParameter)72 IElementParameter (org.talend.core.model.process.IElementParameter)62 ArrayList (java.util.ArrayList)44 List (java.util.List)26 INode (org.talend.core.model.process.INode)20 Map (java.util.Map)19 HashMap (java.util.HashMap)15 Node (org.talend.designer.core.ui.editor.nodes.Node)12 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)11 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)10 Test (org.junit.Test)9 IComponent (org.talend.core.model.components.IComponent)8 ComponentProperties (org.talend.components.api.properties.ComponentProperties)7 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)7 IConnection (org.talend.core.model.process.IConnection)7 Form (org.talend.daikon.properties.presentation.Form)6 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)5 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)5 INodeConnector (org.talend.core.model.process.INodeConnector)5 IProcess (org.talend.core.model.process.IProcess)4