001/*
002 *  Copyright 2015 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.runtime.workspaces.admin;
017
018import java.io.IOException;
019
020import org.apache.excalibur.source.Source;
021
022import org.ametys.runtime.plugin.PluginsManager;
023import org.ametys.runtime.plugin.PluginsManager.Status;
024
025/**
026 * Admin workspace handling safe mode.
027 */
028public class WorkspaceGenerator extends org.ametys.plugins.core.ui.WorkspaceGenerator
029{
030    @Override
031    protected Source getRibbonConfiguration() throws IOException
032    {
033        if (PluginsManager.getInstance().isSafeMode())
034        {
035            Status status = PluginsManager.getInstance().getStatus();
036            if (status == Status.RUNTIME_NOT_LOADED || status == Status.WRONG_DEFINITIONS)
037            {
038                return _resolver.resolveURI("resource://org/ametys/runtime/workspaces/admin/admin-safe-ribbon-broken.xml");
039            }
040            else
041            {
042                return _resolver.resolveURI("resource://org/ametys/runtime/workspaces/admin/admin-safe-ribbon.xml");
043            }
044        }
045        
046        return super.getRibbonConfiguration();
047    }
048    
049    @Override
050    protected Source getUIToolsConfiguration() throws IOException
051    {
052        if (PluginsManager.getInstance().isSafeMode())
053        {
054            Status status = PluginsManager.getInstance().getStatus();
055            if (status == Status.CONFIG_INCOMPLETE || status == Status.NO_CONFIG)
056            {
057                return _resolver.resolveURI("resource://org/ametys/runtime/workspaces/admin/admin-safe-uitools-noconfig.xml");
058            }
059            else
060            {
061                return _resolver.resolveURI("resource://org/ametys/runtime/workspaces/admin/admin-safe-uitools.xml");
062            }
063        }
064        
065        return super.getUIToolsConfiguration();
066    }
067}