Skip to main content
summaryrefslogtreecommitdiffstats
blob: a32dd8e249c9953310aeab325c563930c1580277 (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
101
102
103
/*******************************************************************************
 * Copyright (c) 2006 Oracle Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Cameron Bateman/Oracle - initial API and implementation
 *    
 ********************************************************************************/

package org.eclipse.jst.jsf.context.symbol.internal.provisional.provider;

import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jst.jsf.context.symbol.internal.provisional.provider.IContentProposalProvider.IProposalCreationFactory;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;

/**
 * Default implementation of the proposal creation factory
 * 
 * @author cbateman
 *
 */
public class ProposalCreationFactoryAdapter implements IProposalCreationFactory 
{
    /**
     * The absolute document offset where the replacement is to occur
     */
    protected final int       _replacementOffset;
    /**
     * The number of characters to replace starting from _replaceOffset with
     * the proposal.  0 indicates insertion with no replacement
     */
    protected final int       _replacementLength;
    
    /**
     * @param replacementOffset -- the absolute document offset to do the replacement
     * @param replacementLength  -- the number of characters to replace or 0
     * for insert without any replacement
     */
    public ProposalCreationFactoryAdapter(final int replacementOffset,
                                          final int replacementLength)
    {
        _replacementOffset = replacementOffset;
        _replacementLength = replacementLength;
    }

    public ICompletionProposal createProposal(String replacementText, 
                String displayText, String additionalText, Image displayImage,
                Object targetObject) 
                
    {
        return createDefaultProposal(replacementText, 
                _replacementOffset, 
                _replacementLength, 
                replacementText.length(), 
                displayImage, 
                displayText, 
                null, 
                additionalText,
                1);
    }
    
    /**
     * Simple factory method for creating a default proposal
     * 
     * @param replacementText
     * @param replacementOffset
     * @param replacementLength
     * @param cursorPosition
     * @param displayImage
     * @param displayText
     * @param contextInfo
     * @param additionalText
     * @param relevance
     * @return a default configuration of the completion proposal based on 
     * the CustomCompletionProposal
     */
    protected static ICompletionProposal 
                    createDefaultProposal(final String replacementText,
                                          final int replacementOffset,
                                          final int replacementLength,
                                          final int cursorPosition,
                                          final Image displayImage,
                                          final String displayText,
                                          final IContextInformation contextInfo,
                                          final String additionalText,
                                          final int relevance)
    {
        return new CustomCompletionProposal(replacementText, 
                replacementOffset, 
                replacementLength, 
                cursorPosition, 
                displayImage, 
                displayText, 
                contextInfo, 
                additionalText,
                relevance);
    }
}

Back to the top