|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.testfw.stf.configeditor.editors; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.List; |
|
23 |
|
24 import org.eclipse.jface.text.ITextViewer; |
|
25 import org.eclipse.jface.text.contentassist.CompletionProposal; |
|
26 import org.eclipse.jface.text.contentassist.ICompletionProposal; |
|
27 import org.eclipse.jface.text.contentassist.IContentAssistProcessor; |
|
28 import org.eclipse.jface.text.contentassist.IContextInformation; |
|
29 import org.eclipse.jface.text.contentassist.IContextInformationValidator; |
|
30 |
|
31 import com.nokia.testfw.stf.configmanager.ConfigUtil; |
|
32 import com.nokia.testfw.stf.configmanager.SectionElementType; |
|
33 |
|
34 /** |
|
35 * Config source editor content assistant |
|
36 * |
|
37 */ |
|
38 public class ConfigSourceEditorContentAssistProcessor implements IContentAssistProcessor { |
|
39 /** |
|
40 * List of STIF config keywords |
|
41 */ |
|
42 private List<String> keywords = null; |
|
43 |
|
44 /** |
|
45 * Creates content assistant |
|
46 */ |
|
47 public ConfigSourceEditorContentAssistProcessor() { |
|
48 keywords = new ArrayList<String>(); |
|
49 |
|
50 SectionElementType[] engineDefaultsElements = ConfigUtil.getAllowedEngineDefaultsSectionElements(); |
|
51 for ( int i = 0; i < engineDefaultsElements.length; i++) { |
|
52 keywords.add( ConfigUtil.getEngineDefaultsSectionElementTag(engineDefaultsElements[ i ]) ); |
|
53 } |
|
54 |
|
55 SectionElementType[] loggerDefaultsElements = ConfigUtil.getAllowedLoggerDefaultsSectionElements(); |
|
56 for ( int i = 0; i < loggerDefaultsElements.length; i++) { |
|
57 keywords.add( ConfigUtil.getLoggerDefaultsSectionElementTag(loggerDefaultsElements[ i ]) ); |
|
58 } |
|
59 |
|
60 SectionElementType[] moduleElements = ConfigUtil.getAllowedModuleSectionElements(); |
|
61 for ( int i = 0; i < moduleElements.length; i++) { |
|
62 keywords.add( ConfigUtil.getModuleSectionElementTag(moduleElements[ i ]) ); |
|
63 } |
|
64 } |
|
65 |
|
66 /* (non-Javadoc) |
|
67 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int) |
|
68 */ |
|
69 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, |
|
70 int offset) { |
|
71 |
|
72 String source = viewer.getDocument().get(); |
|
73 int startOffset = offset; |
|
74 for ( int i = offset - 1; i >= 0; i-- ) { |
|
75 if ( Character.isWhitespace(source.charAt( i )) ) { |
|
76 break; |
|
77 } |
|
78 startOffset = i; |
|
79 } |
|
80 |
|
81 List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); |
|
82 String token = source.substring( startOffset, offset ); |
|
83 for ( int i = 0; i < keywords.size(); i++ ) { |
|
84 String keyword = keywords.get( i ); |
|
85 if ( keyword.startsWith( token ) ) { |
|
86 CompletionProposal proposal = new CompletionProposal( |
|
87 keyword,startOffset, offset - startOffset, keyword.length() ); |
|
88 proposals.add( proposal ); |
|
89 } |
|
90 } |
|
91 |
|
92 return proposals.toArray(new ICompletionProposal[0]); |
|
93 } |
|
94 |
|
95 /* (non-Javadoc) |
|
96 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int) |
|
97 */ |
|
98 public IContextInformation[] computeContextInformation(ITextViewer viewer, |
|
99 int offset) { |
|
100 return null; |
|
101 } |
|
102 |
|
103 /* (non-Javadoc) |
|
104 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() |
|
105 */ |
|
106 public char[] getCompletionProposalAutoActivationCharacters() { |
|
107 return null; |
|
108 } |
|
109 |
|
110 /* (non-Javadoc) |
|
111 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters() |
|
112 */ |
|
113 public char[] getContextInformationAutoActivationCharacters() { |
|
114 return null; |
|
115 } |
|
116 |
|
117 /* (non-Javadoc) |
|
118 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator() |
|
119 */ |
|
120 public IContextInformationValidator getContextInformationValidator() { |
|
121 return null; |
|
122 } |
|
123 |
|
124 /* (non-Javadoc) |
|
125 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage() |
|
126 */ |
|
127 public String getErrorMessage() { |
|
128 return null; |
|
129 } |
|
130 |
|
131 } |