use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class MultiSchemasManager method getOriginalValue.
/**
*
* cLi Comment method "getOriginalValue".
*
* check the context or not.
*/
public String getOriginalValue(String value) {
if (value != null) {
IProcess process = this.getMultiSchemasComponent().getProcess();
// TDI-21049:if not context mode,no need to deal with it use below code.
if (process != null && ContextParameterUtils.containContextVariables(value)) {
// add for bug9559
String newValue = null;
if (value.contains("+")) {
//$NON-NLS-1$
// not only use context variable .
//$NON-NLS-1$
String[] split = value.split("\\+");
for (int i = 0; i < split.length; i++) {
split[i] = split[i].trim();
if (split[i].startsWith(TalendTextUtils.getQuoteChar()) && split[i].endsWith(TalendTextUtils.getQuoteChar()) && split[i].length() - 1 > 0) {
split[i] = split[i].substring(1, split[i].length() - 1);
}
String varName = ContextParameterUtils.getVariableFromCode(split[i]);
if (varName != null) {
IContextParameter contextParameter = process.getContextManager().getDefaultContext().getContextParameter(varName);
if (contextParameter != null) {
String value2 = contextParameter.getValue();
if (value2 != null) {
split[i] = value2;
}
}
}
if (newValue == null) {
newValue = split[i];
} else {
newValue = newValue + split[i];
}
}
if (newValue.startsWith(TalendTextUtils.getQuoteChar()) && newValue.endsWith(TalendTextUtils.getQuoteChar())) {
return newValue;
} else {
return TalendTextUtils.addQuotes(newValue);
}
} else {
// only use context variable.
String varName = ContextParameterUtils.getVariableFromCode(value);
if (varName != null) {
IContextParameter contextParameter = process.getContextManager().getDefaultContext().getContextParameter(varName);
if (contextParameter != null) {
String value2 = contextParameter.getValue();
if (value2 != null) {
if (value2.startsWith(TalendTextUtils.getQuoteChar()) && value2.endsWith(TalendTextUtils.getQuoteChar())) {
return value2;
} else {
// no quote
return TalendTextUtils.addQuotes(value2);
}
}
}
}
}
}
}
return value;
}
use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class TalendCompletionProposalComputer method computeCompletionProposals.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#computeCompletionProposals(org.eclipse.jdt.ui.text
* .java.ContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
*/
public List computeCompletionProposals(ITextViewer textViewer, String prefix, int offset, IProgressMonitor monitor) {
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
IProcess process = service.getCurrentProcess();
if (process == null) {
return Collections.EMPTY_LIST;
}
// Compute the length of replacement for proposal. See bug 0004266: Replace value with context value using
// CTRL+Space.
int replacementLength = textViewer.getSelectedRange().y;
if (replacementLength == 0) {
replacementLength = prefix.length();
}
// Proposals based on process context
List<IContextParameter> ctxParams = process.getContextManager().getDefaultContext().getContextParameterList();
for (IContextParameter ctxParam : ctxParams) {
String display = CONTEXT_PREFIX + ctxParam.getName();
String code = getContextContent(ctxParam);
String description = getContextDescription(ctxParam, display);
String ctxName = ctxParam.getName();
if (prefix.equals("") || display.startsWith(prefix)) {
//$NON-NLS-1$
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.CONTEXT_ICON), display, null, description);
proposal.setType(TalendCompletionProposal.CONTEXT);
proposals.add(proposal);
} else if (prefix.equals("") || ctxName.startsWith(prefix)) {
//$NON-NLS-1$
if (code.startsWith(CONTEXT_PREFIX)) {
code = code.replaceFirst(CONTEXT_PREFIX, "");
}
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.CONTEXT_ICON), display, null, description);
proposal.setType(TalendCompletionProposal.CONTEXT);
proposals.add(proposal);
}
}
// Proposals based on global variables
List<? extends INode> nodes = process.getGraphicalNodes();
for (INode node : nodes) {
List<? extends INodeReturn> nodeReturns = node.getReturns();
for (INodeReturn nodeReturn : nodeReturns) {
//$NON-NLS-1$
String display = node.getLabel() + "." + nodeReturn.getName();
if (prefix.equals("") || display.startsWith(prefix)) {
//$NON-NLS-1$
String code = getNodeReturnContent(nodeReturn, node);
String description = getNodeReturnDescription(nodeReturn, node, display);
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), CoreImageProvider.getComponentIcon(node.getComponent(), ICON_SIZE.ICON_16), display, null, description);
proposal.setType(TalendCompletionProposal.NODE_RETURN);
proposals.add(proposal);
}
}
}
// Proposals based on global variables(only perl ).
// add proposals on global variables in java (bugtracker 2554)
// add variables in java
IContentProposal[] javavars = JavaGlobalUtils.getProposals();
for (IContentProposal javavar : javavars) {
String display = javavar.getLabel();
if (prefix.equals("") || display.startsWith(prefix)) {
//$NON-NLS-1$
String code = javavar.getContent();
String description = getGlobalVarDescription(javavar, display);
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.PROCESS_ICON), display, null, description);
proposal.setType(TalendCompletionProposal.VARIABLE);
proposals.add(proposal);
}
}
FunctionManager functionManager = new FunctionManager();
List<TalendType> talendTypes = functionManager.getTalendTypes();
for (TalendType type : talendTypes) {
for (Object objectFunction : type.getFunctions()) {
Function function = (Function) objectFunction;
//$NON-NLS-1$
String display = function.getCategory() + "." + function.getName();
if (prefix.equals("") || display.startsWith(prefix)) {
//$NON-NLS-1$
String code = FunctionManager.getFunctionMethod(function);
String description = getFunctionDescription(function, display, code);
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.ROUTINE_ICON), display, null, description);
proposal.setType(TalendCompletionProposal.ROUTINE);
proposals.add(proposal);
}
}
}
for (IExternalProposals externalProposals : ProposalFactory.getInstances()) {
proposals.addAll(externalProposals.getAdvancedProposals(offset, prefix));
}
return proposals;
}
use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class TalendJavaSourceViewer method createViewerWithVariables.
public static ReconcilerViewer createViewerWithVariables(Composite composite, int styles, IExpressionDataBean dataBean) {
IDocument document = new Document();
StringBuffer buff = new StringBuffer();
//$NON-NLS-1$
buff.append("\npackage internal;\n\n");
buff.append(getImports());
//$NON-NLS-1$ //$NON-NLS-2$
buff.append("public class " + VIEWER_CLASS_NAME + currentId + " {\n");
IRunProcessService runProcessService = getRunProcessService();
if (runProcessService != null && runProcessService.getSelectedContext() != null) {
List<IContextParameter> params = runProcessService.getSelectedContext().getContextParameterList();
buff.append(TEXT_1);
for (IContextParameter ctxParam : params) {
buff.append(TEXT_2);
buff.append(ctxParam.getName());
buff.append(TEXT_3);
buff.append(ctxParam.getName());
buff.append(TEXT_4);
}
buff.append(TEXT_5);
for (IContextParameter ctxParam : params) {
if (//$NON-NLS-1$ //$NON-NLS-2$
ctxParam.getType().equals("id_List Of Value") || ctxParam.getType().equals("id_File") || ctxParam.getType().equals("id_Directory") || ctxParam.getType().equals("id_Character")) {
//$NON-NLS-1$ //$NON-NLS-2$
buff.append(TEXT_6);
buff.append(ctxParam.getName());
buff.append(TEXT_7);
} else {
buff.append(TEXT_8);
buff.append(JavaTypesManager.getTypeToGenerate(ctxParam.getType(), true));
buff.append(TEXT_9);
buff.append(ctxParam.getName());
buff.append(TEXT_10);
}
}
buff.append(TEXT_11);
//$NON-NLS-1$
buff.append("\tprivate static ContextProperties context = new ContextProperties();\n");
//$NON-NLS-1$
buff.append("\tprivate static final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();\n");
if (dataBean != null) {
buff.append(parseVariables(dataBean.getVariables()));
//$NON-NLS-1$ //$NON-NLS-2$
buff.append("\tpublic " + dataBean.getExpressionType() + " myFunction(){\n");
}
//$NON-NLS-1$
buff.append("\t\treturn \n");
}
int length = buff.toString().length();
//$NON-NLS-1$
String defaultValue = "";
//$NON-NLS-1$
buff.append(defaultValue + "\n;\t\n}\n}");
document.set(buff.toString());
return initializeViewer(composite, styles, true, document, length);
}
use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class ProcessContextComposite method checkIsSameContextParameter.
/*
* check same ContextParameter or not.
*/
private boolean checkIsSameContextParameter() {
List<ContextItem> allContextItem = ContextUtils.getAllContextItem();
for (IContext context : process.getContextManager().getListContext()) {
for (IContextParameter param : context.getContextParameterList()) {
if (allContextItem != null) {
ContextItem contextItem = ContextUtils.getContextItemById(allContextItem, param.getSource());
ContextType contextType = ContextUtils.getContextTypeByName(contextItem, context.getName(), true);
ContextParameterType contextParameterType = ContextUtils.getContextParameterTypeByName(contextType, param.getName());
if (!ContextUtils.samePropertiesForContextParameter(param, contextParameterType)) {
return false;
}
// if don't open the job to run it(not use the "Detect and update all jobs"), will show
// UpdateDetectionDialog to update the context ,after updated the item, the contextComboViewer still
// set the old one , so need refresh.
IContext runJobViewContext = getSelectedContext();
if (runJobViewContext != null) {
for (IContextParameter tempContext : runJobViewContext.getContextParameterList()) {
if (tempContext.getName().equals(contextParameterType.getName()) && !ContextUtils.samePropertiesForContextParameter(tempContext, contextParameterType)) {
return false;
}
}
}
}
}
}
return true;
}
use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class ProcessContextComposite method promptConfirmLauch.
public static boolean promptConfirmLauch(Shell shell, IContext context, IProcess process) {
boolean continueLaunch = true;
int nbValues = 0;
if (context == null) {
//$NON-NLS-1$
throw new IllegalArgumentException("Context is null");
}
// Prompt for context values ?
for (IContextParameter parameter : context.getContextParameterList()) {
if (parameter.isPromptNeeded()) {
nbValues++;
}
}
if (nbValues > 0) {
IContext contextCopy = context.clone();
PromptDialog promptDialog = new PromptDialog(shell, contextCopy);
if (promptDialog.open() == PromptDialog.OK) {
for (IContextParameter param : context.getContextParameterList()) {
boolean found = false;
IContextParameter paramCopy = null;
for (int i = 0; i < contextCopy.getContextParameterList().size() & !found; i++) {
paramCopy = contextCopy.getContextParameterList().get(i);
if (param.getName().equals(paramCopy.getName())) {
// param.setValueList(paramCopy.getValueList());
param.setInternalValue(paramCopy.getValue());
found = true;
}
}
}
contextComboViewer.refresh();
contextTableViewer.refresh();
processNeedGenCode(process);
} else {
continueLaunch = false;
}
} else {
if (context.isConfirmationNeeded()) {
continueLaunch = //$NON-NLS-1$
MessageDialog.openQuestion(//$NON-NLS-1$
shell, //$NON-NLS-1$
Messages.getString("ProcessComposite.confirmTitle"), //$NON-NLS-1$
Messages.getString("ProcessComposite.confirmText", context.getName()));
}
updateDefaultValueForListTypeParameter(context.getContextParameterList());
}
return continueLaunch;
}
Aggregations