replace deprecated org.eclipse.jface.util.ListenerList
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / 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.WebUI;
17 import net.sourceforge.phpeclipse.ui.text.rules.FlatNode;
18 import net.sourceforge.phpeclipse.ui.text.rules.MultiViewPartitioner;
19 import net.sourceforge.phpeclipse.ui.text.rules.ViewNode;
20
21 import org.eclipse.jface.text.Assert;
22 import org.eclipse.jface.text.IDocument;
23 import org.eclipse.jface.text.IDocumentPartitioner;
24 import org.eclipse.jface.text.rules.IPartitionTokenScanner;
25
26 /**
27  * 
28  * 
29  * @author Igor Malinin
30  */
31 public class PHPDocumentPartitioner extends MultiViewPartitioner {
32         public static final String PHP_TEMPLATE_DATA = "__php_template_data";
33
34         public static final String PHP_SCRIPT_CODE = "__php_script_code";
35
36         public static final String[] LEGAL_TYPES = { PHP_TEMPLATE_DATA,
37                         PHP_SCRIPT_CODE };
38
39         public PHPDocumentPartitioner(IPartitionTokenScanner scanner) {
40                 super(scanner);
41         }
42
43         protected FlatNode createNode(String type, int offset, int length) {
44                 if (type.equals(PHPPartitionScanner.PHP_SCRIPTING_AREA)) {
45                         if (DEBUG) {
46                                 Assert.isTrue(offset >= 0);
47                         }
48                         ViewNode node = new ViewNode(type);
49                         node.offset = offset;
50                         node.length = length;
51                         return node;
52                 }
53
54                 return super.createNode(type, offset, length);
55         }
56
57         /*
58          * @see net.sf.solareclipse.text.rules.DocumentViewPartitioner#createPartitioner(String)
59          */
60         protected IDocumentPartitioner createPartitioner(String contentType) {
61                 if (contentType == null) {
62                         // return JavaTextTools.createHTMLPartitioner();
63                         return WebUI.getDefault().getJavaTextTools()
64                                         .getXMLTextTools().createPHPXMLPartitioner();
65                 }
66
67                 if (contentType.equals(PHPPartitionScanner.PHP_SCRIPTING_AREA)) {
68                         return WebUI.getDefault().getJavaTextTools()
69                                         .createPHPPartitioner();
70                 }
71                 return null;
72         }
73
74         /*
75          * @see net.sf.solareclipse.text.rules.DocumentViewPartitioner#getContentType(String,
76          *      String)
77          */
78         protected String getContentType(String parent, String view) {
79                 if (parent == null) {
80                         if (view == IDocument.DEFAULT_CONTENT_TYPE) {
81                                 return PHP_TEMPLATE_DATA;
82                         }
83                 } else {
84                         if (view == IDocument.DEFAULT_CONTENT_TYPE) {
85                                 return PHP_SCRIPT_CODE;
86                         }
87                 }
88
89                 return super.getContentType(parent, view);
90         }
91
92         public String[] getLegalContentTypes() {
93                 return LEGAL_TYPES;
94         }
95 }