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.kernel.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  
31          this(namespace, controlName, defaultChoice, _DEFAULT_CHOICES);
32      }
33  
34      public PortletDataHandlerChoice(
35          String namespace, String controlName, int defaultChoice,
36          String[] choices) {
37  
38          super(namespace, controlName);
39  
40          _choices = choices;
41          _defaultChoice = defaultChoice;
42      }
43  
44      public String[] getChoices() {
45          if ((_choices == null) || (_choices.length < 1)) {
46              return _DEFAULT_CHOICES;
47          }
48          else {
49              return _choices;
50          }
51      }
52  
53      public String getDefaultChoice() {
54          return getChoices()[getDefaultChoiceIndex()];
55      }
56  
57      public int getDefaultChoiceIndex() {
58          if ((_defaultChoice < 0) || (_defaultChoice >= _choices.length)) {
59              return 0;
60          }
61          else {
62              return _defaultChoice;
63          }
64      }
65  
66      private static final String[] _DEFAULT_CHOICES = new String[] {
67          "false", "true"
68      };
69  
70      private String[] _choices;
71      private int _defaultChoice;
72  
73  }