diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/InputConfigClassSelectionDialog.form b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/InputConfigClassSelectionDialog.form deleted file mode 100644 index 8993f79..0000000 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/InputConfigClassSelectionDialog.form +++ /dev/null @@ -1,183 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/InputConfigClassSelectionDialog.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/InputConfigClassSelectionDialog.java index 9729cc7..35d499c 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/InputConfigClassSelectionDialog.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/InputConfigClassSelectionDialog.java @@ -6,12 +6,17 @@ import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.GroupLayout; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.LayoutStyle; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; + import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -28,27 +33,19 @@ */ public class InputConfigClassSelectionDialog extends javax.swing.JDialog { - // + // + /** * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always regenerated by the - * Form Editor. + * This is the first part of the popup you see. */ - // //GEN-BEGIN:initComponents - private void initComponents() { + // + private void initComponents() throws IOException, ParserConfigurationException, SAXException { cancelButton = new javax.swing.JButton(); okButton = new javax.swing.JButton(); jSeparator1 = new javax.swing.JSeparator(); messageLabelText = new javax.swing.JLabel(); - neuronsParamsClassLbl = new javax.swing.JLabel(); - synapsesParamsClassLbl = new javax.swing.JLabel(); - connectionsParamsClassLbl = new javax.swing.JLabel(); - layoutParamsClassLbl = new javax.swing.JLabel(); - neuronsParamsClassCBox = new javax.swing.JComboBox<>(); - connectionsParamsClassCBox = new javax.swing.JComboBox<>(); - synapsesParamsClassCBox = new javax.swing.JComboBox<>(); - layoutParamsClassCBox = new javax.swing.JComboBox<>(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Simulator Configuration"); @@ -70,84 +67,120 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { messageLabelText.setText("None"); - neuronsParamsClassLbl.setText("NeuronsParams Class:"); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); - synapsesParamsClassLbl.setText("SynapsesParams Class:"); + GroupLayout.ParallelGroup horizontalComponentsLabels = layout + .createParallelGroup(GroupLayout.Alignment.LEADING); + GroupLayout.ParallelGroup horizontalComponentsCBoxes = layout + .createParallelGroup(GroupLayout.Alignment.LEADING); + GroupLayout.SequentialGroup verticalComponents = layout + .createSequentialGroup().addContainerGap(17, Short.MAX_VALUE); - connectionsParamsClassLbl.setText("ConnectionsParams Class:"); + loadComponents(layout, horizontalComponentsLabels, horizontalComponentsCBoxes, verticalComponents); - layoutParamsClassLbl.setText("LayoutParams Class:"); + verticalComponents + .addComponent(jSeparator1, GroupLayout.PREFERRED_SIZE, + GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(cancelButton).addComponent(okButton).addComponent(messageLabelText)) + .addContainerGap(); - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jSeparator1) .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout - .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup().addComponent(messageLabelText) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, - javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton)) - .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(connectionsParamsClassLbl) - .addComponent(layoutParamsClassLbl, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(synapsesParamsClassLbl, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(neuronsParamsClassLbl, javax.swing.GroupLayout.Alignment.TRAILING)) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(neuronsParamsClassCBox, javax.swing.GroupLayout.PREFERRED_SIZE, - javax.swing.GroupLayout.DEFAULT_SIZE, - javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(connectionsParamsClassCBox, - javax.swing.GroupLayout.PREFERRED_SIZE, - javax.swing.GroupLayout.DEFAULT_SIZE, - javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(synapsesParamsClassCBox, javax.swing.GroupLayout.PREFERRED_SIZE, - javax.swing.GroupLayout.DEFAULT_SIZE, - javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(layoutParamsClassCBox, javax.swing.GroupLayout.PREFERRED_SIZE, - javax.swing.GroupLayout.DEFAULT_SIZE, - javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 131, Short.MAX_VALUE))) + .addGroup(layout.createSequentialGroup().addComponent(messageLabelText) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, + javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton)) + .addGroup(layout.createSequentialGroup() + .addGroup(horizontalComponentsLabels) + .addGap(18, 18, 18) + .addGroup(horizontalComponentsCBoxes) + .addGap(0, 131, Short.MAX_VALUE))) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( - javax.swing.GroupLayout.Alignment.TRAILING, - layout.createSequentialGroup().addContainerGap(17, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(neuronsParamsClassLbl) - .addComponent(neuronsParamsClassCBox, javax.swing.GroupLayout.PREFERRED_SIZE, - javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(synapsesParamsClassLbl) - .addComponent(synapsesParamsClassCBox, javax.swing.GroupLayout.PREFERRED_SIZE, - javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(connectionsParamsClassLbl) - .addComponent(connectionsParamsClassCBox, javax.swing.GroupLayout.PREFERRED_SIZE, - javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(layoutParamsClassLbl) - .addComponent(layoutParamsClassCBox, javax.swing.GroupLayout.PREFERRED_SIZE, - javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) - .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, - javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(cancelButton).addComponent(okButton).addComponent(messageLabelText)) - .addContainerGap())); + javax.swing.GroupLayout.Alignment.TRAILING, verticalComponents)); pack(); } - // //GEN-END:initComponents - private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_okButtonActionPerformed + /** + * Load components and Template paths. + * + * @param layout + * @param horizontalComponentsLabels + * @param horizontalComponentsCBoxes + * @param verticalComponents + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + */ + private void loadComponents(GroupLayout layout, + GroupLayout.ParallelGroup horizontalComponentsLabels, + GroupLayout.ParallelGroup horizontalComponentsCBoxes, + GroupLayout.SequentialGroup verticalComponents) + throws IOException, SAXException, ParserConfigurationException { + Document allParamsClassesDoc = SystemConfig.getAllParamsClassesDoc(); + NodeList roots = allParamsClassesDoc.getChildNodes(); + for (int i = 0; i < roots.getLength(); i++) { + Node root = roots.item(i); + if (root.getNodeType() == Node.ELEMENT_NODE) { + NodeList paramsClassesTypes = root.getChildNodes(); + for (int j = 0; j < paramsClassesTypes.getLength(); j++) { + Node paramsClassesType = paramsClassesTypes.item(j); + if (paramsClassesType.getNodeType() == Node.ELEMENT_NODE) { + ArrayList paramsTemplatePaths = new ArrayList<>(); + String templateDirectory = ((Element) paramsClassesType) + .getAttribute(SystemConfig.TEMPLATE_DIRECTORY_ATTRIBUTE_NAME); + String paramsClassesTypeName = paramsClassesType.getNodeName(); + JLabel classType; + if (paramsClassesTypeName.contains("Classes")) + classType = new JLabel(paramsClassesTypeName + .substring(0, paramsClassesTypeName.length() - 7) + " Class:"); + else + classType = new JLabel(paramsClassesTypeName); + JComboBox classTypeCBox = new JComboBox<>(); + paramsClassesCBoxes.add(classTypeCBox); + horizontalComponentsLabels + .addComponent(classType, GroupLayout.Alignment.TRAILING); + horizontalComponentsCBoxes + .addComponent(classTypeCBox, + GroupLayout.PREFERRED_SIZE, + GroupLayout.DEFAULT_SIZE, + GroupLayout.PREFERRED_SIZE); + verticalComponents + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(classType) + .addComponent(classTypeCBox, GroupLayout.PREFERRED_SIZE, + GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18); + NodeList paramsClasses = paramsClassesType.getChildNodes(); + for (int k = 0; k < paramsClasses.getLength(); k++) { + Node paramsClass = paramsClasses.item(k); + if (paramsClass.getNodeType() == Node.ELEMENT_NODE) { + String className = ((Element) paramsClass) + .getAttribute(SystemConfig.NAME_ATTRIBUTE_NAME); + classTypeCBox.addItem(className); + String templatePath = templateDirectory + + ((Element) paramsClass).getAttribute( + SystemConfig.TEMPLATE_FILE_NAME_ATTRIBUTE_NAME); + paramsTemplatePaths.add(templatePath); + } + } + templatePaths.add(paramsTemplatePaths); + } + } + } + } + } + // // + + private void okButtonActionPerformed(java.awt.event.ActionEvent evt) { LOG.info("Ok Button Clicked"); try { setConfigXMLDoc(); @@ -157,26 +190,18 @@ private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIR okClicked = true; setVisible(false); LOG.info("Ok Button ended"); - }// GEN-LAST:event_okButtonActionPerformed + } - private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_cancelButtonActionPerformed + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { setVisible(false); - }// GEN-LAST:event_cancelButtonActionPerformed + } - // Variables declaration - do not modify//GEN-BEGIN:variables + // Variables declaration - do not modify private javax.swing.JButton cancelButton; - private javax.swing.JComboBox connectionsParamsClassCBox; - private javax.swing.JLabel connectionsParamsClassLbl; private javax.swing.JSeparator jSeparator1; - private javax.swing.JComboBox layoutParamsClassCBox; - private javax.swing.JLabel layoutParamsClassLbl; private javax.swing.JLabel messageLabelText; - private javax.swing.JComboBox neuronsParamsClassCBox; - private javax.swing.JLabel neuronsParamsClassLbl; private javax.swing.JButton okButton; - private javax.swing.JComboBox synapsesParamsClassCBox; - private javax.swing.JLabel synapsesParamsClassLbl; - // End of variables declaration//GEN-END:variables + // End of variables declaration // // @@ -186,39 +211,32 @@ private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN private Document baseTemplateInfoDoc = null; private Document xmlDoc = null; private boolean okClicked = false; - private ArrayList neuronsParamsTemplatePaths = new ArrayList<>(); - private ArrayList synapsesParamsTemplatePaths = new ArrayList<>(); - private ArrayList connectionsParamsTemplatePaths = new ArrayList<>(); - private ArrayList layoutParamsTemplatePaths = new ArrayList<>(); - private String neuronsParamsNodePath = null; - private String synapsesParamsNodePath = null; - private String connectionsParamsNodePath = null; - private String layoutParamsNodePath = null; - private String neuronsParamsClass = null; - private String synapsesParamsClass = null; - private String connectionsParamsClass = null; - private String layoutParamsClass = null; + + private ArrayList> templatePaths = new ArrayList<>(); + private ArrayList nodePaths = new ArrayList<>(); + private ArrayList paramsClassesCBoxes = new ArrayList<>(); // // + /** - * * @param projectName * @param modal * @param configFilename */ public InputConfigClassSelectionDialog(String projectName, boolean modal, - String configFilename) { + String configFilename) { LOG.info("New InputConfigClassSelectionDialog for " + projectName); - initComponents(); - setModal(modal); try { + initComponents(); + setModal(modal); baseTemplateInfoDoc = SystemConfig.getBaseTemplateInfoDoc(); Node baseTemplateInfoNode = baseTemplateInfoDoc.getFirstChild(); icm = new DynamicInputConfigurationManager(configFilename); xmlDoc = icm.getInputConfigDoc(); - loadParamsClassCBoxes(); + loadNodePaths(); + setComboBoxOptions(); } catch (Exception e) { System.err.println(e.toString()); } @@ -241,67 +259,9 @@ public DynamicInputConfigurationManager getInputConfigMgr() { } /** - * setup Parameter classes combo boxes. This is the first part of the popup you see. - * - * @throws IOException - * @throws ParserConfigurationException - * @throws SAXException - * @throws XPathExpressionException + * Get Node paths for each param class. */ - private void loadParamsClassCBoxes() throws IOException, ParserConfigurationException, - SAXException, XPathExpressionException { - Document allParamsClassesDoc = SystemConfig.getAllParamsClassesDoc(); - NodeList roots = allParamsClassesDoc.getChildNodes(); - - // build list of template paths for each params class while adding each class name to the - // appropriate combo box - for (int i = 0; i < roots.getLength(); i++) { - Node root = roots.item(i); - if (root.getNodeType() == Node.ELEMENT_NODE) { - NodeList paramsClassesTypes = root.getChildNodes(); - for (int j = 0; j < paramsClassesTypes.getLength(); j++) { - Node paramsClassesType = paramsClassesTypes.item(j); - if (paramsClassesType.getNodeType() == Node.ELEMENT_NODE) { - String templateDirectory = ((Element) paramsClassesType) - .getAttribute(SystemConfig.TEMPLATE_DIRECTORY_ATTRIBUTE_NAME); - NodeList paramsClasses = paramsClassesType.getChildNodes(); - for (int k = 0; k < paramsClasses.getLength(); k++) { - Node paramsClass = paramsClasses.item(k); - if (paramsClass.getNodeType() == Node.ELEMENT_NODE) { - String className = ((Element) paramsClass) - .getAttribute(SystemConfig.NAME_ATTRIBUTE_NAME); - String templatePath = templateDirectory - + ((Element) paramsClass).getAttribute( - SystemConfig.TEMPLATE_FILE_NAME_ATTRIBUTE_NAME); - String paramsClassesTypeName = paramsClassesType.getNodeName(); - switch (paramsClassesTypeName) { - case SystemConfig.NEURONS_PARAMS_CLASSES_TAG_NAME: - neuronsParamsClassCBox.addItem(className); - neuronsParamsTemplatePaths.add(templatePath); - break; - case SystemConfig.SYNAPSES_PARAMS_CLASSES_TAG_NAME: - synapsesParamsClassCBox.addItem(className); - synapsesParamsTemplatePaths.add(templatePath); - break; - case SystemConfig.CONNECTIONS_PARAMS_CLASSES_TAG_NAME: - connectionsParamsClassCBox.addItem(className); - connectionsParamsTemplatePaths.add(templatePath); - break; - case SystemConfig.LAYOUT_PARAMS_CLASSES_TAG_NAME: - layoutParamsClassCBox.addItem(className); - layoutParamsTemplatePaths.add(templatePath); - break; - default: - // unknown param class type - } - } - } - } - } - } - } - - // get Node paths for each param class + private void loadNodePaths() { Node baseTemplateInfoNode = baseTemplateInfoDoc.getFirstChild(); NodeList paramsClassesNodes = baseTemplateInfoNode.getChildNodes(); for (int i = 0; i < paramsClassesNodes.getLength(); i++) { @@ -311,113 +271,51 @@ private void loadParamsClassCBoxes() throws IOException, ParserConfigurationExce .getAttribute(SystemConfig.NAME_ATTRIBUTE_NAME); String paramsClassesNodePath = ((Element) paramsClassesNode) .getAttribute(SystemConfig.NODE_PATH_ATTRIBUTE_NAME); - switch (paramsClassesType) { - case SystemConfig.NEURONS_PARAMS_CLASSES_TAG_NAME: - neuronsParamsNodePath = paramsClassesNodePath; - break; - case SystemConfig.SYNAPSES_PARAMS_CLASSES_TAG_NAME: - synapsesParamsNodePath = paramsClassesNodePath; - break; - case SystemConfig.CONNECTIONS_PARAMS_CLASSES_TAG_NAME: - connectionsParamsNodePath = paramsClassesNodePath; - break; - case SystemConfig.LAYOUT_PARAMS_CLASSES_TAG_NAME: - layoutParamsNodePath = paramsClassesNodePath; - break; - default: - // unknown param class type + if (!paramsClassesType.contains("SimInfo")) { + nodePaths.add(paramsClassesNodePath); } } } + } - // set combo box options according to params classes from sim config XML file - XPathExpression xpath = XPathFactory.newInstance().newXPath() - .compile(neuronsParamsNodePath); - NodeList nodeList = (NodeList) xpath.evaluate(xmlDoc, XPathConstants.NODESET); - Node node = nodeList.item(0); - neuronsParamsClass = ((Element) node).getAttribute(SystemConfig.CLASS_ATTRIBUTE_NAME); - neuronsParamsClassCBox.setSelectedItem(neuronsParamsClass); - - xpath = XPathFactory.newInstance().newXPath().compile(synapsesParamsNodePath); - nodeList = (NodeList) xpath.evaluate(xmlDoc, XPathConstants.NODESET); - node = nodeList.item(0); - synapsesParamsClass = ((Element) node).getAttribute(SystemConfig.CLASS_ATTRIBUTE_NAME); - synapsesParamsClassCBox.setSelectedItem(synapsesParamsClass); - - xpath = XPathFactory.newInstance().newXPath().compile(connectionsParamsNodePath); - nodeList = (NodeList) xpath.evaluate(xmlDoc, XPathConstants.NODESET); - node = nodeList.item(0); - connectionsParamsClass = ((Element) node).getAttribute(SystemConfig.CLASS_ATTRIBUTE_NAME); - connectionsParamsClassCBox.setSelectedItem(connectionsParamsClass); - - xpath = XPathFactory.newInstance().newXPath().compile(layoutParamsNodePath); - nodeList = (NodeList) xpath.evaluate(xmlDoc, XPathConstants.NODESET); - node = nodeList.item(0); - layoutParamsClass = ((Element) node).getAttribute(SystemConfig.CLASS_ATTRIBUTE_NAME); - layoutParamsClassCBox.setSelectedItem(layoutParamsClass); + /** + * Set combo box options according to params classes from sim config XML file. + * + * @throws XPathExpressionException + */ + private void setComboBoxOptions() throws XPathExpressionException { + XPathExpression xpath; + for (int i = 0; i < nodePaths.size(); i++) { + xpath = XPathFactory.newInstance().newXPath().compile(nodePaths.get(i)); + NodeList nodeList = (NodeList) xpath.evaluate(xmlDoc, XPathConstants.NODESET); + Node node = nodeList.item(0); + String paramsClass = ((Element) node).getAttribute(SystemConfig.CLASS_ATTRIBUTE_NAME); + paramsClassesCBoxes.get(i).setSelectedItem(paramsClass); + } } /** * Set up XML config file according to the selected items in combo boxes. + * + * @throws Exception */ private void setConfigXMLDoc() throws Exception { LOG.info("Start setConfigXMLDoc"); - // get neurons Params Node from the path - XPathExpression xpath = XPathFactory.newInstance().newXPath() - .compile(neuronsParamsNodePath); - NodeList nodeList = (NodeList) xpath.evaluate(xmlDoc, XPathConstants.NODESET); - Node node = nodeList.item(0); - if (!neuronsParamsClass.equals(neuronsParamsClassCBox.getSelectedItem())) { - String templateFileURL = neuronsParamsTemplatePaths.get( - neuronsParamsClassCBox.getSelectedIndex()); - Document templateNode = DocumentBuilderFactory.newInstance().newDocumentBuilder() - .parse(getClass().getResourceAsStream("/templates/" + templateFileURL)); - Node parentNode = node.getParentNode(); - Node newNode = xmlDoc.importNode(templateNode.getFirstChild(), true); - parentNode.replaceChild(newNode, node); - } - - // get synapses Params Node from the path - xpath = XPathFactory.newInstance().newXPath().compile(synapsesParamsNodePath); - nodeList = (NodeList) xpath.evaluate(xmlDoc, XPathConstants.NODESET); - node = nodeList.item(0); - if (!synapsesParamsClass.equals(synapsesParamsClassCBox.getSelectedItem())) { - String templateFileURL = synapsesParamsTemplatePaths.get( - synapsesParamsClassCBox.getSelectedIndex()); - Document templateNode = DocumentBuilderFactory.newInstance().newDocumentBuilder() - .parse(getClass().getResourceAsStream("/templates/" + templateFileURL)); - Node parentNode = node.getParentNode(); - Node newNode = xmlDoc.importNode(templateNode.getFirstChild(), true); - parentNode.replaceChild(newNode, node); - } - - // get connections Params Node from the path - xpath = XPathFactory.newInstance().newXPath().compile(connectionsParamsNodePath); - nodeList = (NodeList) xpath.evaluate(xmlDoc, XPathConstants.NODESET); - node = nodeList.item(0); - if (!connectionsParamsClass.equals( - connectionsParamsClassCBox.getSelectedItem())) { - String templateFileURL = connectionsParamsTemplatePaths.get( - connectionsParamsClassCBox.getSelectedIndex()); - Document templateNode = DocumentBuilderFactory.newInstance().newDocumentBuilder() - .parse(getClass().getResourceAsStream("/templates/" + templateFileURL)); - Node parentNode = node.getParentNode(); - Node newNode = xmlDoc.importNode(templateNode.getFirstChild(), true); - parentNode.replaceChild(newNode, node); - } - - // get layout Params Node from the path - xpath = XPathFactory.newInstance().newXPath().compile(layoutParamsNodePath); - nodeList = (NodeList) xpath.evaluate(xmlDoc, XPathConstants.NODESET); - node = nodeList.item(0); - if (!layoutParamsClass.equals(layoutParamsClassCBox.getSelectedItem())) { - String templateFileURL = layoutParamsTemplatePaths.get( - layoutParamsClassCBox.getSelectedIndex()); - Document templateNode = DocumentBuilderFactory.newInstance().newDocumentBuilder() - .parse(getClass().getResourceAsStream("/templates/" + templateFileURL)); - Node parentNode = node.getParentNode(); - Node newNode = xmlDoc.importNode(templateNode.getFirstChild(), true); - parentNode.replaceChild(newNode, node); + XPathExpression xpath; + for (int i = 0; i < nodePaths.size(); i++) { + xpath = XPathFactory.newInstance().newXPath().compile(nodePaths.get(i)); + NodeList nodeList = (NodeList) xpath.evaluate(xmlDoc, XPathConstants.NODESET); + Node node = nodeList.item(0); + String paramsClass = ((Element) node).getAttribute(SystemConfig.CLASS_ATTRIBUTE_NAME); + if (!paramsClass.equals(paramsClassesCBoxes.get(i).getSelectedItem())) { + String templateFileURL = templatePaths.get(i).get( + paramsClassesCBoxes.get(i).getSelectedIndex()); + Document templateNode = DocumentBuilderFactory.newInstance().newDocumentBuilder() + .parse(getClass().getResourceAsStream("/templates/" + templateFileURL)); + Node parentNode = node.getParentNode(); + Node newNode = xmlDoc.importNode(templateNode.getFirstChild(), true); + parentNode.replaceChild(newNode, node); + } } LOG.info("End setConfigXMLDoc"); }