/*
 * SwingApplicationContextChangedInvoker.java  $Revision: 1.5 $  $Date: 2007/10/03 04:39:40 $
 *
 * Copyright (C) 2007 Meldcraft Corporation
 *
 * This file is part of Scaffold.
 * 
 * Scaffold is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Scaffold is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with Scaffold.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.meldcraft.application.swing;

import com.meldcraft.application.ApplicationContextChangedInvoker;
import com.meldcraft.application.ApplicationElementContext;
import com.meldcraft.gui.swing.SwingUtil;
import com.meldcraft.util.PropertiesHelper;

/**
 * @version $Revision: 1.5 $ $Date: 2007/10/03 04:39:40 $
 * @author Rob Richards
 */
public class SwingApplicationContextChangedInvoker extends ApplicationContextChangedInvoker
{
    public SwingApplicationContextChangedInvoker(ApplicationElementContext context)
    {
        super(context);
        Object check = (SwingApplicationContext)context.getApplicationContext();
    }

    protected void preInvokeMethod(Object target, String method, Object[] args)
    {
        boolean busy = getShowBusyCursor();
        if (busy)
        {
            SwingUtil.setBusyCursor(((SwingApplicationContext)mElementContext.getApplicationContext()).getUIRoot());
        }

        super.preInvokeMethod(target, method, args);
    }

    protected void postInvokeMethod(Object target, String method, Object[] args, Object result, Throwable error, boolean stopped)
    {
        try
        {
            super.postInvokeMethod(target, method, args, result, error, stopped);
        }
        finally
        {
            boolean busy = getShowBusyCursor();
            if (busy)
            {
                SwingUtil.setBusyCursor(((SwingApplicationContext)mElementContext.getApplicationContext()).getUIRoot(), false);
            }
        }
    }

    protected boolean getShowBusyCursor()
    {
        return PropertiesHelper.getBoolean(mConfig, "busyCursor", false); 
    }
}



