public static void updateModuleList(Node node) { List<ModuleNeeded> moduleNeededList = ModulesNeededProvider.getModulesNeeded(); Set<String> moduleNameList = new TreeSet<String>(); Set<String> moduleValueList = new TreeSet<String>(); for (ModuleNeeded module : moduleNeededList) { String moduleName = module.getModuleName(); moduleNameList.add(moduleName); moduleValueList.add(TalendTextUtils.addQuotes(moduleName)); } Comparator<String> comprarator = new IgnoreCaseComparator(); String[] moduleNameArray = moduleNameList.toArray(new String[0]); String[] moduleValueArray = moduleValueList.toArray(new String[0]); Arrays.sort(moduleNameArray, comprarator); Arrays.sort(moduleValueArray, comprarator); for (int i = 0; i < node.getElementParameters().size(); i++) { IElementParameter param = node.getElementParameters().get(i); if (param.getFieldType() == EParameterFieldType.MODULE_LIST) { param.setListItemsDisplayName(moduleNameArray); param.setListItemsValue(moduleValueArray); } else if (param.getFieldType() == EParameterFieldType.TABLE) { Object[] listItemsValue = param.getListItemsValue(); if (listItemsValue != null) { for (Object o : listItemsValue) { if (o instanceof IElementParameter && ((IElementParameter) o).getFieldType() == EParameterFieldType.MODULE_LIST) { ((IElementParameter) o).setListItemsDisplayName(moduleNameArray); ((IElementParameter) o).setListItemsValue(moduleValueArray); } } } } } }
/** * DOC qzhang Comment method "changeTableNameParameter". * * @param newdbTableName * @param olddbTableName * @param uniqueName * @param dbTableElementField */ private void changeTableNameParameter( String newdbTableName, String olddbTableName, String uniqueName, IElementParameter dbTableElementField) { if (dbTableElementField != null) { if (isNotSim) { newdbTableName = newdbTableName == null ? "" : newdbTableName; // $NON-NLS-1$ dbTableElementField.setValue(TalendTextUtils.addQuotes(newdbTableName)); return; } Object value = dbTableElementField.getValue(); String removeQuotes = TalendTextUtils.removeQuotes((String) value); boolean b = value == null || removeQuotes.equals(""); // $NON-NLS-1$ // add the code for table name equals uniqueName b = b || uniqueName.equals(olddbTableName); b = b || value != null && removeQuotes.toString().equals(olddbTableName); if (b) { newdbTableName = newdbTableName == null ? "" : newdbTableName; // $NON-NLS-1$ dbTableElementField.setValue(TalendTextUtils.addQuotes(newdbTableName)); } } }
@Override public void refresh(IElementParameter param, boolean check) { CCombo combo = (CCombo) hashCurControls.get(param.getName()); if (combo == null || combo.isDisposed()) { return; } updateData(); String[] curNameList = param.getListItemsDisplayName(); Object value = param.getValue(); combo.setItems(curNameList); if (value instanceof String) { combo.setText(TalendTextUtils.removeQuotes((String) value)); } if (param.isContextMode()) { Button buttonEdit = (Button) hashCurControls.get(param.getName() + BUTTON_EDIT); combo.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED)); combo.setEnabled(false); buttonEdit.setEnabled(false); } }
/** Constructs a new FileInputNode. */ public FileInputDelimitedNode( String filename, String rowSep, String fieldSep, int limitRows, int headerRows, int footerRows, String escapeChar, String textEnclosure, boolean removeEmptyRow, boolean spitRecord, String encoding, EShadowProcessType fileType) { super("tFileInputDelimited"); // $NON-NLS-1$ boolean csvoption = false; String languageName = LanguageManager.getCurrentLanguage().getName(); switch (fileType) { case FILE_DELIMITED: csvoption = false; if (languageName.equals("perl")) { // $NON-NLS-1$ int max = getColumnCount( filename, rowSep, fieldSep, limitRows, headerRows, escapeChar, textEnclosure, EShadowProcessType.FILE_DELIMITED); this.setColumnNumber(max); } else { int max = 0; try { max = FileInputDelimited.getMaxColumnCount( trimParameter(filename), trimParameter(encoding), trimParameter(StringUtils.loadConvert(fieldSep, languageName)), trimParameter(StringUtils.loadConvert(rowSep, languageName)), true, spitRecord, headerRows, limitRows); } catch (IOException e) { // e.printStackTrace(); ExceptionHandler.process(e); } if (max > 0) { this.setColumnNumber(max); } } break; case FILE_CSV: csvoption = true; if (languageName.equals("perl")) { // $NON-NLS-1$ int max = getColumnCount( filename, rowSep, fieldSep, limitRows, headerRows, escapeChar, textEnclosure, EShadowProcessType.FILE_CSV); this.setColumnNumber(max); } else { CSVFileColumnConnter cr = null; try { cr = new CSVFileColumnConnter(); cr.setSeperator( trimParameter(StringUtils.loadConvert(fieldSep, languageName)).charAt(0)); int columnCount = 0; columnCount = cr.countMaxColumnNumber( new File(TalendTextUtils.removeQuotes(filename)), limitRows); if (columnCount > 0) { this.setColumnNumber(columnCount); } } catch (UnsupportedEncodingException e) { ExceptionHandler.process(e); } catch (FileNotFoundException e) { ExceptionHandler.process(e); } catch (IOException e) { ExceptionHandler.process(e); } } break; default: break; } String[] paramNames = null; if (!csvoption) { paramNames = new String[] { "FILENAME", "ROWSEPARATOR", "FIELDSEPARATOR", "LIMIT", "HEADER", "FOOTER", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ // //$NON-NLS-6$ "ESCAPE_CHAR", "TEXT_ENCLOSURE", "REMOVE_EMPTY_ROW", "ENCODING", "CSV_OPTION", "SPLITRECORD" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ } else { paramNames = new String[] { "FILENAME", "CSVROWSEPARATOR", "FIELDSEPARATOR", "LIMIT", "HEADER", "FOOTER", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ // //$NON-NLS-6$ "ESCAPE_CHAR", "TEXT_ENCLOSURE", "REMOVE_EMPTY_ROW", "ENCODING", "CSV_OPTION", "SPLITRECORD" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ } String[] paramValues = new String[] { filename, rowSep, fieldSep, Integer.toString(limitRows), Integer.toString(headerRows), Integer.toString(footerRows), escapeChar, textEnclosure, Boolean.toString(removeEmptyRow), encoding, Boolean.toString(csvoption), Boolean.toString(spitRecord) }; IComponent component = ComponentsFactoryProvider.getInstance() .get( "tFileInputDelimited", //$NON-NLS-1$ ComponentCategory.CATEGORY_4_DI.getName()); this.setElementParameters(component.createElementParameters(this)); for (int i = 0; i < paramNames.length; i++) { if (paramValues[i] != null) { IElementParameter param = this.getElementParameter(paramNames[i]); if (param != null) { param.setValue(paramValues[i]); } } } }
/** * load the Element's parameters to EMF Model * * @param elemParam * @param paType */ public static void loadElementParameters( Element elemParam, ParametersType paType, String repParamName) { if (paType == null || elemParam == null) { return; } EList listParamType = paType.getElementParameter(); ElementParameterType repositoryParam = null; if (repParamName != null && !repParamName.equals("")) { repositoryParam = findElementParameterType(paType, repParamName); } else { repositoryParam = findElementParameterType( paType, EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.PROPERTY_TYPE.getName()); } IElementParameter statsDBType = null; IElementParameter implicitDBType = null; IElementParameter statsDBVersion = null; IElementParameter implicitDBVersion = null; for (int j = 0; j < listParamType.size(); j++) { ElementParameterType pType = (ElementParameterType) listParamType.get(j); if (pType != null) { String pTypeName = pType.getName(); if (pTypeName != null && !"".equals(pTypeName)) { IElementParameter param = elemParam.getElementParameter(pTypeName); if (pTypeName.equals("DB_TYPE")) { // $NON-NLS-1$ statsDBType = param; } else if (pTypeName.equals("DB_VERSION")) { // $NON-NLS-1$ statsDBVersion = param; } else if (pTypeName.equals("DB_TYPE_IMPLICIT_CONTEXT")) { // $NON-NLS-1$ implicitDBType = param; } else if (pTypeName.equals("DB_VERSION_IMPLICIT_CONTEXT")) { // $NON-NLS-1$ implicitDBVersion = param; } if (param != null) { String name = param.getName(); param.setContextMode(pType.isContextMode()); if (param.isReadOnly() && !(EParameterName.UNIQUE_NAME.getName().equals(name) || EParameterName.VERSION.getName().equals(name))) { continue; // if the parameter is read only, don't load // it (this will prevent to overwrite the // value) } String value = null; if ("STATANDLOG_USE_PROJECT_SETTINGS".equals(name) // $NON-NLS-1$ || "IMPLICITCONTEXT_USE_PROJECT_SETTINGS".equals(name)) { // $NON-NLS-1$ Object value2 = param.getValue(); if (value2 != null) { value = value2.toString(); } } else { value = pType.getValue(); } if (param.getFieldType().equals(EParameterFieldType.CHECK) || param.getFieldType().equals(EParameterFieldType.RADIO)) { if (Boolean.FALSE.toString().equalsIgnoreCase(value) || Boolean.TRUE.toString().equalsIgnoreCase(value) || !pType.isContextMode()) { Boolean boolean1 = new Boolean(value); elemParam.setPropertyValue(pTypeName, boolean1); } else { elemParam.setPropertyValue(pTypeName, value); } // if (EParameterName.ACTIVATE.getName().equals(param.getName())) { // if ((elemParam instanceof Node) && !boolean1) { // ((Node) elemParam).setDummy(!boolean1); // } // } } else if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST)) { boolean valueSet = false; if (!ArrayUtils.contains(param.getListItemsValue(), value)) { if (ArrayUtils.contains(param.getListItemsDisplayName(), value)) { valueSet = true; int index = ArrayUtils.indexOf(param.getListItemsDisplayName(), value); if (index > -1) { elemParam.setPropertyValue(pTypeName, param.getListItemsValue()[index]); } } else if (value.equals("") && name != null && (name.equals("LOAD_NEW_VARIABLE") || name.equals("NOT_LOAD_OLD_VARIABLE"))) { valueSet = true; elemParam.setPropertyValue(pTypeName, param.getListItemsValue()[1]); } } if (!valueSet) { elemParam.setPropertyValue(pTypeName, value); } } else if (param.getFieldType().equals(EParameterFieldType.TABLE)) { List<Map<String, Object>> tableValues = new ArrayList<Map<String, Object>>(); String[] codeList = param.getListItemsDisplayCodeName(); Map<String, Object> lineValues = null; for (ElementValueType elementValue : (List<ElementValueType>) pType.getElementValue()) { boolean found = false; int length = codeList.length; if (length > 0) { for (int i = 0; i < length && !found; i++) { if (codeList[i].equals(elementValue.getElementRef())) { found = true; } } } IElementParameter tmpParam = null; for (Object o : param.getListItemsValue()) { if (o instanceof IElementParameter) { IElementParameter tableParam = (IElementParameter) o; if (tableParam.getName().equals(elementValue.getElementRef())) { tmpParam = tableParam; break; } } } if (found) { if ((lineValues == null) || (lineValues.get(elementValue.getElementRef()) != null)) { lineValues = new HashMap<String, Object>(); tableValues.add(lineValues); } String elemValue = elementValue.getValue(); if (tmpParam != null && EParameterFieldType.PASSWORD.equals(tmpParam.getFieldType())) { elemValue = elementValue.getRawValue(); } lineValues.put(elementValue.getElementRef(), elemValue); if (elementValue.getType() != null) { lineValues.put( elementValue.getElementRef() + IEbcdicConstant.REF_TYPE, elementValue.getType()); } } } elemParam.setPropertyValue(pTypeName, tableValues); } else if (param.getFieldType().equals(EParameterFieldType.PASSWORD)) { param.setValue(pType.getRawValue()); } else if (param.getFieldType().equals(EParameterFieldType.ENCODING_TYPE)) { // fix for bug 2193 boolean setToCustom = false; if (EmfComponent.REPOSITORY.equals( elemParam.getPropertyValue(EParameterName.PROPERTY_TYPE.getName())) && param.getRepositoryValue() != null && param.getRepositoryValue().equals("ENCODING")) { // $NON-NLS-1$ setToCustom = true; } String tempValue = null; IElementParameter iElementParameter = null; Map<String, IElementParameter> childParameters = param.getChildParameters(); if (childParameters != null) { iElementParameter = childParameters.get(EParameterName.ENCODING_TYPE.getName()); if (iElementParameter != null) { tempValue = (String) iElementParameter.getValue(); } } if (tempValue != null && !tempValue.equals(EmfComponent.ENCODING_TYPE_CUSTOM)) { tempValue = tempValue.replaceAll("'", ""); // $NON-NLS-1$ //$NON-NLS-2$ tempValue = tempValue.replaceAll("\"", ""); // $NON-NLS-1$ //$NON-NLS-2$ tempValue = TalendTextUtils.addQuotes(tempValue); if (!tempValue.equals(value)) { setToCustom = true; } } if (iElementParameter != null && setToCustom) { iElementParameter.setValue(EmfComponent.ENCODING_TYPE_CUSTOM); } elemParam.setPropertyValue(pTypeName, value); // end of fix for bug 2193 } else if (!param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE)) { if (param.getRepositoryValue() != null && !param.getFieldType().equals(EParameterFieldType.PROPERTY_TYPE)) { if (repositoryParam != null && EmfComponent.REPOSITORY.equals(repositoryParam.getValue())) { param.setRepositoryValueUsed(true); } else { param.setRepositoryValueUsed(false); } } elemParam.setPropertyValue(pTypeName, value); } } else if (UpdateTheJobsActionsOnTable.isClear && "CLEAR_TABLE".equals(pTypeName) // $NON-NLS-1$ && "true".equals(pType.getValue()) // $NON-NLS-1$ && "NONE" .equals( elemParam .getElementParameter(Process.TABLE_ACTION) .getValue())) { //$NON-NLS-1$ elemParam.setPropertyValue(Process.TABLE_ACTION, "CLEAR"); // $NON-NLS-1$ UpdateTheJobsActionsOnTable.isClear = false; } } } } // update combo list for dbversion if (statsDBType != null && statsDBVersion != null) { JobSettingVersionUtil.setDbVersion( statsDBVersion, String.valueOf(statsDBType.getValue()), String.valueOf(statsDBVersion.getValue())); } if (implicitDBType != null && implicitDBVersion != null) { JobSettingVersionUtil.setDbVersion( implicitDBVersion, String.valueOf(implicitDBType.getValue()), String.valueOf(implicitDBVersion.getValue())); } }
public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode) codeGenArgument.getArgument(); String cid = node.getUniqueName(); String endpoint = ElementParameterParser.getValue(node, "__ENDPOINT__"); String username = ElementParameterParser.getValue(node, "__USER__"); String password = ElementParameterParser.getValue(node, "__PASS__"); String timeout = ElementParameterParser.getValue(node, "__TIMEOUT__"); boolean needCompression = ("true").equals(ElementParameterParser.getValue(node, "__NEED_COMPRESSION__")); boolean httpTraceMessage = ("true").equals(ElementParameterParser.getValue(node, "__HTTP_TRACEMESSAGE__")); boolean useProxy = ("true").equals(ElementParameterParser.getValue(node, "__USE_PROXY__")); String proxyHost = ElementParameterParser.getValue(node, "__PROXY_HOST__"); String proxyPort = ElementParameterParser.getValue(node, "__PROXY_PORT__"); String proxyUsername = ElementParameterParser.getValue(node, "__PROXY_USERNAME__"); String proxyPassword = ElementParameterParser.getValue(node, "__PROXY_PASSWORD__"); boolean bulkConnection = ("true").equals(ElementParameterParser.getValue(node, "__BULK_CONNECTION__")); String apiVersion = ElementParameterParser.getValue(node, "__API_VERSION__"); String clientID = ElementParameterParser.getValue(node, "__CLIENT_ID__"); if (bulkConnection) { stringBuffer.append(TEXT_1); stringBuffer.append(cid); stringBuffer.append(TEXT_2); if (useProxy) { stringBuffer.append(TEXT_3); stringBuffer.append(cid); stringBuffer.append(TEXT_4); stringBuffer.append(proxyHost); stringBuffer.append(TEXT_5); stringBuffer.append(TalendTextUtils.removeQuotes(proxyPort)); stringBuffer.append(TEXT_6); stringBuffer.append(proxyUsername); stringBuffer.append(TEXT_7); stringBuffer.append(proxyPassword); stringBuffer.append(TEXT_8); } stringBuffer.append(TEXT_9); stringBuffer.append(cid); stringBuffer.append(TEXT_10); stringBuffer.append(needCompression); stringBuffer.append(TEXT_11); stringBuffer.append(cid); stringBuffer.append(TEXT_12); stringBuffer.append(httpTraceMessage); stringBuffer.append(TEXT_13); stringBuffer.append(cid); stringBuffer.append(TEXT_14); stringBuffer.append(endpoint); stringBuffer.append(TEXT_15); stringBuffer.append(username); stringBuffer.append(TEXT_16); stringBuffer.append(password); stringBuffer.append(TEXT_17); stringBuffer.append(apiVersion); stringBuffer.append(TEXT_18); stringBuffer.append(cid); stringBuffer.append(TEXT_19); stringBuffer.append(cid); stringBuffer.append(TEXT_20); } else { if (useProxy) { stringBuffer.append(TEXT_21); stringBuffer.append(cid); stringBuffer.append(TEXT_22); stringBuffer.append(cid); stringBuffer.append(TEXT_23); stringBuffer.append(proxyHost); stringBuffer.append(TEXT_24); stringBuffer.append(cid); stringBuffer.append(TEXT_25); stringBuffer.append(proxyPort); stringBuffer.append(TEXT_26); stringBuffer.append(cid); stringBuffer.append(TEXT_27); stringBuffer.append(proxyUsername); stringBuffer.append(TEXT_28); stringBuffer.append(cid); stringBuffer.append(TEXT_29); stringBuffer.append(proxyPassword); stringBuffer.append(TEXT_30); } stringBuffer.append(TEXT_31); stringBuffer.append(cid); stringBuffer.append(TEXT_32); if (clientID != null && !"".equals(clientID) && !"\"\"".equals(clientID)) { stringBuffer.append(TEXT_33); stringBuffer.append(cid); stringBuffer.append(TEXT_34); stringBuffer.append(clientID); stringBuffer.append(TEXT_35); stringBuffer.append(cid); stringBuffer.append(TEXT_36); stringBuffer.append(cid); stringBuffer.append(TEXT_37); } stringBuffer.append(TEXT_38); stringBuffer.append(cid); stringBuffer.append(TEXT_39); stringBuffer.append(cid); stringBuffer.append(TEXT_40); stringBuffer.append(endpoint); stringBuffer.append(TEXT_41); stringBuffer.append(username); stringBuffer.append(TEXT_42); stringBuffer.append(password); stringBuffer.append(TEXT_43); stringBuffer.append(timeout); stringBuffer.append(TEXT_44); stringBuffer.append(needCompression); stringBuffer.append(TEXT_45); stringBuffer.append(cid); stringBuffer.append(TEXT_46); stringBuffer.append(cid); stringBuffer.append(TEXT_47); stringBuffer.append(cid); stringBuffer.append(TEXT_48); stringBuffer.append(cid); stringBuffer.append(TEXT_49); stringBuffer.append(cid); stringBuffer.append(TEXT_50); } stringBuffer.append(TEXT_51); stringBuffer.append(TEXT_52); return stringBuffer.toString(); }
public Command createCommand(Button button) { Node node = (Node) elem; IExternalNode externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node); if (externalNode != null && externalNode.getUniqueName().contains("tBRMS_")) { IConfigurationElement[] elems = Platform.getExtensionRegistry() .getConfigurationElementsFor("org.talend.designer.core.brms_provider"); String propertyName = (String) button.getData(PARAMETER_NAME); for (IConfigurationElement conElem : elems) { IBrmsExtension createExecutableExtension; try { createExecutableExtension = (IBrmsExtension) conElem.createExecutableExtension("class"); createExecutableExtension.initialize(node, propertyName, hashCurControls); BrmsDialog brmsDialog = createExecutableExtension.createBrmsDialog(composite.getShell()); String file = brmsDialog.getFile(); if (file != null && !file.equals("")) { String lastSegment = TalendTextUtils.addQuotes(Path.fromOSString(file).lastSegment()); try { CorePlugin.getDefault() .getLibrariesService() .deployLibrary(Path.fromOSString(file).toFile().toURL()); } catch (Exception e) { ExceptionHandler.process(e); } // update the combo current value CCombo combo = (CCombo) hashCurControls.get(propertyName); if (combo != null && !combo.isDisposed()) { combo.setText(Path.fromOSString(file).lastSegment()); } return new PropertyChangeCommand(elem, propertyName, lastSegment); } } catch (CoreException e) { ExceptionHandler.process(e); } } } else { FileDialog dial = new FileDialog(composite.getShell(), SWT.NONE); dial.setFilterExtensions(FilesUtils.getAcceptJARFilesSuffix()); String file = dial.open(); if (file != null && !file.equals("")) { // $NON-NLS-1$ String propertyName = (String) button.getData(PARAMETER_NAME); String lastSegment = TalendTextUtils.addQuotes(Path.fromOSString(file).lastSegment()); try { CorePlugin.getDefault() .getLibrariesService() .deployLibrary(Path.fromOSString(file).toFile().toURL()); } catch (Exception e) { ExceptionHandler.process(e); } if (!elem.getPropertyValue(propertyName).equals(lastSegment)) { // update the combo current value CCombo combo = (CCombo) hashCurControls.get(propertyName); if (combo != null && !combo.isDisposed()) { combo.setText(Path.fromOSString(file).lastSegment()); } return new PropertyChangeCommand(elem, propertyName, lastSegment); } } } return null; }