diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/ibm/ServerWizard2/Launcher.java | 5 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/LibraryFile.java | 45 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/LibraryManager.java | 30 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/SdrRecord.java | 64 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/ServerWizard2.java | 37 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/SystemModel.java | 505 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/TargetWizardController.java | 264 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/controller/TargetWizardController.java | 267 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/Attribute.java (renamed from src/com/ibm/ServerWizard2/Attribute.java) | 16 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/AttributeValue.java (renamed from src/com/ibm/ServerWizard2/AttributeValue.java) | 4 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/AttributeValueComplex.java (renamed from src/com/ibm/ServerWizard2/AttributeValueComplex.java) | 23 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/AttributeValueNative.java (renamed from src/com/ibm/ServerWizard2/AttributeValueNative.java) | 30 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/AttributeValueSimple.java (renamed from src/com/ibm/ServerWizard2/AttributeValueSimple.java) | 14 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/Connection.java (renamed from src/com/ibm/ServerWizard2/Connection.java) | 4 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/ConnectionEndpoint.java (renamed from src/com/ibm/ServerWizard2/ConnectionEndpoint.java) | 2 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/Enumerator.java (renamed from src/com/ibm/ServerWizard2/Enumerator.java) | 4 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/Errata.java | 87 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/Field.java (renamed from src/com/ibm/ServerWizard2/Field.java) | 5 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/SystemModel.java | 834 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/Target.java (renamed from src/com/ibm/ServerWizard2/Target.java) | 246 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/XmlHandler.java (renamed from src/com/ibm/ServerWizard2/XmlHandler.java) | 14 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/utility/GithubFile.java (renamed from src/com/ibm/ServerWizard2/GithubFile.java) | 10 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/utility/MyLogFormatter.java (renamed from src/com/ibm/ServerWizard2/MyLogFormatter.java) | 2 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/ArrayDialogCellEditor.java (renamed from src/com/ibm/ServerWizard2/ArrayDialogCellEditor.java) | 6 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/ArrayEditingSupport.java (renamed from src/com/ibm/ServerWizard2/ArrayEditingSupport.java) | 2 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/ArrayEditorDialog.java (renamed from src/com/ibm/ServerWizard2/ArrayEditorDialog.java) | 2 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/ArrayLabelProvider.java (renamed from src/com/ibm/ServerWizard2/ArrayLabelProvider.java) | 2 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/AttributeEditingSupport.java (renamed from src/com/ibm/ServerWizard2/AttributeEditingSupport.java) | 19 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/AttributeValidator.java (renamed from src/com/ibm/ServerWizard2/AttributeValidator.java) | 4 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/DialogHandler.java (renamed from src/com/ibm/ServerWizard2/DialogHandler.java) | 2 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/ErrataViewer.java | 112 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/LogViewerDialog.java (renamed from src/com/ibm/ServerWizard2/LogViewerDialog.java) | 2 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/MainDialog.java (renamed from src/com/ibm/ServerWizard2/MainDialog.java) | 301 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/MessagePopup.java (renamed from src/com/ibm/ServerWizard2/MessagePopup.java) | 2 |
34 files changed, 1823 insertions, 1143 deletions
diff --git a/src/com/ibm/ServerWizard2/Launcher.java b/src/com/ibm/ServerWizard2/Launcher.java index 6acffd3..4f15e99 100644 --- a/src/com/ibm/ServerWizard2/Launcher.java +++ b/src/com/ibm/ServerWizard2/Launcher.java @@ -16,6 +16,11 @@ import java.util.zip.ZipFile; import javax.swing.JOptionPane; +import com.ibm.ServerWizard2.utility.GithubFile; +import com.ibm.ServerWizard2.utility.MyLogFormatter; +import com.ibm.ServerWizard2.view.DialogHandler; +import com.ibm.ServerWizard2.view.MessagePopup; + public class Launcher { public final static String JAR_NAME = "serverwiz2"; public final static String ZIP_NAME = "serverwiz2_lib.zip"; diff --git a/src/com/ibm/ServerWizard2/LibraryFile.java b/src/com/ibm/ServerWizard2/LibraryFile.java deleted file mode 100644 index 5d64f8b..0000000 --- a/src/com/ibm/ServerWizard2/LibraryFile.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.ibm.ServerWizard2; - -import java.io.File; - -public class LibraryFile { - private File localFile; - private String filepath; - private FileTypes type; - private long localFileSize=0; - - public enum FileTypes { - ATTRIBUTE_TYPE_XML, TARGET_TYPE_XML, TARGET_INSTANCES_XML, SCRIPT - } - - public LibraryFile(String filepath,FileTypes type) { - this.filepath=filepath; - this.type=type; - this.init(); - } - public static String getWorkingDir() { - // gets working directory whether running as jar or from eclipse - File f = new File("").getAbsoluteFile(); - String workingDir = f.getAbsolutePath() + System.getProperty("file.separator"); - return workingDir; - } - public boolean localFileExists() { - return this.localFileSize > 0; - } - public void init() { - String workingDir=LibraryFile.getWorkingDir(); - this.localFile = new File(workingDir+filepath); - if (this.localFile.exists()) { - localFileSize = this.localFile.length(); - } - } - public String getPath() { - return localFile.getPath(); - } - public String getFilename() { - return localFile.getName(); - } - public FileTypes getType() { - return type; - } -} diff --git a/src/com/ibm/ServerWizard2/LibraryManager.java b/src/com/ibm/ServerWizard2/LibraryManager.java deleted file mode 100644 index fae64c9..0000000 --- a/src/com/ibm/ServerWizard2/LibraryManager.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.ibm.ServerWizard2; - -import com.ibm.ServerWizard2.LibraryFile.FileTypes; - - -public class LibraryManager { - LibraryFile files[] = new LibraryFile[5]; - - public void loadModel(SystemModel model) throws Exception { - for (LibraryFile libFile : files) { - if (libFile.getType() == LibraryFile.FileTypes.ATTRIBUTE_TYPE_XML) { - model.loadAttributes(new XmlHandler(), libFile.getPath()); - } - if (libFile.getType() == LibraryFile.FileTypes.TARGET_TYPE_XML) { - model.loadTargetTypes(new XmlHandler(), libFile.getPath()); - } - if (libFile.getType() == LibraryFile.FileTypes.TARGET_INSTANCES_XML) { - model.loadTargetInstances(libFile.getPath()); - } - } - } - - public void init() { - files[0] = new LibraryFile("xml/attribute_types.xml",FileTypes.ATTRIBUTE_TYPE_XML); - files[1] = new LibraryFile("xml/attribute_types_hb.xml",FileTypes.ATTRIBUTE_TYPE_XML); - files[2] = new LibraryFile("xml/attribute_types_mrw.xml",FileTypes.ATTRIBUTE_TYPE_XML); - files[3] = new LibraryFile("xml/target_types_mrw.xml",FileTypes.TARGET_TYPE_XML); - files[4] = new LibraryFile("xml/target_instances_v3.xml",FileTypes.TARGET_INSTANCES_XML); - } -} diff --git a/src/com/ibm/ServerWizard2/SdrRecord.java b/src/com/ibm/ServerWizard2/SdrRecord.java deleted file mode 100644 index bb593d8..0000000 --- a/src/com/ibm/ServerWizard2/SdrRecord.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.ibm.ServerWizard2; - -import org.w3c.dom.Element; - -public class SdrRecord { - private String name = ""; - private String sdrName = ""; - private Integer sensorId = 0x00; - private Integer entityId = 0x00; - private Integer entityInstance = 0x00; - private Integer sensorType = 0x00; - private Target target = null; - private String entityName = ""; - - public String getAttributeValue() { - return String.format("0x%02X%02X,0x%02X", sensorType,entityId,sensorId); - } - public void setTarget(Target target) { - this.target=target; - } - public Target getTarget() { - return target; - } - public String getName() { - return name; - } - public String getSdrName() { - return sdrName; - } - public Integer getSensorId() { - return sensorId; - } - public Integer getSensorType() { - return sensorType; - } - - public Integer getEntityId() { - return entityId; - } - public Integer getEntityInstance() { - return entityInstance; - } - public void setEntityName(String entityName) { - this.entityName=entityName; - } - public String getEntityName() { - return this.entityName; - } - - public void readXML(Element t) throws Exception { - name = SystemModel.getElement(t, "name"); - try { - sensorId = Integer.decode(SystemModel.getElement(t, "sensor_id")); - entityId = Integer.decode(SystemModel.getElement(t, "entity_id")); - sensorType = Integer.decode(SystemModel.getElement(t, "sensor_type")); - entityInstance = Integer.decode(SystemModel.getElement(t, "entity_instance")); - } catch (Exception e) { - throw new Exception("Invalid SDR entry for: "+name); - } - } - public String toString() { - return String.format("%30s (%3d) Entity Id=%3d; Entity Inst=%3d; Sensor Type=%3d",name,sensorId,entityId,entityInstance,sensorType); - } -} diff --git a/src/com/ibm/ServerWizard2/ServerWizard2.java b/src/com/ibm/ServerWizard2/ServerWizard2.java index 3119483..ff4ee02 100644 --- a/src/com/ibm/ServerWizard2/ServerWizard2.java +++ b/src/com/ibm/ServerWizard2/ServerWizard2.java @@ -2,21 +2,33 @@ package com.ibm.ServerWizard2; import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; + +import com.ibm.ServerWizard2.controller.TargetWizardController; +import com.ibm.ServerWizard2.model.SystemModel; +import com.ibm.ServerWizard2.utility.MyLogFormatter; +import com.ibm.ServerWizard2.view.MainDialog; public class ServerWizard2 { /** * @param args */ public final static Logger LOGGER = Logger.getLogger(ServerWizard2.class.getName()); - public static void printUsage() { + public final static int VERSION_MAJOR = 2; + public final static int VERSION_MINOR = 1; + + public static String getVersionString() { + return VERSION_MAJOR+"."+VERSION_MINOR; + } + private static void printUsage() { System.out.println("Usage:"); System.out.println(" -i [xml filename]"); System.out.println(" -v [update to version]"); + System.out.println(" -f = run xml clean up"); System.out.println(" -h = print this usage"); } public static void main(String[] args) { String inputFilename=""; - String version=""; + Boolean cleanupMode = false; for (int i=0;i<args.length;i++) { if (args[i].equals("-i")) { if (i==args.length-1) { @@ -30,12 +42,14 @@ public class ServerWizard2 { printUsage(); System.exit(3); } - version=args[i+1]; } if (args[i].equals("-h")) { printUsage(); System.exit(0); } + if (args[i].equals("-f")) { + cleanupMode = true; + } } LOGGER.setLevel(Level.CONFIG); LOGGER.setUseParentHandlers(false); @@ -44,30 +58,19 @@ public class ServerWizard2 { LOGGER.addHandler(logConsole); MyLogFormatter formatter = new MyLogFormatter(); logConsole.setFormatter(formatter); - /* - try { - FileHandler logFile = new FileHandler("serverwiz2.%u.%g.log",20000,2,true); - LOGGER.addHandler(logFile); - logFile.setFormatter(formatter); - logFile.setLevel(Level.CONFIG); - } catch (IOException e) { - System.err.println("Unable to create logfile"); - System.exit(3); - } - */ + LOGGER.config("======================================================================"); - LOGGER.config("ServerWiz2 Starting..."); + LOGGER.config("ServerWiz2 Version "+getVersionString()+" Starting..."); TargetWizardController tc = new TargetWizardController(); SystemModel systemModel = new SystemModel(); MainDialog view = new MainDialog(null); tc.setView(view); tc.setModel(systemModel); - systemModel.addPropertyChangeListener(tc); view.setController(tc); + systemModel.cleanupMode = cleanupMode; if (!inputFilename.isEmpty()) { view.mrwFilename=inputFilename; } view.open(); - //d.dispose(); } } diff --git a/src/com/ibm/ServerWizard2/SystemModel.java b/src/com/ibm/ServerWizard2/SystemModel.java deleted file mode 100644 index 4e801cc..0000000 --- a/src/com/ibm/ServerWizard2/SystemModel.java +++ /dev/null @@ -1,505 +0,0 @@ -package com.ibm.ServerWizard2; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Writer; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; -import java.util.Vector; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -public class SystemModel { - // public Target rootTarget; - public Vector<Target> rootTargets = new Vector<Target>(); - private DocumentBuilder builder; - - // From target instances - private HashMap<String, Target> targetInstances = new HashMap<String, Target>(); - private Vector<Target> targetUnitList = new Vector<Target>(); - - // From target types - private TreeMap<String, Target> targetModels = new TreeMap<String, Target>(); - public HashMap<String, Vector<Target>> childTargetTypes = new HashMap<String, Vector<Target>>(); - - // From attribute types - public TreeMap<String, Enumerator> enumerations = new TreeMap<String, Enumerator>(); - public HashMap<String, Attribute> attributes = new HashMap<String, Attribute>(); - - // List of targets in current system - private Vector<Target> targetList = new Vector<Target>(); - private HashMap<String, Target> targetLookup = new HashMap<String, Target>(); - - private Vector<Target> busTypes = new Vector<Target>(); - private PropertyChangeSupport changes = new PropertyChangeSupport(this); - - private TreeMap<String, TreeMap<String, Field>> globalSettings = new TreeMap<String, TreeMap<String, Field>>(); - - public String logData; - - public void addPropertyChangeListener(PropertyChangeListener l) { - changes.addPropertyChangeListener(l); - } - - public Vector<Target> getBusTypes() { - return busTypes; - } - - public Target getTarget(String t) { - return targetLookup.get(t); - } - - public HashMap<String, Target> getTargetLookup() { - return this.targetLookup; - } - - public Vector<Target> getTargetList() { - return this.targetList; - } - - public Collection<Target> getTargetInstances() { - return targetInstances.values(); - } - - public Vector<Target> getConnectionCapableTargets() { - Vector<Target> cards = new Vector<Target>(); - for (Target target : targetList) { - if (target.isCard() || target.isSystem() || target.isNode()) { - //if (!target.isLibraryTarget) { - cards.add(target); - //} - } - } - return cards; - } - - public void initBusses(Target target) { - target.initBusses(busTypes); - } - - public Vector<Target> getChildTargetTypes(String targetType) { - if (targetType.equals("")) { - Vector<Target> a = new Vector<Target>(); - for (Target t : this.targetModels.values()) { - a.add(t); - } - return a; - } - if (childTargetTypes.get(targetType) != null) { - Collections.sort(childTargetTypes.get(targetType)); - } - return childTargetTypes.get(targetType); - } - - public Integer getEnumValue(String enumerator, String value) { - Enumerator e = enumerations.get(enumerator); - return e.getEnumInt(value); - } - - public String getEnumValueStr(String enumerator, String value) { - Enumerator e = enumerations.get(enumerator); - return e.getEnumStr(value); - } - - public static String getElement(Element a, String e) { - Node n = a.getElementsByTagName(e).item(0); - if (n != null) { - Node cn = n.getChildNodes().item(0); - if (cn == null) { - return ""; - } - return n.getChildNodes().item(0).getNodeValue(); - } - return ""; - } - - public static Boolean isElementDefined(Element a, String e) { - Node n = a.getElementsByTagName(e).item(0); - if (n != null) { - Node cn = n.getChildNodes().item(0); - if (cn == null) { - return true; - } - return true; - } - return false; - } - - public TreeMap<String, Target> getTargetModels() { - return targetModels; - } - - public Target getTargetModel(String t) { - return targetModels.get(t); - } - - public void deleteAllInstances() { - this.targetList.clear(); - this.targetLookup.clear(); - this.rootTargets.clear(); - this.globalSettings.clear(); - } - - public void deleteTarget(Target deleteTarget) { - targetList.remove(deleteTarget); - for (Target t : targetList) { - t.removeChildren(deleteTarget.getName()); - } - this.targetLookup.remove(deleteTarget.getName()); - changes.firePropertyChange("DELETE_TARGET", "", ""); - } - - // Reads a previously saved MRW - public void readXML(String filename) throws Exception { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - // delete all existing instances - this.deleteAllInstances(); - this.addUnitInstances(); - DocumentBuilder builder = factory.newDocumentBuilder(); - builder.setErrorHandler(new XmlHandler()); - Document document = builder.parse(filename); - - NodeList settingList = document.getElementsByTagName("globalSetting"); - for (int i = 0; i < settingList.getLength(); ++i) { - Element t = (Element) settingList.item(i); - this.readGlobalSettings(t); - } - - NodeList targetInstanceList = document.getElementsByTagName("targetInstance"); - for (int i = 0; i < targetInstanceList.getLength(); ++i) { - Element t = (Element) targetInstanceList.item(i); - String type = SystemModel.getElement(t, "type"); - if (type.length() > 0) { - Target targetModel = this.getTargetModel(type); - if (targetModel == null) { - ServerWizard2.LOGGER.severe("Invalid target type: " + type); - throw new Exception("Invalid target type: " + type); - } else { - Target target = new Target(targetModel); - target.initBusses(busTypes); - target.readInstanceXML(t, targetModels); - //if (this.targetLookup.containsKey(target.getName())) { - // ServerWizard2.LOGGER.warning("Duplicate Target: "+target.getName()); - //} else { - this.targetLookup.put(target.getName(), target); - this.targetList.add(target); - //} - if (target.getAttribute("CLASS").equals("SYS")) { - this.rootTargets.add(target); - } - /////// - // Check to see if new children defined in model - Target targetInst = this.targetInstances.get(target.getType()); - if (targetInst != null) { - HashMap <String,Boolean> childTest = new HashMap<String,Boolean>(); - for (String child : target.getAllChildren()) { - childTest.put(child, true); - } - for (String child : targetInst.getChildren()) { - if (childTest.get(child)==null) { - target.addChild(child, false); - if (!this.targetLookup.containsKey(child)) { - this.targetLookup.put(child, target); - this.targetList.add(target); - } - childTest.put(child, true); - } - } - for (String child : targetInst.getHiddenChildren()) { - if (childTest.get(child)==null) { - target.addChild(child, true); - if (!this.targetLookup.containsKey(child)) { - this.targetLookup.put(child,target); - this.targetList.add(target); - } - childTest.put(child, true); - } - } - } - } - } else { - throw new Exception("Empty Target Type"); - } - } - } - - public void writeEnumeration(Writer out) throws Exception { - for (String enumeration : enumerations.keySet()) { - Enumerator e = enumerations.get(enumeration); - out.write("<enumerationType>\n"); - out.write("\t<id>" + enumeration + "</id>\n"); - for (Map.Entry<String, String> entry : e.enumValues.entrySet()) { - out.write("\t\t<enumerator>\n"); - out.write("\t\t<name>" + entry.getKey() + "</name>\n"); - out.write("\t\t<value>" + entry.getValue() + "</value>\n"); - out.write("\t\t</enumerator>\n"); - } - out.write("</enumerationType>\n"); - } - } - - public Field setGlobalSetting(String path, String attribute, String value) { - TreeMap<String, Field> s = globalSettings.get(path); - if (s == null) { - s = new TreeMap<String, Field>(); - globalSettings.put(path, s); - } - Field f = s.get(attribute); - if (f == null) { - f = new Field(); - f.attributeName = attribute; - s.put(attribute, f); - } - f.value = value; - return f; - } - - public Boolean isGlobalSetting(String path, String attribute) { - TreeMap<String, Field> s = globalSettings.get(path); - if (s == null) { - return false; - } - Field f=s.get(attribute); - if (f==null) { - return false; - } - return true; - } - - public Field getGlobalSetting(String path, String attribute) { - TreeMap<String, Field> s = globalSettings.get(path); - if (s == null) { - Field f=this.setGlobalSetting(path, attribute, ""); - return f; - } - Field f=s.get(attribute); - if (f==null) { - f=this.setGlobalSetting(path, attribute, ""); - } - return f; - } - - public TreeMap<String, Field> getGlobalSettings(String path) { - TreeMap<String, Field> s = globalSettings.get(path); - return s; - } - - public void writeGlobalSettings(Writer out) throws Exception { - for (Map.Entry<String, TreeMap<String, Field>> entry : this.globalSettings.entrySet()) { - out.write("<globalSetting>\n"); - out.write("\t<id>" + entry.getKey() + "</id>\n"); - for (Map.Entry<String, Field> setting : entry.getValue().entrySet()) { - out.write("\t<property>\n"); - out.write("\t<id>" + setting.getKey() + "</id>\n"); - out.write("\t<value>" + setting.getValue().value + "</value>\n"); - out.write("\t</property>\n"); - } - out.write("</globalSetting>\n"); - } - } - - public void readGlobalSettings(Element setting) { - String targetId = SystemModel.getElement(setting, "id"); - NodeList propertyList = setting.getElementsByTagName("property"); - for (int i = 0; i < propertyList.getLength(); ++i) { - Element t = (Element) propertyList.item(i); - String property = SystemModel.getElement(t, "id"); - String value = SystemModel.getElement(t, "value"); - this.setGlobalSetting(targetId, property, value); - } - } - - // Writes MRW to file - public void writeXML(String filename) throws Exception { - Writer out = new BufferedWriter(new FileWriter(filename)); - out.write("<targetInstances>\n"); - this.writeEnumeration(out); - this.writeGlobalSettings(out); - HashMap<String, Boolean> targetWritten = new HashMap<String, Boolean>(); - for (Target target : targetList) { - target.writeInstanceXML(out, targetLookup, targetWritten); - } - out.write("</targetInstances>\n"); - out.close(); - } - - public void addTarget(Target parentTarget, Target newTarget) throws Exception { - if (parentTarget == null) { - this.rootTargets.add(newTarget); - } else { - parentTarget.addChild(newTarget.getName(), false); - } - this.updateTargetList(newTarget); - initBusses(newTarget); - changes.firePropertyChange("ADD_TARGET", "", ""); - } - - public Target getTargetInstance(String type) { - return targetInstances.get(type); - } - - // Add target to target database. - // only contains targets that user has added - // not library targets - public void updateTargetList(Target target) throws Exception { - String id = target.getName(); - if (!this.targetLookup.containsKey(id)) { - this.targetLookup.put(id, target); - this.targetList.add(target); - } else { - String msg="Duplicate Target: "+target.getName(); - ServerWizard2.LOGGER.warning(msg); - throw new Exception(msg); - } - } - - public void addParentAttributes(Target childTarget, Target t) { - if (t == null) { - return; - } - Target parent = targetModels.get(t.parent); - if (parent == null) { - return; - } - childTarget.copyAttributesFromParent(parent); - addParentAttributes(childTarget, parent); - } - - public void loadTargetTypes(DefaultHandler errorHandler, String fileName) throws SAXException, - IOException, ParserConfigurationException { - ServerWizard2.LOGGER.info("Loading Target Types: " + fileName); - - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - builder = factory.newDocumentBuilder(); - builder.setErrorHandler(errorHandler); - - Document document = builder.parse(fileName); - NodeList targetList = document.getElementsByTagName("targetType"); - for (int i = 0; i < targetList.getLength(); ++i) { - Element t = (Element) targetList.item(i); - Target target = new Target(); - target.readModelXML(t, attributes); - targetModels.put(target.getType(), target); - Vector<String> parentTypes = target.getParentType(); - for (int j = 0; j < parentTypes.size(); j++) { - String parentType = parentTypes.get(j); - Vector<Target> childTypes = childTargetTypes.get(parentType); - if (childTypes == null) { - childTypes = new Vector<Target>(); - childTargetTypes.put(parentType, childTypes); - } - childTypes.add(target); - } - } - for (Map.Entry<String, Target> entry : targetModels.entrySet()) { - Target target = entry.getValue(); - - // add inherited attributes - addParentAttributes(target, target); - if (target.getAttribute("CLASS").equals("BUS")) { - busTypes.add(target); - } - } - } - - public void loadAttributes(DefaultHandler errorHandler, String fileName) throws SAXException, - IOException, ParserConfigurationException { - ServerWizard2.LOGGER.info("Loading Attributes: " + fileName); - - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - builder = factory.newDocumentBuilder(); - builder.setErrorHandler(errorHandler); - - Document document = builder.parse(fileName); - NodeList enumList = document.getElementsByTagName("enumerationType"); - for (int i = 0; i < enumList.getLength(); ++i) { - Element t = (Element) enumList.item(i); - Enumerator en = new Enumerator(); - en.readXML(t); - enumerations.put(en.id, en); - } - NodeList attrList = document.getElementsByTagName("attribute"); - for (int i = 0; i < attrList.getLength(); ++i) { - Element t = (Element) attrList.item(i); - Attribute a = new Attribute(); - a.readModelXML(t); - attributes.put(a.name, a); - - if (a.getValue().getType().equals("enumeration")) { - a.getValue().setEnumerator(enumerations.get(a.name)); - } - } - } - - public void loadTargetInstances(String filename) throws Exception { - ServerWizard2.LOGGER.info("Loading Instances: " + filename); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - builder.setErrorHandler(new XmlHandler()); - Document document = builder.parse(filename); - NodeList targetInstanceList = document.getElementsByTagName("targetInstance"); - for (int i = 0; i < targetInstanceList.getLength(); ++i) { - Element t = (Element) targetInstanceList.item(i); - String type = SystemModel.getElement(t, "type"); - if (type.length() > 0) { - Target targetModel = this.getTargetModel(type); - if (targetModel == null) { - ServerWizard2.LOGGER.severe("Invalid target type: " + type); - throw new Exception("Invalid target type: " + type); - } else { - Target target = new Target(targetModel); - target.readInstanceXML(t, targetModels); - if (target.instanceModel) { - targetInstances.put(type, target); - target.isLibraryTarget = true; - } else { - // this.targetLookup.put(target.getName(), target); - this.targetUnitList.add(target); - target.isLibraryTarget = true; - } - } - } else { - throw new Exception("Empty Target Type"); - } - } - } - - public void addUnitInstances() { - for (Target target : this.targetUnitList) { - this.targetLookup.put(target.getName(), target); - } - } - - public void updateTargetPosition(Target target, Target parentTarget, int position) { - if (position > 0) { - target.setPosition(position); - return; - } - int p = -1; - // set target position to +1 of any target found of same type - for (Target t : targetList) { - if (t.getType().equals(target.getType())) { - if (t.getPosition() >= p) { - p = t.getPosition(); - } - } - } - target.setPosition(p + 1); - target.setSpecialAttributes(); - } -} diff --git a/src/com/ibm/ServerWizard2/TargetWizardController.java b/src/com/ibm/ServerWizard2/TargetWizardController.java deleted file mode 100644 index 0a6f0a1..0000000 --- a/src/com/ibm/ServerWizard2/TargetWizardController.java +++ /dev/null @@ -1,264 +0,0 @@ -package com.ibm.ServerWizard2; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.StringWriter; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; -import java.util.HashMap; -import java.util.TreeMap; -import java.util.Vector; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.TreeItem; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -public class TargetWizardController implements PropertyChangeListener { - SystemModel model; - MainDialog view; - LibraryManager xmlLib = new LibraryManager(); - private final String PROCESSING_SCRIPT="scripts/processMrw.pl"; - - public TargetWizardController() { - } - - public void init() { - xmlLib.init(); - try { - //xmlLib.update(version); - xmlLib.loadModel(model); - this.initModel(); - } catch (Exception e) { - ServerWizard2.LOGGER.severe(e.toString()); - MessageDialog.openError(null, "Error",e.toString()); - e.printStackTrace(); - System.exit(4); - } - } - public void initModel() throws Exception { - model.deleteAllInstances(); - model.addUnitInstances(); - - String parentTargetName = "sys-sys-power8"; - Target parentTarget = model.getTargetModels().get(parentTargetName); - if (parentTarget == null) { - throw new Exception("Parent model " + parentTargetName - + " is not valid"); - } - // Create root instance - Target sys = new Target(parentTarget); - sys.setPosition(0); - this.addTargetInstance(sys, null, null, ""); - //model.addTarget(null, sys); - } - - public Target getTargetModel(String type) { - return model.getTargetModel(type); - } - public void setView(MainDialog view) { - this.view = view; - } - - public void setModel(SystemModel model) { - this.model = model; - } - - public Vector<String> getEnums(String e) { - if (model.enumerations.get(e)==null) { - ServerWizard2.LOGGER.severe("Enum not found: "+e); - return null; - } - return model.enumerations.get(e).enumList; - } - public Boolean isEnum(String e) { - if (model.enumerations.get(e)==null) { - return false; - } - return true; - } - - - public void deleteTarget(Target target) { - //model.deleteTarget(target, model.rootTarget); - model.deleteTarget(target); - } - - public void addTargetInstance(Target targetModel, Target parentTarget, - TreeItem parentItem,String nameOverride) { - - Target targetInstance; - Target instanceCheck = model.getTargetInstance(targetModel.getType()); - if (instanceCheck!=null) { - //target instance found of this model type - targetInstance = new Target(instanceCheck); - targetInstance.copyChildren(instanceCheck); - } else { - targetInstance = new Target(targetModel); - } - targetInstance.setName(nameOverride); - model.updateTargetPosition(targetInstance, parentTarget, -1); - try { - model.addTarget(parentTarget, targetInstance); - view.updateInstanceTree(targetInstance, parentItem); - } catch (Exception e) { - MessageDialog.openError(null, "Add Target Error", e.getMessage()); - } - } - public Target copyTargetInstance(Target target, Target parentTarget,Boolean incrementPosition) { - Target newTarget = new Target(target); - if (incrementPosition) { - newTarget.setPosition(newTarget.getPosition()+1); - newTarget.setSpecialAttributes(); - } - try { - model.addTarget(parentTarget, newTarget); - newTarget.copyChildren(target); - } catch (Exception e) { - MessageDialog.openError(null, "Add Target Error", e.getMessage()); - newTarget=null; - } - return newTarget; - } - public void deleteConnection(Target target,Target busTarget,Connection conn) { - target.deleteConnection(busTarget,conn); - } - public Vector<Target> getRootTargets() { - return model.rootTargets; - } - - public void writeXML(String filename) { - try { - String tmpFilename=filename+".tmp"; - model.writeXML(tmpFilename); - File from = new File(tmpFilename); - File to = new File(filename); - Files.copy( from.toPath(), to.toPath(),StandardCopyOption.REPLACE_EXISTING ); - Files.delete(from.toPath()); - ServerWizard2.LOGGER.info(filename + " Saved"); - } catch (Exception exc) { - MessageDialog.openError(null, "Error", exc.getMessage()); - exc.printStackTrace(); - } - } - - public void readXML(String filename) { - try { - model.readXML(filename); - } catch (Exception e) { - MessageDialog.openError(null, "Error", e.getMessage()); - e.printStackTrace(); - } - } - public Vector<Target> getConnectionCapableTargets() { - return model.getConnectionCapableTargets(); - } - public void setGlobalSetting(String path,String attribute,String value) { - model.setGlobalSetting(path, attribute, value); - } - public Field getGlobalSetting(String path,String attribute) { - return model.getGlobalSetting(path, attribute); - } - public TreeMap<String,Field> getGlobalSettings(String path) { - return model.getGlobalSettings(path); - } - public Vector<Target> getChildTargets(Target target) { - //if (target.instanceModel) { - // return model.getChildTargetTypes(""); - //} - return model.getChildTargetTypes(target.getType()); - } - - public void hideBusses(Target target) { - target.hideBusses(model.getTargetLookup()); - } - public Vector<Target> getVisibleChildren(Target target,boolean showHidden) { - Vector<Target> children = new Vector<Target>(); - for (String c : target.getChildren()) { - Target t = model.getTarget(c); - if (t==null) { - String msg="Invalid Child target id: "+c; - ServerWizard2.LOGGER.severe(msg); - } - children.add(t); - } - if (showHidden) { - for (String c : target.getHiddenChildren()) { - Target t = model.getTarget(c); - if (t==null) { - String msg="Invalid Child target id: "+c; - ServerWizard2.LOGGER.severe(msg); - } - children.add(t); - } - } - return children; - } - - public void initBusses(Target target) { - model.initBusses(target); - } - public Vector<Target> getBusTypes() { - return model.getBusTypes(); - } - public void runChecks(String filename) { - String commandLine[] = { - "perl", - "-I", - LibraryFile.getWorkingDir(), - LibraryFile.getWorkingDir()+PROCESSING_SCRIPT, - "-x", - filename, - "-f" - }; - String commandLineStr=""; - for (int i=0;i<commandLine.length;i++) { - commandLineStr=commandLineStr+commandLine[i]+" "; - } - ServerWizard2.LOGGER.info("Running: "+commandLineStr); - try { - final ProcessBuilder builder = new ProcessBuilder(commandLine).redirectErrorStream(true); - - final Process process = builder.start(); - final StringWriter writer = new StringWriter(); - - new Thread(new Runnable() { - public void run() { - char[] buffer = new char[1024]; - int len; - InputStreamReader in = new InputStreamReader(process.getInputStream()); - - try { - while ((len = in.read(buffer)) != -1) { - writer.write(buffer, 0, len); - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - }).start(); - - final int exitValue = process.waitFor(); - final String processOutput = writer.toString(); - ServerWizard2.LOGGER.info(processOutput); - ServerWizard2.LOGGER.info("Return Code: "+exitValue); - LogViewerDialog dlg = new LogViewerDialog(null); - dlg.setData(processOutput); - dlg.open(); - } catch (Exception e){ - e.printStackTrace(); - } - } - - public void propertyChange(PropertyChangeEvent arg0) { - //view.setDirtyState(true); - } -}
\ No newline at end of file diff --git a/src/com/ibm/ServerWizard2/controller/TargetWizardController.java b/src/com/ibm/ServerWizard2/controller/TargetWizardController.java new file mode 100644 index 0000000..2302412 --- /dev/null +++ b/src/com/ibm/ServerWizard2/controller/TargetWizardController.java @@ -0,0 +1,267 @@ +package com.ibm.ServerWizard2.controller; + +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.util.Vector; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.TreeItem; + +import com.ibm.ServerWizard2.ServerWizard2; +import com.ibm.ServerWizard2.model.Connection; +import com.ibm.ServerWizard2.model.Field; +import com.ibm.ServerWizard2.model.SystemModel; +import com.ibm.ServerWizard2.model.Target; +import com.ibm.ServerWizard2.view.LogViewerDialog; +import com.ibm.ServerWizard2.view.MainDialog; + +public class TargetWizardController { + private SystemModel model; + private MainDialog view; + private Boolean modelCreationMode = false; + + private String PROCESSING_SCRIPT = "scripts/gen_html.pl"; + + public TargetWizardController() { + } + + public void setModelCreationMode() { + this.modelCreationMode = true; + } + public Boolean getModelCreationMode() { + return this.modelCreationMode; + } + + public void init() { + try { + //xmlLib.init(); + //xmlLib.loadModel(model); + model.loadLibrary("xml"); + this.initModel(); + } catch (Exception e) { + ServerWizard2.LOGGER.severe(e.toString()); + MessageDialog.openError(null, "Error", e.toString()); + e.printStackTrace(); + System.exit(4); + } + } + + public void initModel() throws Exception { + this.modelCreationMode = false; + model.deleteAllInstances(); + model.addUnitInstances(); + } + + public void deepCopyAttributes(Target t) { + t.deepCopyAttributes(model.getUnitTargetModel(), model.getTargetLookup()); + } + public void setView(MainDialog view) { + this.view = view; + } + + public void setModel(SystemModel model) { + this.model = model; + } + + public void deleteTarget(Target target) { + model.deleteTarget(target); + } + + public void addTargetInstance(Target targetModel, Target parentTarget, + TreeItem parentItem, String nameOverride) { + + Target targetInstance; + Target instanceCheck = model.getTargetInstance(targetModel.getType()); + if (instanceCheck != null) { + // target instance found of this model type + targetInstance = new Target(instanceCheck); + targetInstance.copyChildren(instanceCheck); + } else { + targetInstance = new Target(targetModel); + } + targetInstance.setName(nameOverride); + model.updateTargetPosition(targetInstance, parentTarget, -1); + try { + model.addTarget(parentTarget, targetInstance, modelCreationMode); + view.updateInstanceTree(targetInstance, parentItem); + } catch (Exception e) { + MessageDialog.openError(null, "Add Target Error", e.getMessage()); + } + } + + public Target copyTargetInstance(Target target, Target parentTarget, + Boolean incrementPosition) { + Target newTarget = new Target(target); + if (incrementPosition) { + newTarget.setPosition(newTarget.getPosition() + 1); + newTarget.setSpecialAttributes(); + } + try { + model.addTarget(parentTarget, newTarget, false); + newTarget.copyChildren(target); + } catch (Exception e) { + MessageDialog.openError(null, "Add Target Error", e.getMessage()); + newTarget = null; + } + return newTarget; + } + + public void deleteConnection(Target target, Target busTarget, + Connection conn) { + target.deleteConnection(busTarget, conn); + } + + public Vector<Target> getRootTargets() { + return model.rootTargets; + } + + public void writeXML(String filename) { + try { + String tmpFilename = filename + ".tmp"; + model.writeXML(tmpFilename, this.modelCreationMode); + File from = new File(tmpFilename); + File to = new File(filename); + Files.copy(from.toPath(), to.toPath(), + StandardCopyOption.REPLACE_EXISTING); + Files.delete(from.toPath()); + ServerWizard2.LOGGER.info(filename + " Saved"); + } catch (Exception exc) { + MessageDialog.openError(null, "Error", exc.getMessage()); + exc.printStackTrace(); + } + } + + public Boolean readXML(String filename) { + Boolean rtn = false; + try { + model.readXML(filename); + this.modelCreationMode = model.partsMode; + rtn = model.errataUpdated; + } catch (Exception e) { + MessageDialog.openError(null, "Error", e.getMessage()); + e.printStackTrace(); + } + return rtn; + } + + public Vector<Target> getConnectionCapableTargets() { + return model.getConnectionCapableTargets(); + } + + public void setGlobalSetting(String path, String attribute, String value) { + model.setGlobalSetting(path, attribute, value); + } + + public Field getGlobalSetting(String path, String attribute) { + return model.getGlobalSetting(path, attribute); + } + + public Boolean isGlobalSettings(String path, String attribute) { + return model.isGlobalSetting(path, attribute); + } + public Vector<Target> getChildTargets(Target target) { + + if (target == null) { + return model.getTopLevelTargets(); + } + if (this.modelCreationMode) { + Boolean override = false; + if (target.getType().startsWith("targetoverride")) { override = true; } + return model.getUnitTargets(override); + } + return model.getChildTargetTypes(target.getType()); + } + + public void hideBusses(Target target) { + target.hideBusses(model.getTargetLookup()); + } + + public Vector<Target> getVisibleChildren(Target target, boolean showHidden) { + Vector<Target> children = new Vector<Target>(); + for (String c : target.getChildren()) { + Target t = model.getTarget(c); + if (t == null) { + String msg = "Invalid Child target id: " + c; + ServerWizard2.LOGGER.severe(msg); + } + children.add(t); + } + if (showHidden) { + for (String c : target.getHiddenChildren()) { + Target t = model.getTarget(c); + if (t == null) { + String msg = "Invalid Child target id: " + c; + ServerWizard2.LOGGER.severe(msg); + } + children.add(t); + } + } + return children; + } + + public Vector<Target> getBusTypes() { + return model.getBusTypes(); + } + public String getWorkingDir() { + File f = new File("").getAbsoluteFile(); + String workingDir = f.getAbsolutePath() + System.getProperty("file.separator"); + return workingDir; + } + public void loadLibrary(String path) { + try { + model.loadLibrary(path); + } catch (Exception e) { + ServerWizard2.LOGGER.severe("Unable to load library: "+path); + } + } + public void runChecks(String xmlFile, String htmlFile) { + + String workingDir = this.getWorkingDir(); + String commandLine[] = { "perl", "-I", workingDir + "/scripts", + workingDir + PROCESSING_SCRIPT, "-x", + xmlFile, "-f", "-o", htmlFile }; + String commandLineStr = ""; + for (int i = 0; i < commandLine.length; i++) { + commandLineStr = commandLineStr + commandLine[i] + " "; + } + ServerWizard2.LOGGER.info("Running: " + commandLineStr); + try { + final ProcessBuilder builder = new ProcessBuilder(commandLine) + .redirectErrorStream(true); + + final Process process = builder.start(); + final StringWriter writer = new StringWriter(); + + new Thread(new Runnable() { + public void run() { + char[] buffer = new char[1024]; + int len; + InputStreamReader in = new InputStreamReader( + process.getInputStream()); + + try { + while ((len = in.read(buffer)) != -1) { + writer.write(buffer, 0, len); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + }).start(); + + final int exitValue = process.waitFor(); + final String processOutput = writer.toString(); + ServerWizard2.LOGGER.info(processOutput); + ServerWizard2.LOGGER.info("Return Code: " + exitValue); + LogViewerDialog dlg = new LogViewerDialog(null); + dlg.setData(processOutput); + dlg.open(); + } catch (Exception e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/src/com/ibm/ServerWizard2/Attribute.java b/src/com/ibm/ServerWizard2/model/Attribute.java index 3dca54c..17b346c 100644 --- a/src/com/ibm/ServerWizard2/Attribute.java +++ b/src/com/ibm/ServerWizard2/model/Attribute.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.model; import java.io.Writer; @@ -8,10 +8,12 @@ import org.w3c.dom.Node; public class Attribute implements java.io.Serializable { private static final long serialVersionUID = 1L; public String name = ""; + public String group = ""; public AttributeValue value; public String inherited = ""; public String desc = ""; + public String compareStr = ""; public Boolean readable = false; public Boolean writeable = false; public Boolean readonly = false; @@ -30,6 +32,7 @@ public class Attribute implements java.io.Serializable { public Attribute(Attribute a) { this.name = a.name; this.desc = a.desc; + this.group = a.group; this.persistency = a.persistency; this.readable = a.readable; this.writeable = a.writeable; @@ -66,12 +69,10 @@ public class Attribute implements java.io.Serializable { return hide; } - public Boolean isBitmask() { - return bitmask; - } public boolean isGlobal() { return this.global; } + public String toString() { String rtn="Attribute: "+name+" = "; rtn="Attribute: "+name+" = "+value.toString()+" inherited="+this.inherited; @@ -102,9 +103,9 @@ public class Attribute implements java.io.Serializable { } public void readModelXML(Element attribute) { - //name = attribute.getElementsByTagName("id").item(0).getChildNodes().item(0).getNodeValue(); name = SystemModel.getElement(attribute, "id"); desc = SystemModel.getElement(attribute,"description"); + group = SystemModel.getElement(attribute,"group"); String p = SystemModel.getElement(attribute,"persistency"); if (!p.isEmpty()) { setPersistence(p); } @@ -159,5 +160,10 @@ public class Attribute implements java.io.Serializable { out.write("\t\t<id>"+name+"</id>\n"); value.writeInstanceXML(out); out.write("\t</attribute>\n"); + } + + public String compare(Object o) { + Attribute a = (Attribute) o; + return value.compare(a.getValue()); } } diff --git a/src/com/ibm/ServerWizard2/AttributeValue.java b/src/com/ibm/ServerWizard2/model/AttributeValue.java index 18eb28d..f155c58 100644 --- a/src/com/ibm/ServerWizard2/AttributeValue.java +++ b/src/com/ibm/ServerWizard2/model/AttributeValue.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.model; import java.io.Writer; import java.util.Vector; @@ -20,6 +20,8 @@ public abstract class AttributeValue { public abstract void setValue(String value); public abstract String toString(); public abstract Boolean isEmpty(); + public abstract String compare(Object o); + public void setEnumerator(Enumerator enumerator) { for (Field f : fields) { f.enumerator=enumerator; diff --git a/src/com/ibm/ServerWizard2/AttributeValueComplex.java b/src/com/ibm/ServerWizard2/model/AttributeValueComplex.java index c4db2c3..9b96f07 100644 --- a/src/com/ibm/ServerWizard2/AttributeValueComplex.java +++ b/src/com/ibm/ServerWizard2/model/AttributeValueComplex.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.model; import java.io.Writer; import java.util.Vector; @@ -25,6 +25,7 @@ public class AttributeValueComplex extends AttributeValue { f.name = SystemModel.getElement((Element) fieldList.item(i), "name"); f.desc = SystemModel .getElement((Element) fieldList.item(i), "description"); + f.group = SystemModel.getElement((Element) fieldList.item(i), "group"); f.type = SystemModel.getElement((Element) fieldList.item(i), "type"); f.bits = SystemModel.getElement((Element) fieldList.item(i), "bits"); f.defaultv = SystemModel.getElement((Element) fieldList.item(i), "default"); @@ -59,7 +60,6 @@ public class AttributeValueComplex extends AttributeValue { @Override public String getValue() { - // TODO Auto-generated method stub return "complex"; } @@ -90,4 +90,23 @@ public class AttributeValueComplex extends AttributeValue { fields.add(f); } } + @Override + public String compare(Object o) { + AttributeValueComplex a = (AttributeValueComplex) o; + String cmp = ""; + for (Field f : fields) { + Boolean found = false; + for (Field fc : a.fields) { + if (f.name.equals(fc.name)) { + found = true; + if (!f.value.equals(fc.value)) { + cmp = cmp + f.attributeName +"(" +f.name +")" +" : "+f.value+" != "+fc.value+"\n"; + ; + } + } + } + if (!found) { return "invalid attribute"; } + } + return cmp; + } } diff --git a/src/com/ibm/ServerWizard2/AttributeValueNative.java b/src/com/ibm/ServerWizard2/model/AttributeValueNative.java index bb9a4d4..df8688e 100644 --- a/src/com/ibm/ServerWizard2/AttributeValueNative.java +++ b/src/com/ibm/ServerWizard2/model/AttributeValueNative.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.model; import java.io.Writer; @@ -12,6 +12,7 @@ public class AttributeValueNative extends AttributeValue { field = new Field(); field.attributeName=a.name; field.desc=a.desc; + field.group=a.group; fields.add(field); } public AttributeValueNative(AttributeValueNative a) { @@ -59,25 +60,14 @@ public class AttributeValueNative extends AttributeValue { field.value = n.field.value; field.name = n.field.name; } -/* - @Override - public Control getEditor(Table table, AttributeTableItem item) { - Text text = new Text(table, SWT.NONE); - text.setData(item); - text.setText(value); - text.setSelection(text.getText().length()); - text.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - Text text = (Text) e.getSource(); - AttributeTableItem a = (AttributeTableItem) text.getData(); - AttributeValueSimple v = (AttributeValueSimple) a.getAttribute(); - v.value = text.getText(); - a.getItem().setText(2, v.value); - } - }); - return text; + @Override + public String compare(Object o) { + String cmp = ""; + AttributeValueNative s = (AttributeValueNative) o; + if (!field.value.equals(s.field.value)) { + cmp = field.attributeName +" : "+field.value + " != "+s.field.value; + } + return cmp; } - */ } diff --git a/src/com/ibm/ServerWizard2/AttributeValueSimple.java b/src/com/ibm/ServerWizard2/model/AttributeValueSimple.java index be17a41..434efb2 100644 --- a/src/com/ibm/ServerWizard2/AttributeValueSimple.java +++ b/src/com/ibm/ServerWizard2/model/AttributeValueSimple.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.model; import java.io.Writer; @@ -14,6 +14,7 @@ public class AttributeValueSimple extends AttributeValue { field = new Field(); field.attributeName = a.name; field.desc=a.desc; + field.group=a.group; fields.add(field); } public AttributeValueSimple(AttributeValueSimple a) { @@ -77,7 +78,7 @@ public class AttributeValueSimple extends AttributeValue { @Override public String toString() { // TODO Auto-generated method stub - return field.value + " (" + type + ")"; + return "Simple: "+field.value + " (" + type + ")"; } @Override @@ -96,4 +97,13 @@ public class AttributeValueSimple extends AttributeValue { field.value = n.field.value; field.name = n.field.name; } + @Override + public String compare(Object o) { + String cmp = ""; + AttributeValueSimple s = (AttributeValueSimple) o; + if (!field.value.equals(s.field.value)) { + cmp = field.attributeName +" : "+field.value + " != "+s.field.value; + } + return cmp; + } } diff --git a/src/com/ibm/ServerWizard2/Connection.java b/src/com/ibm/ServerWizard2/model/Connection.java index 5c9cfe8..cbb6497 100644 --- a/src/com/ibm/ServerWizard2/Connection.java +++ b/src/com/ibm/ServerWizard2/model/Connection.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.model; import java.io.Writer; import java.util.Map; @@ -6,6 +6,8 @@ import java.util.Map; import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import com.ibm.ServerWizard2.ServerWizard2; + public class Connection { public int id = 0; diff --git a/src/com/ibm/ServerWizard2/ConnectionEndpoint.java b/src/com/ibm/ServerWizard2/model/ConnectionEndpoint.java index 90b7e21..21c893b 100644 --- a/src/com/ibm/ServerWizard2/ConnectionEndpoint.java +++ b/src/com/ibm/ServerWizard2/model/ConnectionEndpoint.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.model; public class ConnectionEndpoint { //private Target target; diff --git a/src/com/ibm/ServerWizard2/Enumerator.java b/src/com/ibm/ServerWizard2/model/Enumerator.java index 815459f..e0c56e6 100644 --- a/src/com/ibm/ServerWizard2/Enumerator.java +++ b/src/com/ibm/ServerWizard2/model/Enumerator.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.model; import java.util.HashMap; import java.util.Vector; @@ -9,6 +9,7 @@ import org.w3c.dom.NodeList; public class Enumerator { public String id=""; public String desc=""; + public String group=""; public HashMap<String,String> enumValues = new HashMap<String,String>(); public Vector<String> enumList = new Vector<String>(); @@ -20,6 +21,7 @@ public class Enumerator { public void readXML(Element e) { id = SystemModel.getElement(e, "id"); desc = SystemModel.getElement(e,"description"); + group = SystemModel.getElement(e,"group"); NodeList enumList = e.getElementsByTagName("enumerator"); for (int i = 0; i < enumList.getLength(); ++i) { Element en=(Element)enumList.item(i); diff --git a/src/com/ibm/ServerWizard2/model/Errata.java b/src/com/ibm/ServerWizard2/model/Errata.java new file mode 100644 index 0000000..30093ab --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/Errata.java @@ -0,0 +1,87 @@ +package com.ibm.ServerWizard2.model;
+
+import java.util.HashMap;
+import java.util.Vector;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class Errata {
+ private String id = "";
+ private String desc = "";
+ private Boolean applied = false;
+ private Vector<Attribute> attributes = new Vector<Attribute>();
+ private String compareDetail = "";
+ private Vector<Target> targets = new Vector<Target>();
+ private String targetType = "";
+
+ public Errata() {
+
+ }
+ public Errata(Errata e) {
+ id = e.id;
+ desc = e.desc;
+ applied = e.applied;
+ targetType = e.targetType;
+ //don't deep copy attributes
+ attributes = e.attributes;
+ }
+ public void addTarget(Target t) {
+ targets.add(t);
+ }
+ public String getDetail() {
+ return compareDetail;
+ }
+ public void setDetail(String d) {
+ this.compareDetail = d;
+ }
+ public void setApplied(Boolean applied) {
+ this.applied = applied;
+ }
+ public Boolean isApplied() {
+ return applied;
+ }
+ public String getTargetType() {
+ return this.targetType;
+ }
+ public void updateAttributes() {
+ for (Target t : targets) {
+ for (Attribute a : attributes) {
+ Attribute attrNew = new Attribute(a);
+ t.getAttributes().put(attrNew.name,attrNew);
+ }
+ }
+ }
+ public void read(Element t, HashMap<String, Attribute> attributeModel) {
+ attributes.removeAllElements();
+ this.id = SystemModel.getElement(t, "errata_id");
+ this.desc = SystemModel.getElement(t, "description");
+ this.targetType = SystemModel.getElement(t, "target_type");
+ NodeList attributeList = t.getElementsByTagName("attribute");
+ for (int j = 0; j < attributeList.getLength(); ++j) {
+ String attrId = SystemModel.getElement((Element) attributeList.item(j), "id");
+ Attribute aModel = attributeModel.get(attrId);
+ if (aModel == null) {
+ MessageDialog.openError(null, "Error", "Invalid attribute " + attrId + " in Errata: " + id);
+ return;
+ } else {
+ Attribute a = new Attribute(aModel);
+ a.value.readInstanceXML((Element) attributeList.item(j));
+ attributes.add(a);
+ }
+ }
+ }
+ public String getId() {
+ return id;
+ }
+ public String getDesc() {
+ return desc;
+ }
+ public Vector<Attribute> getAttributes() {
+ return attributes;
+ }
+ public void readInstance() {
+
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/Field.java b/src/com/ibm/ServerWizard2/model/Field.java index 3d8c56f..e616642 100644 --- a/src/com/ibm/ServerWizard2/Field.java +++ b/src/com/ibm/ServerWizard2/model/Field.java @@ -1,10 +1,12 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.model; + public class Field { public String attributeName=""; public String name=""; public String desc=""; + public String group=""; public String type=""; public String bits=""; public String defaultv=""; @@ -20,6 +22,7 @@ public class Field { attributeName = f.attributeName; name=f.name; desc=f.desc; + group=f.group; type=f.type; bits=f.bits; value=f.value; diff --git a/src/com/ibm/ServerWizard2/model/SystemModel.java b/src/com/ibm/ServerWizard2/model/SystemModel.java new file mode 100644 index 0000000..b2470ce --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/SystemModel.java @@ -0,0 +1,834 @@ +package com.ibm.ServerWizard2.model; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; +import java.util.Vector; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import com.ibm.ServerWizard2.ServerWizard2; +import com.ibm.ServerWizard2.view.ErrataViewer; + +public class SystemModel { + // public Target rootTarget; + public Vector<Target> rootTargets = new Vector<Target>(); + private DocumentBuilder builder; + + // From target instances + private HashMap<String, Target> targetInstances = new HashMap<String, Target>(); + private Vector<Target> targetUnitList = new Vector<Target>(); + private HashMap<String, Target> targetUnitModels = new HashMap<String,Target>(); + + // From target types + private TreeMap<String, Target> targetModels = new TreeMap<String, Target>(); + private HashMap<String, Vector<Target>> childTargetTypes = new HashMap<String, Vector<Target>>(); + + // From attribute types + public TreeMap<String, Enumerator> enumerations = new TreeMap<String, Enumerator>(); + private HashMap<String, Attribute> attributes = new HashMap<String, Attribute>(); + private TreeMap<String, Vector<String>> attributeGroups = new TreeMap<String, Vector<String>>(); + private TreeMap<String, Errata> errata = new TreeMap<String, Errata>(); + + // List of targets in current system + private Vector<Target> targetList = new Vector<Target>(); + private HashMap<String, Target> targetLookup = new HashMap<String, Target>(); + private TreeMap<String, Errata> errataList = new TreeMap<String, Errata>(); + + private TreeMap<String, Target> busTypesTree = new TreeMap<String, Target>(); + private Vector<Target> busTypes = new Vector<Target>(); + + private TreeMap<String, TreeMap<String, Field>> globalSettings = new TreeMap<String, TreeMap<String, Field>>(); + + public Boolean partsMode = false; + public Boolean cleanupMode = false; + public Boolean errataUpdated = false; + + + public Vector<Target> getBusTypes() { + return busTypes; + } + + public Target getTarget(String t) { + return targetLookup.get(t); + } + + public HashMap<String, Target> getTargetLookup() { + return this.targetLookup; + } + + public Vector<Target> getTargetList() { + return this.targetList; + } + + public Collection<Target> getTargetInstances() { + return targetInstances.values(); + } + + public Target getRootTarget() { + return rootTargets.get(0); + } + + public Vector<Target> getTopLevelTargets() { + //TODO: need a better way to determine top level targets + Vector<Target> topLevel = new Vector<Target>(); + for (Target target : targetModels.values()) { + String type = target.getType(); + if (type.equals("chip") || type.startsWith("sys") || type.equals("targetoverride")) { + topLevel.add(target); + } + } + return topLevel; + } + + public Vector<Target> getUnitTargets(Boolean override) { + //TODO: need a better way to determine top level targets + Vector<Target> topLevel = new Vector<Target>(); + for (Target target : targetModels.values()) { + if (override == false) { + if (target.isUnit()) { topLevel.add(target); } + } else { + if (target.isOverride()) { + topLevel.add(target); + } + } + } + return topLevel; + } + + public Vector<Target> getConnectionCapableTargets() { + Vector<Target> cards = new Vector<Target>(); + for (Target target : targetList) { + if (target.isCard() || target.isSystem() || target.isNode()) { + cards.add(target); + } + } + return cards; + } + + public void initBusses(Target target) { + target.initBusses(busTypes); + } + + public Vector<Target> getChildTargetTypes(String targetType) { + if (targetType.equals("")) { + Vector<Target> a = new Vector<Target>(); + for (Target t : this.targetModels.values()) { + a.add(t); + } + return a; + } + if (childTargetTypes.get(targetType) != null) { + Collections.sort(childTargetTypes.get(targetType)); + } + return childTargetTypes.get(targetType); + } + + + private void writeErrata(Writer out) throws Exception { + out.write("<appliedErratas>\n"); + for (String e : errataList.keySet()) { + out.write("<appliedErrata>"); + out.write("\t<id>" + e + "</id>"); + out.write("\t<is_applied>" + errataList.get(e).isApplied() + "</is_applied>"); + out.write("</appliedErrata>\n"); + } + out.write("</appliedErratas>\n"); + } + + + private void writeGroups(Writer out) throws Exception { + out.write("<attributeGroups>\n"); + for (String group : attributeGroups.keySet()) { + out.write("<attributeGroup>\n"); + out.write("\t<id>" + group + "</id>\n"); + for (String attribute : attributeGroups.get(group)) { + out.write("\t<attribute>" + attribute + "</attribute>\n"); + } + out.write("</attributeGroup>\n"); + } + out.write("</attributeGroups>\n"); + } + private void writeEnumeration(Writer out) throws Exception { + out.write("<enumerationTypes>\n"); + for (String enumeration : enumerations.keySet()) { + Enumerator e = enumerations.get(enumeration); + out.write("<enumerationType>\n"); + out.write("\t<id>" + enumeration + "</id>\n"); + for (Map.Entry<String, String> entry : e.enumValues.entrySet()) { + out.write("\t\t<enumerator>\n"); + out.write("\t\t<name>" + entry.getKey() + "</name>\n"); + out.write("\t\t<value>" + entry.getValue() + "</value>\n"); + out.write("\t\t</enumerator>\n"); + } + out.write("</enumerationType>\n"); + } + out.write("</enumerationTypes>\n"); + } + + private NodeList isXMLValid(Document document, String tag) { + NodeList n = document.getElementsByTagName(tag); + if (n != null) { + if (n.item(0) != null) { + String version = SystemModel.getElement((Element)n.item(0), "version"); + if (!version.isEmpty()) { + ServerWizard2.LOGGER.info("XML Version found: "+version); + if (Double.valueOf(version) >= ServerWizard2.VERSION_MAJOR) { + return n; + } + } + } + } + return null; + } + public void loadLibrary(String path) throws Exception { + File xmlDir = new File(path); + File[] filesList = xmlDir.listFiles(); + if (filesList == null) { + ServerWizard2.LOGGER.warning("No library loaded"); + } else { + for (File file : filesList) { + if (file.isFile() && file.getAbsolutePath().endsWith(".xml")) { + if (file.getName().startsWith("attribute_types")) { + this.loadAttributes(file.getPath()); + } + if (file.getName().startsWith("target_types")) { + this.loadTargetTypes(file.getPath()); + } + } + } + } + File partsDir = new File(path+File.separator+"parts"+File.separator); + filesList = partsDir.listFiles(); + if (filesList == null) { + ServerWizard2.LOGGER.warning("No parts loaded"); + } else { + for (File file : filesList) { + if (file.isFile() && file.getAbsolutePath().endsWith(".xml")) { + this.loadTargets(file.getPath()); + } + } + } + } + + // Reads a previously saved MRW + public void readXML(String filename) throws Exception { + ServerWizard2.LOGGER.info("Reading XML: "+filename); + File f = new File(filename); + this.loadLibrary(f.getParent()); + long startTime = System.currentTimeMillis(); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + // delete all existing instances + this.deleteAllInstances(); + this.addUnitInstances(); + + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new XmlHandler()); + Document document = builder.parse(filename); + + NodeList system = isXMLValid(document,"systemInstance"); + NodeList part = isXMLValid(document,"partInstance"); + if (system == null && part == null) { + String msg = "ServerWiz cannot read this version of XML: "+filename; + ServerWizard2.LOGGER.severe(msg); + MessageDialog.openError(null, "XML Load Error", msg); + } + partsMode = false; + String targetTag = "targetInstance"; + if (part != null) { + partsMode = true; + targetTag = "targetPart"; + ServerWizard2.LOGGER.info("Setting Parts mode"); + } + + NodeList settingList = document.getElementsByTagName("globalSettings"); + Element t = (Element) settingList.item(0); + if (t != null) { + NodeList settingList2 = t.getElementsByTagName("globalSetting"); + for (int j = 0; j < settingList2.getLength(); ++j) { + Element t2 = (Element) settingList2.item(j); + this.readGlobalSettings(t2); + } + } + NodeList errataList = document.getElementsByTagName("appliedErratas"); + Element te = (Element) errataList.item(0); + if (te != null) { + NodeList errataList2 = te.getElementsByTagName("appliedErrata"); + for (int j = 0; j < errataList2.getLength(); ++j) { + Element t2 = (Element) errataList2.item(j); + this.readErrata(t2); + } + } + NodeList targetInstances = document.getElementsByTagName("targetInstances"); + t = (Element) targetInstances.item(0); + NodeList targetInstanceList = t.getElementsByTagName(targetTag); + + for (int i = 0; i < targetInstanceList.getLength(); ++i) { + t = (Element) targetInstanceList.item(i); + String type = SystemModel.getElement(t, "type"); + if (type.length() > 0) { + Target targetModel = this.getTargetModel(type); + if (targetModel == null) { + ServerWizard2.LOGGER.severe("Invalid target type: " + type); + throw new Exception("Invalid target type: " + type); + } else { + Target target = new Target(targetModel); + target.initBusses(busTypes); + target.readInstanceXML(t, targetModels); + this.targetLookup.put(target.getName(), target); + this.targetList.add(target); + + if (target.isRoot()) { + this.rootTargets.add(target); + } + /////// + // Check to see if new children defined in model + Target targetInst = this.targetInstances.get(target.getType()); + if (targetInst != null) { + HashMap <String,Boolean> childTest = new HashMap<String,Boolean>(); + for (String child : target.getAllChildren()) { + childTest.put(child, true); + } + for (String child : targetInst.getChildren()) { + if (childTest.get(child)==null) { + target.addChild(child, false); + if (!this.targetLookup.containsKey(child)) { + this.targetLookup.put(child, target); + this.targetList.add(target); + } + childTest.put(child, true); + } + } + for (String child : targetInst.getHiddenChildren()) { + if (childTest.get(child)==null) { + target.addChild(child, true); + if (!this.targetLookup.containsKey(child)) { + this.targetLookup.put(child,target); + this.targetList.add(target); + } + childTest.put(child, true); + } + } + } + } + } else { + throw new Exception("Empty Target Type"); + } + } + if (cleanupMode) { this.xmlCleanup(); } + long endTime = System.currentTimeMillis(); + ServerWizard2.LOGGER.info("Loaded XML in " + (endTime - startTime) + " milliseconds"); + + checkErrata(); + } + + public void checkErrata() { + Vector<Errata> errataNew = new Vector<Errata>(); + + //Determine errata that has not been acknowledged + for (String errata_id : errata.keySet()) { + if (!errataList.containsKey(errata_id)) { + Errata e = new Errata(errata.get(errata_id)); + errataNew.add(e); + } + } + + HashMap<String,Errata> errataCheck = new HashMap<String,Errata>(); + for (Target tchk : this.targetLookup.values()) { + for (Errata e : errataNew) { + if (e.getTargetType().equals(tchk.getType())) { + Boolean found = false; + String cmpSummary = e.getDesc()+"\n===========================================\n"; + for (Attribute errataAttr : e.getAttributes()) { + if (tchk.attributeExists(errataAttr.name)) { + Attribute currentAttr = tchk.getAttributes().get(errataAttr.name); + String cmp = errataAttr.compare(currentAttr); + if (!cmp.isEmpty()) { + cmpSummary = cmpSummary + cmp +"\n"; + errataCheck.put(e.getId(), e); + e.setDetail(cmpSummary); + found = true; + } + } + } + if (found) { e.addTarget(tchk); } + } + } + } + Vector<Errata> errataV = new Vector<Errata>(); + for (Errata e : errataCheck.values()) { + errataV.add(e); + } + if (errataCheck.size() > 0) { + ErrataViewer dlg = new ErrataViewer(null,errataV); + int rtn = dlg.open(); + if (rtn == Dialog.OK) { + for (Errata e : errataV) { + if (e.isApplied()) { + e.updateAttributes(); + } + errataUpdated = true; + errataList.put(e.getId(), e); + } + } + } + } + + /////////////////////////////////////////////// + // global settings + + public Field setGlobalSetting(String path, String attribute, String value) { + TreeMap<String, Field> s = globalSettings.get(path); + if (s == null) { + s = new TreeMap<String, Field>(); + globalSettings.put(path, s); + } + Field f = s.get(attribute); + if (f == null) { + f = new Field(); + f.attributeName = attribute; + s.put(attribute, f); + } + f.value = value; + return f; + } + + public Boolean isGlobalSetting(String path, String attribute) { + TreeMap<String, Field> s = globalSettings.get(path); + if (s == null) { + return false; + } + Field f=s.get(attribute); + if (f==null) { + return false; + } + return true; + } + + public Field getGlobalSetting(String path, String attribute) { + TreeMap<String, Field> s = globalSettings.get(path); + if (s == null) { + if (s == null) { + s = new TreeMap<String, Field>(); + globalSettings.put(path, s); + } + return null; + } + Field f=s.get(attribute); + return f; + } + + public TreeMap<String, Field> getGlobalSettings(String path) { + TreeMap<String, Field> s = globalSettings.get(path); + return s; + } + + private void writeGlobalSettings(Writer out) throws Exception { + out.write("<globalSettings>\n"); + for (Map.Entry<String, TreeMap<String, Field>> entry : this.globalSettings.entrySet()) { + out.write("<globalSetting>\n"); + out.write("\t<id>" + entry.getKey() + "</id>\n"); + for (Map.Entry<String, Field> setting : entry.getValue().entrySet()) { + out.write("\t<property>\n"); + out.write("\t<id>" + setting.getKey() + "</id>\n"); + out.write("\t<value>" + setting.getValue().value + "</value>\n"); + out.write("\t</property>\n"); + } + out.write("</globalSetting>\n"); + } + out.write("</globalSettings>\n"); + } + + private void readGlobalSettings(Element setting) { + String targetId = SystemModel.getElement(setting, "id"); + NodeList propertyList = setting.getElementsByTagName("property"); + for (int i = 0; i < propertyList.getLength(); ++i) { + Element t = (Element) propertyList.item(i); + String property = SystemModel.getElement(t, "id"); + String value = SystemModel.getElement(t, "value"); + this.setGlobalSetting(targetId, property, value); + } + } + private void readErrata(Element setting) { + String errata_id = SystemModel.getElement(setting, "id"); + if (this.errata.containsKey(errata_id)) { + Errata e = new Errata(this.errata.get(errata_id)); + errataList.put(errata_id, e); + } + } + + ///////////////////////////////////////////////// + // Writes MRW to file + public void writeXML(String filename, Boolean partsMode) throws Exception { + Writer out = new BufferedWriter(new FileWriter(filename)); + String topTag = "systemInstance"; + if (partsMode) { topTag = "partInstance"; } + + out.write("<"+topTag+">\n"); + out.write("<version>"+ServerWizard2.getVersionString()+"</version>\n"); + if (!partsMode) { + this.writeEnumeration(out); + this.writeGlobalSettings(out); + this.writeGroups(out); + this.writeErrata(out); + } + out.write("<targetInstances>\n"); + HashMap<String, Boolean> targetWritten = new HashMap<String, Boolean>(); + for (Target target : targetList) { + if (partsMode) { + target.writeTargetXML(out, targetLookup, targetWritten); + } else { + target.writeInstanceXML(out, targetLookup, targetWritten); + } + } + out.write("</targetInstances>\n"); + out.write("</"+topTag+">\n"); + out.close(); + } + + public void addTarget(Target parentTarget, Target newTarget,Boolean pathMode) throws Exception { + if (parentTarget == null) { + this.rootTargets.add(newTarget); + newTarget.setRoot(); + if (pathMode) { + newTarget.parent = newTarget.getType(); + newTarget.setType(newTarget.parent+"-"+newTarget.getRawName()); + } + } else { + newTarget.clearRoot(); + if (pathMode) { + String name = newTarget.getRawName(); + if (name.isEmpty()) { name = newTarget.getIdPrefix(); } + newTarget.setName(parentTarget.getName()+"."+name); + } + parentTarget.addChild(newTarget.getName(), false); + } + this.updateTargetList(newTarget); + initBusses(newTarget); + } + public void loadTargetTypes(String fileName) throws SAXException, + IOException, ParserConfigurationException { + ServerWizard2.LOGGER.info("Loading Target Types: " + fileName); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new XmlHandler()); + + Document document = builder.parse(fileName); + NodeList targetList = document.getElementsByTagName("targetType"); + for (int i = 0; i < targetList.getLength(); ++i) { + Element t = (Element) targetList.item(i); + Target target = new Target(); + target.readModelXML(t, attributes); + targetModels.put(target.getType(), target); + } + for (Map.Entry<String, Target> entry : targetModels.entrySet()) { + Target target = entry.getValue(); + + // add inherited attributes + addParentAttributes(target, target); + if (target.getAttribute("CLASS").equals("BUS")) { + busTypesTree.put(entry.getKey(),target); + } + } + busTypes.removeAllElements(); + for (Target t : busTypesTree.values()) { + busTypes.add(t); + } + } + + public void loadAttributes(String fileName) throws SAXException, + IOException, ParserConfigurationException { + ServerWizard2.LOGGER.info("Loading Attributes: " + fileName); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new XmlHandler()); + + Document document = builder.parse(fileName); + NodeList enumList = document.getElementsByTagName("enumerationType"); + for (int i = 0; i < enumList.getLength(); ++i) { + Element t = (Element) enumList.item(i); + Enumerator en = new Enumerator(); + en.readXML(t); + enumerations.put(en.id, en); + } + NodeList attrList = document.getElementsByTagName("attribute"); + for (int i = 0; i < attrList.getLength(); ++i) { + Element t = (Element) attrList.item(i); + Attribute a = new Attribute(); + a.readModelXML(t); + attributes.put(a.name, a); + + if (!a.group.isEmpty()) { + Vector<String> grp = attributeGroups.get(a.group); + if (grp == null) { + grp = new Vector<String>(); + attributeGroups.put(a.group, grp); + } + grp.add(a.name); + } + + if (a.getValue().getType().equals("enumeration")) { + a.getValue().setEnumerator(enumerations.get(a.value.getFields().get(0).name)); + } + } + } + + public void loadTargets(String filename) throws Exception { + ServerWizard2.LOGGER.info("Loading Part: " + filename); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new XmlHandler()); + Document document = builder.parse(filename); + NodeList targetInstanceList = document.getElementsByTagName("targetPart"); + for (int i = 0; i < targetInstanceList.getLength(); ++i) { + Element t = (Element) targetInstanceList.item(i); + String type = SystemModel.getElement(t, "type"); + Target tmodel = targetModels.get(type); + Target target = null; + if (tmodel == null) { + target = new Target(); + } else { + target = new Target(tmodel); + } + target.readTargetXML(t, targetModels, attributes); + addParentAttributes(target, target); + if (target.isRoot()) { + target.clearRoot(); + targetModels.put(target.getType(), target); + targetInstances.put(target.getType(), target); + Vector<String> parentTypes = target.getParentType(); + for (int j = 0; j < parentTypes.size(); j++) { + String parentType = parentTypes.get(j); + + Vector<Target> childTypes = childTargetTypes.get(parentType); + if (childTypes == null) { + childTypes = new Vector<Target>(); + childTargetTypes.put(parentType, childTypes); + } + childTypes.add(target); + } + } else { + if (!targetUnitModels.containsKey(target.getName())) { + this.targetUnitList.add(target); + this.targetUnitModels.put(target.getName(), target); + } + if (!targetModels.containsKey(target.getType())) { + targetModels.put(target.getType(), target); + } + } + } + } + public void loadErrata(String filename) throws Exception { + ServerWizard2.LOGGER.info("Loading Errata: " + filename); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new XmlHandler()); + Document document = builder.parse(filename); + NodeList list = document.getElementsByTagName("errata"); + for (int i = 0; i < list.getLength(); ++i) { + Element t = (Element) list.item(i); + Errata e = new Errata(); + e.read(t, attributes); + errata.put(e.getId(), e); + } + } + + //////////////////////////////////////////////////////////////////////// + // Target manipulation + public Target getTargetInstance(String type) { + return targetInstances.get(type); + } + + public HashMap<String,Target> getUnitTargetModel() { + return this.targetUnitModels; + } + // Add target to target database. + // only contains targets that user has added + // not library targets + private void updateTargetList(Target target) throws Exception { + String id = target.getName(); + if (!this.targetLookup.containsKey(id)) { + this.targetLookup.put(id, target); + this.targetList.add(target); + } else { + String msg="Duplicate Target: "+target.getName(); + ServerWizard2.LOGGER.warning(msg); + throw new Exception(msg); + } + } + + private void addParentAttributes(Target childTarget, Target t) { + if (t == null) { + return; + } + if (t.parent == null || t.parent.isEmpty()) { + return; + } + Target parent = targetModels.get(t.parent); + if (parent == null) { + MessageDialog.openError(null, "Error", "Invalid parent target: "+t.parent ); + } + childTarget.copyAttributesFromParent(parent); + addParentAttributes(childTarget, parent); + } + + public void addUnitInstances() { + for (Target target : this.targetUnitList) { + this.targetLookup.put(target.getName(), target); + } + } + + public void updateTargetPosition(Target target, Target parentTarget, int position) { + if (position > 0) { + target.setPosition(position); + return; + } + if (parentTarget == null) { + target.setName(target.getIdPrefix()); + target.setPosition(-1); + return; + } + int p = -1; + // set target position to +1 of any target found of same type + for (Target t : targetList) { + if (t.getType().equals(target.getType())) { + if (t.getPosition() >= p) { + p = t.getPosition(); + } + } + } + target.setPosition(p + 1); + target.setSpecialAttributes(); + } + public TreeMap<String, Target> getTargetModels() { + return targetModels; + } + + public Target getTargetModel(String t) { + return targetModels.get(t); + } + + public void deleteAllInstances() { + errataUpdated = false; + this.targetList.clear(); + this.targetLookup.clear(); + this.rootTargets.clear(); + this.globalSettings.clear(); + this.errataList.clear(); + } + + public void deleteTarget(Target deleteTarget) { + //if (deleteTarget == null) { + // return; + //} + targetList.remove(deleteTarget); + //Vector<String> children = deleteTarget.getAllChildren(); + //for (String s : children) { + // Target d = targetLookup.get(s); + // deleteTarget(d); + //} + + for (Target t : targetList) { + t.removeChildren(deleteTarget.getName()); + } + this.targetLookup.remove(deleteTarget.getName()); + } + + ///////////////////////////////////////////////////////////////// + // Utility static methods + public static String getElement(Element a, String e) { + Node n = a.getElementsByTagName(e).item(0); + if (n != null) { + Node cn = n.getChildNodes().item(0); + if (cn == null) { + return ""; + } + return cn.getNodeValue(); + } + return ""; + } + + public static Boolean isElementDefined(Element a, String e) { + Node n = a.getElementsByTagName(e).item(0); + if (n != null) { + Node cn = n.getChildNodes().item(0); + if (cn == null) { + return true; + } + return true; + } + return false; + } + + ////////////////////////////////////////////////////////////////////////////// + // Special method to cleanup past bugs + private void targetWalk(Target target, String path, HashMap<String,Target> targets) { + targets.put(path, target); + for (String child : target.getChildren()) { + Target childTarget = getTarget(child); + targetWalk(childTarget, path + "/" + child, targets); + } + } + + private void xmlCleanup() { + String path = "/"+this.getRootTarget().getName(); + HashMap<String,Target> targets = new HashMap<String,Target>(); + targetWalk(this.getRootTarget(),path,targets); + + ServerWizard2.LOGGER.info("Running XML cleanup..."); + + // IO_CONFIG_SELECT bug + TreeMap<String, TreeMap<String,Field>> tmpSettings = new TreeMap<String, TreeMap<String,Field>>(globalSettings); + + for (Map.Entry<String, TreeMap<String,Field>> settings : tmpSettings.entrySet()) { + TreeMap<String,Field> tmpFields = new TreeMap<String,Field>(settings.getValue()); + Target t = targets.get(settings.getKey()); + if (t == null) { + ServerWizard2.LOGGER.warning("Target not found, removing: "+settings.getKey()); + globalSettings.remove(settings.getKey()); + } else { + for (Field f : tmpFields.values()) { + Attribute a = t.getAttributes().get(f.attributeName); + if (a == null) { + ServerWizard2.LOGGER.info("Not an attribute in target, removing: "+f.attributeName); + globalSettings.get(settings.getKey()).remove(f.attributeName); + } else { + if (!a.isGlobal()) { + globalSettings.get(settings.getKey()).remove(f.attributeName); + ServerWizard2.LOGGER.info("Removing global property: "+f.attributeName); + } + } + } + } + TreeMap<String,Field> tmpSettings2 = globalSettings.get(settings.getKey()); + + if (tmpSettings2 != null) { + if (tmpSettings2.isEmpty()) { + ServerWizard2.LOGGER.info("Removing global target: "+settings.getKey()); + globalSettings.remove(settings.getKey()); + } + } + } + // End IO_CONFIG_SELECT bug + } + +} diff --git a/src/com/ibm/ServerWizard2/Target.java b/src/com/ibm/ServerWizard2/model/Target.java index 0d41e4e..ef452f4 100644 --- a/src/com/ibm/ServerWizard2/Target.java +++ b/src/com/ibm/ServerWizard2/model/Target.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.model; import java.io.Writer; import java.util.HashMap; @@ -9,6 +9,8 @@ import java.util.Vector; import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import com.ibm.ServerWizard2.ServerWizard2; + public class Target implements Comparable<Target>, java.io.Serializable { private static final long serialVersionUID = 1L; @@ -16,17 +18,15 @@ public class Target implements Comparable<Target>, java.io.Serializable { private String type = ""; private int position = -1; public String parent = ""; // says which parent to inherit attributes from - // target_types - public boolean instanceModel = false; - public boolean isLibraryTarget = false; + private Vector<String> parentType = new Vector<String>(); private TreeMap<String, Attribute> attributes = new TreeMap<String, Attribute>(); - //private Vector<Target> children = new Vector<Target>(); private Vector<String> children = new Vector<String>(); private Vector<String> childrenHidden = new Vector<String>(); private TreeMap<Target,Vector<Connection>> busses = new TreeMap<Target,Vector<Connection>>(); private Boolean busInited=false; private Boolean hidden = false; + private Boolean root = false; private HashMap<String,Boolean> childrenBusTypes = new HashMap<String,Boolean>(); public Target() { @@ -38,8 +38,8 @@ public class Target implements Comparable<Target>, java.io.Serializable { this.parent = s.parent; this.position = s.position; this.hidden = s.hidden; + this.root = s.root; this.parentType.addAll(s.parentType); - this.isLibraryTarget=s.isLibraryTarget; for (Map.Entry<String, Attribute> entry : s.getAttributes().entrySet()) { String key = new String(entry.getKey()); @@ -51,17 +51,10 @@ public class Target implements Comparable<Target>, java.io.Serializable { return busses; } - public void hide(Boolean h) { - this.hidden=h; - } public Boolean isHidden() { return this.hidden; } - public void linkBusses(Target t){ - busses=t.getBusses(); - } - public String getName() { if (position==-1 && !name.isEmpty()) { return name; @@ -78,7 +71,15 @@ public class Target implements Comparable<Target>, java.io.Serializable { public void setName(String name) { this.name = name; } - + public void setRoot() { this.root = true; } + public void clearRoot() { this.root = false; } + public Boolean isRoot() { + //this is for backwards compatibility + if (this.getAttribute("CLASS").equals("SYS")) { + this.root = true; + } + return this.root; + } //////////////////////////////////////////// // Target children handling public Vector<String> getChildren() { @@ -141,6 +142,9 @@ public class Target implements Comparable<Target>, java.io.Serializable { public Vector<String> getParentType() { return this.parentType; } + public void addParentType(String parent_type) { + this.parentType.add(parent_type); + } public void setType(String type) { this.type = type; } @@ -150,11 +154,13 @@ public class Target implements Comparable<Target>, java.io.Serializable { } public String getIdPrefix() { - String t = type.split("-")[1]; - if (t.equals("processor")) { - t = "proc"; + String s[] = type.split("-"); + if (s.length == 1) { return this.name; } + + if (s[1].equals("processor")) { + s[1] = "proc"; } - return t; + return s[1]; } //////////////////////////////////////////////////////// @@ -162,18 +168,24 @@ public class Target implements Comparable<Target>, java.io.Serializable { public TreeMap<String, Attribute> getAttributes() { return attributes; } - public void copyAttributes(Target s) { - for (Map.Entry<String, Attribute> entry : s.getAttributes().entrySet()) { + + public void deepCopyAttributes(HashMap<String,Target> model,HashMap<String,Target> instances) { + ServerWizard2.LOGGER.info("Defaulting attributes for: "+this.getName()); + Target source = model.get(this.getName()); + if (source == null) { + source = instances.get(this.getName()); + } + for (Map.Entry<String, Attribute> entry : source.getAttributes().entrySet()) { String key = new String(entry.getKey()); Attribute value = new Attribute(entry.getValue()); this.attributes.put(key, value); } + for (String c : this.getAllChildren()) { + Target child = instances.get(c); + child.deepCopyAttributes(model, instances); + } } - - public void linkAttributes(Target t) { - this.attributes.clear(); - this.attributes = t.getAttributes(); - } + public boolean attributeExists(String attribute) { if (attributes.get(attribute) == null) { return false; @@ -186,13 +198,8 @@ public class Target implements Comparable<Target>, java.io.Serializable { } return attributes.get(attribute).getValue().getValue(); } - public boolean isAttribute(String attribute) { - if (attributes.get(attribute) == null) { - return false; - } - return true; - } - public void copyAttributesFromParent(Target s) { + + void copyAttributesFromParent(Target s) { for (Map.Entry<String, Attribute> entry : s.getAttributes().entrySet()) { String key = entry.getKey(); Attribute tmpAttribute = entry.getValue(); @@ -209,24 +216,6 @@ public class Target implements Comparable<Target>, java.io.Serializable { } } - public void updateAttributeValue(String attributeName, String value) { - Attribute attribute = attributes.get(attributeName); - if (attribute == null) { - throw new NullPointerException("Invalid Attribute " + attributeName + " in Target " - + this.type); - } - AttributeValue val = attribute.getValue(); - val.setValue(value); - } - - public void updateAttributeValue(String attributeName, AttributeValue value) { - Attribute attribute = attributes.get(attributeName); - if (attribute == null) { - throw new NullPointerException("Invalid Attribute " + attributeName + " in Target " - + this.type); - } - attribute.getValue().setValue(value); - } public Boolean isInput() { String dir = this.getAttribute("DIRECTION"); if (dir.equals("IN") || dir.equals("INOUT")) { @@ -245,7 +234,7 @@ public class Target implements Comparable<Target>, java.io.Serializable { public Boolean isSystem() { return (this.getAttribute("CLASS").equals("SYS")); } - public Boolean isCard() { + Boolean isCard() { return (this.getAttribute("CLASS").equals("CARD") || this.getAttribute("CLASS").equals( "MOTHERBOARD")); } @@ -255,8 +244,18 @@ public class Target implements Comparable<Target>, java.io.Serializable { public Boolean isNode() { return (this.getAttribute("CLASS").equals("ENC")); } - - public void setAttributeValue(String attr, String value) { + Boolean isUnit() { + return (this.getAttribute("CLASS").equals("UNIT") && !this.type.equals("unit") && type.startsWith("unit-")); + } + Boolean isOverrideGroup() { + return (this.getAttribute("MRW_TYPE").equals("TARGET_OVERRIDE_GROUP")); + } + Boolean isOverride() { + return (this.getAttribute("MRW_TYPE").equals("TARGET_OVERRIDE")); + } + + + private void setAttributeValue(String attr, String value) { Attribute attribute = this.attributes.get(attr); if (attribute == null) { return; @@ -268,22 +267,11 @@ public class Target implements Comparable<Target>, java.io.Serializable { this.setAttributeValue("POSITION", String.valueOf(this.getPosition())); } -/* - public String toString() { - String s = "TARGET: " + this.type; - for (Map.Entry<String, Attribute> entry : this.getAttributes().entrySet()) { - Attribute attr = new Attribute(entry.getValue()); - s = s + "\t" + attr.toString() + "\n"; - } - return s; - } -*/ public int compareTo(Target arg0) { Target t = (Target)arg0; return this.getType().compareTo(t.getType()); } - /////////////////////////////////////////////////// // connection/bus handling public Boolean isBusHidden(String busType) { @@ -372,35 +360,28 @@ public class Target implements Comparable<Target>, java.io.Serializable { } public void readInstanceXML(Element t, TreeMap<String, Target> targetModels) throws Exception { - instanceModel = true; name = SystemModel.getElement(t, "instance_name"); type = SystemModel.getElement(t, "type"); - String library_target = SystemModel.getElement(t, "library_target"); - if (library_target.equals("true")) { - this.isLibraryTarget=true; - } else { - this.isLibraryTarget=false; - } + String rootStr = SystemModel.getElement(t, "is_root"); + if (rootStr.equals("true")) { this.root = true; } + if (name.isEmpty()) { name = SystemModel.getElement(t, "id"); - instanceModel = false; } else { String tmpPos = SystemModel.getElement(t, "position"); if (!tmpPos.isEmpty()) { setPosition(tmpPos); } } - + NodeList childList = t.getElementsByTagName("child_id"); for (int j = 0; j < childList.getLength(); ++j) { Element attr = (Element) childList.item(j); - //TargetName targetName = new TargetName(attr.getFirstChild().getNodeValue(),false); children.add(attr.getFirstChild().getNodeValue()); } childList = t.getElementsByTagName("hidden_child_id"); for (int j = 0; j < childList.getLength(); ++j) { Element attr = (Element) childList.item(j); - //argetName targetName = new TargetName(attr.getFirstChild().getNodeValue(),true); childrenHidden.add(attr.getFirstChild().getNodeValue()); } @@ -430,6 +411,7 @@ public class Target implements Comparable<Target>, java.io.Serializable { busses.get(busTarget).add(conn); } } + public void writeInstanceXML(Writer out,HashMap<String,Target> targetLookup,HashMap<String,Boolean>targetWritten) throws Exception { if (targetWritten.containsKey(this.getName())) { return; @@ -438,8 +420,9 @@ public class Target implements Comparable<Target>, java.io.Serializable { out.write("<targetInstance>\n"); out.write("\t<id>" + this.getName() + "</id>\n"); out.write("\t<type>" + this.getType() + "</type>\n"); - out.write("\t<library_target>" + this.isLibraryTarget + "</library_target>\n"); - //out.write("\t<class>" + this.getAttribute("CLASS") + "</class>\n"); + String rootStr = "false"; + if (this.isRoot()) { rootStr = "true"; } + out.write("\t<is_root>" + rootStr + "</is_root>\n"); if (!this.name.isEmpty()) { out.write("\t<instance_name>" + this.name + "</instance_name>\n"); } else { @@ -474,4 +457,113 @@ public class Target implements Comparable<Target>, java.io.Serializable { child.writeInstanceXML(out, targetLookup, targetWritten); } } + + // New format + public void readTargetXML(Element t, TreeMap<String, Target> targetModels, HashMap<String, Attribute> attributeModels) throws Exception { + name = SystemModel.getElement(t, "instance_name"); + type = SystemModel.getElement(t, "type"); + String rootStr = SystemModel.getElement(t, "is_root"); + if (rootStr.equals("true")) { this.root = true; } + + String tmpPos = SystemModel.getElement(t, "position"); + if (!tmpPos.isEmpty()) { + setPosition(tmpPos); + } + parent = SystemModel.getElement(t, "parent"); + parentType.removeAllElements(); + NodeList parentList = t.getElementsByTagName("parent_type"); + for (int i = 0; i < parentList.getLength(); i++) { + Element e = (Element) parentList.item(i); + parentType.add(e.getChildNodes().item(0).getNodeValue()); + } + + NodeList childList = t.getElementsByTagName("child_id"); + for (int j = 0; j < childList.getLength(); ++j) { + Element attr = (Element) childList.item(j); + children.add(attr.getFirstChild().getNodeValue()); + } + childList = t.getElementsByTagName("hidden_child_id"); + for (int j = 0; j < childList.getLength(); ++j) { + Element attr = (Element) childList.item(j); + childrenHidden.add(attr.getFirstChild().getNodeValue()); + } + + NodeList attrList = t.getElementsByTagName("attribute"); + for (int j = 0; j < attrList.getLength(); ++j) { + Element attr = (Element) attrList.item(j); + String id = SystemModel.getElement(attr, "id"); + Attribute a = attributeModels.get(id); + if (a==null) { + ServerWizard2.LOGGER.info("Attribute dropped: "+id+" from "+this.getName()); + } else { + Attribute newA = new Attribute(a); + attributes.put(newA.name, newA); + newA.value.readInstanceXML(attr); + } + } + NodeList busList = t.getElementsByTagName("bus"); + for (int j = 0; j < busList.getLength(); ++j) { + Element bus = (Element) busList.item(j); + String busType = SystemModel.getElement(bus, "bus_type"); + Connection conn = new Connection(); + conn.busType=busType; + Target busTarget=targetModels.get(busType); + if (busTarget==null) { + throw new Exception("Invalid Bus Type "+busType+" for target "+this.getName()); + } + conn.busTarget = new Target(busTarget); + conn.readInstanceXML(bus); + busses.get(busTarget).add(conn); + } + } + public void writeTargetXML(Writer out,HashMap<String,Target> targetLookup, HashMap<String,Boolean>targetWritten) throws Exception { + if (targetWritten.containsKey(this.getName())) { + return; + } + targetWritten.put(this.getName(), true); + out.write("<targetPart>\n"); + out.write("\t<id>" + this.getName() + "</id>\n"); + out.write("\t<type>" + this.getType() + "</type>\n"); + String rootStr = "false"; + if (this.isRoot()) { rootStr = "true"; } + out.write("\t<is_root>" + rootStr + "</is_root>\n"); + if (!this.name.isEmpty()) { + out.write("\t<instance_name>" + this.name + "</instance_name>\n"); + } else { + out.write("\t<instance_name>" + this.getIdPrefix() + "</instance_name>\n"); + } + + out.write("\t<position>" + getPosition() + "</position>\n"); + out.write("\t<parent>" + this.parent + "</parent>\n"); + for (String p_type : this.parentType) { + out.write("\t<parent_type>" + p_type + "</parent_type>\n"); + } + + //write children + for (String childStr : this.children) { + out.write("\t<child_id>"+childStr+"</child_id>\n"); + } + for (String childStr : this.childrenHidden) { + out.write("\t<hidden_child_id>"+childStr+"</hidden_child_id>\n"); + } + //write attributes + for (Map.Entry<String, Attribute> entry : getAttributes().entrySet()) { + Attribute attr = new Attribute(entry.getValue()); + attr.writeInstanceXML(out); + + } + //write busses + for (Map.Entry<Target, Vector<Connection>> entry : busses.entrySet()) { + for (Connection conn : entry.getValue()) { + conn.writeInstanceXML(out); + } + } + out.write("</targetPart>\n"); + + //recursively write children + for (String childStr : this.getAllChildren()) { + Target child = targetLookup.get(childStr); + child.writeTargetXML(out, targetLookup, targetWritten); + } + } } diff --git a/src/com/ibm/ServerWizard2/XmlHandler.java b/src/com/ibm/ServerWizard2/model/XmlHandler.java index c2c0743..0849ef5 100644 --- a/src/com/ibm/ServerWizard2/XmlHandler.java +++ b/src/com/ibm/ServerWizard2/model/XmlHandler.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.model; import java.util.ArrayList; @@ -7,22 +7,18 @@ import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; public class XmlHandler extends DefaultHandler { - protected boolean validationError = false; - protected SAXParseException saxParseException = null; - protected ArrayList<String> warnings = new ArrayList<String>(); - protected String detailedErrorString = ""; + + private ArrayList<String> warnings = new ArrayList<String>(); + + private String detailedErrorString = ""; public void error(SAXParseException exception) throws SAXException { detailedErrorString += "Line:" + exception.getLineNumber() + " , Col:" + exception.getColumnNumber() + ", Error:" + exception.getMessage() + "\n"; - validationError = true; - saxParseException = exception; } public void fatalError(SAXParseException exception) throws SAXException { detailedErrorString += "Line:" + exception.getLineNumber() + " , Col:" + exception.getColumnNumber() + ", Error:" + exception.getMessage() + "\n"; - validationError = true; - saxParseException = exception; } public void warning(SAXParseException exception) throws SAXException { diff --git a/src/com/ibm/ServerWizard2/GithubFile.java b/src/com/ibm/ServerWizard2/utility/GithubFile.java index 1f36d46..6d14e50 100644 --- a/src/com/ibm/ServerWizard2/GithubFile.java +++ b/src/com/ibm/ServerWizard2/utility/GithubFile.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.utility; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -21,6 +21,8 @@ import javax.swing.ProgressMonitorInputStream; import org.eclipse.jface.dialogs.MessageDialog; import org.json.simple.parser.JSONParser; +import com.ibm.ServerWizard2.ServerWizard2; + public class GithubFile { private final String API_URL="https://api.github.com/repos/"; private static String UPDATE_FILE="serverwiz2.update"; @@ -56,7 +58,7 @@ public class GithubFile { public String getVersion() { return version; } - public static String getWorkingDir() { + private static String getWorkingDir() { // gets working directory whether running as jar or from eclipse File f = new File("").getAbsoluteFile(); String workingDir = f.getAbsolutePath() + System.getProperty("file.separator"); @@ -65,7 +67,7 @@ public class GithubFile { public boolean localFileExists() { return this.localFileSize > 0; } - public void init() { + private void init() { String subDir=this.subDirectory+System.getProperty("file.separator"); String workingDir=GithubFile.getWorkingDir(); if (this.isRelease) { @@ -84,7 +86,7 @@ public class GithubFile { localFileSize = this.localFile.length(); } } - public void mkdir() throws Exception { + private void mkdir() throws Exception { //create local directory File sdir = new File(localDirectory); if (!sdir.exists()) { diff --git a/src/com/ibm/ServerWizard2/MyLogFormatter.java b/src/com/ibm/ServerWizard2/utility/MyLogFormatter.java index 2bac399..8de6406 100644 --- a/src/com/ibm/ServerWizard2/MyLogFormatter.java +++ b/src/com/ibm/ServerWizard2/utility/MyLogFormatter.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.utility; import java.text.DateFormat; import java.text.SimpleDateFormat; diff --git a/src/com/ibm/ServerWizard2/ArrayDialogCellEditor.java b/src/com/ibm/ServerWizard2/view/ArrayDialogCellEditor.java index 12393e9..97d246c 100644 --- a/src/com/ibm/ServerWizard2/ArrayDialogCellEditor.java +++ b/src/com/ibm/ServerWizard2/view/ArrayDialogCellEditor.java @@ -1,12 +1,14 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.view; import org.eclipse.jface.viewers.DialogCellEditor; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import com.ibm.ServerWizard2.model.Field; + public class ArrayDialogCellEditor extends DialogCellEditor { - Field field; + private Field field; public ArrayDialogCellEditor(Composite parent,Field field) { super(parent); diff --git a/src/com/ibm/ServerWizard2/ArrayEditingSupport.java b/src/com/ibm/ServerWizard2/view/ArrayEditingSupport.java index afff1b3..8a65f6f 100644 --- a/src/com/ibm/ServerWizard2/ArrayEditingSupport.java +++ b/src/com/ibm/ServerWizard2/view/ArrayEditingSupport.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.view; import java.util.Vector; diff --git a/src/com/ibm/ServerWizard2/ArrayEditorDialog.java b/src/com/ibm/ServerWizard2/view/ArrayEditorDialog.java index 69ddf44..f4f0ca2 100644 --- a/src/com/ibm/ServerWizard2/ArrayEditorDialog.java +++ b/src/com/ibm/ServerWizard2/view/ArrayEditorDialog.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.view; import java.util.Vector; diff --git a/src/com/ibm/ServerWizard2/ArrayLabelProvider.java b/src/com/ibm/ServerWizard2/view/ArrayLabelProvider.java index 1f13fb4..77df8aa 100644 --- a/src/com/ibm/ServerWizard2/ArrayLabelProvider.java +++ b/src/com/ibm/ServerWizard2/view/ArrayLabelProvider.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.view; import java.util.Vector; diff --git a/src/com/ibm/ServerWizard2/AttributeEditingSupport.java b/src/com/ibm/ServerWizard2/view/AttributeEditingSupport.java index 99f7234..6b63098 100644 --- a/src/com/ibm/ServerWizard2/AttributeEditingSupport.java +++ b/src/com/ibm/ServerWizard2/view/AttributeEditingSupport.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.view; import java.util.Vector; @@ -12,18 +12,25 @@ import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TextCellEditor; import org.eclipse.swt.SWT; +import com.ibm.ServerWizard2.model.Field; + public class AttributeEditingSupport extends EditingSupport { private CellEditor editor; private TableViewer viewer; + private Boolean ignoreReadonly = false; public AttributeEditingSupport(TableViewer viewer) { super(viewer); this.viewer=viewer; } + public void setIgnoreReadonly() { + ignoreReadonly = true; + } @Override protected boolean canEdit(Object obj) { Field f = (Field)obj; + if (this.ignoreReadonly == true) { return true; } return !f.readonly; } @@ -52,8 +59,6 @@ public class AttributeEditingSupport extends EditingSupport { this.editor.addListener(new ICellEditorListener() { public void applyEditorValue() { - // TODO Auto-generated method stub - } public void cancelEditor() { @@ -62,7 +67,6 @@ public class AttributeEditingSupport extends EditingSupport { } public void editorValueChanged(boolean arg0, boolean arg1) { - // TODO Auto-generated method stub if (!arg1) { MessageDialog.openError(null, "Invalid format", editor.getErrorMessage()); } @@ -82,7 +86,10 @@ public class AttributeEditingSupport extends EditingSupport { @Override protected void setValue(Object obj, Object value) { Field f = (Field) obj; - f.value = (String) value; - this.getViewer().update(obj, null); + if (f.value==null || !f.value.equals((String)value)) { + f.value = (String) value; + this.getViewer().update(obj, null); + this.viewer.getTable().notifyListeners(SWT.CHANGED, null); + } } } diff --git a/src/com/ibm/ServerWizard2/AttributeValidator.java b/src/com/ibm/ServerWizard2/view/AttributeValidator.java index 0a2ff0e..ca20e3f 100644 --- a/src/com/ibm/ServerWizard2/AttributeValidator.java +++ b/src/com/ibm/ServerWizard2/view/AttributeValidator.java @@ -1,7 +1,9 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.view; import org.eclipse.jface.viewers.ICellEditorValidator; +import com.ibm.ServerWizard2.model.Field; + public class AttributeValidator implements ICellEditorValidator { Field f; public AttributeValidator(Field f) { diff --git a/src/com/ibm/ServerWizard2/DialogHandler.java b/src/com/ibm/ServerWizard2/view/DialogHandler.java index 0bfa0a4..9c7a073 100644 --- a/src/com/ibm/ServerWizard2/DialogHandler.java +++ b/src/com/ibm/ServerWizard2/view/DialogHandler.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.view; import java.util.logging.ConsoleHandler; import java.util.logging.LogRecord; diff --git a/src/com/ibm/ServerWizard2/view/ErrataViewer.java b/src/com/ibm/ServerWizard2/view/ErrataViewer.java new file mode 100644 index 0000000..8c62cbc --- /dev/null +++ b/src/com/ibm/ServerWizard2/view/ErrataViewer.java @@ -0,0 +1,112 @@ +package com.ibm.ServerWizard2.view;
+
+import java.util.Vector;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.wb.swt.SWTResourceManager;
+
+import com.ibm.ServerWizard2.model.Errata;
+
+public class ErrataViewer extends Dialog {
+
+ /**
+ * Create the dialog.
+ *
+ * @param parentShell
+ */
+ Vector<Errata> errata = new Vector<Errata>();
+ private Table table;
+ private StyledText styledText;
+
+ public ErrataViewer(Shell parentShell, Vector<Errata> errata) {
+ super(parentShell);
+ this.errata = errata;
+ }
+
+ /**
+ * Create contents of the dialog.
+ *
+ * @param parent
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite container = (Composite) super.createDialogArea(parent);
+ container.setLayout(new FillLayout(SWT.HORIZONTAL));
+
+ table = new Table(container, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+ table.setSize(100, 100);
+
+ styledText = new StyledText(container, SWT.BORDER);
+ styledText.setFont(SWTResourceManager.getFont("Courier New", 8, SWT.NORMAL));
+
+ for (int i=errata.size()-1;i>=0;i--) {
+ TableItem item = new TableItem(table, SWT.NONE);
+ item.setText(errata.get(i).getId());
+ item.setData(errata.get(i));
+ }
+
+ table.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ if (table.getSelectionCount() > 0) {
+ TableItem item = table.getSelection()[0];
+ Errata e = (Errata) item.getData();
+ styledText.setText(e.getDetail());
+ }
+ }
+ });
+
+ table.addListener (SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ TableItem item = (TableItem) event.item;
+ Errata e = (Errata) item.getData();
+ if (item.getChecked()) {
+ e.setApplied(true);
+ } else {
+ e.setApplied(false);
+ }
+ }
+ });
+
+ return container;
+ }
+
+ /**
+ * Create contents of the button bar.
+ *
+ * @param parent
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ Button button = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+ }
+
+ /**
+ * Return the initial size of the dialog.
+ */
+ @Override
+ protected Point getInitialSize() {
+ return new Point(675, 377);
+ }
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Errata Viewer");
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/LogViewerDialog.java b/src/com/ibm/ServerWizard2/view/LogViewerDialog.java index 6195ee9..7777a1c 100644 --- a/src/com/ibm/ServerWizard2/LogViewerDialog.java +++ b/src/com/ibm/ServerWizard2/view/LogViewerDialog.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.view; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; diff --git a/src/com/ibm/ServerWizard2/MainDialog.java b/src/com/ibm/ServerWizard2/view/MainDialog.java index 08c287d..9aa5d30 100644 --- a/src/com/ibm/ServerWizard2/MainDialog.java +++ b/src/com/ibm/ServerWizard2/view/MainDialog.java @@ -1,8 +1,6 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.view; -import java.util.HashMap; import java.util.Map; -import java.util.TreeMap; import java.util.Vector; import org.eclipse.jface.dialogs.Dialog; @@ -28,6 +26,7 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Label; @@ -45,6 +44,15 @@ import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.swt.widgets.TreeItem; import org.eclipse.wb.swt.SWTResourceManager; +import com.ibm.ServerWizard2.ServerWizard2; +import com.ibm.ServerWizard2.controller.TargetWizardController; +import com.ibm.ServerWizard2.model.Attribute; +import com.ibm.ServerWizard2.model.Connection; +import com.ibm.ServerWizard2.model.ConnectionEndpoint; +import com.ibm.ServerWizard2.model.Field; +import com.ibm.ServerWizard2.model.Target; +import com.ibm.ServerWizard2.utility.GithubFile; + public class MainDialog extends Dialog { private TableViewer viewer; private Tree tree; @@ -60,14 +68,16 @@ public class MainDialog extends Dialog { private ConnectionEndpoint source; private ConnectionEndpoint dest; - TargetWizardController controller; + private TargetWizardController controller; // Buttons private Button btnAddTarget; private Button btnCopyInstance; + private Button btnDefaults; private Button btnDeleteTarget; private Button btnSave; private Button btnOpen; + private Button btnOpenLib; private Button btnDeleteConnection; private Button btnSaveAs; @@ -83,6 +93,7 @@ public class MainDialog extends Dialog { private Label lblInstanceType; private Composite compositeInstance; private Composite composite; + private Composite buttonRow1; private Vector<Field> attributes; private Combo cmbBusses; @@ -100,7 +111,10 @@ public class MainDialog extends Dialog { private Composite compositeDir; private Button btnHideBusses; private Button btnShowHidden; - + + private AttributeEditingSupport attributeEditor; + private Label label; + private Label label_1; /** * Create the dialog. * @@ -129,9 +143,12 @@ public class MainDialog extends Dialog { protected Control createDialogArea(Composite parent) { container = (Composite) super.createDialogArea(parent); container.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); - container.setLayout(new GridLayout(1, false)); + GridLayout gl_container = new GridLayout(1, false); + gl_container.verticalSpacing = 0; + container.setLayout(gl_container); composite = new Composite(container, SWT.NONE); + RowLayout rl_composite = new RowLayout(SWT.HORIZONTAL); rl_composite.spacing = 20; rl_composite.wrap = false; @@ -147,7 +164,17 @@ public class MainDialog extends Dialog { gd_sashForm_1.heightHint = 375; gd_sashForm_1.widthHint = 712; sashForm_1.setLayoutData(gd_sashForm_1); + + buttonRow1 = new Composite(container, SWT.NONE); + GridData gd_buttonRow1 = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1); + gd_buttonRow1.widthHint = 751; + buttonRow1.setLayoutData(gd_buttonRow1); + GridLayout rl_buttonRow1 = new GridLayout(18, false); + buttonRow1.setLayout(rl_buttonRow1); + this.createButtonsForButtonBar2(buttonRow1); + + sashForm = new SashForm(sashForm_1, SWT.NONE); // Target Instances View @@ -189,7 +216,7 @@ public class MainDialog extends Dialog { lblInstanceType.setText("Instance Type:"); lblInstanceType.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); - combo = new Combo(compositeInstance, SWT.NONE); + combo = new Combo(compositeInstance, SWT.READ_ONLY); GridData gd_combo = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); gd_combo.widthHint = 167; combo.setLayoutData(gd_combo); @@ -216,17 +243,24 @@ public class MainDialog extends Dialog { btnDeleteTarget.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); btnDeleteTarget.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); btnDeleteTarget.setText("Delete Instance"); - new Label(compositeInstance, SWT.NONE); - + btnShowHidden = new Button(compositeInstance, SWT.CHECK); + GridData gd_btnShowHidden = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_btnShowHidden.heightHint = 10; + btnShowHidden.setLayoutData(gd_btnShowHidden); btnShowHidden.setText(" Show Hidden"); - - btnCopyInstance = new Button(compositeInstance, SWT.NONE); - btnCopyInstance.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1)); - btnCopyInstance.setText("Copy Node or Connector"); - btnCopyInstance.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); - btnCopyInstance.setEnabled(false); - // new Label(compositeInstance, SWT.NONE); + + btnCopyInstance = new Button(compositeInstance, SWT.NONE); + btnCopyInstance.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1)); + btnCopyInstance.setText("Copy Node or Connector"); + btnCopyInstance.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); + btnCopyInstance.setEnabled(false); + + btnDefaults = new Button(compositeInstance, SWT.NONE); + btnDefaults.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1)); + btnDefaults.setText("Restore Defaults"); + btnDefaults.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); + btnDefaults.setEnabled(false); // //////////////////////////////////////////////////// // Add Busses Tab @@ -279,8 +313,8 @@ public class MainDialog extends Dialog { lblInstanceDirections = new Label(compositeDir, SWT.NONE); lblInstanceDirections.setFont(SWTResourceManager.getFont("Arial", 8, SWT.NORMAL)); - lblInstanceDirections.setText("Steps for adding a new instance\r\n" - + "1. Select parent instance in Instance Tree (sys-0 if just starting)\r\n" + lblInstanceDirections.setText("Select 'chip' to create a new part or 'sys-' to create a system\r\n" + + "1. Select parent instance in Instance Tree\r\n" + "2. Select new instance type in dropdown\r\n" + "3. (Optional) Enter custom name\r\n" + "4. Click \"Add Instance\""); lblInstanceDirections.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE)); @@ -305,7 +339,6 @@ public class MainDialog extends Dialog { this.setDirtyState(false); // load file if passed on command line if (!mrwFilename.isEmpty()) { - ServerWizard2.LOGGER.info("Loading MRW: " + mrwFilename); controller.readXML(mrwFilename); setFilename(mrwFilename); } @@ -317,18 +350,23 @@ public class MainDialog extends Dialog { // columnName.setWidth(200); sashForm.setWeights(new int[] { 1, 1 }); columnName.pack(); + return container; } - /** - * Create contents of the button bar. - * - * @param parent - */ - @Override protected void createButtonsForButtonBar(Composite parent) { - parent.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); - Button btnNew = createButton(parent, IDialogConstants.NO_ID, "New", false); + parent.setEnabled(false); + GridLayout layout = (GridLayout)parent.getLayout(); + layout.marginHeight = 0; + } + + protected void createButtonsForButtonBar2(Composite row1) { + row1.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); + + Button btnNew = createButton(row1, IDialogConstants.NO_ID, "New", false); + GridData gd_btnNew = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_btnNew.widthHint = 70; + btnNew.setLayoutData(gd_btnNew); btnNew.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); btnNew.addSelectionListener(new SelectionAdapter() { @Override @@ -345,13 +383,20 @@ public class MainDialog extends Dialog { setFilename(""); initAll(); setDirtyState(false); + refreshInstanceTree(); + refreshConnections(); + updateView(); + } catch (Exception e1) { e1.printStackTrace(); } } }); - btnOpen = createButton(parent, IDialogConstants.NO_ID, "Open", false); + btnOpen = createButton(row1, IDialogConstants.NO_ID, "Open...", false); + GridData gd_btnOpen = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_btnOpen.widthHint = 70; + btnOpen.setLayoutData(gd_btnOpen); btnOpen.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); btnOpen.addSelectionListener(new SelectionAdapter() { @Override @@ -371,15 +416,18 @@ public class MainDialog extends Dialog { if (filename == null) { return; } - controller.readXML(filename); + Boolean dirty = controller.readXML(filename); setFilename(filename); initAll(); - setDirtyState(false); + setDirtyState(dirty); } }); btnOpen.setToolTipText("Loads XML from file"); - btnSave = createButton(parent, IDialogConstants.NO_ID, "Save", false); + btnSave = createButton(row1, IDialogConstants.NO_ID, "Save", false); + GridData gd_btnSave = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_btnSave.widthHint = 70; + btnSave.setLayoutData(gd_btnSave); btnSave.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); btnSave.addSelectionListener(new SelectionAdapter() { @Override @@ -403,7 +451,10 @@ public class MainDialog extends Dialog { }); btnSave.setText("Save"); - btnSaveAs = createButton(parent, IDialogConstants.NO_ID, "Save As...", false); + btnSaveAs = createButton(row1, IDialogConstants.NO_ID, "Save As...", false); + GridData gd_btnSaveAs = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_btnSaveAs.widthHint = 70; + btnSaveAs.setLayoutData(gd_btnSaveAs); btnSaveAs.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -424,23 +475,56 @@ public class MainDialog extends Dialog { btnSaveAs.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); btnSaveAs.setEnabled(true); - - btnRunChecks = createButton(parent, IDialogConstants.NO_ID, "Run Checks", false); + + label = new Label(buttonRow1, SWT.SEPARATOR | SWT.VERTICAL); + GridData gd_sep = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_sep.heightHint = 30; + gd_sep.widthHint = 50; + label.setLayoutData(gd_sep); + + btnOpenLib = createButton(row1, IDialogConstants.NO_ID, "Open Lib", false); + GridData gd_btnOpenLib = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_btnOpenLib.widthHint = 74; + + btnOpenLib.setLayoutData(gd_btnOpenLib); + btnOpenLib.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); + btnOpenLib.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Button b = (Button) e.getSource(); + DirectoryDialog fdlg = new DirectoryDialog(b.getShell(), SWT.OPEN); + fdlg.setFilterPath(controller.getWorkingDir()); + String libPath = fdlg.open(); + if (libPath == null) { + return; + } + controller.loadLibrary(libPath); + } + }); + btnOpenLib.setToolTipText("Loads External Library"); + + + btnRunChecks = createButton(row1, IDialogConstants.NO_ID, "Export HTML", false); + GridData gd_btnRunChecks = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_btnRunChecks.widthHint = 80; + btnRunChecks.setLayoutData(gd_btnRunChecks); btnRunChecks.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent arg0) { String tempFile = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + "~temp.xml"; controller.writeXML(tempFile); - controller.runChecks(tempFile); + String htmlFilename = mrwFilename; + htmlFilename = htmlFilename.replace(".xml", "") + ".html"; + controller.runChecks(tempFile,htmlFilename); } }); btnRunChecks.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); - Button btnSpacer = createButton(parent, IDialogConstants.NO_ID, "Spacer", false); - btnSpacer.setVisible(false); - - Button btnForceUpdate = createButton(parent, IDialogConstants.NO_ID, "Force Update", false); + Button btnForceUpdate = createButton(row1, IDialogConstants.NO_ID, "Force Update", false); + GridData gd_btnForceUpdate = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_btnForceUpdate.widthHint = 80; + btnForceUpdate.setLayoutData(gd_btnForceUpdate); btnForceUpdate.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); btnForceUpdate.addSelectionListener(new SelectionAdapter() { @Override @@ -448,8 +532,17 @@ public class MainDialog extends Dialog { GithubFile.removeUpdateFile(true); } }); - - Button btnExit = createButton(parent, IDialogConstants.CLOSE_ID, "Exit", false); + + label_1 = new Label(buttonRow1, SWT.SEPARATOR | SWT.VERTICAL); + GridData gd_sep2 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_sep2.heightHint = 30; + gd_sep2.widthHint = 50; + label_1.setLayoutData(gd_sep2); + + Button btnExit = createButton(row1, IDialogConstants.CLOSE_ID, "Exit", false); + GridData gd_btnExit = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_btnExit.widthHint = 80; + btnExit.setLayoutData(gd_btnExit); btnExit.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); btnExit.addSelectionListener(new SelectionAdapter() { @Override @@ -477,12 +570,12 @@ public class MainDialog extends Dialog { return null; } - public void initAll() { + private void initAll() { tabFolder.setSelection(0); initInstanceMode(); } - public void initBusMode() { + private void initBusMode() { busMode = true; this.lblBusDirections.setEnabled(true); this.lblBusDirections.setVisible(true); @@ -491,19 +584,21 @@ public class MainDialog extends Dialog { // update card combo cmbCards.removeAll(); + this.targetForConnections = null; for (Target target : controller.getConnectionCapableTargets()) { cmbCards.add(target.getName()); cmbCards.setData(target.getName(), target); } if (cmbCards.getItemCount() > 0) { - cmbCards.select(0); + cmbCards.select(-1); + //this.targetForConnections = (Target)cmbCards.getData(); } for (TreeItem item : tree.getItems()) { Target target = (Target) item.getData(); // controller.getRootTarget().hideBusses(); controller.hideBusses(target); } - this.targetForConnections = null; + this.source = null; this.dest = null; @@ -513,7 +608,7 @@ public class MainDialog extends Dialog { this.updateView(); } - public void initInstanceMode() { + private void initInstanceMode() { busMode = false; this.lblInstanceDirections.setEnabled(true); this.lblInstanceDirections.setVisible(true); @@ -543,12 +638,14 @@ public class MainDialog extends Dialog { } } - public void updateView() { + private void updateView() { Target targetInstance = getSelectedTarget(); if (targetInstance == null) { btnAddTarget.setEnabled(false); btnDeleteTarget.setEnabled(false); btnCopyInstance.setEnabled(false); + btnDefaults.setEnabled(false); + updateChildCombo(null); return; } updatePopupMenu(targetInstance); @@ -568,10 +665,11 @@ public class MainDialog extends Dialog { } else { btnCopyInstance.setEnabled(false); } + btnDefaults.setEnabled(true); } - public void updatePopupMenu(Target selectedTarget) { + private void updatePopupMenu(Target selectedTarget) { if (selectedTarget == null || tree.getSelectionCount()==0) { return; } @@ -660,7 +758,6 @@ public class MainDialog extends Dialog { } ConnectionEndpoint ep = getEndpoint(parentItem,null); String path = "/"+ep.getName(); - controller.setGlobalSetting(path, "INSTANCE_ID", configParentTarget.getName()); if (config) { controller.setGlobalSetting(path, "IO_CONFIG_SELECT", configNum); } else { @@ -674,7 +771,7 @@ public class MainDialog extends Dialog { this.updateInstanceTree(configParentTarget, grandParentItem, parentItem); } - public ConnectionEndpoint getEndpoint(TreeItem item, String stopCard) { + private ConnectionEndpoint getEndpoint(TreeItem item, String stopCard) { ConnectionEndpoint endpoint = new ConnectionEndpoint(); Target target = (Target) item.getData(); @@ -707,7 +804,7 @@ public class MainDialog extends Dialog { return endpoint; } - public ConnectionEndpoint getEndpoint(boolean setBold) { + private ConnectionEndpoint getEndpoint(boolean setBold) { TreeItem item = tree.getSelection()[0]; ConnectionEndpoint endpoint = getEndpoint(item,cmbCards.getText()); if (setBold && endpoint != null) { @@ -730,17 +827,17 @@ public class MainDialog extends Dialog { Attribute attribute = entry.getValue(); if (!attribute.isHidden()) { - if (attribute.isGlobal()) { + if (attribute.isGlobal() && !controller.getModelCreationMode()) { if (ep !=null) { String path="/"+ep.getName(); - TreeMap<String,Field> settings = controller.getGlobalSettings(path); - if (settings == null) { - controller.setGlobalSetting(path, attribute.name, ""); - controller.setGlobalSetting(path, "INSTANCE_ID", ep.getTargetName()); - } Field field = controller.getGlobalSetting(path, attribute.name); if (field==null) { - ServerWizard2.LOGGER.severe("Field Null: "+path+"; "+attribute.name); + controller.setGlobalSetting(path, attribute.name, ""); + field = controller.getGlobalSetting(path, attribute.name); + } + field.type = attribute.getValue().getType(); + if (field.type.equals("enumeration")) { + field.enumerator = attribute.getValue().getFields().get(0).enumerator; } attributes.add(field); } @@ -753,7 +850,7 @@ public class MainDialog extends Dialog { viewer.refresh(); } - public void clearTreeAll() { + private void clearTreeAll() { if (tree.getItemCount() > 0) { clearTree(tree.getItem(0)); } @@ -767,12 +864,15 @@ public class MainDialog extends Dialog { treeitem.removeAll(); treeitem.dispose(); } - public void refreshInstanceTree() { + private void refreshInstanceTree() { currentPath=""; targetFound = false; for (Target target : controller.getRootTargets()) { this.updateInstanceTree(target, null); } + if (controller.getRootTargets().size() == 0) { + this.clearTreeAll(); + } btnAddTarget.setEnabled(false); } @@ -780,7 +880,7 @@ public class MainDialog extends Dialog { this.updateInstanceTree(target, parentItem, null); } - public void updateInstanceTree(Target target, TreeItem parentItem, TreeItem item) { + private void updateInstanceTree(Target target, TreeItem parentItem, TreeItem item) { if (target == null) { return; } @@ -806,8 +906,8 @@ public class MainDialog extends Dialog { } } if (parentItem != null) { - Field cnfgSelect = controller.getGlobalSetting(lastPath, "IO_CONFIG_SELECT"); - if (cnfgSelect != null) { + if (controller.isGlobalSettings(lastPath, "IO_CONFIG_SELECT")) { + Field cnfgSelect = controller.getGlobalSetting(lastPath, "IO_CONFIG_SELECT"); if (!cnfgSelect.value.isEmpty() && !cnfgSelect.value.equals("0")) { String cnfg = target.getAttribute("IO_CONFIG_NUM"); if (!cnfg.equals(cnfgSelect.value)) { @@ -844,7 +944,9 @@ public class MainDialog extends Dialog { treeitem = new TreeItem(parentItem, SWT.VIRTUAL | SWT.BORDER); } } - + //Just display last part of instance name path + //String nameA[] = name.split("\\."); + //treeitem.setText(nameA[nameA.length-1]); treeitem.setText(name); treeitem.setData(target); @@ -870,12 +972,12 @@ public class MainDialog extends Dialog { currentPath=lastPath; } - public void addConnection(Connection conn) { + private void addConnection(Connection conn) { listBusses.add(conn.getName()); listBusses.setData(conn.getName(), conn); } - public void refreshConnections() { + private void refreshConnections() { this.source=null; this.dest=null; listBusses.removeAll(); @@ -900,7 +1002,7 @@ public class MainDialog extends Dialog { } } - public void setFontStyle(TreeItem item, int style, boolean selected) { + private void setFontStyle(TreeItem item, int style, boolean selected) { if (item.isDisposed()) { return; } @@ -926,14 +1028,14 @@ public class MainDialog extends Dialog { return super.close(); } - public void addConnection(Boolean cabled) { + private void addConnection(Boolean cabled) { Target busTarget = (Target) cmbBusses.getData(cmbBusses.getText()); Connection conn = targetForConnections.addConnection(busTarget, source, dest, cabled); this.addConnection(conn); setDirtyState(true); } - public void deleteConnection() { + private void deleteConnection() { if (targetForConnections == null || listBusses.getSelectionCount() == 0) { return; } @@ -957,11 +1059,13 @@ public class MainDialog extends Dialog { public void setFilename(String filename) { this.mrwFilename = filename; - this.btnSave.setEnabled(true); + if (btnSave != null) { + this.btnSave.setEnabled(true); + } this.getShell().setText("ServerWiz2 - " + this.mrwFilename); } - public void addEvents() { + private void addEvents() { btnShowHidden.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent arg0) { @@ -1000,12 +1104,24 @@ public class MainDialog extends Dialog { public void widgetSelected(SelectionEvent e) { Target chk = (Target) combo.getData(combo.getText()); if (chk != null) { - TreeItem selectedItem = tree.getSelection()[0]; - Target parentTarget = (Target) selectedItem.getData(); + TreeItem selectedItem = null; + Target parentTarget = null; + if (tree.getSelectionCount() > 0) { + selectedItem = tree.getSelection()[0]; + parentTarget = (Target) selectedItem.getData(); + } + if (chk.getType().equals("chip") || chk.getType().equals("targetoverride")) { + ServerWizard2.LOGGER.info("Entering model creation mode"); + attributeEditor.setIgnoreReadonly(); + controller.setModelCreationMode(); + tbtmAddBusses.dispose(); + } String nameOverride = txtInstanceName.getText(); controller.addTargetInstance(chk, parentTarget, selectedItem, nameOverride); txtInstanceName.setText(""); - selectedItem.setExpanded(true); + if (tree.getSelectionCount() > 0) { + selectedItem.setExpanded(true); + } columnName.pack(); setDirtyState(true); } @@ -1039,6 +1155,23 @@ public class MainDialog extends Dialog { setDirtyState(true); } }); + btnDefaults.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent arg0) { + TreeItem selectedItem = tree.getSelection()[0]; + if (selectedItem == null) { + return; + } + if (!MessageDialog.openConfirm(null, "Restore Defaults", "Are you sure you want to restore default attribute values on this target and all of it's children?")) { + return; + } + ServerWizard2.LOGGER.info("Restoring Defaults"); + Target target = (Target) selectedItem.getData(); + controller.deepCopyAttributes(target); + setDirtyState(true); + } + }); + cmbCards.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -1078,7 +1211,7 @@ public class MainDialog extends Dialog { }); } - public void createAttributeTable() { + private void createAttributeTable() { Table table = viewer.getTable(); table.setHeaderVisible(true); @@ -1089,7 +1222,7 @@ public class MainDialog extends Dialog { setDirtyState(true); } }); - + final TableViewerColumn colName = new TableViewerColumn(viewer, SWT.NONE); colName.getColumn().setWidth(256); colName.getColumn().setText("Attribute"); @@ -1125,8 +1258,9 @@ public class MainDialog extends Dialog { return f.value; } }); - colValue.setEditingSupport(new AttributeEditingSupport(viewer)); - + attributeEditor = new AttributeEditingSupport(viewer); + colValue.setEditingSupport(attributeEditor); + final TableViewerColumn colDesc = new TableViewerColumn(viewer, SWT.NONE); colDesc.getColumn().setWidth(350); colDesc.getColumn().setText("Description"); @@ -1138,6 +1272,17 @@ public class MainDialog extends Dialog { } }); + final TableViewerColumn colGroup = new TableViewerColumn(viewer, SWT.NONE); + colGroup.getColumn().setWidth(120); + colGroup.getColumn().setText("Group"); + colGroup.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + Field f = (Field) element; + return f.group; + } + }); + viewer.setContentProvider(ArrayContentProvider.getInstance()); attributes = new Vector<Field>(); viewer.setInput(attributes); diff --git a/src/com/ibm/ServerWizard2/MessagePopup.java b/src/com/ibm/ServerWizard2/view/MessagePopup.java index 03b277c..6bfef88 100644 --- a/src/com/ibm/ServerWizard2/MessagePopup.java +++ b/src/com/ibm/ServerWizard2/view/MessagePopup.java @@ -1,4 +1,4 @@ -package com.ibm.ServerWizard2; +package com.ibm.ServerWizard2.view; import java.awt.BorderLayout; import java.awt.event.ActionEvent; |