use of org.eclipse.jface.text.contentassist.ICompletionProposal in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonContentAssistProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
if (!(viewer.getDocument() instanceof JsonDocument)) {
return super.computeCompletionProposals(viewer, documentOffset);
}
maybeSwitchScope(documentOffset);
final JsonDocument document = (JsonDocument) viewer.getDocument();
final ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
int line = 0, lineOffset = 0, column = 0;
try {
line = document.getLineOfOffset(documentOffset);
lineOffset = document.getLineOffset(line);
column = selection.getOffset() - lineOffset;
} catch (BadLocationException e) {
}
final String prefix = extractPrefix(viewer, documentOffset);
// column to resolve the path
if (!prefix.isEmpty()) {
column -= prefix.length();
}
Model model = document.getModel(documentOffset - prefix.length());
currentPath = model.getPath(line, column);
isRefCompletion = referenceProposalProvider.canProvideProposal(currentPath);
Collection<Proposal> p;
if (isRefCompletion) {
updateStatus();
p = referenceProposalProvider.getProposals(currentPath, document, currentScope);
} else {
clearStatus();
p = proposalProvider.getProposals(currentPath, model, prefix);
}
final Collection<ICompletionProposal> proposals = getCompletionProposals(p, prefix, documentOffset);
// compute template proposals
if (!isRefCompletion) {
final ICompletionProposal[] templateProposals = super.computeCompletionProposals(viewer, documentOffset);
if (templateProposals != null && templateProposals.length > 0) {
proposals.addAll(Lists.newArrayList(templateProposals));
}
}
return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
use of org.eclipse.jface.text.contentassist.ICompletionProposal in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonContentAssistProcessor method getCompletionProposals.
protected Collection<ICompletionProposal> getCompletionProposals(Collection<Proposal> proposals, String prefix, int offset) {
final List<ICompletionProposal> result = new ArrayList<>();
prefix = Strings.emptyToNull(prefix);
for (Proposal proposal : proposals) {
StyledCompletionProposal styledProposal = proposal.asStyledCompletionProposal(prefix, offset);
if (styledProposal != null) {
result.add(styledProposal);
}
}
return result;
}
use of org.eclipse.jface.text.contentassist.ICompletionProposal 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.eclipse.jface.text.contentassist.ICompletionProposal in project tdi-studio-se by Talend.
the class SQLCompletionProcessor method getProposalsByNode.
/**
* DOC dev Comment method "getProposalsByNode".
*
* @param documentOffset
* @param node
* @return
*/
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private ICompletionProposal[] getProposalsByNode(int documentOffset, INode node) {
Object[] children = (Object[]) node.getChildNodes();
ArrayList propList = new ArrayList();
if (children != null) {
for (int i = 0; i < children.length; i++) {
String childName = children[i].toString().toLowerCase();
if (//$NON-NLS-1$
childName.equals("table") || childName.equals("view")) {
//$NON-NLS-1$
Object[] tables = (Object[]) ((INode) children[i]).getChildNodes();
if (tables != null) {
for (int j = 0; j < tables.length; j++) {
Image tmpImage = null;
String tableName = tables[j].toString();
if (tables[j] instanceof TableNode) {
if (((TableNode) tables[j]).isTable()) {
tmpImage = tableImage;
} else if (((TableNode) tables[j]).isView()) {
tmpImage = viewImage;
}
propList.add(new ExtendedCompletionProposal(tableName, documentOffset, 0, tableName.length(), tmpImage, tableName, (TableNode) tables[j]));
}
}
}
}
}
}
ICompletionProposal[] res = new ICompletionProposal[propList.size()];
System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
Arrays.sort(res, new ICompletionProposalComparator());
return res;
}
use of org.eclipse.jface.text.contentassist.ICompletionProposal in project tdi-studio-se by Talend.
the class SQLCompletionProcessor method inputNotContainDot.
/**
* DOC dev Comment method "inputNotContainDot".
*
* @param documentOffset
* @param string
* @param length
* @return
*/
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private ICompletionProposal[] inputNotContainDot(int documentOffset, String string, int length) {
// The string does not contain "."
String[] keywordProposal = Dictionary.matchKeywordsPrefix(string);
ICompletionProposal[] resKey = new ICompletionProposal[keywordProposal.length];
for (int i = 0; i < keywordProposal.length; i++) {
resKey[i] = new CompletionProposal(keywordProposal[i], documentOffset - length, length, keywordProposal[i].length(), keywordImage, keywordProposal[i], null, null);
}
String[] proposalsString = dictionary.matchTablePrefix(string.toLowerCase());
ArrayList propList = new ArrayList();
for (int i = 0; i < proposalsString.length; i++) {
ArrayList ls = dictionary.getTableObjectList(proposalsString[i]);
for (int j = 0; j < ls.size(); j++) {
TableNode tbNode = (TableNode) ls.get(j);
Image tmpImage = null;
if (tbNode.isView()) {
tmpImage = viewImage;
} else if (tbNode.isTable()) {
tmpImage = tableImage;
}
ICompletionProposal cmp = new ExtendedCompletionProposal(proposalsString[i], documentOffset - length, length, proposalsString[i].length(), tmpImage, proposalsString[i], tbNode);
propList.add(cmp);
}
}
String[] proposalsString2 = dictionary.matchCatalogSchemaPrefix(string.toLowerCase());
ICompletionProposal[] resKey2 = new ICompletionProposal[proposalsString2.length];
for (int i = 0; i < proposalsString2.length; i++) {
resKey2[i] = new CompletionProposal(proposalsString2[i], documentOffset - length, length, proposalsString2[i].length(), catalogImage, proposalsString2[i], null, null);
}
ICompletionProposal[] res = new ICompletionProposal[propList.size() + keywordProposal.length + resKey2.length];
System.arraycopy(resKey, 0, res, 0, resKey.length);
System.arraycopy(propList.toArray(), 0, res, resKey.length, propList.size());
System.arraycopy(resKey2, 0, res, resKey.length + propList.size(), resKey2.length);
Arrays.sort(res, new ICompletionProposalComparator());
return res;
}
Aggregations