Source code: org/eclipse/jface/text/IDocumentExtension3.java
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 package org.eclipse.jface.text;
12
13 /**
14 * Extension interface for {@link org.eclipse.jface.text.IDocument}.
15 * <p>
16 * Adds the concept of multiple partitionings and the concept of zero-length
17 * partitions in conjunction with open and delimited partitions. A delimited
18 * partition has a well defined start delimiter and a well defined end
19 * delimiter. Between two delimited partitions there may be an open partition of
20 * length zero.
21 * <p>
22 *
23 * In order to fulfill the contract of this interface, the document must be
24 * configured with a document partitioner implementing
25 * {@link org.eclipse.jface.text.IDocumentPartitionerExtension2}.
26 *
27 * @see org.eclipse.jface.text.IDocumentPartitionerExtension2
28 * @since 3.0
29 */
30 public interface IDocumentExtension3 {
31
32 /**
33 * The identifier of the default partitioning.
34 */
35 final static String DEFAULT_PARTITIONING= "__dftl_partitioning"; //$NON-NLS-1$
36
37
38 /**
39 * Returns the existing partitionings for this document. This includes
40 * the default partitioning.
41 *
42 * @return the existing partitionings for this document
43 */
44 String[] getPartitionings();
45
46 /**
47 * Returns the set of legal content types of document partitions for the given partitioning
48 * This set can be empty. The set can contain more content types than contained by the
49 * result of <code>getPartitioning(partitioning, 0, getLength())</code>.
50 *
51 * @param partitioning the partitioning for which to return the legal content types
52 * @return the set of legal content types
53 * @exception BadPartitioningException if partitioning is invalid for this document
54 */
55 String[] getLegalContentTypes(String partitioning) throws BadPartitioningException;
56
57
58 /**
59 * Returns the type of the document partition containing the given offset
60 * for the given partitioning. This is a convenience method for
61 * <code>getPartition(partitioning, offset, boolean).getType()</code>.
62 * <p>
63 * If <code>preferOpenPartitions</code> is <code>true</code>,
64 * precedence is given to an open partition ending at <code>offset</code>
65 * over a delimited partition starting at <code>offset</code>. If it is
66 * <code>false</code>, precedence is given to the partition that does not
67 * end at <code>offset</code>.
68 * </p>
69 * This is only supported if the connected <code>IDocumentPartitioner</code>
70 * supports it, i.e. implements <code>IDocumentPartitionerExtension2</code>.
71 * Otherwise, <code>preferOpenPartitions</code> is ignored.
72 * </p>
73 *
74 * @param partitioning the partitioning
75 * @param offset the document offset
76 * @param preferOpenPartitions <code>true</code> if precedence should be
77 * given to a open partition ending at <code>offset</code> over a
78 * closed partition starting at <code>offset</code>
79 * @return the partition type
80 * @exception BadLocationException if offset is invalid in this document
81 * @exception BadPartitioningException if partitioning is invalid for this document
82 */
83 String getContentType(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException;
84
85 /**
86 * Returns the document partition of the given partitioning in which the
87 * given offset is located.
88 * <p>
89 * If <code>preferOpenPartitions</code> is <code>true</code>,
90 * precedence is given to an open partition ending at <code>offset</code>
91 * over a delimited partition starting at <code>offset</code>. If it is
92 * <code>false</code>, precedence is given to the partition that does not
93 * end at <code>offset</code>.
94 * </p>
95 * This is only supported if the connected <code>IDocumentPartitioner</code>
96 * supports it, i.e. implements <code>IDocumentPartitionerExtension2</code>.
97 * Otherwise, <code>preferOpenPartitions</code> is ignored.
98 * </p>
99 *
100 * @param partitioning the partitioning
101 * @param offset the document offset
102 * @param preferOpenPartitions <code>true</code> if precedence should be
103 * given to a open partition ending at <code>offset</code> over a
104 * closed partition starting at <code>offset</code>
105 * @return a specification of the partition
106 * @exception BadLocationException if offset is invalid in this document
107 * @exception BadPartitioningException if partitioning is invalid for this document
108 */
109 ITypedRegion getPartition(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException;
110
111 /**
112 * Computes the partitioning of the given document range based on the given
113 * partitioning type.
114 * <p>
115 * If <code>includeZeroLengthPartitions</code> is <code>true</code>, a
116 * zero-length partition of an open partition type (usually the default
117 * partition) is included between two closed partitions. If it is
118 * <code>false</code>, no zero-length partitions are included.
119 * </p>
120 * This is only supported if the connected <code>IDocumentPartitioner</code>
121 * supports it, i.e. implements <code>IDocumentPartitionerExtension2</code>.
122 * Otherwise, <code>includeZeroLengthPartitions</code> is ignored.
123 * </p>
124 *
125 * @param partitioning the document's partitioning type
126 * @param offset the document offset at which the range starts
127 * @param length the length of the document range
128 * @param includeZeroLengthPartitions <code>true</code> if zero-length
129 * partitions should be returned as part of the computed partitioning
130 * @return a specification of the range's partitioning
131 * @exception BadLocationException if the range is invalid in this document$
132 * @exception BadPartitioningException if partitioning is invalid for this document
133 */
134 ITypedRegion[] computePartitioning(String partitioning, int offset, int length, boolean includeZeroLengthPartitions) throws BadLocationException, BadPartitioningException;
135
136 /**
137 * Sets this document's partitioner. The caller of this method is responsible for
138 * disconnecting the document's old partitioner from the document and to
139 * connect the new partitioner to the document. Informs all document partitioning
140 * listeners about this change.
141 *
142 * @param partitioning the partitioning for which to set the partitioner
143 * @param partitioner the document's new partitioner
144 * @see IDocumentPartitioningListener
145 */
146 void setDocumentPartitioner(String partitioning, IDocumentPartitioner partitioner);
147
148 /**
149 * Returns the partitioner for the given partitioning or <code>null</code> if
150 * no partitioner is registered.
151 *
152 * @param partitioning the partitioning for which to set the partitioner
153 * @return the partitioner for the given partitioning
154 */
155 IDocumentPartitioner getDocumentPartitioner(String partitioning);
156 }