comparison artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java @ 8870:c26fb37899ca

Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui. Also using now the localization info from the server instead of localizing the modules again on the client side.
author gernotbelger
date Wed, 07 Feb 2018 11:59:13 +0100
parents 5e38e2924c07
children ef5754ba5573
comparison
equal deleted inserted replaced
8869:20b85ea3b524 8870:c26fb37899ca
615 */ 615 */
616 protected void configureModules(Document cfg, RiverContext context) { 616 protected void configureModules(Document cfg, RiverContext context) {
617 NodeList modulenodes = (NodeList) XMLUtils.xpath( 617 NodeList modulenodes = (NodeList) XMLUtils.xpath(
618 cfg, XPATH_MODULES, XPathConstants.NODESET); 618 cfg, XPATH_MODULES, XPathConstants.NODESET);
619 619
620 int num = modulenodes != null ? modulenodes.getLength() : 0; 620 final int num = modulenodes != null ? modulenodes.getLength() : 0;
621 ArrayList<Module> modules = new ArrayList<Module>(num); 621
622 final List<Module> modules = new ArrayList<>(num);
622 623
623 for (int i = 0; i < num; i++) { 624 for (int i = 0; i < num; i++) {
624 Element e = (Element) modulenodes.item(i); 625 final Element e = (Element) modulenodes.item(i);
625 String modulename = e.getAttribute("name"); 626 final String modulename = e.getAttribute("name");
626 String attrselected = e.getAttribute("selected"); 627 final String attrselected = e.getAttribute("selected");
627 boolean selected = attrselected == null ? false : 628 final boolean selected = Boolean.parseBoolean(attrselected);
628 attrselected.equalsIgnoreCase("true"); 629 final String group = e.getAttribute("group");
630
629 log.debug("Loaded module " + modulename); 631 log.debug("Loaded module " + modulename);
630 NodeList children = e.getChildNodes(); 632
631 List<String> rivers = new ArrayList<String>(children.getLength()); 633 final NodeList children = e.getChildNodes();
634 final List<String> rivers = new ArrayList<>(children.getLength());
632 for (int j = 0; j < children.getLength(); j++) { 635 for (int j = 0; j < children.getLength(); j++) {
633 if (children.item(j).getNodeType() != Node.ELEMENT_NODE) { 636 if (children.item(j).getNodeType() != Node.ELEMENT_NODE) {
634 continue; 637 continue;
635 } 638 }
636 Element ce = (Element)children.item(j); 639
640 final Element ce = (Element)children.item(j);
637 if (ce.hasAttribute("uuid")) { 641 if (ce.hasAttribute("uuid")) {
638 rivers.add(ce.getAttribute("uuid")); 642 rivers.add(ce.getAttribute("uuid"));
639 } 643 }
640 else if (ce.hasAttribute("name")) { 644 else if (ce.hasAttribute("name")) {
641 List<River> allRivers = RiverFactory.getRivers(); 645 final List<River> allRivers = RiverFactory.getRivers();
642 String name = ce.getAttribute("name"); 646 final String name = ce.getAttribute("name");
643 for (River r: allRivers) { 647 for (final River r: allRivers) {
644 if (name.equals(r.getName())) { 648 if (name.equals(r.getName())) {
645 rivers.add(r.getModelUuid()); 649 rivers.add(r.getModelUuid());
646 break; 650 break;
647 } 651 }
648 } 652 }
649 } 653 }
650 } 654 }
651 modules.add(new Module(modulename, selected, rivers)); 655 modules.add(new Module(modulename, selected, group, rivers));
652 } 656 }
653 context.put(RiverContext.MODULES, modules); 657 context.put(RiverContext.MODULES, modules);
654 } 658 }
655 } 659 }
656 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 660 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org