Search in sources :

Example 1 with AutoConversionType

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

the class AutoConversionTypesEditorView method createTargetDataTypeColumn.

private TableViewerCreatorColumn createTargetDataTypeColumn(TableViewerCreator<AutoConversionType> tableViewerCreator) {
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
    //$NON-NLS-1$
    column.setTitle(Messages.getString("AutoConversionTypesEditor.table.column.targetDataType"));
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<AutoConversionType, String>() {

        @Override
        public String get(AutoConversionType bean) {
            return bean.getTargetDataType();
        }

        @Override
        public void set(AutoConversionType bean, String value) {
            bean.setTargetDataType(value);
        }
    });
    column.setModifiable(true);
    column.setWeight(30);
    column.setMinimumWidth(50);
    configureTypeColumn(tableViewerCreator, column);
    return column;
}
Also used : AutoConversionType(org.talend.core.model.metadata.types.AutoConversionType) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)

Example 2 with AutoConversionType

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

the class AutoConvertTypesUtils method load.

public static List<AutoConversionType> load(File file) {
    beanList = new ArrayList<>();
    try {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder analyseur = documentBuilderFactory.newDocumentBuilder();
        analyseur.setErrorHandler(new ErrorHandler() {

            @Override
            public void error(final SAXParseException exception) throws SAXException {
                throw exception;
            }

            @Override
            public void fatalError(final SAXParseException exception) throws SAXException {
                throw exception;
            }

            @Override
            public void warning(final SAXParseException exception) throws SAXException {
                throw exception;
            }
        });
        Document document = analyseur.parse(file);
        //$NON-NLS-1$
        NodeList typeNodes = document.getElementsByTagName("conversionType");
        for (int i = 0; i < typeNodes.getLength(); i++) {
            Node typeNode = typeNodes.item(i);
            NamedNodeMap typeAttributes = typeNode.getAttributes();
            AutoConversionType typeObj = new AutoConversionType();
            //$NON-NLS-1$
            typeObj.setSourceDataType(typeAttributes.getNamedItem("source").getNodeValue());
            //$NON-NLS-1$
            typeObj.setTargetDataType(typeAttributes.getNamedItem("target").getNodeValue());
            //$NON-NLS-1$
            typeObj.setConversionFunction(typeAttributes.getNamedItem("function").getNodeValue());
            beanList.add(typeObj);
        }
    } catch (Exception e) {
        return beanList;
    }
    return beanList;
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) PersistenceException(org.talend.commons.exception.PersistenceException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) AutoConversionType(org.talend.core.model.metadata.types.AutoConversionType) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException)

Example 3 with AutoConversionType

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

the class AutoConvertTypesUtilsTest method init.

@Before
public void init() throws Exception {
    //$NON-NLS-1$
    Bundle b = Platform.getBundle("org.talend.repository.test");
    //$NON-NLS-1$
    URL url = FileLocator.toFileURL(FileLocator.find(b, new Path("AutoConversionTypesTest.xml"), null));
    Assert.assertNotNull(url);
    testFile = new File(url.getPath());
    Assert.assertTrue(testFile.exists());
    //
    AutoConversionType bean = new AutoConversionType();
    bean.setSourceDataType(JavaTypesManager.getDefaultJavaType().getId());
    bean.setTargetDataType(JavaTypesManager.INTEGER.getId());
    //$NON-NLS-1$
    bean.setConversionFunction("Integer.parseInt(${0})");
    testBeanList.add(bean);
}
Also used : Path(org.eclipse.core.runtime.Path) AutoConversionType(org.talend.core.model.metadata.types.AutoConversionType) Bundle(org.osgi.framework.Bundle) File(java.io.File) URL(java.net.URL) Before(org.junit.Before)

Example 4 with AutoConversionType

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

the class AutoConvertTypesUtils method save.

