Search in sources :

Example 1 with SelectedTreeItemEnum

use of com.sldeditor.common.xml.ui.SelectedTreeItemEnum in project sldeditor by robward-scisys.

the class SLDTree method selectTreeItem.

/**
 * Select tree item.
 *
 * @param data the data
 * @return true, if successful
 */
public boolean selectTreeItem(TreeSelectionData data) {
    symbolTree.clearSelection();
    SelectedTreeItemEnum selectedTreeItemEnum = data.getSelection();
    int layerIndex = data.getLayerIndex();
    int styleIndex = data.getStyleIndex();
    int featureTypeStyleIndex = data.getFeatureTypeStyleIndex();
    int ruleIndex = data.getRuleIndex();
    int symbolizerIndex = data.getSymbolizerIndex();
    int symbolizerDetailIndex = data.getSymbolizerDetailIndex();
    DefaultMutableTreeNode layerNode = null;
    DefaultMutableTreeNode styleNode = null;
    DefaultMutableTreeNode ftsNode = null;
    DefaultMutableTreeNode ruleNode = null;
    DefaultMutableTreeNode symbolizerNode = null;
    DefaultMutableTreeNode symbolizerDetailNode = null;
    TreePath path = null;
    if ((layerIndex < 0) || (layerIndex >= rootNode.getChildCount())) {
        return false;
    }
    layerNode = (DefaultMutableTreeNode) rootNode.getChildAt(layerIndex);
    if (selectedTreeItemEnum == SelectedTreeItemEnum.LAYER) {
        path = getPath(layerNode);
    } else {
        if (layerNode == null) {
            return false;
        }
        if ((styleIndex < 0) || (styleIndex >= layerNode.getChildCount())) {
            return false;
        }
        styleNode = (DefaultMutableTreeNode) layerNode.getChildAt(styleIndex);
        if (selectedTreeItemEnum == SelectedTreeItemEnum.STYLE) {
            path = getPath(styleNode);
        } else {
            if (styleNode == null) {
                return false;
            }
            if ((featureTypeStyleIndex < 0) || (featureTypeStyleIndex >= styleNode.getChildCount())) {
                return false;
            }
            ftsNode = (DefaultMutableTreeNode) styleNode.getChildAt(featureTypeStyleIndex);
            if (selectedTreeItemEnum == SelectedTreeItemEnum.FEATURETYPESTYLE) {
                path = getPath(ftsNode);
            } else {
                if (ftsNode == null) {
                    return false;
                }
                if ((ruleIndex < 0) || (ruleIndex >= ftsNode.getChildCount())) {
                    return false;
                }
                ruleNode = (DefaultMutableTreeNode) ftsNode.getChildAt(ruleIndex);
                if (selectedTreeItemEnum == SelectedTreeItemEnum.RULE) {
                    path = getPath(ruleNode);
                } else {
                    if (ruleNode == null) {
                        return false;
                    }
                    if ((symbolizerIndex < 0) || (symbolizerIndex >= ruleNode.getChildCount())) {
                        return false;
                    }
                    symbolizerNode = (DefaultMutableTreeNode) ruleNode.getChildAt(symbolizerIndex);
                    if ((selectedTreeItemEnum == SelectedTreeItemEnum.POINT_SYMBOLIZER) || (selectedTreeItemEnum == SelectedTreeItemEnum.LINE_SYMBOLIZER) || (selectedTreeItemEnum == SelectedTreeItemEnum.POLYGON_SYMBOLIZER) || (selectedTreeItemEnum == SelectedTreeItemEnum.RASTER_SYMBOLIZER) || (selectedTreeItemEnum == SelectedTreeItemEnum.TEXT_SYMBOLIZER)) {
                        path = getPath(symbolizerNode);
                    } else {
                        if ((symbolizerDetailIndex < 0) || (symbolizerDetailIndex >= symbolizerNode.getChildCount())) {
                            return false;
                        }
                        symbolizerDetailNode = (DefaultMutableTreeNode) symbolizerNode.getChildAt(symbolizerDetailIndex);
                        if (symbolizerDetailNode == null) {
                            return false;
                        }
                        if ((selectedTreeItemEnum == SelectedTreeItemEnum.POINT_FILL) || (selectedTreeItemEnum == SelectedTreeItemEnum.POLYGON_FILL) || (selectedTreeItemEnum == SelectedTreeItemEnum.STROKE)) {
                            path = getPath(symbolizerDetailNode);
                        }
                    }
                }
            }
        }
    }
    symbolTree.setSelectionPath(path);
    return true;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) SelectedTreeItemEnum(com.sldeditor.common.xml.ui.SelectedTreeItemEnum)

