com.foreach.across.modules.entity.handlers.MenuEventsHandler Maven / Gradle / Ivy
/*
* Copyright 2014 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.foreach.across.modules.entity.handlers;
import com.foreach.across.core.annotations.AcrossEventHandler;
import com.foreach.across.core.annotations.Event;
import com.foreach.across.core.context.info.AcrossModuleInfo;
import com.foreach.across.modules.adminweb.menu.AdminMenuEvent;
import com.foreach.across.modules.adminweb.menu.EntityAdminMenuEvent;
import com.foreach.across.modules.entity.registry.EntityAssociation;
import com.foreach.across.modules.entity.registry.EntityConfiguration;
import com.foreach.across.modules.entity.registry.EntityRegistry;
import com.foreach.across.modules.entity.support.EntityMessageCodeResolver;
import com.foreach.across.modules.entity.views.support.EntityMessages;
import com.foreach.across.modules.entity.web.EntityLinkBuilder;
import com.foreach.across.modules.spring.security.actions.AllowableAction;
import com.foreach.across.modules.spring.security.actions.AllowableActions;
import com.foreach.across.modules.web.menu.PathBasedMenuBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
@AcrossEventHandler
public class MenuEventsHandler
{
@Autowired
private EntityRegistry entityRegistry;
@Event
public void adminMenu( AdminMenuEvent adminMenuEvent ) {
PathBasedMenuBuilder builder = adminMenuEvent.builder();
builder.item( "/entities", "Entity management" );
for ( EntityConfiguration entityConfiguration : entityRegistry.getEntities() ) {
AllowableActions allowableActions = entityConfiguration.getAllowableActions();
if ( !entityConfiguration.isHidden() && allowableActions.contains( AllowableAction.READ ) ) {
EntityMessageCodeResolver messageCodeResolver = entityConfiguration.getEntityMessageCodeResolver();
EntityMessages messages = new EntityMessages( messageCodeResolver );
EntityLinkBuilder linkBuilder = entityConfiguration.getAttribute( EntityLinkBuilder.class );
AcrossModuleInfo moduleInfo = entityConfiguration.getAttribute( AcrossModuleInfo.class );
String group = "/entities";
if ( moduleInfo != null ) {
group = "/entities/" + moduleInfo.getName();
builder.group( group, moduleInfo.getName() ).disable();
}
builder.item( group + "/" + entityConfiguration.getName(),
messageCodeResolver.getNameSingular(),
linkBuilder.overview() );
if ( allowableActions.contains( AllowableAction.CREATE ) ) {
builder.item( group + "/" + entityConfiguration.getName() + "/create",
messages.createAction(),
linkBuilder.create()
);
}
}
}
}
@Event
@SuppressWarnings("unchecked")
public void entityMenu( EntityAdminMenuEvent menu ) {
PathBasedMenuBuilder builder = menu.builder();
EntityConfiguration
© 2015 - 2024 Weber Informatics LLC | Privacy Policy