use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class TalendEditorComponentProposalProvider method getProposals.
/**
* Return an array of Objects representing the valid content proposals for a field.
*
* @param contents the current contents of the field (only consulted if filtering is set to <code>true</code>)
* @param position the current cursor position within the field (ignored)
* @return the array of Objects that represent valid proposals for the field given its current content.
*/
@Override
public IContentProposal[] getProposals(String contents, int position) {
List<IComponent> relatedComponent = TalendEditorPaletteFactory.getRelatedComponents(componentsFactory, contents);
if (componentAssistant != null) {
relatedComponent = componentAssistant.filterComponents(relatedComponent);
}
proposalList.clear();
// add joblet components in joblet editor.
List<PaletteEntry> extraPaletteEntry = ComponentPaletteUtilities.getExtraPaletteEntry();
if (extraPaletteEntry != null) {
for (PaletteEntry entry : extraPaletteEntry) {
if (entry != null && entry.isVisible() && entry instanceof TalendCreationToolEntry) {
TalendCreationToolEntry tool = (TalendCreationToolEntry) entry;
CreationFactory creationFactory = tool.getFactory();
if (creationFactory != null && creationFactory instanceof PaletteComponentFactory) {
PaletteComponentFactory componentFactory = (PaletteComponentFactory) creationFactory;
proposalList.add(new ComponentContentProposal(componentFactory.getComponent()));
}
}
}
}
if (relatedComponent != null && !relatedComponent.isEmpty()) {
Iterator<IComponent> iter = relatedComponent.iterator();
while (iter.hasNext()) {
IComponent component = iter.next();
// proposalList.add(new ComponentContentProposal(component.getName(), component.getLongName(),
// component));
proposalList.add(new ComponentContentProposal(component));
}
}
/**
* Always add Note
*/
//$NON-NLS-1$
DummyComponent noteComponent = new DummyComponent("Note");
noteComponent.setIcon16(ImageProvider.getImageDesc(ECoreImage.NOTE_SMALL_ICON));
//$NON-NLS-1$
noteComponent.setOriginalFamilyName("Misc");
proposalList.add(new ComponentContentProposal(noteComponent));
return proposalList.toArray(new IContentProposal[0]);
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class TalendEditorConnectionTargetAssist method filterComponents.
@Override
protected List<IComponent> filterComponents(List<IComponent> components) {
components = super.filterComponents(components);
if (components == null || components.isEmpty()) {
return components;
}
Iterator<IComponent> iter = components.iterator();
while (iter.hasNext()) {
IComponent component = iter.next();
if (component == null) {
continue;
}
if (!TalendEditorComponentCreationUtil.isComponentAllowedWithConnectionType(component, connectionType)) {
iter.remove();
}
}
return components;
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class TalendEditorComponentCreationUtil method getComponentsInType.
public static Map<String, IComponent> getComponentsInType(String categoryName, EConnectionType type) {
if (type == null) {
type = ConnectionManager.getNewConnectionType();
}
Map<String, IComponent> lineTypeMap = lineTypeEntries.get(type);
if (lineTypeMap != null && !lineTypeMap.isEmpty()) {
return lineTypeMap;
}
Map<String, IComponent> map = entries.get(categoryName);
if (map == null) {
map = new HashMap<String, IComponent>();
entries.put(categoryName, map);
readComponentsInCategory(categoryName, map);
}
lineTypeMap = new HashMap<String, IComponent>();
for (String key : map.keySet()) {
IComponent component = map.get(key);
if (isComponentAllowedWithConnectionType(component, type)) {
lineTypeMap.put(component.getName(), component);
}
}
lineTypeEntries.put(type, lineTypeMap);
return lineTypeMap;
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class DesignerCoreService method getRefrenceNode.
@Override
public INode getRefrenceNode(String componentName, String paletteType) {
if (componentName == null) {
return null;
}
IComponentsFactory compFac = CorePlugin.getDefault().getRepositoryService().getComponentsFactory();
IComponent component = compFac.get(componentName, paletteType);
if (component == null) {
return null;
}
return new DataNode(component, componentName);
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class GuessSchemaProcess method buildProcess.
private void buildProcess() {
process = new Process(property);
process.getContextManager().getListContext().addAll(node.getProcess().getContextManager().getListContext());
process.getContextManager().setDefaultContext(this.selectContext);
outputComponent = ComponentsFactoryProvider.getInstance().get(EDatabaseComponentName.FILEDELIMITED.getOutPutComponentName(), ComponentCategory.CATEGORY_4_DI.getName());
if (node.getModulesNeeded().size() > 0 && !node.getComponent().getName().equals("tRedshiftInput")) {
//$NON-NLS-1$
for (ModuleNeeded module : node.getModulesNeeded()) {
if (module.isRequired(node.getElementParameters())) {
Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE, ComponentCategory.CATEGORY_4_DI.getName()), process);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
NodeContainer nc = process.loadNodeContainer(libNode1, false);
process.addNodeContainer(nc);
}
}
} else {
// hywang add for 9594
if (node.getComponent().getName().equals("tJDBCInput") || node.getComponent().getName().equals("tRedshiftInput")) {
List<String> drivers = EDatabaseVersion4Drivers.getDrivers(info.getTrueDBTypeForJDBC(), info.getDbVersion());
String moduleNeedName = "";
Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE, ComponentCategory.CATEGORY_4_DI.getName()), process);
if (drivers.size() > 0) {
// use the first driver as defalult.
// added for bug 13592
moduleNeedName = drivers.get(0).toString();
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode1.setPropertyValue("LIBRARY", "\"" + moduleNeedName + "\"");
}
process.addNodeContainer(new NodeContainer(libNode1));
}
}
INode connectionNode = null;
IElementParameter existConnection = node.getElementParameter("USE_EXISTING_CONNECTION");
boolean useExistConnection = (existConnection == null ? false : (Boolean) existConnection.getValue());
if (useExistConnection) {
IElementParameter connector = node.getElementParameter("CONNECTION");
if (connector != null) {
String connectorValue = connector.getValue().toString();
List<? extends INode> generatingNodes = originalProcess.getGeneratingNodes();
for (INode node : generatingNodes) {
if (node.getUniqueName().equals(connectorValue)) {
connectionNode = node;
break;
}
}
}
}
List<ModuleNeeded> neededLibraries = new ArrayList<ModuleNeeded>();
JavaProcessUtil.addNodeRelatedModules(process, neededLibraries, node);
for (ModuleNeeded module : neededLibraries) {
Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
process.addNodeContainer(new NodeContainer(libNode1));
}
if (connectionNode != null) {
neededLibraries = new ArrayList<ModuleNeeded>();
JavaProcessUtil.addNodeRelatedModules(process, neededLibraries, connectionNode);
for (ModuleNeeded module : neededLibraries) {
Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
process.addNodeContainer(new NodeContainer(libNode1));
}
}
// create the tLibraryLoad for the output component which is "tFileOutputDelimited"
for (ModuleNeeded module : outputComponent.getModulesNeeded()) {
Node libNode2 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode2.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
process.addNodeContainer(new NodeContainer(libNode2));
}
// for sql statement, feature 6622.
int fetchSize = maximumRowsToPreview;
if (maximumRowsToPreview > 1000) {
fetchSize = 1000;
}
String codeStart, codeMain, codeEnd;
temppath = buildTempCSVFilename();
// Should also replace "/r". NMa.
// ISO-8859-15
memoSQL = memoSQL.replace("\r", " ");
// fix for TDI-26285
//$NON-NLS-1$
String createStatament = "conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY)";
//$NON-NLS-1$
String systemProperty = "";
if (info.isHive()) {
//$NON-NLS-1$
createStatament = "conn.createStatement()";
systemProperty = //$NON-NLS-1$ //$NON-NLS-2$
"System.setProperty(\"mapred.job.tracker\",\"" + info.getJobTracker() + "\");\r\n" + "System.setProperty(\"fs.default.name\", \"" + info.getNameNode() + //$NON-NLS-1$ //$NON-NLS-2$
"\");\r\n";
// only embeded hive need the following params
if (info.getThrifturi() != null) {
systemProperty = //$NON-NLS-1$
systemProperty + " System.setProperty(\"hive.metastore.local\", \"false\");\r\n" + " System.setProperty(\"hive.metastore.uris\", \"" + info.getThrifturi() + //$NON-NLS-1$ //$NON-NLS-2$
"\");\r\n" + //$NON-NLS-1$
"System.setProperty(\"hive.metastore.execute.setugi\", \"true\");\r\n";
}
}
// add for bug TDI-27137 by fwang on 27 August, 2013.
EDatabaseTypeName dbType = EDatabaseTypeName.JAVADB_EMBEDED.getTypeFromDbType(info.getDbType());
if (EDatabaseTypeName.JAVADB_EMBEDED.equals(dbType)) {
IElementParameter dbPathElement = node.getElementParameter("DBPATH");
if (dbPathElement != null) {
String derbyPath = dbPathElement.getValue().toString().replace("\"", "").trim();
systemProperty = systemProperty + "System.setProperty(\"derby.system.home\",\"" + derbyPath + "\");\r\n";
}
}
// the Sqlite
if (EDatabaseTypeName.SQLITE.getXmlName().equals(info.getDbType())) {
createStatament = "conn.createStatement()";
}
// the VERTICA
if (ConnectionUtils.isVertica(info.getUrl())) {
createStatament = "conn.createStatement()";
}
if (EDatabaseTypeName.GENERAL_JDBC.getXmlName().equals(info.getDbType()) && "com.sap.db.jdbc.Driver".equals(info.getDriverClassName()) || EDatabaseTypeName.SAPHana.getXmlName().equals(info.getDbType())) {
createStatament = "conn.createStatement()";
}
codeStart = systemProperty + getCodeStart(connectionNode, createStatament, fetchSize);
codeMain = //$NON-NLS-1$ //$NON-NLS-2$
"String[] dataOneRow = new String[numbOfColumn];\r\n" + "for (int i = 1; i <= numbOfColumn; i++) {\r\n" + " \r\n" + " try{\r\n" + " String tempStr = rs.getString(i);\r\n" + " dataOneRow[i-1] = tempStr;\r\n" + " } catch (java.sql.SQLException e) {\r\n" + "}\r\n" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"}\r\n" + //$NON-NLS-1$
"csvWriter.writeNext(dataOneRow);";
if (EDatabaseTypeName.REDSHIFT.getXmlName().equals(info.getDbType())) {
codeEnd = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"nbRows++;\r\n" + " if (nbRows > " + maximumRowsToPreview + ") break;\r\n" + "}\r\n" + "conn.close();\r\n" + //$NON-NLS-1$ //$NON-NLS-2$
"csvWriter.close();\r\n";
} else {
codeEnd = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"nbRows++;\r\n" + " if (nbRows > " + maximumRowsToPreview + ") break;\r\n" + "}\r\n" + "conn.close();\r\n" + //$NON-NLS-1$ //$NON-NLS-2$
"csvWriter.close();\r\n";
}
IComponent component = null;
switch(LanguageManager.getCurrentLanguage()) {
case JAVA:
//$NON-NLS-1$
component = ComponentsFactoryProvider.getInstance().get("tJavaFlex");
break;
case PERL:
default:
//$NON-NLS-1$
component = ComponentsFactoryProvider.getInstance().get("tPerlFlex");
break;
}
Node flexNode = new Node(component, process);
//$NON-NLS-1$
flexNode.setPropertyValue("CODE_START", codeStart);
//$NON-NLS-1$
flexNode.setPropertyValue("CODE_MAIN", codeMain);
//$NON-NLS-1$
flexNode.setPropertyValue("CODE_END", codeEnd);
process.addNodeContainer(new NodeContainer(flexNode));
}
Aggregations