1) Reintroduced PHPPerspectiveFactory (was lost with refactoring).
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpdt / internal / corext / template / php / HTMLContextType.java
1 /*
2  * (c) Copyright IBM Corp. 2000, 2001.
3  * All Rights Reserved.
4  */
5 package net.sourceforge.phpdt.internal.corext.template.php;
6
7 // import net.sourceforge.phpdt.core.ICompilationUnit;
8
9 import net.sourceforge.phpdt.core.ICompilationUnit;
10
11 import org.eclipse.jface.text.IDocument;
12 import org.eclipse.jface.text.templates.GlobalTemplateVariables;
13 import org.eclipse.jface.text.templates.TemplateException;
14 import org.eclipse.jface.text.templates.TemplateVariable;
15
16 /**
17  * A context type for javadoc.
18  */
19 public class HTMLContextType extends CompilationUnitContextType {
20
21         /**
22          * Creates a java context type.
23          */
24         public HTMLContextType() {
25                 super("html"); //$NON-NLS-1$
26
27                 // global
28                 addResolver(new GlobalTemplateVariables.Cursor());
29                 addResolver(new GlobalTemplateVariables.WordSelection());
30                 addResolver(new GlobalTemplateVariables.LineSelection());
31                 addResolver(new GlobalTemplateVariables.Dollar());
32                 addResolver(new GlobalTemplateVariables.Date());
33                 addResolver(new GlobalTemplateVariables.Year());
34                 addResolver(new GlobalTemplateVariables.Time());
35                 addResolver(new GlobalTemplateVariables.User());
36
37                 addResolver(new File());
38         }
39
40         /*
41          * @see ContextType#createContext()
42          */
43         public CompilationUnitContext createContext(IDocument document, int offset,
44                         int length, ICompilationUnit compilationUnit) {
45                 return new HTMLUnitContext(this, document, offset, length,
46                                 compilationUnit);
47         }
48
49         /*
50          * (non-Javadoc)
51          * 
52          * @see net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContextType#createContext(org.eclipse.jface.text.IDocument,
53          *      int, int, net.sourceforge.phpdt.core.ICompilationUnit)
54          */
55         // public CompilationUnitContext createContext(IDocument document, int
56         // offset, int length, ICompilationUnit compilationUnit) {
57         // return new JavaDocContext(this, document, offset, length,
58         // compilationUnit);
59         // }
60         /*
61          * (non-Javadoc)
62          * 
63          * @see net.sourceforge.phpdt.internal.corext.template.ContextType#validateVariables(net.sourceforge.phpdt.internal.corext.template.TemplateVariable[])
64          */
65         protected void validateVariables(TemplateVariable[] variables)
66                         throws TemplateException {
67                 // check for multiple cursor variables
68                 for (int i = 0; i < variables.length; i++) {
69                         TemplateVariable var = variables[i];
70                         if (var.getType().equals(GlobalTemplateVariables.Cursor.NAME)) {
71                                 if (var.getOffsets().length > 1) {
72                                         throw new TemplateException(
73                                                         JavaTemplateMessages
74                                                                         .getString("ContextType.error.multiple.cursor.variables")); //$NON-NLS-1$
75                                 }
76                         }
77                 }
78         }
79 }