*** empty log message ***
[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.PHPPartitionScanner;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.jface.text.IDocument;
19 import org.eclipse.jface.text.IDocumentPartitioner;
20 import org.eclipse.jface.text.rules.DefaultPartitioner;
21 import org.eclipse.ui.editors.text.FileDocumentProvider;
22
23 /** 
24  * The PHPDocumentProvider provides the IDocuments used by java editors.
25  */
26
27 public class PHPDocumentProvider extends FileDocumentProvider {
28
29   // private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC, PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
30   private final static String[] TYPES = new String[] { 
31     PHPPartitionScanner.PHP,
32 //    PHPPartitionScanner.HTML, 
33     PHPPartitionScanner.HTML_MULTILINE_COMMENT };
34
35   private static PHPPartitionScanner fgScanner = null;
36
37   public PHPDocumentProvider() {
38     super();
39   }
40
41   /* (non-Javadoc)
42    * Method declared on AbstractDocumentProvider
43    */
44   protected IDocument createDocument(Object element) throws CoreException {
45     IDocument document = super.createDocument(element);
46     if (document != null) {
47       IDocumentPartitioner partitioner = createPHPPartitioner();
48       document.setDocumentPartitioner(partitioner);
49       partitioner.connect(document);
50     }
51     return document;
52   }
53
54   /**
55    * Return a partitioner for .php files.
56    */
57   private IDocumentPartitioner createPHPPartitioner() {
58     return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
59   }
60
61   /**
62    * Return a scanner for creating java partitions.
63    */
64   private PHPPartitionScanner getPHPPartitionScanner() {
65     if (fgScanner == null)
66       fgScanner = new PHPPartitionScanner();
67     return fgScanner;
68   }
69 }