1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.lar;
16  
17  /**
18   * <a href="PortletDataHandlerChoice.java.html"><b><i>View Source</i></b></a>
19   *
20   * @author Raymond Augé
21   */
22  public class PortletDataHandlerChoice extends PortletDataHandlerControl {
23  
24      public PortletDataHandlerChoice(String namespace, String controlName) {
25          this(namespace, controlName, 0, _DEFAULT_CHOICES);
26      }
27  
28      public PortletDataHandlerChoice(
29          String namespace, String controlName, int defaultChoice) {
30          this(namespace, controlName, defaultChoice, _DEFAULT_CHOICES);
31      }
32  
33      public PortletDataHandlerChoice(
34          String namespace, String controlName, int defaultChoice,
35          String[] choices) {
36  
37          super(namespace, controlName);
38  
39          _choices = choices;
40          _defaultChoice = defaultChoice;
41      }
42  
43      public String[] getChoices() {
44          if ((_choices == null) || (_choices.length < 1)) {
45              return _DEFAULT_CHOICES;
46          }
47          else {
48              return _choices;
49          }
50      }
51  
52      public String getDefaultChoice() {
53          return getChoices()[getDefaultChoiceIndex()];
54      }
55  
56      public int getDefaultChoiceIndex() {
57          if ((_defaultChoice < 0) || (_defaultChoice >= _choices.length)) {
58              return 0;
59          }
60          else {
61              return _defaultChoice;
62          }
63      }
64  
65      private static final String[] _DEFAULT_CHOICES = new String[] {
66          "false", "true"
67      };
68  
69      private String[] _choices;
70      private int _defaultChoice;
71  
72  }