use of org.talend.designer.rowgenerator.data.Function in project tdi-studio-se by Talend.
the class RowGeneratorComponent method convert.
/**
* Coverts <code>MetadataColumn</code> to <code>MetadataColumnExt</code>
*
* @param metadataTable
* @return
*/
private void convert(IMetadataTable metadataTable) {
List<IMetadataColumn> exts = new ArrayList<IMetadataColumn>();
for (int j = 0; j < metadataTable.getListColumns().size(); j++) {
IMetadataColumn column = metadataTable.getListColumns().get(j);
if (column instanceof MetadataColumn) {
MetadataColumnExt ext = new MetadataColumnExt((MetadataColumn) column);
String columnValue = this.getColumnValue(ext, j);
if (columnValue != null && columnValue.length() > 0) {
//$NON-NLS-1$ //$NON-NLS-2$
columnValue = columnValue.replaceAll("\"", "");
//$NON-NLS-1$
columnValue = columnValue.substring(columnValue.lastIndexOf(".") + 1);
Function function = new Function();
function.setName(columnValue);
ext.setFunction(function);
}
exts.add(ext);
}
}
metadataTable.setListColumns(exts);
}
use of org.talend.designer.rowgenerator.data.Function 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.designer.rowgenerator.data.Function in project tdi-studio-se by Talend.
the class MetadataColumnExtTest method testSetFunction.
@Test
public void testSetFunction() {
MetadataColumnExt column = new MetadataColumnExt();
Function func = new Function();
//$NON-NLS-1$
func.setName("testFunc");
column.setFunction(func);
assertNotNull(column.getAdditionalField().get(MetadataColumnExt.FUNCTION_INFO));
}
use of org.talend.designer.rowgenerator.data.Function in project tdi-studio-se by Talend.
the class CategoryComposite method getProposals.
/**
* yzhang Comment method "getProposals".
*
* @return
*/
public IContentProposal[] getProposals(String categoryFunction, int position) {
String category = null;
String function = null;
boolean displayFunction = false;
if (categoryFunction.indexOf(".") != -1) {
//$NON-NLS-1$
//$NON-NLS-1$
String[] cf = categoryFunction.split("\\.");
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < cf.length - 1; i++) {
buffer.append(cf[i]);
if (i != cf.length - 2) {
//$NON-NLS-1$
buffer.append(".");
}
}
if (cf.length == 1) {
category = cf[cf.length - 1];
} else {
function = cf[cf.length - 1];
category = buffer.toString();
}
displayFunction = true;
} else {
category = categoryFunction;
}
java.util.List<IContentProposal> proposals = new LinkedList<IContentProposal>();
java.util.List<Category> categories = manager.getInputCategory("java");
//$NON-NLS-1$
boolean addAllCategory = category.equals("*C") ? true : false;
if (!displayFunction) {
for (Category cg : categories) {
if (!cg.getName().startsWith("*") && (addAllCategory || cg.getName().startsWith(category))) {
//$NON-NLS-1$
//$NON-NLS-1$
proposals.add(new ExpressionContentProposal(cg.getName(), "", position));
}
}
java.util.List<Variable> vars = ExpressionBuilderDialog.getTestComposite().getVariableList();
for (Variable var : vars) {
if (addAllCategory || var.getName().startsWith(category)) {
proposals.add(new ExpressionContentProposal(var.getName(), var.getValue(), position));
}
}
} else {
for (Category cg : categories) {
if (cg.getName().equals(category)) {
java.util.List<Function> funs = cg.getFunctions();
boolean addAll = (function == null ? true : false);
for (Function fun : funs) {
if (addAll || fun.getName().startsWith(function)) {
proposals.add(new //$NON-NLS-1$
ExpressionContentProposal(//$NON-NLS-1$
fun.getName() + "()", //$NON-NLS-1$
fun.getDescription(), position));
}
}
}
}
}
Collections.sort(proposals, new CategoryFunctionCompartor());
String replaceString;
if (displayFunction) {
//$NON-NLS-1$
replaceString = function == null ? "" : function;
} else {
replaceString = category;
}
ExpressionBuilderDialog.getExpressionComposite().setReplacedText(replaceString);
return proposals.toArray(new IContentProposal[proposals.size()]);
}
use of org.talend.designer.rowgenerator.data.Function in project tdi-studio-se by Talend.
the class Category method toString.
public String toString() {
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
sb.append(Messages.getString("TalendType.TypeName", name)).append("\n").append(" ");
Function[] f = functionsToArray();
for (int i = 0; i < f.length; i++) {
Function function = f[i];
//$NON-NLS-1$ //$NON-NLS-2$
sb.append(function).append("\n").append(" ");
}
return sb.toString();
}
Aggregations