intial source from ttp://www.sf.net/projects/wdte
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.js.ui / src / net / sourceforge / phpeclipse / js / ui / editors / JSDocumentProvider.java
1 /*
2  * $RCSfile: JSDocumentProvider.java,v $
3  *
4  * Copyright 2002
5  * CH-1700 Fribourg, Switzerland
6  * All rights reserved.
7  *
8  *========================================================================
9  * Modifications history
10  *========================================================================
11  * $Log: not supported by cvs2svn $
12  * Revision 1.2  2004/02/26 02:25:57  agfitzp
13  * renamed packages to match xml & css
14  *
15  * Revision 1.1  2004/02/05 03:13:28  agfitzp
16  * Initial submission, outline view is broken due to refactoring
17  *
18  * Revision 1.1.2.1  2003/12/12 21:37:24  agfitzp
19  * Experimental work for Classes view
20  *
21  * Revision 1.1  2003/05/28 15:17:11  agfitzp
22  * net.sourceforge.phpeclipse.js.ui 0.0.1 code base
23  *
24  *========================================================================
25 */
26
27 package net.sourceforge.phpeclipse.js.ui.editors;
28
29 import net.sourceforge.phpeclipse.js.core.parser.JSPartitionScanner;
30
31 import org.eclipse.core.runtime.CoreException;
32 import org.eclipse.jface.text.IDocument;
33 import org.eclipse.jface.text.IDocumentPartitioner;
34 import org.eclipse.jface.text.rules.DefaultPartitioner;
35 import org.eclipse.ui.editors.text.FileDocumentProvider;
36
37 /**
38  * 
39  *
40  * @author $Author: jsurfer $, $Date: 2004-09-02 18:23:49 $
41  *
42  * @version $Revision: 1.1 $
43  */
44 public class JSDocumentProvider extends FileDocumentProvider {
45
46         /**
47          * Array of constant token types that will be color hilighted.
48          */
49         private static String[] colorTokens= { 
50                 JSPartitionScanner.JS_COMMENT,
51                 JSPartitionScanner.JS_STRING, 
52                 JSPartitionScanner.JS_KEYWORD 
53         };
54
55         /**
56          * Constructor for JSDocumentProvider.
57          */
58         public JSDocumentProvider() {
59                 super();
60         }
61
62         /**
63          * @param element 
64          *
65          * @return 
66          *
67          * @throws CoreException 
68          */
69         protected IDocument createDocument(Object element) throws CoreException {
70                 IDocument document = super.createDocument(element);
71
72                 if (document != null) {
73                         IDocumentPartitioner partitioner =
74                                 new DefaultPartitioner(new JSPartitionScanner(), colorTokens);
75                         partitioner.connect(document);
76                         document.setDocumentPartitioner(partitioner);
77                 }
78
79                 return document;
80         }
81 }