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.web.administration.welcome;
017
018import java.util.List;
019import java.util.Map;
020
021import org.apache.avalon.framework.service.ServiceException;
022import org.apache.avalon.framework.service.ServiceManager;
023
024import org.ametys.core.ui.Callable;
025import org.ametys.core.ui.StaticClientSideElement;
026import org.ametys.runtime.plugin.PluginsManager;
027import org.ametys.runtime.plugin.PluginsManager.Status;
028
029/**
030 * Admin welcome client side element.
031 */
032public class AdminWelcomeClientSideElement extends StaticClientSideElement
033{
034    /** The WelcomeStep Extension Point */
035    protected WelcomeStepExtensionPoint _welcomeStepEP;
036
037    @Override
038    public void service(ServiceManager smanager) throws ServiceException
039    {
040        super.service(smanager);
041        _welcomeStepEP = (WelcomeStepExtensionPoint) smanager.lookup(WelcomeStepExtensionPoint.ROLE);
042    }
043    
044    /**
045     * Gets all the steps of the welcome tool, in the right order.
046     * @return The steps.
047     */
048    @Callable
049    public List<Map<String, Object>> getSteps()
050    {
051        return _welcomeStepEP.getStepsAsMap();
052    }
053    
054    /**
055     * Gets the index of the current step, i.e. the first step which is not performed yet.
056     * If all steps are performed, return -1
057     * @return The index of the current step.
058     */
059    @Callable
060    public int getCurrentStep()
061    {
062        return _welcomeStepEP.getCurrentStep();
063    }
064    
065    /**
066     * Returns true if the tool can be opened.
067     * @return true if the tool can be opened.
068     */
069    @Callable
070    public boolean canOpenTool()
071    {
072        Status status = PluginsManager.getInstance().getStatus();
073        return getCurrentStep() != -1 && (Status.NO_CONFIG.equals(status) || Status.CONFIG_INCOMPLETE.equals(status) || Status.OK.equals(status));
074    }
075}