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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text.template.contentassist;
13 import java.util.HashMap;
16 import org.eclipse.jface.text.Assert;
17 import org.eclipse.jface.text.templates.TemplateVariable;
23 public class MultiVariable extends TemplateVariable {
24 private final Map fValueMap= new HashMap();
26 private Object fDefaultKey= null;
28 public MultiVariable(String type, String defaultValue, int[] offsets) {
29 super(type, defaultValue, offsets);
30 fValueMap.put(fDefaultKey, new String[] { defaultValue });
31 fSet= getDefaultValue();
35 * Sets the values of this variable under a specific set.
37 * @param set the set identifier for which the values are valid
38 * @param values the possible values of this variable
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) {
46 fSet= getDefaultValue();
52 * @see org.eclipse.jface.text.templates.TemplateVariable#setValues(java.lang.String[])
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();
65 * @see org.eclipse.jface.text.templates.TemplateVariable#getValues()
67 public String[] getValues() {
68 return (String[]) fValueMap.get(fDefaultKey);
72 * Returns the choices for the set identified by <code>set</code>.
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.
78 public String[] getValues(Object set) {
79 return (String[]) fValueMap.get(set);
85 public Object getSet() {
89 public void setSet(Object set) {