All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.chandre.admintool.core.AdminToolImpl Maven / Gradle / Ivy

package de.chandre.admintool.core;

import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import de.chandre.admintool.core.component.AdminComponent;
import de.chandre.admintool.core.component.AdminComponentComparator;
import de.chandre.admintool.core.component.MenuEntry;

/**
 * the admin tool
* * create a new {@link AdminComponent} and use {@link AdminTool#addComponent(AdminComponent)} to get it displayed * * @author Andre * */ @Component("adminTool") public class AdminToolImpl implements AdminTool { private static final Log LOGGER = LogFactory.getLog(AdminToolImpl.class); private Set components = new TreeSet<>(new AdminComponentComparator()); private Map globalJavaScripts = new LinkedHashMap<>(); private Map globalStyleSheets = new LinkedHashMap<>(); @Override public void setComponentComparator(Comparator comparator) { if (null == comparator) { this.components = new TreeSet<>(); } else { Set newComponents = new TreeSet<>(new AdminComponentComparator()); newComponents.addAll(this.components); this.components = newComponents; } } /** * @return the components */ @Override public Set getComponents() { return components; } /** * @param components the components to set */ @Override public void addComponent(AdminComponent components) { this.components.add(components); } /** * @param components the components to set */ @Override public void addComponents(Set components) { this.components.addAll(components); } public void setComponents(Set components) { this.components = components; } @Override public Map getGlobalJavaScripts() { return globalJavaScripts; } public void setGlobalJavaScripts(Map globalJavaScripts) { this.globalJavaScripts = globalJavaScripts; } @Override public void addGlobalJavaScript(String globalJavaScript, boolean local) { this.globalJavaScripts.put(globalJavaScript, local); } @Override public Map getGlobalStyleSheets() { return globalStyleSheets; } public void setGlobalStyleSheet(Map globalStyleSheets) { this.globalStyleSheets = globalStyleSheets; } @Override public void addGlobalStyleSheet(String globalStyleSheet, boolean local) { this.globalStyleSheets.put(globalStyleSheet, local); } @Override public MenuEntrySearchResult searchComponent(final String menuName) { MenuEntrySearchResult result = null; LOGGER.debug("search for component for menuName: " + menuName); Optional menuEntry = Optional.empty(); for (AdminComponent comp : getComponents()) { menuEntry = comp.getMainMenu().flattened().filter(entry -> null != entry.getName() && entry.getName().equals(menuName)).findFirst(); if (menuEntry.isPresent()) { result = new MenuEntrySearchResult(comp, menuEntry.get()); break; } } if (null == result && menuName.lastIndexOf('/') != -1) { result = searchComponent(menuName.substring(0, menuName.lastIndexOf('/'))); } return result; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy