001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.lar;
016    
017    /**
018     * @author Raymond Aug??
019     */
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    }