use of org.eclipse.jface.text.contentassist.ICompletionProposal in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonQuickAssistProcessor method computeQuickAssistProposals.
@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
List<IMarker> markers;
try {
markers = getMarkersFor(invocationContext.getSourceViewer(), invocationContext.getOffset());
} catch (BadLocationException e) {
errorMessage = e.getMessage();
return new ICompletionProposal[0];
}
List<ICompletionProposal> result = Lists.newArrayList();
for (IMarker marker : markers) {
for (IMarkerResolution markerResolution : quickFixer.getResolutions(marker)) {
result.add(new MarkerResolutionProposal(marker, markerResolution, invocationContext.getSourceViewer()));
}
}
return result.toArray(new ICompletionProposal[0]);
}
use of org.eclipse.jface.text.contentassist.ICompletionProposal in project tdi-studio-se by Talend.
the class TalendJavaCompletionProcessor method sortProposals.
/*
* (non-Javadoc)
*
* @see org.eclipse.jdt.internal.ui.text.java.JavaCompletionProcessor#filterAndSortProposals(java.util.List,
* org.eclipse.core.runtime.IProgressMonitor, org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext)
*/
@Override
protected List<ICompletionProposal> sortProposals(List<ICompletionProposal> proposals, IProgressMonitor monitor, ContentAssistInvocationContext context) {
proposals = super.sortProposals(proposals, monitor, context);
Map<String, ICompletionProposal> completionProposalMap = new HashMap<String, ICompletionProposal>();
boolean globalFieldsDone = false;
for (Object o : proposals) {
ICompletionProposal proposal = (ICompletionProposal) o;
String longna = proposal.getDisplayString();
//$NON-NLS-1$
int indexna = longna.indexOf("-");
boolean shouldRemove = false;
if (indexna > 0) {
if (longna.substring(indexna + 2, longna.length()).equals(TalendJavaSourceViewer.getClassName())) {
shouldRemove = true;
}
}
if (proposal instanceof JavaCompletionProposal) {
JavaCompletionProposal javaProposal = ((JavaCompletionProposal) proposal);
if (javaProposal.getJavaElement() instanceof SourceField) {
globalFieldsDone = true;
}
if (javaProposal.getJavaElement() == null && globalFieldsDone) {
shouldRemove = true;
}
}
if (proposal.getDisplayString().startsWith(TalendJavaSourceViewer.VIEWER_CLASS_NAME)) {
shouldRemove = true;
}
if (!shouldRemove) {
completionProposalMap.put(longna, proposal);
}
}
List<ICompletionProposal> newProposals = new ArrayList<ICompletionProposal>(completionProposalMap.values());
Collections.sort(newProposals, new Comparator<ICompletionProposal>() {
@Override
public int compare(ICompletionProposal arg0, ICompletionProposal arg1) {
if (arg1 instanceof TalendCompletionProposal && (!(arg0 instanceof TalendCompletionProposal))) {
return 1;
} else if (arg0 instanceof TalendCompletionProposal && (!(arg1 instanceof TalendCompletionProposal))) {
return -1;
} else if (arg1 instanceof TalendCompletionProposal && (arg0 instanceof TalendCompletionProposal)) {
TalendCompletionProposal a = (TalendCompletionProposal) arg0;
TalendCompletionProposal b = (TalendCompletionProposal) arg1;
return a.getType().compareTo(b.getType());
}
return 0;
}
});
return newProposals;
}
use of org.eclipse.jface.text.contentassist.ICompletionProposal in project tdi-studio-se by Talend.
the class TalendJavaSourceViewer method createViewerForComponent.
public static ISourceViewer createViewerForComponent(Composite composite, int styles, CompilationUnitEditor editor, List<Variable> variableList, String uniqueName, String codePart) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String selectedPart = "[" + uniqueName + " " + codePart + " ] start";
IDocument originalDocument = editor.getDocumentProvider().getDocument(editor.getEditorInput());
int documentOffset = -1;
//$NON-NLS-1$
String globalFields = "";
//$NON-NLS-1$
String localFields = "";
//$NON-NLS-1$
globalFields = "\tprivate static java.util.Properties context = new java.util.Properties();\n";
//$NON-NLS-1$
globalFields += "\tprivate static final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();\n";
IDocument newDoc = new Document();
boolean checkCode = false;
FindReplaceDocumentAdapter frda = null;
// hywang modified for bug 9180
String documentText = originalDocument.get();
if (documentText != null && !documentText.equals("") && documentText.length() > 0) {
//$NON-NLS-1$
frda = new FindReplaceDocumentAdapter(originalDocument);
}
try {
Region region = null;
if (frda != null) {
region = (Region) frda.find(0, selectedPart, true, false, false, false);
}
if (region != null) {
checkCode = true;
documentOffset = region.getOffset();
documentOffset = originalDocument.getLineOffset(originalDocument.getLineOfOffset(documentOffset) + 2);
JavaCompletionProcessor processor = new JavaCompletionProcessor(editor, new ContentAssistant(), IDocument.DEFAULT_CONTENT_TYPE);
boolean globalFieldsDone = false;
//$NON-NLS-1$
globalFields = "";
String className = editor.getPartName().substring(0, editor.getPartName().indexOf('.') + 1);
ICompletionProposal[] proposals = processor.computeCompletionProposals(editor.getViewer(), documentOffset);
for (ICompletionProposal curProposal : proposals) {
if (curProposal instanceof JavaCompletionProposal) {
JavaCompletionProposal javaProposal = ((JavaCompletionProposal) curProposal);
if (javaProposal.getJavaElement() instanceof SourceField) {
globalFieldsDone = true;
SourceField sourceField = (SourceField) javaProposal.getJavaElement();
//$NON-NLS-1$ //$NON-NLS-2$
globalFields += "\t" + sourceField.getSource() + "\n";
// System.out.println();
}
if (javaProposal.getJavaElement() == null && !globalFieldsDone) {
//$NON-NLS-1$
String[] str = javaProposal.getSortString().split(" ");
//$NON-NLS-1$
String variable = "";
for (int i = str.length - 1; i >= 0; i--) {
//$NON-NLS-1$
variable += str[i].length() == 0 ? " " : str[i];
}
if (variable.contains(className)) {
continue;
}
//$NON-NLS-1$
variable += ";";
//$NON-NLS-1$ //$NON-NLS-2$
localFields += "\t\t" + variable + "\n";
// System.out.println(variable);
}
}
}
}
} catch (BadLocationException e) {
ExceptionHandler.process(e);
} catch (JavaModelException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
StringBuffer buff = new StringBuffer();
//$NON-NLS-1$
buff.append("package internal;\n\n");
buff.append(getImports());
//$NON-NLS-1$ //$NON-NLS-2$
buff.append("public class " + VIEWER_CLASS_NAME + currentId + " {\n");
buff.append(globalFields);
//$NON-NLS-1$
buff.append("\tpublic void myFunction(){\n");
buff.append(localFields);
documentOffset = buff.toString().length();
//$NON-NLS-1$
buff.append("\n\t\n}\n}");
newDoc.set(buff.toString());
return initializeViewer(composite, styles, checkCode, newDoc, documentOffset);
}
use of org.eclipse.jface.text.contentassist.ICompletionProposal in project tdi-studio-se by Talend.
the class SQLCompletionProcessor method compare.
public int compare(Object o1, Object o2) {
ICompletionProposal i1 = (ICompletionProposal) o1;
ICompletionProposal i2 = (ICompletionProposal) o2;
String s1 = i1.getDisplayString();
String s2 = i2.getDisplayString();
return Collator.getInstance().compare(s1, s2);
}
use of org.eclipse.jface.text.contentassist.ICompletionProposal in project sling by apache.
the class ProposalComputer method addAttributeProposal.
private void addAttributeProposal(final ContentAssistRequest contentAssistRequest, ProposalDescription proposalDescription) {
String replacementString = proposalDescription.getInsertionText();
int replacementOffset = contentAssistRequest.getReplacementBeginPosition();
int replacementLength = contentAssistRequest.getReplacementLength();
int cursorPosition = getCursorPositionForProposedText(replacementString);
ICompletionProposal proposal = new MarkupCompletionProposal(replacementString.toString(), replacementOffset, replacementLength, cursorPosition, SharedImages.SIGHTLY_ICON.createImage(), proposalDescription.getLabel(), null, proposalDescription.getAdditionalInfo(), XMLRelevanceConstants.R_TAG_NAME);
contentAssistRequest.addProposal(proposal);
}
Aggregations