KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > IDocumentPartitioner


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;
12
13
14
15 /**
16  * A document partitioner divides a document into a set
17  * of disjoint text partitions. Each partition has a content type, an
18  * offset, and a length. The document partitioner is connected to one document
19  * and informed about all changes of this document before any of the
20  * document's document listeners. A document partitioner can thus
21  * incrementally update on the receipt of a document change event.<p>
22  *
23  * In order to provided backward compatibility for clients of <code>IDocumentPartitioner</code>, extension
24  * interfaces are used to provide a means of evolution. The following extension interfaces
25  * exist:
26  * <ul>
27  * <li> {@link org.eclipse.jface.text.IDocumentPartitionerExtension} since version 2.0 replacing
28  * the <code>documentChanged</code> method with a new one returning the minimal document region
29  * comprising all partition changes.</li>
30  * <li> {@link org.eclipse.jface.text.IDocumentPartitionerExtension2} since version 3.0
31  * introducing zero-length partitions in conjunction with the distinction between
32  * open and closed partitions. Also provides inside in the implementation of the partitioner
33  * by exposing the position category used for managing the partitioning information.</li>
34  * <li> {@link org.eclipse.jface.text.IDocumentPartitionerExtension3} since version 3.1 introducing
35  * rewrite session. It also replaces the existing {@link #connect(IDocument)} method with
36  * a new one: {@link org.eclipse.jface.text.IDocumentPartitionerExtension3#connect(IDocument, boolean)}.
37  * </ul>
38  * <p>
39  * Clients may implement this interface and its extension interfaces or use the standard
40  * implementation <code>DefaultPartitioner</code>.
41  * </p>
42  *
43  * @see org.eclipse.jface.text.IDocumentPartitionerExtension
44  * @see org.eclipse.jface.text.IDocumentPartitionerExtension2
45  * @see org.eclipse.jface.text.IDocument
46  */

47 public interface IDocumentPartitioner {
48
49     /**
50      * Connects the partitioner to a document.
51      * Connect indicates the begin of the usage of the receiver
52      * as partitioner of the given document. Thus, resources the partitioner
53      * needs to be operational for this document should be allocated.<p>
54      *
55      * The caller of this method must ensure that this partitioner is
56      * also set as the document's document partitioner.<p>
57      *
58      * This method has been replaced with {@link IDocumentPartitionerExtension3#connect(IDocument, boolean)}.
59      * Implementers should default a call <code>connect(document)</code> to
60      * <code>connect(document, false)</code> in order to sustain the same semantics.
61      *
62      * @param document the document to be connected to
63      */

64     void connect(IDocument document);
65
66     /**
67      * Disconnects the partitioner from the document it is connected to.
68      * Disconnect indicates the end of the usage of the receiver as
69      * partitioner of the connected document. Thus, resources the partitioner
70      * needed to be operation for its connected document should be deallocated.<p>
71      * The caller of this method should also must ensure that this partitioner is
72      * no longer the document's partitioner.
73      */

74     void disconnect();
75
76     /**
77      * Informs about a forthcoming document change. Will be called by the
78      * connected document and is not intended to be used by clients
79      * other than the connected document.
80      *
81      * @param event the event describing the forthcoming change
82      */

83     void documentAboutToBeChanged(DocumentEvent event);
84
85     /**
86      * The document has been changed. The partitioner updates
87      * the document's partitioning and returns whether the structure of the
88      * document partitioning has been changed, i.e. whether partitions
89      * have been added or removed. Will be called by the connected document and
90      * is not intended to be used by clients other than the connected document.<p>
91      *
92      * This method has been replaced by {@link IDocumentPartitionerExtension#documentChanged2(DocumentEvent)}.
93      *
94      * @param event the event describing the document change
95      * @return <code>true</code> if partitioning changed
96      */

97     boolean documentChanged(DocumentEvent event);
98
99     /**
100      * Returns the set of all legal content types of this partitioner.
101      * I.e. any result delivered by this partitioner may not contain a content type
102      * which would not be included in this method's result.
103      *
104      * @return the set of legal content types
105      */

106     String JavaDoc[] getLegalContentTypes();
107
108     /**
109      * Returns the content type of the partition containing the
110      * given offset in the connected document. There must be a
111      * document connected to this partitioner.<p>
112      *
113      * Use {@link IDocumentPartitionerExtension2#getContentType(int, boolean)} when
114      * zero-length partitions are supported. In that case this method is
115      * equivalent:
116      * <pre>
117      * IDocumentPartitionerExtension2 extension= (IDocumentPartitionerExtension2) partitioner;
118      * return extension.getContentType(offset, false);
119      * </pre>
120      *
121      * @param offset the offset in the connected document
122      * @return the content type of the offset's partition
123      */

124     String JavaDoc getContentType(int offset);
125
126     /**
127      * Returns the partitioning of the given range of the connected
128      * document. There must be a document connected to this partitioner.<p>
129      *
130      * Use {@link IDocumentPartitionerExtension2#computePartitioning(int, int, boolean)} when
131      * zero-length partitions are supported. In that case this method is
132      * equivalent:
133      * <pre>
134      * IDocumentPartitionerExtension2 extension= (IDocumentPartitionerExtension2) partitioner;
135      * return extension.computePartitioning(offset, length, false);
136      * </pre>
137      *
138      * @param offset the offset of the range of interest
139      * @param length the length of the range of interest
140      * @return the partitioning of the range
141      */

142     ITypedRegion[] computePartitioning(int offset, int length);
143
144     /**
145      * Returns the partition containing the given offset of
146      * the connected document. There must be a document connected to this
147      * partitioner.<p>
148      *
149      * Use {@link IDocumentPartitionerExtension2#getPartition(int, boolean)} when
150      * zero-length partitions are supported. In that case this method is
151      * equivalent:
152      * <pre>
153      * IDocumentPartitionerExtension2 extension= (IDocumentPartitionerExtension2) partitioner;
154      * return extension.getPartition(offset, false);
155      * </pre>
156      *
157      * @param offset the offset for which to determine the partition
158      * @return the partition containing the offset
159      */

160     ITypedRegion getPartition(int offset);
161 }
162
Popular Tags