Example 2 with SelectedTreeItemEnum

use of com.sldeditor.common.xml.ui.SelectedTreeItemEnum in project sldeditor by robward-scisys.

the class SLDOutputTest method getString.

/**
 * Gets the string.
 *
 * @param sldContentString the sld content string
 * @param selectionData the selection data
 * @param field the field
 * @param suffix the suffix
 * @return the string
 */
public String getString(String sldContentString, TreeSelectionData selectionData, FieldIdEnum field, String suffix) {
    Document doc = getXMLDocument(sldContentString);
    String extractedString = null;
    XPath xpath = xPathfactory.newXPath();
    XPathExpression expr;
    try {
        String xPathString = null;
        SelectedTreeItemEnum selection = selectionData.getSelection();
        String prefix = prefixMap.get(selection);
        Map<FieldIdEnum, String> fieldMap = xPathMap.get(selection);
        if (fieldMap == null) {
            System.err.println("Unknown selected tree item : " + selection);
        } else {
            String configXPathString = fieldMap.get(field);
            if (configXPathString == null) {
                System.err.println("Unknown XPath : " + field);
            }
            StringBuilder sb = new StringBuilder();
            sb.append(prefix);
            sb.append("/");
            sb.append(configXPathString);
            if (suffix != null) {
                sb.append(suffix);
            }
            String fieldString = sb.toString();
            switch(selection) {
                case LAYER:
                    xPathString = getLayerString(selectionData, fieldString);
                    break;
                case STYLE:
                    xPathString = getStyleString(selectionData, fieldString);
                    break;
                case POINT_SYMBOLIZER:
                case LINE_SYMBOLIZER:
                case POLYGON_SYMBOLIZER:
                case TEXT_SYMBOLIZER:
                case RASTER_SYMBOLIZER:
                    xPathString = getSymbolizerString(selectionData, fieldString);
                    break;
                case RULE:
                    xPathString = getRuleString(selectionData, fieldString);
                    break;
                case POINT_FILL:
                case POLYGON_FILL:
                    xPathString = getFillString(selectionData, fieldString);
                    break;
                case STROKE:
                    xPathString = getStrokeString(selectionData, fieldString);
                    break;
                default:
                    break;
            }
            if (xPathString != null) {
                expr = xpath.compile(xPathString);
                extractedString = expr.evaluate(doc);
                if ((extractedString == null) || extractedString.isEmpty()) {
                    System.out.println("SLD : " + sldContentString);
                    System.out.println("XPath : " + xPathString);
                }
            } else {
                System.out.println("No XPath string");
            }
        }
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    }
    return extractedString;
}
Also used : XPath(javax.xml.xpath.XPath) SLDXPath(com.sldeditor.common.xml.ui.SLDXPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathExpressionException(javax.xml.xpath.XPathExpressionException) XMLSetFieldLiteralString(com.sldeditor.common.xml.ui.XMLSetFieldLiteralString) Document(org.w3c.dom.Document) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) SelectedTreeItemEnum(com.sldeditor.common.xml.ui.SelectedTreeItemEnum)

Example 3 with SelectedTreeItemEnum

use of com.sldeditor.common.xml.ui.SelectedTreeItemEnum in project sldeditor by robward-scisys.

the class SLDOutputTest method initialise.

/**
 * Initialise.
 */
