001/* 002 * Copyright 2016 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.core.ui.ribbonconfiguration; 017 018import java.util.ArrayList; 019import java.util.List; 020 021import org.slf4j.Logger; 022 023/** 024 * The class represents a menu, containing a list of ribbon elements 025 */ 026public class RibbonMenu 027{ 028 /** The App menu elements of the ribbon */ 029 protected List<Element> _menuElements = new ArrayList<>(); 030 031 private RibbonElementsInjectionHelper<Element> _injectionHelper; 032 033 /** 034 * Type of exclusion in the ribbon configuration 035 */ 036 public enum MENUTYPE 037 { 038 /** Excluding an extension */ 039 APPMENU("app-menu"), 040 /** Excluding a file */ 041 USERMENU("user-menu"); 042 043 private String _value; 044 045 private MENUTYPE(String value) 046 { 047 this._value = value; 048 } 049 050 @Override 051 public String toString() 052 { 053 return _value; 054 } 055 056 /** 057 * Converts a string to a MENUTYPE 058 * @param type The type to convert 059 * @return The exclude type corresponding to the string or null if unknown 060 */ 061 public static MENUTYPE createsFromString(String type) 062 { 063 for (MENUTYPE v : MENUTYPE.values()) 064 { 065 if (v.toString().equals(type)) 066 { 067 return v; 068 } 069 } 070 return null; 071 } 072 } 073 074 /** 075 * Get the list of elements contains in the menu 076 * @return The list of elements 077 */ 078 public List<Element> getElements() 079 { 080 return _menuElements; 081 } 082 083 /** 084 * Add a list of elements to the menu at the specified order index 085 * @param elements The list of elements 086 * @param order The order 087 * @param logger The logger 088 */ 089 public void addElements(List<Element> elements, String order, Logger logger) 090 { 091 if (elements.size() == 0) 092 { 093 return; 094 } 095 096 if (_injectionHelper == null) 097 { 098 _injectionHelper = new RibbonElementsInjectionHelper<>(_menuElements, logger); 099 } 100 101 for (Element element : elements) 102 { 103 _injectionHelper.injectElements(element, order); 104 } 105 } 106 107}