Syntax highlighting is changeable.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / template / contentassist / MultiVariable.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation 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://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text.template.contentassist;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import org.eclipse.jface.text.Assert;
17 import org.eclipse.jface.text.templates.TemplateVariable;
18
19
20 /**
21  * 
22  */
23 public class MultiVariable extends TemplateVariable {
24         private final Map fValueMap= new HashMap();
25         private Object fSet;
26         private Object fDefaultKey= null;
27         
28         public MultiVariable(String type, String defaultValue, int[] offsets) {
29                 super(type, defaultValue, offsets);
30                 fValueMap.put(fDefaultKey, new String[] { defaultValue });
31                 fSet= getDefaultValue();
32         }
33         
34         /**
35          * Sets the values of this variable under a specific set.
36          * 
37          * @param set the set identifier for which the values are valid
38          * @param values the possible values of this variable
39          */
40         public void setValues(Object set, String[] values) {
41                 Assert.isNotNull(set);
42                 Assert.isTrue(values.length > 0);
43                 fValueMap.put(set, values);
44                 if (fDefaultKey == null) {
45                         fDefaultKey= set;
46                         fSet= getDefaultValue();
47                 }
48         }
49         
50         
51         /*
52          * @see org.eclipse.jface.text.templates.TemplateVariable#setValues(java.lang.String[])
53          */
54         public void setValues(String[] values) {
55                 if (fValueMap != null) {
56                         Assert.isNotNull(values);
57                         Assert.isTrue(values.length > 0);
58                         fValueMap.put(fDefaultKey, values);
59                         fSet= getDefaultValue();
60                 }
61         }
62         
63         
64         /*
65          * @see org.eclipse.jface.text.templates.TemplateVariable#getValues()
66          */
67         public String[] getValues() {
68                 return (String[]) fValueMap.get(fDefaultKey);
69         }
70         
71         /**
72          * Returns the choices for the set identified by <code>set</code>.
73          * 
74          * @param set the set identifier
75          * @return the choices for this variable and the given set, or
76          *         <code>null</code> if the set is not defined.
77          */
78         public String[] getValues(Object set) {
79                 return (String[]) fValueMap.get(set);
80         }
81
82         /**
83          * @return
84          */
85         public Object getSet() {
86                 return fSet;
87         }
88         
89         public void setSet(Object set) {
90                 fSet= set;
91         }
92
93 }