use of org.apache.pivot.xml.Node in project pivot by apache.
the class XMLViewer method updateProperties.
public void updateProperties() {
Node node = (Node) treeView.getSelectedNode();
if (node == null) {
// no selection, but it's ok
} else if (node instanceof TextNode) {
TextNode textNode = (TextNode) node;
textArea.setText(textNode.getText());
propertiesCardPane.setSelectedIndex(1);
} else if (node instanceof Element) {
Element element = (Element) node;
// Populate the namespaces table
ArrayList<HashMap<String, String>> namespacesTableData = new ArrayList<>();
String defaultNamespaceURI = element.getDefaultNamespaceURI();
if (defaultNamespaceURI != null) {
HashMap<String, String> row = new HashMap<>();
row.put("prefix", "(default)");
row.put("uri", defaultNamespaceURI);
namespacesTableData.add(row);
}
Element.NamespaceDictionary namespaceDictionary = element.getNamespaces();
for (String prefix : namespaceDictionary) {
HashMap<String, String> row = new HashMap<>();
row.put("prefix", prefix);
row.put("uri", namespaceDictionary.get(prefix));
namespacesTableData.add(row);
}
namespacesTableView.setTableData(namespacesTableData);
// Populate the attributes table
ArrayList<HashMap<String, String>> attributesTableData = new ArrayList<>();
for (Element.Attribute attribute : element.getAttributes()) {
HashMap<String, String> row = new HashMap<>();
String attributeName = attribute.getName();
row.put("name", attributeName);
row.put("value", element.getElementDictionary().get(attributeName));
attributesTableData.add(row);
}
attributesTableView.setTableData(attributesTableData);
propertiesCardPane.setSelectedIndex(0);
} else {
throw new IllegalStateException();
}
}