2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.propertysheet
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.jface
.text
.ITextViewer
;
17 import org
.eclipse
.jface
.text
.contentassist
.CompletionProposal
;
18 import org
.eclipse
.jface
.text
.contentassist
.ICompletionProposal
;
19 import org
.eclipse
.jface
.text
.contentassist
.IContentAssistProcessor
;
20 import org
.eclipse
.jface
.text
.contentassist
.IContextInformation
;
21 import org
.eclipse
.jface
.text
.contentassist
.IContextInformationValidator
;
23 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
30 public class CompletionProcessor
implements IContentAssistProcessor
{
31 private static final Logger logger
= Logger
32 .getLogger(CompletionProcessor
.class);
35 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
37 public ICompletionProposal
[] computeCompletionProposals(
38 ITextViewer viewer
, int documentOffset
) {
39 String context
= "Describe formatting / parsing of this rel. type.";
40 // Image img = ResourceManager.getPluginImage(Activator.getDefault(), "icons/unknown.gif");
41 // ICompletionProposal[] result =
42 // new ICompletionProposal[myProposals.length];
43 // for (int i = 0; i < myProposals.length; i++) {
44 // IContextInformation contextInfo =
45 // new ContextInformation(null, myProposals[i]+" Style");
46 // result[i] = new CompletionProposal(myProposals[i],documentOffset, 0,
47 // myProposals[i].length(), ResourceManager.getPluginImage(Activator.getDefault(), myIcons[i]),
48 // myProposals[i], contextInfo, context);
52 String searchText
= viewer
.getTextWidget().getText() + "%";
53 // List<TaxonNameBase> names = CdmUtil.getNameByName(searchText);
54 List
<TaxonNameBase
> names
= null;
55 logger
.warn(names
.size() + " names");
56 List
<ICompletionProposal
> proposals
= new ArrayList
<ICompletionProposal
>();
57 // String[] test = new String[] {"suggestion 1", "suggestion 2", "suggestion 3"};
58 for (TaxonNameBase name
: names
) {
59 String proposalText
= name
.getTitleCache();
60 // for (String proposalText : test) {
61 proposals
.add(new CompletionProposal(proposalText
,
64 proposalText
.length(),
71 logger
.warn(proposals
.size() + " proposals.");
72 return proposals
.toArray(new ICompletionProposal
[proposals
.size()]);
76 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
78 public IContextInformation
[] computeContextInformation(ITextViewer viewer
,
84 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
86 public char[] getCompletionProposalAutoActivationCharacters() {
87 return new char[] {'a','b','c','d','e','f','g','H'};
91 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
93 public char[] getContextInformationAutoActivationCharacters() {
98 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
100 public IContextInformationValidator
getContextInformationValidator() {
105 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
107 public String
getErrorMessage() {