Added PHPUnitEditor and corresponding PHPPreferencePage
[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.DefaultLineTracker;
20 import org.eclipse.jface.text.IDocument;
21 import org.eclipse.jface.text.IDocumentPartitioner;
22 import org.eclipse.jface.text.ILineTracker;
23 import org.eclipse.jface.text.rules.DefaultPartitioner;
24 import org.eclipse.ui.editors.text.FileDocumentProvider;
25
26 /** 
27  * The PHPDocumentProvider provides the IDocuments used by java editors.
28  */
29
30 public class PHPDocumentProvider extends FileDocumentProvider {
31
32   // private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC, PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
33   private final static String[] TYPES = new String[] { 
34         IPHPPartitionScannerConstants.PHP,
35         IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
36     IPHPPartitionScannerConstants.HTML, 
37         IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
38         IPHPPartitionScannerConstants.JAVASCRIPT,
39         IPHPPartitionScannerConstants.CSS};
40
41   private static PHPPartitionScanner fgScanner = null;
42
43   public PHPDocumentProvider() {
44     super();
45   }
46
47   /* (non-Javadoc)
48    * Method declared on AbstractDocumentProvider
49    */
50   protected IDocument createDocument(Object element) throws CoreException {
51     IDocument document = super.createDocument(element);
52     if (document != null) {
53       IDocumentPartitioner partitioner = createPHPPartitioner();
54       document.setDocumentPartitioner(partitioner);
55       partitioner.connect(document);
56     }
57     return document;
58   }
59
60   /**
61    * Return a partitioner for .php files.
62    */
63   private IDocumentPartitioner createPHPPartitioner() {
64     return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
65   }
66
67   /**
68    * Return a scanner for creating java partitions.
69    */
70   private PHPPartitionScanner getPHPPartitionScanner() {
71     if (fgScanner == null)
72       fgScanner = new PHPPartitionScanner();
73     return fgScanner;
74   }
75   
76   /**
77    * Creates a line tracker working with the same line delimiters as the document
78    * of the given element. Assumes the element to be managed by this document provider.
79    * 
80    * @param element the element serving as blue print
81    * @return a line tracker based on the same line delimiters as the element's document
82    */
83   public ILineTracker createLineTracker(Object element) {
84     return new DefaultLineTracker();
85   }
86 }