updating version for 1.2.3 release
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpdt / externaltools / variable / ExpandVariableContext.java
1 package net.sourceforge.phpdt.externaltools.variable;
2
3 /**********************************************************************
4  Copyright (c) 2002 IBM Corp. and others. All rights reserved.
5  This file is made available under the terms of the Common Public License v1.0
6  which accompanies this distribution, and is available at
7  http://www.eclipse.org/legal/cpl-v10.html
8  �
9  Contributors:
10  **********************************************************************/
11
12 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
13
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.resources.IncrementalProjectBuilder;
17
18 /**
19  * Represents the context the external tool is running in that a variable uses
20  * to expand itself.
21  */
22 public final class ExpandVariableContext {
23         public static final ExpandVariableContext EMPTY_CONTEXT = new ExpandVariableContext(
24                         null);
25
26         private IProject project = null;
27
28         private IResource selectedResource = null;
29
30         private String buildType = IExternalToolConstants.BUILD_TYPE_NONE;
31
32         /**
33          * Create a context for an external tool running as a builder on the given
34          * project.
35          * 
36          * @param project
37          *            the <code>IProject</code> being built.
38          * @param buildKind
39          *            the kind of build being performed (see
40          *            <code>IncrementalProjectBuilder</code>).
41          */
42         public ExpandVariableContext(IProject project, int buildKind) {
43                 super();
44                 this.project = project;
45                 switch (buildKind) {
46                 case IncrementalProjectBuilder.INCREMENTAL_BUILD:
47                         this.buildType = IExternalToolConstants.BUILD_TYPE_INCREMENTAL;
48                         break;
49                 case IncrementalProjectBuilder.FULL_BUILD:
50                         this.buildType = IExternalToolConstants.BUILD_TYPE_FULL;
51                         break;
52                 case IncrementalProjectBuilder.AUTO_BUILD:
53                         this.buildType = IExternalToolConstants.BUILD_TYPE_AUTO;
54                         break;
55                 default:
56                         this.buildType = IExternalToolConstants.BUILD_TYPE_NONE;
57                         break;
58                 }
59         }
60
61         /**
62          * Create a context for an external tool running with the given resource
63          * selected.
64          * 
65          * @param selectedResource
66          *            the <code>IResource</code> selected or <code>null</code>
67          *            if none.
68          */
69         public ExpandVariableContext(IResource selectedResource) {
70                 super();
71                 if (selectedResource != null) {
72                         this.selectedResource = selectedResource;
73                         this.project = selectedResource.getProject();
74                 }
75         }
76
77         /**
78          * Returns the build type being performed if the external tool is being run
79          * as a project builder.
80          * 
81          * @return one of the <code>IExternalToolConstants.BUILD_TYPE_*</code>
82          *         constants.
83          */
84         public String getBuildType() {
85                 return buildType;
86         }
87
88         /**
89          * Returns the project which the variable can use. This will the the project
90          * being built if the tool is being run as a builder. Otherwise, it is the
91          * project of the selected resource, or <code>null</code> if none.
92          * 
93          * @return the <code>IProject</code> or <code>null</code> if none
94          */
95         public IProject getProject() {
96                 return project;
97         }
98
99         /**
100          * Returns the resource selected at the time the tool is run, or
101          * <code>null</code> if none selected.
102          * 
103          * @return the <code>IResource</code> selected, or <code>null</code> if
104          *         none
105          */
106         public IResource getSelectedResource() {
107                 return selectedResource;
108         }
109 }