KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > contentassist > ContextInformationValidator


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.jface.text.contentassist;
12
13 import org.eclipse.jface.text.ITextViewer;
14
15
16 /**
17  * A default implementation of the <code>IContextInfomationValidator</code> interface.
18  * This implementation determines whether the information is valid by asking the content
19  * assist processor for all context information objects for the current position. If the
20  * currently displayed information is in the result set, the context information is
21  * considered valid.
22  */

23 public final class ContextInformationValidator implements IContextInformationValidator {
24
25     /** The content assist processor. */
26     private IContentAssistProcessor fProcessor;
27     /** The context information to be validated. */
28     private IContextInformation fContextInformation;
29     /** The associated text viewer. */
30     private ITextViewer fViewer;
31
32     /**
33      * Creates a new context information validator which is ready to be installed on
34      * a particular context information.
35      *
36      * @param processor the processor to be used for validation
37      */

38     public ContextInformationValidator(IContentAssistProcessor processor) {
39         fProcessor= processor;
40     }
41
42     /*
43      * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
44      */

45     public void install(IContextInformation contextInformation, ITextViewer viewer, int offset) {
46         fContextInformation= contextInformation;
47         fViewer= viewer;
48     }
49
50     /*
51      * @see IContentAssistTipCloser#isContextInformationValid(int)
52      */

53     public boolean isContextInformationValid(int offset) {
54         IContextInformation[] infos= fProcessor.computeContextInformation(fViewer, offset);
55         if (infos != null && infos.length > 0) {
56             for (int i= 0; i < infos.length; i++)
57                 if (fContextInformation.equals(infos[i]))
58                     return true;
59         }
60         return false;
61     }
62 }
63
Popular Tags