KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > java > ProposalContextInformation


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

11 package org.eclipse.jdt.internal.ui.text.java;
12
13
14
15 import org.eclipse.swt.graphics.Image;
16
17 import org.eclipse.jface.resource.ImageDescriptor;
18
19 import org.eclipse.jface.text.contentassist.IContextInformation;
20 import org.eclipse.jface.text.contentassist.IContextInformationExtension;
21
22 import org.eclipse.jdt.core.CompletionProposal;
23
24 import org.eclipse.jdt.ui.text.java.CompletionProposalLabelProvider;
25
26 import org.eclipse.jdt.internal.ui.JavaPlugin;
27
28
29 /**
30  * Implementation of the <code>IContextInformation</code> interface.
31  */

32 public final class ProposalContextInformation implements IContextInformation, IContextInformationExtension {
33
34     private final String JavaDoc fContextDisplayString;
35     private final String JavaDoc fInformationDisplayString;
36     private final Image fImage;
37     private int fPosition;
38
39     /**
40      * Creates a new context information.
41      */

42     public ProposalContextInformation(CompletionProposal proposal) {
43         // don't cache the core proposal because the ContentAssistant might
44
// hang on to the context info.
45
CompletionProposalLabelProvider labelProvider= new CompletionProposalLabelProvider();
46         fInformationDisplayString= labelProvider.createParameterList(proposal);
47         ImageDescriptor descriptor= labelProvider.createImageDescriptor(proposal);
48         if (descriptor != null)
49             fImage= JavaPlugin.getImageDescriptorRegistry().get(descriptor);
50         else
51             fImage= null;
52         if (proposal.getCompletion().length == 0)
53             fPosition= proposal.getCompletionLocation() + 1;
54         else
55             fPosition= -1;
56         fContextDisplayString= labelProvider.createLabel(proposal);
57     }
58
59     /*
60      * @see IContextInformation#equals
61      */

62     public boolean equals(Object JavaDoc object) {
63         if (object instanceof IContextInformation) {
64             IContextInformation contextInformation= (IContextInformation) object;
65             boolean equals= getInformationDisplayString().equalsIgnoreCase(contextInformation.getInformationDisplayString());
66             if (getContextDisplayString() != null)
67                 equals= equals && getContextDisplayString().equalsIgnoreCase(contextInformation.getContextDisplayString());
68             return equals;
69         }
70         return false;
71     }
72
73     /*
74      * @see IContextInformation#getInformationDisplayString()
75      */

76     public String JavaDoc getInformationDisplayString() {
77         return fInformationDisplayString;
78     }
79
80     /*
81      * @see IContextInformation#getImage()
82      */

83     public Image getImage() {
84         return fImage;
85     }
86
87     /*
88      * @see IContextInformation#getContextDisplayString()
89      */

90     public String JavaDoc getContextDisplayString() {
91         return fContextDisplayString;
92     }
93
94     /*
95      * @see IContextInformationExtension#getContextInformationPosition()
96      */

97     public int getContextInformationPosition() {
98         return fPosition;
99     }
100     
101     /**
102      * Sets the context information position.
103      *
104      * @param position the new position, or -1 for unknown.
105      * @since 3.1
106      */

107     public void setContextInformationPosition(int position) {
108         fPosition= position;
109     }
110 }
111
Popular Tags