1) Reintroduced PHPPerspectiveFactory (was lost with refactoring).
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / 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 //incastrix
17 //import org.eclipse.jface.text.Assert;
18 import org.eclipse.core.runtime.Assert;
19 import org.eclipse.jface.text.templates.TemplateVariable;
20
21 /**
22  * 
23  */
24 public class MultiVariable extends TemplateVariable {
25         private final Map fValueMap = new HashMap();
26
27         private Object fSet;
28
29         private Object fDefaultKey = null;
30
31         public MultiVariable(String type, String defaultValue, int[] offsets) {
32                 super(type, defaultValue, offsets);
33                 fValueMap.put(fDefaultKey, new String[] { defaultValue });
34                 fSet = getDefaultValue();
35         }
36
37         /**
38          * Sets the values of this variable under a specific set.
39          * 
40          * @param set
41          *            the set identifier for which the values are valid
42          * @param values
43          *            the possible values of this variable
44          */
45 //      public void setValues(Object set, String[] values) {
46 //              Assert.isNotNull(set);
47 //              Assert.isTrue(values.length > 0);
48 //              fValueMap.put(set, values);
49 //              if (fDefaultKey == null) {
50 //                      fDefaultKey = set;
51 //                      fSet = getDefaultValue();
52 //              }
53 //      }
54
55         /*
56          * @see org.eclipse.jface.text.templates.TemplateVariable#setValues(java.lang.String[])
57          */
58         public void setValues(String[] values) {
59                 if (fValueMap != null) {
60                         Assert.isNotNull(values);
61                         Assert.isTrue(values.length > 0);
62                         fValueMap.put(fDefaultKey, values);
63                         fSet = getDefaultValue();
64                 }
65         }
66
67         /*
68          * @see org.eclipse.jface.text.templates.TemplateVariable#getValues()
69          */
70         public String[] getValues() {
71                 return (String[]) fValueMap.get(fDefaultKey);
72         }
73
74         /**
75          * Returns the choices for the set identified by <code>set</code>.
76          * 
77          * @param set
78          *            the set identifier
79          * @return the choices for this variable and the given set, or
80          *         <code>null</code> if the set is not defined.
81          */
82         public String[] getValues(Object set) {
83                 return (String[]) fValueMap.get(set);
84         }
85
86         /**
87          * @return
88          */
89         public Object getSet() {
90                 return fSet;
91         }
92
93         public void setSet(Object set) {
94                 fSet = set;
95         }
96
97 }