use of org.geotools.styling.RuleImpl in project sldeditor by robward-scisys.
the class SLDTreeToolsTest method testMoveItemRules.
/**
* Check Rules Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#moveItem(boolean)}.
*/
@Test
public void testMoveItemRules() {
SLDTreeTools treeTools = new SLDTreeTools();
TestSLDTree sldTree = new TestSLDTree(null, treeTools);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
// Start off with just a top level SLD and no structure below it
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
SelectedSymbol.getInstance().setSld(sld);
sldTree.populateSLD();
sldTree.selectFirstSymbol();
treeTools.addNewThing(NamedLayer.class);
treeTools.addNewThing(null);
treeTools.addNewThing(null);
treeTools.addNewThing(null);
DefaultMutableTreeNode rootNode = sldTree.getRootNode();
DefaultMutableTreeNode rule1Node = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
RuleImpl rule1 = (RuleImpl) rule1Node.getUserObject();
String expectedRule1 = "rule 1";
rule1.setName(expectedRule1);
TreeSelectionData data = new TreeSelectionData();
data.setLayerIndex(0);
data.setStyleIndex(0);
data.setFeatureTypeStyleIndex(0);
sldTree.selectTreeItem(data);
treeTools.addNewThing(null);
DefaultMutableTreeNode rule2Node = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(1);
RuleImpl rule2 = (RuleImpl) rule2Node.getUserObject();
String expectedRule2 = "rule 2";
rule2.setName(expectedRule2);
// Have 2 styles
data = new TreeSelectionData();
data.setLayerIndex(0);
data.setStyleIndex(0);
data.setFeatureTypeStyleIndex(0);
data.setRuleIndex(1);
sldTree.selectTreeItem(data);
// Move style 2 so that they are reversed
treeTools.moveItem(true);
DefaultMutableTreeNode testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
RuleImpl testRule = (RuleImpl) testNode.getUserObject();
assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
// Try and move 'style 2' up to index -1 which is invalid, result should be same as last
// time
data.setRuleIndex(0);
sldTree.selectTreeItem(data);
treeTools.moveItem(true);
testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
testRule = (RuleImpl) testNode.getUserObject();
assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
// Move it back
data.setRuleIndex(0);
sldTree.selectTreeItem(data);
treeTools.moveItem(false);
testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(1);
testRule = (RuleImpl) testNode.getUserObject();
assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
// Move it beyond the end of the list, should be the same answer as before
data.setRuleIndex(1);
sldTree.selectTreeItem(data);
treeTools.moveItem(false);
testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(1);
testRule = (RuleImpl) testNode.getUserObject();
assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
// Undo the last valid move
UndoManager.getInstance().undo();
testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
testRule = (RuleImpl) testNode.getUserObject();
assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
// Redo the last valid move
UndoManager.getInstance().redo();
testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(1);
testRule = (RuleImpl) testNode.getUserObject();
assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
}
Aggregations