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;
}
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;
}
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);
}
Aggregations