Added Constants for the new PartitionScanner
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPDocumentProvider.java
1 package net.sourceforge.phpeclipse.phpeditor;
2
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
9
10 Contributors:
11     IBM Corporation - Initial implementation
12     Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
14
15 import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants;
16 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
17
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.jface.text.IDocument;
20 import org.eclipse.jface.text.IDocumentPartitioner;
21 import org.eclipse.jface.text.rules.DefaultPartitioner;
22 import org.eclipse.ui.editors.text.FileDocumentProvider;
23
24 /** 
25  * The PHPDocumentProvider provides the IDocuments used by java editors.
26  */
27
28 public class PHPDocumentProvider extends FileDocumentProvider {
29
30   // private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC, PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
31   private final static String[] TYPES = new String[] { 
32         IPHPPartitionScannerConstants.PHP,
33         IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
34     IPHPPartitionScannerConstants.HTML, 
35         IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
36         IPHPPartitionScannerConstants.JAVASCRIPT,
37         IPHPPartitionScannerConstants.CSS};
38
39   private static PHPPartitionScanner fgScanner = null;
40
41   public PHPDocumentProvider() {
42     super();
43   }
44
45   /* (non-Javadoc)
46    * Method declared on AbstractDocumentProvider
47    */
48   protected IDocument createDocument(Object element) throws CoreException {
49     IDocument document = super.createDocument(element);
50     if (document != null) {
51       IDocumentPartitioner partitioner = createPHPPartitioner();
52       document.setDocumentPartitioner(partitioner);
53       partitioner.connect(document);
54     }
55     return document;
56   }
57
58   /**
59    * Return a partitioner for .php files.
60    */
61   private IDocumentPartitioner createPHPPartitioner() {
62     return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
63   }
64
65   /**
66    * Return a scanner for creating java partitions.
67    */
68   private PHPPartitionScanner getPHPPartitionScanner() {
69     if (fgScanner == null)
70       fgScanner = new PHPPartitionScanner();
71     return fgScanner;
72   }
73 }