001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jface.text;
011:
012: /**
013: * Extension interface for {@link org.eclipse.jface.text.IDocument}.
014: * <p>
015: * Adds the concept of multiple partitionings and the concept of zero-length
016: * partitions in conjunction with open and delimited partitions. A delimited
017: * partition has a well defined start delimiter and a well defined end
018: * delimiter. Between two delimited partitions there may be an open partition of
019: * length zero.
020: * <p>
021: *
022: * In order to fulfill the contract of this interface, the document must be
023: * configured with a document partitioner implementing
024: * {@link org.eclipse.jface.text.IDocumentPartitionerExtension2}.
025: *
026: * @see org.eclipse.jface.text.IDocumentPartitionerExtension2
027: * @since 3.0
028: */
029: public interface IDocumentExtension3 {
030:
031: /**
032: * The identifier of the default partitioning.
033: */
034: final static String DEFAULT_PARTITIONING = "__dftl_partitioning"; //$NON-NLS-1$
035:
036: /**
037: * Returns the existing partitionings for this document. This includes
038: * the default partitioning.
039: *
040: * @return the existing partitionings for this document
041: */
042: String[] getPartitionings();
043:
044: /**
045: * Returns the set of legal content types of document partitions for the given partitioning
046: * This set can be empty. The set can contain more content types than contained by the
047: * result of <code>getPartitioning(partitioning, 0, getLength())</code>.
048: *
049: * @param partitioning the partitioning for which to return the legal content types
050: * @return the set of legal content types
051: * @exception BadPartitioningException if partitioning is invalid for this document
052: */
053: String[] getLegalContentTypes(String partitioning)
054: throws BadPartitioningException;
055:
056: /**
057: * Returns the type of the document partition containing the given offset
058: * for the given partitioning. This is a convenience method for
059: * <code>getPartition(partitioning, offset, boolean).getType()</code>.
060: * <p>
061: * If <code>preferOpenPartitions</code> is <code>true</code>,
062: * precedence is given to an open partition ending at <code>offset</code>
063: * over a delimited partition starting at <code>offset</code>. If it is
064: * <code>false</code>, precedence is given to the partition that does not
065: * end at <code>offset</code>.
066: * </p>
067: * This is only supported if the connected <code>IDocumentPartitioner</code>
068: * supports it, i.e. implements <code>IDocumentPartitionerExtension2</code>.
069: * Otherwise, <code>preferOpenPartitions</code> is ignored.
070: * </p>
071: *
072: * @param partitioning the partitioning
073: * @param offset the document offset
074: * @param preferOpenPartitions <code>true</code> if precedence should be
075: * given to a open partition ending at <code>offset</code> over a
076: * closed partition starting at <code>offset</code>
077: * @return the partition type
078: * @exception BadLocationException if offset is invalid in this document
079: * @exception BadPartitioningException if partitioning is invalid for this document
080: */
081: String getContentType(String partitioning, int offset,
082: boolean preferOpenPartitions) throws BadLocationException,
083: BadPartitioningException;
084:
085: /**
086: * Returns the document partition of the given partitioning in which the
087: * given offset is located.
088: * <p>
089: * If <code>preferOpenPartitions</code> is <code>true</code>,
090: * precedence is given to an open partition ending at <code>offset</code>
091: * over a delimited partition starting at <code>offset</code>. If it is
092: * <code>false</code>, precedence is given to the partition that does not
093: * end at <code>offset</code>.
094: * </p>
095: * This is only supported if the connected <code>IDocumentPartitioner</code>
096: * supports it, i.e. implements <code>IDocumentPartitionerExtension2</code>.
097: * Otherwise, <code>preferOpenPartitions</code> is ignored.
098: * </p>
099: *
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,
110: boolean preferOpenPartitions) throws BadLocationException,
111: BadPartitioningException;
112:
113: /**
114: * Computes the partitioning of the given document range based on the given
115: * partitioning type.
116: * <p>
117: * If <code>includeZeroLengthPartitions</code> is <code>true</code>, a
118: * zero-length partition of an open partition type (usually the default
119: * partition) is included between two closed partitions. If it is
120: * <code>false</code>, no zero-length partitions are included.
121: * </p>
122: * This is only supported if the connected <code>IDocumentPartitioner</code>
123: * supports it, i.e. implements <code>IDocumentPartitionerExtension2</code>.
124: * Otherwise, <code>includeZeroLengthPartitions</code> is ignored.
125: * </p>
126: *
127: * @param partitioning the document's partitioning type
128: * @param offset the document offset at which the range starts
129: * @param length the length of the document range
130: * @param includeZeroLengthPartitions <code>true</code> if zero-length
131: * partitions should be returned as part of the computed partitioning
132: * @return a specification of the range's partitioning
133: * @exception BadLocationException if the range is invalid in this document$
134: * @exception BadPartitioningException if partitioning is invalid for this document
135: */
136: ITypedRegion[] computePartitioning(String partitioning, int offset,
137: int length, boolean includeZeroLengthPartitions)
138: throws BadLocationException, BadPartitioningException;
139:
140: /**
141: * Sets this document's partitioner. The caller of this method is responsible for
142: * disconnecting the document's old partitioner from the document and to
143: * connect the new partitioner to the document. Informs all document partitioning
144: * listeners about this change.
145: *
146: * @param partitioning the partitioning for which to set the partitioner
147: * @param partitioner the document's new partitioner
148: * @see IDocumentPartitioningListener
149: */
150: void setDocumentPartitioner(String partitioning,
151: IDocumentPartitioner partitioner);
152:
153: /**
154: * Returns the partitioner for the given partitioning or <code>null</code> if
155: * no partitioner is registered.
156: *
157: * @param partitioning the partitioning for which to set the partitioner
158: * @return the partitioner for the given partitioning
159: */
160: IDocumentPartitioner getDocumentPartitioner(String partitioning);
161: }
|