editor now updatable via updateSite
[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 * FIXME This looks very incomplete
27 *
28 * @author p.ciardelli
29 * @created 19.05.2008
30 * @version 1.0
31 */
32 public class CompletionProcessor implements IContentAssistProcessor {
33 private static final Logger logger = Logger
34 .getLogger(CompletionProcessor.class);
35
36 /* (non-Javadoc)
37 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
38 */
39 public ICompletionProposal[] computeCompletionProposals(
40 ITextViewer viewer, int documentOffset) {
41 String context = "Describe formatting / parsing of this rel. type.";
42 // Image img = ResourceManager.getPluginImage(Activator.getDefault(), "icons/unknown.gif");
43 // ICompletionProposal[] result =
44 // new ICompletionProposal[myProposals.length];
45 // for (int i = 0; i < myProposals.length; i++) {
46 // IContextInformation contextInfo =
47 // new ContextInformation(null, myProposals[i]+" Style");
48 // result[i] = new CompletionProposal(myProposals[i],documentOffset, 0,
49 // myProposals[i].length(), ResourceManager.getPluginImage(Activator.getDefault(), myIcons[i]),
50 // myProposals[i], contextInfo, context);
51 //
52 // }
53 // return result;
54 String searchText = viewer.getTextWidget().getText() + "%";
55 // List<TaxonNameBase> names = CdmUtil.getNameByName(searchText);
56 List<TaxonNameBase> names = null;
57 logger.warn(names.size() + " names");
58 List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
59 // String[] test = new String[] {"suggestion 1", "suggestion 2", "suggestion 3"};
60 for (TaxonNameBase name : names) {
61 String proposalText = name.getTitleCache();
62 // for (String proposalText : test) {
63 proposals.add(new CompletionProposal(proposalText,
64 0,
65 searchText.length(),
66 proposalText.length(),
67 null,
68 proposalText,
69 null,
70 null
71 ));
72 }
73 logger.warn(proposals.size() + " proposals.");
74 return proposals.toArray(new ICompletionProposal[proposals.size()]);
75 }
76
77 /* (non-Javadoc)
78 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
79 */
80 public IContextInformation[] computeContextInformation(ITextViewer viewer,
81 int offset) {
82 return null;
83 }
84
85 /* (non-Javadoc)
86 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
87 */
88 public char[] getCompletionProposalAutoActivationCharacters() {
89 return new char[] {'a','b','c','d','e','f','g','H'};
90 }
91
92 /* (non-Javadoc)
93 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
94 */
95 public char[] getContextInformationAutoActivationCharacters() {
96 return null;
97 }
98
99 /* (non-Javadoc)
100 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
101 */
102 public IContextInformationValidator getContextInformationValidator() {
103 return null;
104 }
105
106 /* (non-Javadoc)
107 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
108 */
109 public String getErrorMessage() {
110 return null;
111 }
112 }