Search in sources :

Example 1 with JavaType

use of org.talend.core.model.metadata.types.JavaType in project tdi-studio-se by Talend.

the class AddSchemaDefaultValue4tFileInputDelimited method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    IComponentFilter filter = new NameComponentFilter("tFileInputDelimited");
    try {
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {

            public void transform(NodeType node) {
                EList<EObject> list = node.eContents();
                for (EObject object : list) {
                    if (object instanceof MetadataType) {
                        MetadataType flow = (MetadataType) object;
                        if ("FLOW".equalsIgnoreCase(flow.getConnector())) {
                            Iterator<?> columns = flow.getColumn().iterator();
                            while (columns.hasNext()) {
                                Object outColumn = columns.next();
                                if (outColumn instanceof ColumnType) {
                                    ColumnType column = ((ColumnType) outColumn);
                                    JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getType());
                                    boolean isJavaPrimitiveType = JavaTypesManager.isJavaPrimitiveType(javaType, column.isNullable());
                                    if (isJavaPrimitiveType && (column.getDefaultValue() == null || column.getDefaultValue().isEmpty())) {
                                        String defaultValue = JavaTypesManager.getDefaultValueFromJavaType(javaType.getPrimitiveClass().getSimpleName(), null);
                                        if (defaultValue != null) {
                                            column.setDefaultValue(defaultValue);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }));
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) JavaType(org.talend.core.model.metadata.types.JavaType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) EObject(org.eclipse.emf.ecore.EObject) PersistenceException(org.talend.commons.exception.PersistenceException) EObject(org.eclipse.emf.ecore.EObject) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 2 with JavaType

use of org.talend.core.model.metadata.types.JavaType in project tdi-studio-se by Talend.

the class MetadataTypeLengthPreferencePage method createJavaFieldEditors.

/**
     * DOC qwei Comment method "createJavaFieldEditors".
     */
private void createJavaFieldEditors(Composite com) {
    JavaType[] strTypeValue = JavaTypesManager.getJavaTypes();
    String[] strDisplay = new String[strTypeValue.length];
    String[] strValue = new String[strTypeValue.length];
    for (int i = 0; i < strDisplay.length; i++) {
        strDisplay[i] = strTypeValue[i].getNullableClass().getSimpleName();
        strValue[i] = strTypeValue[i].getId();
    }
    String[][] strvalueType = new String[strDisplay.length][2];
    for (int i = 0; i < strDisplay.length; i++) {
        strvalueType[i][0] = strDisplay[i];
        strvalueType[i][1] = strValue[i];
    }
    comboValueTypeField = new ComboFieldEditor(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE, Messages.getString("MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE"), strvalueType, //$NON-NLS-1$
    com);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 4;
    com.setLayoutData(gridData);
    GridLayout gridLayout = (GridLayout) com.getLayout();
    gridLayout.numColumns = 6;
    com.setLayout(gridLayout);
    valueLengthField = new StringFieldEditor(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH, Messages.getString("MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH"), //$NON-NLS-1$
    valueGroup);
    addField(comboValueTypeField);
    addField(valueLengthField);
    /**
         * set Fields
         * 
         */
    fieldGroup = new Group(parent, SWT.NONE);
    //$NON-NLS-1$
    fieldGroup.setText(Messages.getString("MetadataTypeLengthPreferencePage.FIELD"));
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    fieldGroup.setLayoutData(gd);
    com = new Composite(fieldGroup, SWT.NONE);
    comboFieldTypeField = new ComboFieldEditor(MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE, Messages.getString("MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE"), strvalueType, //$NON-NLS-1$
    com);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 4;
    com.setLayoutData(gridData);
    gridLayout = (GridLayout) com.getLayout();
    gridLayout.numColumns = 6;
    com.setLayout(gridLayout);
    fieldLengthField = new StringFieldEditor(MetadataTypeLengthConstants.FIELD_DEFAULT_LENGTH, Messages.getString("MetadataTypeLengthConstants.FIELD_DEFAULT_LENGTH"), //$NON-NLS-1$
    fieldGroup);
    /**
         * set data Type
         */
    dbTypeGroup = new Group(parent, SWT.NONE);
    //$NON-NLS-1$
    dbTypeGroup.setText(Messages.getString("MetadataTypeLengthPreferencePage.DBTYPE"));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    dbTypeGroup.setLayoutData(gd);
    booleanField = new StringFieldEditor(MetadataTypeLengthConstants.ID_BOOLEAN, Messages.getString("MetadataTypeLengthConstants.BOOLEAN_LENGTH"), //$NON-NLS-1$
    dbTypeGroup);
    bigDecimalField = new StringFieldEditor(MetadataTypeLengthConstants.ID_BIGDECIMAL, Messages.getString("MetadataTypeLengthConstants.BIGDECIMAL_LENGTH"), //$NON-NLS-1$
    dbTypeGroup);
    byteField = new StringFieldEditor(MetadataTypeLengthConstants.ID_BYTE, Messages.getString("MetadataTypeLengthConstants.BYTE_LENGTH"), //$NON-NLS-1$
    dbTypeGroup);
    integerField = new StringFieldEditor(MetadataTypeLengthConstants.ID_INTEGER, Messages.getString("MetadataTypeLengthConstants.INTEGER_LENGTH"), //$NON-NLS-1$
    dbTypeGroup);
    bytearrayField = new StringFieldEditor(MetadataTypeLengthConstants.ID_BYTEARRAY, Messages.getString("MetadataTypeLengthConstants.BYTEARRAY_LENGTH"), //$NON-NLS-1$
    dbTypeGroup);
    longField = new StringFieldEditor(MetadataTypeLengthConstants.ID_LONG, Messages.getString("MetadataTypeLengthConstants.LONG_LENGTH"), //$NON-NLS-1$
    dbTypeGroup);
    characterField = new StringFieldEditor(MetadataTypeLengthConstants.ID_CHARACTER, Messages.getString("MetadataTypeLengthConstants.CHARACTER_LENGTH"), //$NON-NLS-1$
    dbTypeGroup);
    objectField = new StringFieldEditor(MetadataTypeLengthConstants.ID_OBJECT, Messages.getString("MetadataTypeLengthConstants.OBJECT_LENGTH"), //$NON-NLS-1$
    dbTypeGroup);
    dateField = new StringFieldEditor(MetadataTypeLengthConstants.ID_DATE, Messages.getString("MetadataTypeLengthConstants.DATE_LENGHT"), //$NON-NLS-1$
    dbTypeGroup);
    shortField = new StringFieldEditor(MetadataTypeLengthConstants.ID_SHORT, Messages.getString("MetadataTypeLengthConstants.SHORT_LENGTH"), //$NON-NLS-1$
    dbTypeGroup);
    doubleField = new StringFieldEditor(MetadataTypeLengthConstants.ID_DOUBLE, Messages.getString("MetadataTypeLengthConstants.DOUBLE_LENGTH"), //$NON-NLS-1$
    dbTypeGroup);
    stringField = new StringFieldEditor(MetadataTypeLengthConstants.ID_STRING, Messages.getString("MetadataTypeLengthConstants.STRING_LENGTH"), //$NON-NLS-1$
    dbTypeGroup);
    floatField = new StringFieldEditor(MetadataTypeLengthConstants.ID_FLOAT, Messages.getString("MetadataTypeLengthConstants.FLOAT_LENGTH"), //$NON-NLS-1$
    dbTypeGroup);
    listField = new StringFieldEditor(MetadataTypeLengthConstants.ID_LIST, Messages.getString("MetadataTypeLengthConstants.LIST_LENGTH"), //$NON-NLS-1$
    dbTypeGroup);
    addField(comboFieldTypeField);
    addField(fieldLengthField);
    gridLayout = (GridLayout) dbTypeGroup.getLayout();
    gridLayout.numColumns = 4;
    dbTypeGroup.setLayout(gridLayout);
    addField(bigDecimalField);
    addField(booleanField);
    addField(byteField);
    addField(integerField);
    addField(bytearrayField);
    addField(longField);
    addField(characterField);
    addField(objectField);
    addField(dateField);
    addField(shortField);
    addField(doubleField);
    addField(stringField);
    addField(floatField);
    addField(listField);
}
Also used : StringFieldEditor(org.eclipse.jface.preference.StringFieldEditor) Group(org.eclipse.swt.widgets.Group) JavaType(org.talend.core.model.metadata.types.JavaType) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) ComboFieldEditor(org.talend.commons.ui.utils.workbench.preferences.ComboFieldEditor)

Example 3 with JavaType

use of org.talend.core.model.metadata.types.JavaType in project tdi-studio-se by Talend.

the class XmlMapNodeDirectEditManager method getTypeDisplayValue.

private String getTypeDisplayValue(VarNode varNode) {
    JavaType javaType = JavaTypesManager.getJavaTypeFromId(varNode.getType());
    Class primitiveClass = javaType.getPrimitiveClass();
    Boolean nullable = varNode.isNullable();
    String displayedValue = null;
    if (primitiveClass != null && !nullable.equals(Boolean.TRUE)) {
        displayedValue = primitiveClass.getSimpleName();
    } else if (varNode.getType().equals(JavaTypesManager.DIRECTORY.getId()) || varNode.getType().equals(JavaTypesManager.FILE.getId()) || varNode.getType().equals(JavaTypesManager.VALUE_LIST.getId())) {
        displayedValue = javaType.getLabel();
    } else {
        displayedValue = javaType.getNullableClass().getSimpleName();
    }
    if (displayedValue == null) {
        displayedValue = JavaTypesManager.getDefaultJavaType().getLabel();
    }
    return displayedValue;
}
Also used : JavaType(org.talend.core.model.metadata.types.JavaType)

Example 4 with JavaType

use of org.talend.core.model.metadata.types.JavaType in project tdi-studio-se by Talend.

the class VarEntityFigure method getTypeDisplayValue.

private String getTypeDisplayValue(String type, boolean nullable) {
    JavaType javaType = JavaTypesManager.getJavaTypeFromId(type);
    Class primitiveClass = javaType.getPrimitiveClass();
    String displayedValue = null;
    if (primitiveClass != null && !Boolean.TRUE.equals(nullable)) {
        displayedValue = primitiveClass.getSimpleName();
    } else if (type.equals(JavaTypesManager.DIRECTORY.getId()) || type.equals(JavaTypesManager.FILE.getId()) || type.equals(JavaTypesManager.VALUE_LIST.getId())) {
        displayedValue = javaType.getLabel();
    } else {
        displayedValue = javaType.getNullableClass().getSimpleName();
    }
    if (displayedValue == null) {
        displayedValue = JavaTypesManager.getDefaultJavaType().getLabel();
    }
    return displayedValue;
}
Also used : JavaType(org.talend.core.model.metadata.types.JavaType)

Example 5 with JavaType

use of org.talend.core.model.metadata.types.JavaType in project tdi-studio-se by Talend.

the class ContextParameterPage method getJavaDisplayedType.

private String getJavaDisplayedType(String originalTypedValue) {
    JavaType javaType;
    javaType = ContextParameterJavaTypeManager.getJavaTypeFromLabel(originalTypedValue);
    String type;
    if (javaType == null) {
        type = MetadataTalendType.getDefaultTalendType();
    } else {
        type = javaType.getId();
    }
    return type;
}
Also used : JavaType(org.talend.core.model.metadata.types.JavaType)

Aggregations

JavaType (org.talend.core.model.metadata.types.JavaType)10 ArrayList (java.util.ArrayList)5 List (java.util.List)2 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)2 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)2 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 Document (org.dom4j.Document)1 Element (org.dom4j.Element)1 SAXReader (org.dom4j.io.SAXReader)1 DefaultElement (org.dom4j.tree.DefaultElement)1 EList (org.eclipse.emf.common.util.EList)1 EObject (org.eclipse.emf.ecore.EObject)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 StringFieldEditor (org.eclipse.jface.preference.StringFieldEditor)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1