KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > contentassist > SubjectControlContextInformationValidator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jface.contentassist;
12
13 import org.eclipse.jface.text.ITextViewer;
14 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
15 import org.eclipse.jface.text.contentassist.IContextInformation;
16
17
18 /**
19  * A default implementation of the {@link SubjectControlContextInformationValidator} interface.
20  * This implementation determines whether the information is valid by asking the content
21  * assist processor for all context information objects for the current position. If the
22  * currently displayed information is in the result set, the context information is
23  * considered valid.
24  *
25  * @since 3.0
26  * @deprecated As of 3.2, replaced by Platform UI's field assist support
27  */

28 public final class SubjectControlContextInformationValidator implements ISubjectControlContextInformationValidator {
29
30     /** The content assist processor. */
31     private IContentAssistProcessor fProcessor;
32     /** The context information to be validated. */
33     private IContextInformation fContextInformation;
34     /** The content assist subject control. */
35     private IContentAssistSubjectControl fContentAssistSubjectControl;
36
37     /**
38      * Creates a new context information validator which is ready to be installed on
39      * a particular context information.
40      *
41      * @param processor the processor to be used for validation
42      */

43     public SubjectControlContextInformationValidator(IContentAssistProcessor processor) {
44         fProcessor= processor;
45     }
46
47     /*
48      * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
49      */

50     public void install(IContextInformation contextInformation, ITextViewer viewer, int offset) {
51         throw new UnsupportedOperationException JavaDoc();
52     }
53
54     /*
55      * @see ISubjectControlContextInformationValidator#install(IContextInformation, IContentAssistSubjectControl, int)
56      */

57     public void install(IContextInformation contextInformation, IContentAssistSubjectControl contentAssistSubjectControl, int offset) {
58         fContextInformation= contextInformation;
59         fContentAssistSubjectControl= contentAssistSubjectControl;
60     }
61
62     /*
63      * @see IContentAssistTipCloser#isContextInformationValid(int)
64      */

65     public boolean isContextInformationValid(int offset) {
66         if (fContentAssistSubjectControl != null && fProcessor instanceof ISubjectControlContentAssistProcessor) {
67             IContextInformation[] infos= ((ISubjectControlContentAssistProcessor)fProcessor).computeContextInformation(fContentAssistSubjectControl, offset);
68             if (infos != null && infos.length > 0) {
69                 for (int i= 0; i < infos.length; i++) {
70                     if (fContextInformation.equals(infos[i]))
71                         return true;
72                 }
73             }
74         }
75         return false;
76     }
77 }
78
Popular Tags