KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > contentassist > TempNameProcessor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.ui.refactoring.contentassist;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Arrays JavaDoc;
16
17 import org.eclipse.swt.graphics.Image;
18
19 import org.eclipse.jface.contentassist.IContentAssistSubjectControl;
20 import org.eclipse.jface.contentassist.ISubjectControlContentAssistProcessor;
21 import org.eclipse.jface.text.ITextViewer;
22 import org.eclipse.jface.text.contentassist.ICompletionProposal;
23 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
24 import org.eclipse.jface.text.contentassist.IContextInformation;
25 import org.eclipse.jface.text.contentassist.IContextInformationValidator;
26 import org.eclipse.jface.util.Assert;
27
28 import org.eclipse.jdt.internal.ui.JavaPlugin;
29 import org.eclipse.jdt.internal.ui.JavaPluginImages;
30 import org.eclipse.jdt.internal.ui.JavaUIMessages;
31 import org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal;
32 import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
33
34 public class TempNameProcessor implements IContentAssistProcessor, ISubjectControlContentAssistProcessor {
35
36     private String JavaDoc[] fTempNameProposals;
37     private String JavaDoc fErrorMessage;
38     private ImageDescriptorRegistry fImageRegistry= JavaPlugin.getImageDescriptorRegistry();
39
40     public TempNameProcessor(String JavaDoc[] tempNameProposals) {
41         fTempNameProposals= (String JavaDoc[]) tempNameProposals.clone();
42         Arrays.sort(fTempNameProposals);
43     }
44
45     /*
46      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
47      */

48     public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
49         Assert.isTrue(false, "ITextViewer not supported"); //$NON-NLS-1$
50
return null;
51     }
52
53     /*
54      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
55      */

56     public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
57         Assert.isTrue(false, "ITextViewer not supported"); //$NON-NLS-1$
58
return null;
59     }
60
61     /*
62      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
63      */

64     public char[] getCompletionProposalAutoActivationCharacters() {
65         return null;
66     }
67
68     /*
69      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
70      */

71     public char[] getContextInformationAutoActivationCharacters() {
72         return null; //no context
73
}
74
75     /*
76      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
77      */

78     public String JavaDoc getErrorMessage() {
79         return fErrorMessage;
80     }
81
82     /*
83      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
84      */

85     public IContextInformationValidator getContextInformationValidator() {
86         return null; //no context
87
}
88
89     /*
90      * @see org.eclipse.jface.contentassist.IContentAssistProcessorExtension#computeContextInformation(org.eclipse.jface.contentassist.IContentAssistSubject, int)
91      */

92     public IContextInformation[] computeContextInformation(IContentAssistSubjectControl contentAssistSubject, int documentOffset) {
93         return null; //no context
94
}
95
96     /*
97      * @see org.eclipse.jface.contentassist.IContentAssistProcessorExtension#computeCompletionProposals(org.eclipse.jface.contentassist.IContentAssistSubject, int)
98      */

99     public ICompletionProposal[] computeCompletionProposals(IContentAssistSubjectControl contentAssistSubject, int documentOffset) {
100         if (fTempNameProposals.length == 0)
101             return null;
102         String JavaDoc input= contentAssistSubject.getDocument().get();
103         
104         ArrayList JavaDoc proposals= new ArrayList JavaDoc();
105         String JavaDoc prefix= input.substring(0, documentOffset);
106         Image image= fImageRegistry.get(JavaPluginImages.DESC_OBJS_LOCAL_VARIABLE);
107         for (int i= 0; i < fTempNameProposals.length; i++) {
108             String JavaDoc tempName= fTempNameProposals[i];
109             if (tempName.length() == 0 || ! tempName.startsWith(prefix))
110                 continue;
111             JavaCompletionProposal proposal= new JavaCompletionProposal(tempName, 0, input.length(), image, tempName, 0);
112             proposals.add(proposal);
113         }
114         fErrorMessage= proposals.size() > 0 ? null : JavaUIMessages.getString("JavaEditor.codeassist.noCompletions"); //$NON-NLS-1$
115
return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
116     }
117
118 }
119
Popular Tags