6f8353e66a892de2675e6a6833487b4212f975d6
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / propertysheet / CompletionProcessor.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.propertysheet;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
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;
22
23 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
24
25 /**
26 * @author p.ciardelli
27 * @created 19.05.2008
28 * @version 1.0
29 */
30 public class CompletionProcessor implements IContentAssistProcessor {
31 private static final Logger logger = Logger
32 .getLogger(CompletionProcessor.class);
33
34 /* (non-Javadoc)
35 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
36 */
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);
49 //
50 // }
51 // return result;
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,
62 0,
63 searchText.length(),
64 proposalText.length(),
65 null,
66 proposalText,
67 null,
68 null
69 ));
70 }
71 logger.warn(proposals.size() + " proposals.");
72 return proposals.toArray(new ICompletionProposal[proposals.size()]);
73 }
74
75 /* (non-Javadoc)
76 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
77 */
78 public IContextInformation[] computeContextInformation(ITextViewer viewer,
79 int offset) {
80 return null;
81 }
82
83 /* (non-Javadoc)
84 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
85 */
86 public char[] getCompletionProposalAutoActivationCharacters() {
87 return new char[] {'a','b','c','d','e','f','g','H'};
88 }
89
90 /* (non-Javadoc)
91 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
92 */
93 public char[] getContextInformationAutoActivationCharacters() {
94 return null;
95 }
96
97 /* (non-Javadoc)
98 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
99 */
100 public IContextInformationValidator getContextInformationValidator() {
101 return null;
102 }
103
104 /* (non-Javadoc)
105 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
106 */
107 public String getErrorMessage() {
108 return null;
109 }
110 }