public static boolean save(List<AutoConversionType> beans, File file) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    OutputStreamWriter output = null;
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setErrorHandler(new ErrorHandler() {

            @Override
            public void error(final SAXParseException exception) throws SAXException {
                throw exception;
            }

            @Override
            public void fatalError(final SAXParseException exception) throws SAXException {
                throw exception;
            }

            @Override
            public void warning(final SAXParseException exception) throws SAXException {
                throw exception;
            }
        });
        Document document = builder.newDocument();
        //document.setXmlVersion("1.0");//$NON-NLS-1$
        //$NON-NLS-1$
        Element root = document.createElement("mapping");
        document.appendChild(root);
        for (int i = 0; i < beans.size(); i++) {
            AutoConversionType bean = beans.get(i);
            //$NON-NLS-1$
            Element typeNode = document.createElement("conversionType");
            //$NON-NLS-1$
            typeNode.setAttribute("source", bean.getSourceDataType());
            //$NON-NLS-1$
            typeNode.setAttribute("target", bean.getTargetDataType());
            //$NON-NLS-1$
            typeNode.setAttribute("function", bean.getConversionFunction());
            root.appendChild(typeNode);
        }
        // save into file
        if (document != null) {
            XMLSerializer serializer = new XMLSerializer();
            OutputFormat outputFormat = new OutputFormat();
            outputFormat.setIndenting(true);
            serializer.setOutputFormat(outputFormat);
            output = new OutputStreamWriter(new FileOutputStream(file));
            serializer.setOutputCharStream(output);
            serializer.serialize(document);
            // update
            beanList = new ArrayList<>();
            beanList.addAll(beans);
        }
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } finally {
        if (output != null) {
            output.close();
        }
    }
    return true;
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) XMLSerializer(com.sun.org.apache.xml.internal.serialize.XMLSerializer) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) OutputFormat(com.sun.org.apache.xml.internal.serialize.OutputFormat) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) AutoConversionType(org.talend.core.model.metadata.types.AutoConversionType) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 5 with AutoConversionType

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

the class AutoConversionTypesEditorView method configureTypeColumn.

private void configureTypeColumn(TableViewerCreator<AutoConversionType> tableViewerCreator, TableViewerCreatorColumn column) {
    IBeanPropertyAccessors<AutoConversionType, Boolean> nullableAccessors = new IBeanPropertyAccessors<AutoConversionType, Boolean>() {

        @Override
        public Boolean get(AutoConversionType bean) {
            return Boolean.TRUE;
        }

        @Override
        public void set(AutoConversionType bean, Boolean value) {
            return;
        }
    };
    CellEditorValueAdapter comboValueAdapter = new JavaTypeComboValueAdapter(JavaTypesManager.getDefaultJavaType(), nullableAccessors);
    String[] arrayTalendTypes = new String[0];
    try {
        arrayTalendTypes = MetadataTalendType.getTalendTypesLabels();
    } catch (NoClassDefFoundError e) {
        // shouln't be happend
        // e.printStackTrace();
        ExceptionHandler.process(e);
    } catch (ExceptionInInitializerError e) {
        // shouln't be happend
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
    ComboBoxCellEditor typeComboEditor = new ComboBoxCellEditor(tableViewerCreator.getTable(), arrayTalendTypes, SWT.READ_ONLY);
    CCombo typeCombo = (CCombo) typeComboEditor.getControl();
    typeCombo.setEditable(false);
    column.setCellEditor(typeComboEditor, comboValueAdapter);
}
Also used : AutoConversionType(org.talend.core.model.metadata.types.AutoConversionType) CCombo(org.eclipse.swt.custom.CCombo) JavaTypeComboValueAdapter(org.talend.core.ui.metadata.celleditor.JavaTypeComboValueAdapter) CellEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) IBeanPropertyAccessors(org.talend.commons.utils.data.bean.IBeanPropertyAccessors)

Aggregations

AutoConversionType (org.talend.core.model.metadata.types.AutoConversionType)8 TableViewerCreatorColumn (org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Document (org.w3c.dom.Document)2 ErrorHandler (org.xml.sax.ErrorHandler)2 SAXException (org.xml.sax.SAXException)2 SAXParseException (org.xml.sax.SAXParseException)2 OutputFormat (com.sun.org.apache.xml.internal.serialize.OutputFormat)1 XMLSerializer (com.sun.org.apache.xml.internal.serialize.XMLSerializer)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Path (org.eclipse.core.runtime.Path)1 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)1 CCombo (org.eclipse.swt.custom.CCombo)1