001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2007 JBoss Inc
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: package com.izforge.izpack.panels;
022:
023: import java.util.HashMap;
024: import java.util.Iterator;
025: import java.util.Vector;
026:
027: import net.n3.nanoxml.XMLElement;
028:
029: import com.izforge.izpack.Pack;
030: import com.izforge.izpack.installer.AutomatedInstallData;
031: import com.izforge.izpack.installer.PanelAutomation;
032: import com.izforge.izpack.panels.InstallationGroupPanel.GroupData;
033: import com.izforge.izpack.util.Debug;
034:
035: /**
036: * An automation helper for the InstallationGroupPanel
037: *
038: * @author Scott.Stark@jboss.org
039: * @version $Revision:$
040: */
041: public class InstallationGroupPanelAutomationHelper implements
042: PanelAutomation {
043: /**
044: *
045: */
046: public void makeXMLData(AutomatedInstallData idata,
047: XMLElement panelRoot) {
048: GroupData[] rows = (GroupData[]) idata
049: .getAttribute("GroupData");
050: HashMap packsByName = (HashMap) idata
051: .getAttribute("packsByName");
052: // Write out the group to pack mappings
053: for (GroupData gd : rows) {
054: XMLElement xgroup = new XMLElement("group");
055: xgroup.setAttribute("name", gd.name);
056: Iterator<String> names = gd.packNames.iterator();
057: while (names.hasNext()) {
058: String name = names.next();
059: Pack pack = (Pack) packsByName.get(name);
060: int index = idata.availablePacks.indexOf(pack);
061: XMLElement xpack = new XMLElement("pack");
062: xpack.setAttribute("name", name);
063: xpack.setAttribute("index", "" + index);
064: xgroup.addChild(xpack);
065: }
066: panelRoot.addChild(xgroup);
067: }
068: }
069:
070: /**
071: * TODO Need to add a InstallationGroupPanelAutomationHelper to read the
072: * xml data to allow an install group to specify the selected packs.
073: */
074: public boolean runAutomated(AutomatedInstallData idata,
075: XMLElement panelRoot) {
076: String installGroup = idata.getVariable("INSTALL_GROUP");
077: Debug
078: .trace("InstallationGroupPanelAutomationHelper: runAutomated, INSTALL_GROUP: "
079: + installGroup);
080: if (installGroup != null) {
081: Vector<XMLElement> groups = panelRoot
082: .getChildrenNamed("group");
083: for (XMLElement group : groups) {
084: String name = group.getAttribute("name");
085: Debug
086: .trace("InstallationGroupPanelAutomationHelper: Checking INSTALL_GROUP against: "
087: + name);
088: if (name.equalsIgnoreCase(installGroup)) {
089: Debug.trace("Found INSTALL_GROUP match for: "
090: + installGroup);
091: idata.selectedPacks.clear();
092: Vector<XMLElement> packs = group
093: .getChildrenNamed("pack");
094: Debug.trace(name + " pack count: " + packs.size());
095: Debug.trace("Available pack count: "
096: + idata.availablePacks.size());
097: for (XMLElement xpack : packs) {
098: String pname = xpack.getAttribute("name");
099: String indexStr = xpack.getAttribute("index");
100: int index = Integer.parseInt(indexStr);
101: if (index >= 0) {
102: Pack pack = (Pack) idata.availablePacks
103: .get(index);
104: idata.selectedPacks.add(pack);
105: Debug.trace("Added pack: " + pack.name);
106: }
107: }
108: Debug.trace("Set selectedPacks to: "
109: + idata.selectedPacks);
110: break;
111: }
112: }
113: }
114: return true;
115: }
116:
117: }
|