001// Generated by delombok at Fri Mar 22 16:21:46 GMT 2024
002/*
003 *  Licensed to the Apache Software Foundation (ASF) under one
004 *  or more contributor license agreements.  See the NOTICE file
005 *  distributed with this work for additional information
006 *  regarding copyright ownership.  The ASF licenses this file
007 *  to you under the Apache License, Version 2.0 (the
008 *  "License"); you may not use this file except in compliance
009 *  with the License.  You may obtain a copy of the License at
010 *
011 *        http://www.apache.org/licenses/LICENSE-2.0
012 *
013 *  Unless required by applicable law or agreed to in writing,
014 *  software distributed under the License is distributed on an
015 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 *  KIND, either express or implied.  See the License for the
017 *  specific language governing permissions and limitations
018 *  under the License.
019 */
020package org.apache.causeway.testing.h2console.ui.services;
021
022import java.util.Optional;
023import javax.annotation.Priority;
024import javax.inject.Inject;
025import javax.inject.Named;
026import org.apache.causeway.applib.CausewayModuleApplib;
027import org.apache.causeway.applib.annotation.Action;
028import org.apache.causeway.applib.annotation.ActionLayout;
029import org.apache.causeway.applib.annotation.DomainService;
030import org.apache.causeway.applib.annotation.DomainServiceLayout;
031import org.apache.causeway.applib.annotation.MemberSupport;
032import org.apache.causeway.applib.annotation.PriorityPrecedence;
033import org.apache.causeway.applib.annotation.RestrictTo;
034import org.apache.causeway.applib.annotation.SemanticsOf;
035import org.apache.causeway.applib.value.LocalResourcePath;
036import org.apache.causeway.core.config.CausewayConfiguration;
037import org.apache.causeway.testing.h2console.ui.CausewayModuleTestingH2ConsoleUi;
038import org.apache.causeway.testing.h2console.ui.webmodule.WebModuleH2Console;
039
040/**
041 * @since 2.0 {@index}
042 */
043@DomainService
044@Named(CausewayModuleTestingH2ConsoleUi.NAMESPACE + ".H2ManagerMenu")
045@DomainServiceLayout(named = "Prototyping", menuBar = DomainServiceLayout.MenuBar.SECONDARY)
046@Priority(PriorityPrecedence.EARLY)
047public class H2ManagerMenu {
048    private final WebModuleH2Console webModule;
049    private final CausewayConfiguration causewayConfiguration;
050
051
052    public static class ActionDomainEvent extends CausewayModuleApplib.ActionDomainEvent<H2ManagerMenu> {
053    }
054
055    @Action(semantics = SemanticsOf.SAFE, restrictTo = RestrictTo.PROTOTYPING, domainEvent = ActionDomainEvent.class)
056    @ActionLayout(named = "H2 Console", cssClassFa = "database", sequence = "500.800")
057    public LocalResourcePath openH2Console() {
058        return getPathToH2Console().orElse(null);
059    }
060
061    @MemberSupport
062    public boolean hideOpenH2Console() {
063        return getPathToH2Console().isEmpty();
064    }
065
066    // -- HELPER
067    private Optional<LocalResourcePath> getPathToH2Console() {
068        return Optional.ofNullable(webModule).map(WebModuleH2Console::getLocalResourcePathIfEnabled);
069    }
070
071    @Inject
072    @java.lang.SuppressWarnings("all")
073    public H2ManagerMenu(final WebModuleH2Console webModule, final CausewayConfiguration causewayConfiguration) {
074        this.webModule = webModule;
075        this.causewayConfiguration = causewayConfiguration;
076    }
077}