001/* 002 * Copyright 2021 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.forms.question.types; 017 018import java.util.List; 019 020import org.ametys.plugins.forms.helper.FormElementDefinitionHelper; 021import org.ametys.plugins.forms.repository.FormQuestion; 022import org.ametys.runtime.i18n.I18nizableText; 023import org.ametys.runtime.model.ElementDefinition; 024import org.ametys.runtime.model.ModelItem; 025import org.ametys.runtime.model.SimpleViewItemGroup; 026import org.ametys.runtime.model.ViewElement; 027import org.ametys.runtime.model.type.ModelItemTypeConstants; 028 029/** 030 * Class for creating check box question type 031 */ 032public class CheckBoxQuestionType extends AbstractFormQuestionType 033{ 034 /** Constant for default value attribute */ 035 public static final String ATTRIBUTE_IS_CHECKED = "is-checked"; 036 037 /** Constant for default title */ 038 public static final String DEFAULT_TITLE = "PLUGIN_FORMS_QUESTION_DEFAULT_TITLE_CHECKBOX"; 039 040 @Override 041 protected List<ModelItem> _getModelItems() 042 { 043 List<ModelItem> modelItems = super._getModelItems(); 044 045 ElementDefinition<Boolean> checked = FormElementDefinitionHelper.getElementDefinition(ATTRIBUTE_IS_CHECKED, ModelItemTypeConstants.BOOLEAN_TYPE_ID, "PLUGINS_FORMS_QUESTIONS_DIALOG_BOOLEAN_DEFAULT_VALUE", "PLUGINS_FORMS_QUESTIONS_DIALOG_BOOLEAN_DEFAULT_VALUE_DESC", null); 046 modelItems.add(checked); 047 048 return modelItems; 049 } 050 051 @Override 052 protected SimpleViewItemGroup _getMainTab() 053 { 054 SimpleViewItemGroup mainFieldset = super._getMainTab(); 055 056 ViewElement checked = new ViewElement(); 057 checked.setDefinition((ElementDefinition< ? >) getModel().getModelItem(ATTRIBUTE_IS_CHECKED)); 058 mainFieldset.addViewItem(checked); 059 060 return mainFieldset; 061 } 062 063 public String getStorageType(FormQuestion question) 064 { 065 return ModelItemTypeConstants.BOOLEAN_TYPE_ID; 066 } 067 068 public I18nizableText getDefaultTitle() 069 { 070 return new I18nizableText("plugin.forms", DEFAULT_TITLE); 071 } 072}