A minor change of a page design
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / php / PHPDocumentPartitioner.java
1 /**********************************************************************
2  Copyright (c) 2002  Widespace, OU  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://solareclipse.sourceforge.net/legal/cpl-v10.html
7
8  Contributors:
9  Igor Malinin - initial contribution
10
11  $Id: PHPDocumentPartitioner.java,v 1.6 2006-10-21 23:18:33 pombredanne Exp $
12  **********************************************************************/
13 package net.sourceforge.phpeclipse.phpeditor.php;
14
15 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
16 import net.sourceforge.phpeclipse.ui.text.rules.FlatNode;
17 import net.sourceforge.phpeclipse.ui.text.rules.MultiViewPartitioner;
18 import net.sourceforge.phpeclipse.ui.text.rules.ViewNode;
19
20 import org.eclipse.jface.text.Assert;
21 import org.eclipse.jface.text.IDocument;
22 import org.eclipse.jface.text.IDocumentPartitioner;
23 import org.eclipse.jface.text.rules.IPartitionTokenScanner;
24
25 /**
26  * 
27  * 
28  * @author Igor Malinin
29  */
30 public class PHPDocumentPartitioner extends MultiViewPartitioner {
31         public static final String PHP_TEMPLATE_DATA = "__php_template_data";
32
33         public static final String PHP_SCRIPT_CODE = "__php_script_code";
34
35         public static final String[] LEGAL_TYPES = { PHP_TEMPLATE_DATA,
36                         PHP_SCRIPT_CODE };
37
38         public PHPDocumentPartitioner(IPartitionTokenScanner scanner) {
39                 super(scanner);
40         }
41
42         protected FlatNode createNode(String type, int offset, int length) {
43                 if (type.equals(PHPPartitionScanner.PHP_SCRIPTING_AREA)) {
44                         if (DEBUG) {
45                                 Assert.isTrue(offset >= 0);
46                         }
47                         ViewNode node = new ViewNode(type);
48                         node.offset = offset;
49                         node.length = length;
50                         return node;
51                 }
52
53                 return super.createNode(type, offset, length);
54         }
55
56         /*
57          * @see net.sf.solareclipse.text.rules.DocumentViewPartitioner#createPartitioner(String)
58          */
59         protected IDocumentPartitioner createPartitioner(String contentType) {
60                 if (contentType == null) {
61                         // return JavaTextTools.createHTMLPartitioner();
62                         return PHPeclipsePlugin.getDefault().getJavaTextTools()
63                                         .getXMLTextTools().createPHPXMLPartitioner();
64                 }
65
66                 if (contentType.equals(PHPPartitionScanner.PHP_SCRIPTING_AREA)) {
67                         return PHPeclipsePlugin.getDefault().getJavaTextTools()
68                                         .createPHPPartitioner();
69                 }
70                 return null;
71         }
72
73         /*
74          * @see net.sf.solareclipse.text.rules.DocumentViewPartitioner#getContentType(String,
75          *      String)
76          */
77         protected String getContentType(String parent, String view) {
78                 if (parent == null) {
79                         if (view == IDocument.DEFAULT_CONTENT_TYPE) {
80                                 return PHP_TEMPLATE_DATA;
81                         }
82                 } else {
83                         if (view == IDocument.DEFAULT_CONTENT_TYPE) {
84                                 return PHP_SCRIPT_CODE;
85                         }
86                 }
87
88                 return super.getContentType(parent, view);
89         }
90
91         public String[] getLegalContentTypes() {
92                 return LEGAL_TYPES;
93         }
94 }