Small fix to tidy up the run menu. Axel will likely roll this back once he gets more...
[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
20  * that a variable uses to expand itself.
21  */
22 public final class ExpandVariableContext {
23         public static final ExpandVariableContext EMPTY_CONTEXT = new ExpandVariableContext(null);
24         
25         private IProject project = null;
26         private IResource selectedResource = null;
27         private String buildType = IExternalToolConstants.BUILD_TYPE_NONE;
28         
29         /**
30          * Create a context for an external tool running
31          * as a builder on the given project.
32          * 
33          * @param project the <code>IProject</code> being built.
34          * @param buildKind the kind of build being performed
35          *              (see <code>IncrementalProjectBuilder</code>).
36          */
37         public ExpandVariableContext(IProject project, int buildKind) {
38                 super();
39                 this.project = project;
40                 switch (buildKind) {
41                         case IncrementalProjectBuilder.INCREMENTAL_BUILD :
42                                 this.buildType = IExternalToolConstants.BUILD_TYPE_INCREMENTAL;
43                                 break;
44                         case IncrementalProjectBuilder.FULL_BUILD :
45                                 this.buildType = IExternalToolConstants.BUILD_TYPE_FULL;
46                                 break;
47                         case IncrementalProjectBuilder.AUTO_BUILD :
48                                 this.buildType = IExternalToolConstants.BUILD_TYPE_AUTO;
49                                 break;
50                         default :
51                                 this.buildType = IExternalToolConstants.BUILD_TYPE_NONE;
52                                 break;
53                 }
54         }
55         
56         /**
57          * Create a context for an external tool running
58          * with the given resource selected.
59          * 
60          * @param selectedResource the <code>IResource</code> selected
61          *              or <code>null</code> if none.
62          */
63         public ExpandVariableContext(IResource selectedResource) {
64                 super();
65                 if (selectedResource != null) {
66                         this.selectedResource = selectedResource;
67                         this.project = selectedResource.getProject();
68                 }
69         }
70         
71         /**
72          * Returns the build type being performed if the
73          * external tool is being run as a project builder.
74          * 
75          * @return one of the <code>IExternalToolConstants.BUILD_TYPE_*</code> constants.
76          */
77         public String getBuildType() {
78                 return buildType;
79         }
80         
81         /**
82          * Returns the project which the variable can use. This
83          * will the the project being built if the tool is being
84          * run as a builder. Otherwise, it is the project of the
85          * selected resource, or <code>null</code> if none.
86          * 
87          * @return the <code>IProject</code> or <code>null</code> if none
88          */
89         public IProject getProject() {
90                 return project;
91         }
92         
93         /**
94          * Returns the resource selected at the time the tool
95          * is run, or <code>null</code> if none selected.
96          * 
97          * @return the <code>IResource</code> selected, or <code>null</code> if none
98          */
99         public IResource getSelectedResource() {
100                 return selectedResource;
101         }
102 }