1 | /* |
---|
2 | * generated by Xtext |
---|
3 | */ |
---|
4 | package com.framsticks.framclipse.ui.contentassist; |
---|
5 | |
---|
6 | import org.eclipse.jface.text.contentassist.ICompletionProposal; |
---|
7 | import org.eclipse.jface.viewers.StyledString; |
---|
8 | import org.eclipse.swt.graphics.Image; |
---|
9 | import org.eclipse.xtext.resource.IEObjectDescription; |
---|
10 | import org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal; |
---|
11 | import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext; |
---|
12 | |
---|
13 | import com.framsticks.framclipse.framScript.Proposable; |
---|
14 | import com.google.common.base.Function; |
---|
15 | import com.google.inject.Inject; |
---|
16 | |
---|
17 | /** |
---|
18 | * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#contentAssist on how to customize content |
---|
19 | * assistant |
---|
20 | */ |
---|
21 | public class FramScriptProposalProvider extends AbstractFramScriptProposalProvider { |
---|
22 | |
---|
23 | @Inject |
---|
24 | private DescriptorProvider descripter; |
---|
25 | |
---|
26 | @Override |
---|
27 | protected Function<IEObjectDescription, ICompletionProposal> getProposalFactory(String ruleName, |
---|
28 | ContentAssistContext contentAssistContext) { |
---|
29 | return new FramScriptProposalCreator(contentAssistContext, ruleName); |
---|
30 | } |
---|
31 | |
---|
32 | protected class FramScriptProposalCreator extends DefaultProposalCreator { |
---|
33 | |
---|
34 | private final ContentAssistContext cac; |
---|
35 | |
---|
36 | protected FramScriptProposalCreator(ContentAssistContext contentAssistContext, String ruleName) { |
---|
37 | super(contentAssistContext, ruleName); |
---|
38 | this.cac = contentAssistContext; |
---|
39 | } |
---|
40 | |
---|
41 | public ICompletionProposal apply(IEObjectDescription candidate) { |
---|
42 | if (candidate != null && candidate.getEObjectOrProxy() instanceof Proposable) { |
---|
43 | return createCompletionProposal((Proposable) candidate.getEObjectOrProxy(), cac); |
---|
44 | } else { |
---|
45 | return super.apply(candidate); |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | } |
---|
50 | |
---|
51 | public ICompletionProposal createCompletionProposal(Proposable proposable, |
---|
52 | ContentAssistContext contentAssistContext) { |
---|
53 | String proposal = proposable.proposal(); |
---|
54 | StyledString display = descripter.display(proposable.display()); |
---|
55 | String description = descripter.description(proposable.description()); |
---|
56 | Image image = getLabelProvider().getImage(proposable); |
---|
57 | |
---|
58 | ConfigurableCompletionProposal p = (ConfigurableCompletionProposal) createCompletionProposal( |
---|
59 | proposal, display, image, contentAssistContext); |
---|
60 | if (p != null) { |
---|
61 | p.setAutoInsertable(true); |
---|
62 | p.setAdditionalProposalInfo(description); |
---|
63 | getPriorityHelper().adjustCrossReferencePriority(p, contentAssistContext.getPrefix()); |
---|
64 | } |
---|
65 | return p; |
---|
66 | } |
---|
67 | } |
---|