/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.editors.config;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.editors.helpers.AttributeValueLookup;
import de.innovationgate.eclipse.editors.tml.TMLRegion;
public class TMLTagAttribute {
public String getValueLookupClass() {
return _valueLookupClass;
}
public void setValueLookupClass(String valueLookupClass) {
_valueLookupClass = valueLookupClass;
}
private String _name;
private String _description;
private boolean _required = false;
private Set<String> _values = new HashSet<String>();
private String _valueLookupClass;
private boolean _valueHelpEnabled = true;
private Set<String> _validValues = new HashSet<String>();
private boolean _tmlscriptExpression = false;
private String _deprecated = null;
static Map<String, String> getXStreamAliasFields() {
Map<String,String> aliases = new HashMap<String, String>();
aliases.put("_name", "name");
aliases.put("_description", "description");
aliases.put("_required", "required");
aliases.put("_values", "values");
aliases.put("_valueLookupClass", "valueLookupClass");
aliases.put("_valueHelpEnabled", "valueHelpEnabled");
aliases.put("_validValues", "validValues");
aliases.put("_tmlscriptExpression", "tmlscriptExpression");
aliases.put("_deprecated", "deprecated");
return aliases;
}
public String getName() {
return _name;
}
public void setName(String name) {
_name = name;
}
public String getDescription() {
return _description;
}
public void setDescription(String description) {
_description = description;
}
public boolean isRequired() {
return _required;
}
public void setRequired(boolean required) {
_required = required;
}
public Set<String> computeValues(TMLRegion region, IDocument document, ITextViewer viewer, IFile activeFile) {
Set<String> allValues = new HashSet<String>(_values);
AttributeValueLookup lookup = null;
if (_valueLookupClass != null) {
try {
lookup = (AttributeValueLookup) Class.forName(_valueLookupClass.trim()).newInstance();
} catch (Exception e) {
Plugin.getDefault().logError("Unable to intitialize attribute value lookup '" + _valueLookupClass + "'.", e);
}
}
if (lookup != null) {
allValues.addAll(lookup.lookupValues(region, document, viewer, activeFile));
}
return allValues;
}
void setValues(Set<String> values) {
_values = values;
}
public boolean isValueHelpEnabled() {
return _valueHelpEnabled;
}
public void setValueHelpEnabled(boolean valueHelpEnabled) {
_valueHelpEnabled = valueHelpEnabled;
}
public Set<String> getValidValues() {
if (_validValues == null) {
_validValues = new HashSet<String>();
}
return _validValues;
}
public void setValidValues(Set<String> validValues) {
_validValues = validValues;
}
public boolean isTmlscriptExpression() {
return _tmlscriptExpression;
}
public void setTmlscriptExpression(boolean tmlscriptExpression) {
_tmlscriptExpression = tmlscriptExpression;
}
public String getDeprecated() {
return _deprecated;
}
public void setDeprecated(String deprecated) {
_deprecated = deprecated;
}
public boolean isDeprecated() {
if (_deprecated == null || _deprecated.trim().equals("")) {
return false;
} else {
return true;
}
}
}