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