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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations