Rough version of images module that doesn't actually save image URLs i.e. Taxon has...
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / 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 import eu.etaxonomy.taxeditor.model.CdmUtil;
25
26 /**
27 * @author p.ciardelli
28 * @created 19.05.2008
29 * @version 1.0
30 */
31 public class CompletionProcessor implements IContentAssistProcessor {
32 private static final Logger logger = Logger
33 .getLogger(CompletionProcessor.class);
34
35 /* (non-Javadoc)
36 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
37 */
38 public ICompletionProposal[] computeCompletionProposals(
39 ITextViewer viewer, int documentOffset) {
40 String context = "Describe formatting / parsing of this rel. type.";
41 // Image img = ResourceManager.getPluginImage(Activator.getDefault(), "icons/unknown.gif");
42 // ICompletionProposal[] result =
43 // new ICompletionProposal[myProposals.length];
44 // for (int i = 0; i < myProposals.length; i++) {
45 // IContextInformation contextInfo =
46 // new ContextInformation(null, myProposals[i]+" Style");
47 // result[i] = new CompletionProposal(myProposals[i],documentOffset, 0,
48 // myProposals[i].length(), ResourceManager.getPluginImage(Activator.getDefault(), myIcons[i]),
49 // myProposals[i], contextInfo, context);
50 //
51 // }
52 // return result;
53 String searchText = viewer.getTextWidget().getText() + "%";
54 // List<TaxonNameBase> names = CdmUtil.getNameByName(searchText);
55 List<TaxonNameBase> names = null;
56 logger.warn(names.size() + " names");
57 List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
58 // String[] test = new String[] {"suggestion 1", "suggestion 2", "suggestion 3"};
59 for (TaxonNameBase name : names) {
60 String proposalText = name.getTitleCache();
61 // for (String proposalText : test) {
62 proposals.add(new CompletionProposal(proposalText,
63 0,
64 searchText.length(),
65 proposalText.length(),
66 null,
67 proposalText,
68 null,
69 null
70 ));
71 }
72 logger.warn(proposals.size() + " proposals.");
73 return proposals.toArray(new ICompletionProposal[proposals.size()]);
74 }
75
76 /* (non-Javadoc)
77 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
78 */
79 public IContextInformation[] computeContextInformation(ITextViewer viewer,
80 int offset) {
81 // TODO Auto-generated method stub
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 // TODO Auto-generated method stub
97 return null;
98 }
99
100 /* (non-Javadoc)
101 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
102 */
103 public IContextInformationValidator getContextInformationValidator() {
104 // TODO Auto-generated method stub
105 return null;
106 }
107
108 /* (non-Javadoc)
109 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
110 */
111 public String getErrorMessage() {
112 // TODO Auto-generated method stub
113 return null;
114 }
115 }