001/*
002 *  Copyright 2018 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.runtime.model;
017
018import java.util.Map;
019import java.util.Set;
020
021import org.xml.sax.ContentHandler;
022import org.xml.sax.SAXException;
023
024import org.ametys.runtime.i18n.I18nizableText;
025import org.ametys.runtime.model.checker.ItemCheckerDescriptor;
026import org.ametys.runtime.model.disableconditions.DisableCondition;
027import org.ametys.runtime.model.disableconditions.DisableConditions;
028import org.ametys.runtime.model.type.ModelItemType;
029import org.ametys.runtime.util.ModifiableLabelable;
030
031/**
032 * Interface for model items
033 */
034public interface ModelItem extends ModifiableLabelable, Comparable<ModelItem>
035{
036    /** Separator used for item paths in definitions */
037    public static final String ITEM_PATH_SEPARATOR = "/";
038    
039    /**
040     * Returns the {@link ItemCheckerDescriptor}s associated with this group.
041     * @return the {@link ItemCheckerDescriptor}s associated with this group.
042     */
043    public Set<ItemCheckerDescriptor> getItemCheckers();
044    
045    /**
046     * Add an item checker to the group
047     * @param itemChecker the item checker to add
048     */
049    public void addItemChecker(ItemCheckerDescriptor itemChecker);
050
051    /**
052     * Retrieves the path of the model item
053     * @return the item path
054     */
055    public String getPath();
056
057    /**
058     * Retrieves the model of the item
059     * @return the model
060     */
061    public Model getModel();
062    
063    /**
064     * Sets the model of the element
065     * @param model the model to set
066     */
067    public void setModel(Model model);
068    
069    /**
070     * Retrieves the parent of the item
071     * @return the parent group
072     */
073    public ModelItemGroup getParent();
074
075    /**
076     * Sets the parent of the item
077     * @param parent the parent to set
078     */
079    public void setParent(ModelItemGroup parent);
080    
081    /**
082     * Converts the model item in a JSON map
083     * @param context the context of the definition
084     * @return The model item as a JSON map, or an empty map
085     */
086    public Map<String, Object> toJSON(DefinitionContext context);
087    
088    /**
089     * Generates SAX events for the model item
090     * @param contentHandler the {@link ContentHandler} that will receive the SAX events 
091     * @param context the context of the definition
092     * @throws SAXException if an error occurs during the SAX events generation
093     */
094    public void toSAX(ContentHandler contentHandler, DefinitionContext context) throws SAXException;
095    
096    /**
097     * Retrieves the type.
098     * @return the type.
099     */
100    public ModelItemType getType();
101    
102    /**
103     * Set the type.
104     * @param type the type.
105     */
106    public void setType(ModelItemType type);
107    
108    /**
109     * Retrieves the name of the plugin declaring this element.
110     * @return the plugin name.
111     */
112    public String getPluginName();
113
114    /**
115     * Set the name of the plugin declaring this element.
116     * @param pluginName the plugin name.
117     */
118    public void setPluginName(String pluginName);
119    
120
121    /**
122     * Retrieves the widget to use for rendering.
123     * @return the widget or <code>null</code> if none is defined.
124     */
125    public String getWidget();
126
127    /**
128     * Set the widget.
129     * @param widget the widget.
130     */
131    public void setWidget(String widget);
132    
133    /**
134     * Get the widget's parameters
135     * @return the widget's parameters
136     */
137    public Map<String, I18nizableText> getWidgetParameters();
138    
139    /**
140     * Set the widget's parameters
141     * @param params the parameters to set
142     */
143    public void setWidgetParameters (Map<String, I18nizableText> params);
144    
145    /**
146     * Retrieves the disable condition.
147     * @return the disable condition or <code>null</code> if none is defined.
148     */
149    public DisableConditions<? extends DisableCondition> getDisableConditions();
150
151    /**
152     * Sets the disable condition.
153     * @param disableConditions the disable condition.
154     */
155    public void setDisableConditions(DisableConditions disableConditions);    
156}