Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 49ed7afdf0cad24d5fe52064b3d27a335f0a283c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package org.eclipse.wst.jsdt.web.ui.internal.contentassist;

import java.util.Arrays;
import java.util.Vector;

import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.wst.jsdt.web.core.internal.java.IJSPTranslation;
import org.eclipse.wst.jsdt.web.core.internal.java.JSPTranslation;
import org.eclipse.wst.jsdt.web.core.internal.java.JSPTranslationAdapter;
import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor;

public class JSDTContentAssistant extends AbstractContentAssistProcessor {
    
    private JSDTContentAssistantProcessor fContentAssistProcessor;
   
    private JSDTTemplateAssistProcessor   fTemplateAssistProcessor;
    
    private JSPTranslationAdapter fTranslationAdapter ;
   
    
    public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
            int documentPosition) {
        
        Vector proposals = new Vector();
        
        ICompletionProposal[] completionProposals;
        
        JSDTProposalCollector theCollector =  getProposalCollector(viewer, documentPosition);
        /* --------- Content Assistant --------- */
         getContentAssistProcessor().setProposalCollector(theCollector);
         completionProposals = getContentAssistProcessor().computeCompletionProposals(viewer, documentPosition);
         proposals.addAll(Arrays.asList(completionProposals));
         
         
        /* --------- template completions --------- */
        getTemplateCompletionProcessor().setProposalCollector(theCollector);
        completionProposals = getTemplateCompletionProcessor().computeCompletionProposals(viewer, documentPosition);
        proposals.addAll(Arrays.asList(completionProposals));
     

        return (ICompletionProposal[]) proposals
                .toArray(new ICompletionProposal[0]);
    }
    
    protected JSDTProposalCollector getProposalCollector(ITextViewer viewer, int offset) {
        JSPTranslation tran =  getJSPTranslation(viewer,offset);
        
        return  new JSDTProposalCollector( tran );
    }
    
    private JSPTranslation getJSPTranslation(ITextViewer viewer, int offset){
        
    
        IDOMModel xmlModel = null;
    
      
        
        try {
        	xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(viewer.getDocument());
        	IDOMDocument xmlDoc = xmlModel.getDocument();
            
            if (fTranslationAdapter == null) {
                fTranslationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
            }
            if (fTranslationAdapter != null) {
                
                return fTranslationAdapter.getJSPTranslation();
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally{
            if (xmlModel != null) {
                xmlModel.releaseFromRead();
            }
        }
        return null;
}
    
    private JSDTContentAssistantProcessor getContentAssistProcessor() {
        if (fContentAssistProcessor == null) {
            fContentAssistProcessor = new JSDTContentAssistantProcessor();
        }
        
        return fContentAssistProcessor;
    }
    
    private JSDTTemplateAssistProcessor getTemplateCompletionProcessor() {
        if (fTemplateAssistProcessor == null) {
            fTemplateAssistProcessor = new JSDTTemplateAssistProcessor();
        }
      
        return fTemplateAssistProcessor;
    }
    
}

Back to the top