private void initialise() {
    String fullPath = "/test/SLDXPath.xml";
    SLDXPath xPath = (SLDXPath) ParseXML.parseFile("", fullPath, OUTPUT_SCHEMA_RESOURCE, SLDXPath.class);
    Map<SelectedTreeItemEnum, String> initialPrefixMap = new HashMap<SelectedTreeItemEnum, String>();
    for (XMLTestSection section : xPath.getSection()) {
        initialPrefixMap.put(section.getSldtype(), "/" + section.getPrefix());
        Map<FieldIdEnum, String> fieldMap = new HashMap<FieldIdEnum, String>();
        for (XMLTestSectionField xmlField : section.getField()) {
            fieldMap.put(xmlField.getId(), xmlField.getXpath());
        }
        xPathMap.put(section.getSldtype(), fieldMap);
    }
    prefixMap.put(SelectedTreeItemEnum.SLD, initialPrefixMap.get(SelectedTreeItemEnum.SLD));
    populatePrefixMap(SelectedTreeItemEnum.LAYER, SelectedTreeItemEnum.SLD, initialPrefixMap);
    populatePrefixMap(SelectedTreeItemEnum.STYLE, SelectedTreeItemEnum.LAYER, initialPrefixMap);
    populatePrefixMap(SelectedTreeItemEnum.FEATURETYPESTYLE, SelectedTreeItemEnum.STYLE, initialPrefixMap);
    populatePrefixMap(SelectedTreeItemEnum.RULE, SelectedTreeItemEnum.FEATURETYPESTYLE, initialPrefixMap);
    populatePrefixMap(SelectedTreeItemEnum.POINT_SYMBOLIZER, SelectedTreeItemEnum.RULE, initialPrefixMap);
    populatePrefixMap(SelectedTreeItemEnum.LINE_SYMBOLIZER, SelectedTreeItemEnum.RULE, initialPrefixMap);
    populatePrefixMap(SelectedTreeItemEnum.POLYGON_SYMBOLIZER, SelectedTreeItemEnum.RULE, initialPrefixMap);
    populatePrefixMap(SelectedTreeItemEnum.TEXT_SYMBOLIZER, SelectedTreeItemEnum.RULE, initialPrefixMap);
    populatePrefixMap(SelectedTreeItemEnum.RASTER_SYMBOLIZER, SelectedTreeItemEnum.RULE, initialPrefixMap);
    populatePrefixMap(SelectedTreeItemEnum.POINT_FILL, SelectedTreeItemEnum.RULE, initialPrefixMap);
    populatePrefixMap(SelectedTreeItemEnum.POLYGON_FILL, SelectedTreeItemEnum.RULE, initialPrefixMap);
    populatePrefixMap(SelectedTreeItemEnum.STROKE, SelectedTreeItemEnum.RULE, initialPrefixMap);
}
Also used : SLDXPath(com.sldeditor.common.xml.ui.SLDXPath) XMLTestSectionField(com.sldeditor.common.xml.ui.XMLTestSectionField) HashMap(java.util.HashMap) XMLTestSection(com.sldeditor.common.xml.ui.XMLTestSection) XMLSetFieldLiteralString(com.sldeditor.common.xml.ui.XMLSetFieldLiteralString) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) SelectedTreeItemEnum(com.sldeditor.common.xml.ui.SelectedTreeItemEnum)

Aggregations

SelectedTreeItemEnum (com.sldeditor.common.xml.ui.SelectedTreeItemEnum)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)2 SLDXPath (com.sldeditor.common.xml.ui.SLDXPath)2 XMLSetFieldLiteralString (com.sldeditor.common.xml.ui.XMLSetFieldLiteralString)2 XMLTestSection (com.sldeditor.common.xml.ui.XMLTestSection)1 XMLTestSectionField (com.sldeditor.common.xml.ui.XMLTestSectionField)1 HashMap (java.util.HashMap)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreePath (javax.swing.tree.TreePath)1 XPath (javax.xml.xpath.XPath)1 XPathExpression (javax.xml.xpath.XPathExpression)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 Document (org.w3c.dom.Document)1