Search in sources :

Example 1 with Node

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();
    }
}
Also used : HashMap(org.apache.pivot.collections.HashMap) Node(org.apache.pivot.xml.Node) TextNode(org.apache.pivot.xml.TextNode) Element(org.apache.pivot.xml.Element) ArrayList(org.apache.pivot.collections.ArrayList) TextNode(org.apache.pivot.xml.TextNode)

Aggregations

ArrayList (org.apache.pivot.collections.ArrayList)1 HashMap (org.apache.pivot.collections.HashMap)1 Element (org.apache.pivot.xml.Element)1 Node (org.apache.pivot.xml.Node)1 TextNode (org.apache.pivot.xml.TextNode)1