Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2006 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.recipeeditor; |
12 |
|
13 |
import org.eclipse.jface.text.IDocument; |
14 |
import org.eclipse.jface.text.IDocumentExtension3; |
15 |
import org.eclipse.jface.text.IDocumentPartitioner; |
16 |
import org.eclipse.jface.text.rules.FastPartitioner; |
17 |
import org.eclipse.jface.text.rules.IPredicateRule; |
18 |
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; |
19 |
import org.eclipse.jface.text.rules.SingleLineRule; |
20 |
import org.eclipse.jface.text.rules.Token; |
21 |
import org.eclipse.ui.editors.text.FileDocumentProvider; |
22 |
|
23 |
public class RecipeDocumentProvider extends FileDocumentProvider { |
24 |
/** |
25 |
* The recipe partitioning. It contains two partition types: {@link #RECIPE_CODE} and |
26 |
* {@link #RECIPE_COMMENT}. |
27 |
*/ |
28 |
public static final String RECIPE_PARTITIONING= "org.recipeeditor.recipepartitioning"; //$NON-NLS-1$ |
29 |
|
30 |
/** |
31 |
* The identifier of the comment body type. |
32 |
*/ |
33 |
public static final String RECIPE_CODE= IDocument.DEFAULT_CONTENT_TYPE; |
34 |
/** |
35 |
* The identifier of the comment partition type. |
36 |
*/ |
37 |
public static final String RECIPE_COMMENT= "RECIPE_COMMENT"; //$NON-NLS-1$ |
38 |
|
39 |
private static final String[] CONTENT_TYPES= { |
40 |
RECIPE_CODE, |
41 |
RECIPE_COMMENT |
42 |
}; |
43 |
|
44 |
protected void setupDocument(Object element,IDocument document) { |
45 |
if (document instanceof IDocumentExtension3) { |
46 |
IDocumentExtension3 ext= (IDocumentExtension3) document; |
47 |
IDocumentPartitioner partitioner= createRecipePartitioner(); |
48 |
ext.setDocumentPartitioner(RECIPE_PARTITIONING, partitioner); |
49 |
partitioner.connect(document); |
50 |
} |
51 |
} |
52 |
|
53 |
private IDocumentPartitioner createRecipePartitioner() { |
54 |
IPredicateRule[] rules= { new SingleLineRule("#", null, new Token(RECIPE_COMMENT), (char) 0, true, false) }; //$NON-NLS-1$ |
55 |
|
56 |
RuleBasedPartitionScanner scanner= new RuleBasedPartitionScanner(); |
57 |
scanner.setPredicateRules(rules); |
58 |
|
59 |
return new FastPartitioner(scanner, CONTENT_TYPES); |
60 |
} |
61 |
|
62 |
} |