001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *        http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 */
019package org.apache.causeway.viewer.commons.applib.services.menu;
020
021import org.springframework.lang.Nullable;
022
023import org.apache.causeway.commons.internal.base._Strings;
024import org.apache.causeway.core.metamodel.interactions.managed.ManagedAction;
025
026import lombok.NonNull;
027import lombok.Value;
028import lombok.val;
029
030@Value(staticConstructor = "of")
031public class MenuItemDto {
032
033    @NonNull
034    private final String name;
035
036    @Nullable
037    private final String cssClassFa;
038
039    @Nullable // eg. topLevel
040    private final ManagedAction managedAction;
041
042    private final boolean isTertiaryRoot;
043
044    public static MenuItemDto topLevel(final String name, final String cssClassFa) {
045        return of(name, cssClassFa, null, false);
046    }
047
048    public static MenuItemDto tertiaryRoot(final String name, final String cssClassFa) {
049        return of(name, cssClassFa, null, true);
050    }
051
052    public static MenuItemDto subMenu(@NonNull final ManagedAction managedAction, final String named, final String cssClassFa) {
053        val name = _Strings.isNotEmpty(named)
054                ? named
055                : managedAction.getFriendlyName();
056        return of(name, cssClassFa, managedAction, false);
057    }
058
059}