001/*
002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved.
003 * 
004 * http://www.izforge.com/izpack/
005 * http://developer.berlios.de/projects/izpack/
006 * 
007 * Copyright 2003 Jonathan Halliday
008 * 
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *     http://www.apache.org/licenses/LICENSE-2.0
014 *     
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 */
021
022package com.izforge.izpack.panels;
023
024import java.io.IOException;
025
026import net.n3.nanoxml.XMLElement;
027
028import com.izforge.izpack.installer.AutomatedInstallData;
029import com.izforge.izpack.installer.PanelAutomation;
030import com.izforge.izpack.installer.PanelAutomationHelper;
031import com.izforge.izpack.installer.ProcessPanelWorker;
032import com.izforge.izpack.util.AbstractUIProcessHandler;
033
034/**
035 * Functions to support automated usage of the CompilePanel
036 * 
037 * @author Jonathan Halliday
038 * @author Tino Schwarze
039 */
040public class ProcessPanelAutomationHelper extends PanelAutomationHelper implements PanelAutomation,
041        AbstractUIProcessHandler
042{
043
044    private ProcessPanelWorker worker = null;
045
046    private int noOfJobs = 0;
047
048    private int currentJob = 0;
049
050    /**
051     * Save data for running automated.
052     * 
053     * @param installData installation parameters
054     * @param panelRoot unused.
055     */
056    public void makeXMLData(AutomatedInstallData installData, XMLElement panelRoot)
057    {
058        // not used here - during automatic installation, no automatic
059        // installation information is generated
060    }
061
062    /**
063     * Perform the installation actions.
064     * 
065     * @param panelRoot The panel XML tree root.
066     */
067    public void runAutomated(AutomatedInstallData idata, XMLElement panelRoot)
068    {
069        try
070        {
071            this.worker = new ProcessPanelWorker(idata, this);
072
073            this.worker.run();
074        }
075        catch (IOException e)
076        {
077            e.printStackTrace();
078        }
079
080    }
081
082    public void logOutput(String message, boolean stderr)
083    {
084        if (stderr)
085        {
086            System.err.println(message);
087        }
088        else
089        {
090            System.out.println(message);
091        }
092    }
093
094    /**
095     * Reports progress on System.out
096     * 
097     * @see com.izforge.izpack.util.AbstractUIProcessHandler#startProcessing(int)
098     */
099    public void startProcessing(int noOfJobs)
100    {
101        System.out.println("[ Starting processing ]");
102        this.noOfJobs = noOfJobs;
103    }
104
105    /**
106     * 
107     * @see com.izforge.izpack.util.AbstractUIProcessHandler#finishProcessing()
108     */
109    public void finishProcessing()
110    {
111        System.out.println("[ Processing finished ]");
112    }
113
114    /**
115     * 
116     */
117    public void startProcess(String name)
118    {
119        this.currentJob++;
120        System.out.println("Starting process " + name + " (" + Integer.toString(this.currentJob)
121                + "/" + Integer.toString(this.noOfJobs) + ")");
122    }
123
124    public void finishProcess()
125    {
126    }
127}