001
014
015 package com.liferay.portal.kernel.lar;
016
017
020 public class PortletDataHandlerChoice extends PortletDataHandlerControl {
021
022 public PortletDataHandlerChoice(String namespace, String controlName) {
023 this(namespace, controlName, 0, _DEFAULT_CHOICES);
024 }
025
026 public PortletDataHandlerChoice(
027 String namespace, String controlName, int defaultChoice) {
028
029 this(namespace, controlName, defaultChoice, _DEFAULT_CHOICES);
030 }
031
032 public PortletDataHandlerChoice(
033 String namespace, String controlName, int defaultChoice,
034 String[] choices) {
035
036 super(namespace, controlName);
037
038 _choices = choices;
039 _defaultChoice = defaultChoice;
040 }
041
042 public String[] getChoices() {
043 if ((_choices == null) || (_choices.length < 1)) {
044 return _DEFAULT_CHOICES;
045 }
046 else {
047 return _choices;
048 }
049 }
050
051 public String getDefaultChoice() {
052 return getChoices()[getDefaultChoiceIndex()];
053 }
054
055 public int getDefaultChoiceIndex() {
056 if ((_defaultChoice < 0) || (_defaultChoice >= _choices.length)) {
057 return 0;
058 }
059 else {
060 return _defaultChoice;
061 }
062 }
063
064 private static final String[] _DEFAULT_CHOICES = new String[] {
065 "false", "true"
066 };
067
068 private String[] _choices;
069 private int _defaultChoice;
070
071 }