comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java @ 456:b8080695ea62

Splitted code pathes of dynamic and static nodes. Static nodes contain the selected value only instead of transfering the whole stack of options again. gnv-artifacts/trunk@506 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 04 Jan 2010 15:41:29 +0000
parents 88cd37c3b5e4
children 3ddc22aab764
comparison
equal deleted inserted replaced
455:363236fc462d 456:b8080695ea62
40 import de.intevation.gnv.utils.ArtifactXMLUtilities; 40 import de.intevation.gnv.utils.ArtifactXMLUtilities;
41 import de.intevation.gnv.utils.InputValidator; 41 import de.intevation.gnv.utils.InputValidator;
42 42
43 /** 43 /**
44 * @author Tim Englich <tim.englich@intevation.de> 44 * @author Tim Englich <tim.englich@intevation.de>
45 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de>
45 * 46 *
46 */ 47 */
47 public abstract class StateBase implements State { 48 public abstract class StateBase implements State {
48 49
49 /** 50 /**
525 Node dynamic = xmlutilities.createArtifactElement(document, 526 Node dynamic = xmlutilities.createArtifactElement(document,
526 "dynamic"); 527 "dynamic");
527 rootNode.appendChild(staticNode); 528 rootNode.appendChild(staticNode);
528 rootNode.appendChild(dynamic); 529 rootNode.appendChild(dynamic);
529 while (it.hasNext()) { 530 while (it.hasNext()) {
530
531 Object o = it.next(); 531 Object o = it.next();
532 if (o instanceof Collection<?>) { 532 if ((!it.hasNext() && dataName != null)) {
533 String name = null; 533 appendToDynamicNode(document, dynamic, callMeta, o);
534 boolean multiselect = false; 534 }
535 if (o instanceof NamedCollection<?>) { 535 else {
536 NamedCollection<?> nc = ((NamedCollection<?>) o); 536 appendToStaticNode(document, staticNode, callMeta, o);
537 name = nc.getName(); 537 }
538 multiselect = nc.isMultiSelect(); 538 }
539 } else { 539 }
540 Object[] names = this.inputValueNames.toArray(); 540 }
541 name = names[names.length - 1].toString(); 541
542 } 542
543 543 protected void appendToStaticNode(
544 Element selectNode = xmlutilities.createXFormElement( 544 Document document,
545 document, multiselect ? "select" : "select1"); 545 Node staticNode,
546 selectNode.setAttribute("ref", name); 546 CallMeta callMeta,
547 547 Object o
548 Element lableNode = xmlutilities.createXFormElement( 548 ) {
549 if (o instanceof Collection<?>) {
550 String name = null;
551 boolean multiselect = false;
552 if (o instanceof NamedCollection<?>) {
553 NamedCollection<?> nc = ((NamedCollection<?>) o);
554 name = nc.getName();
555 multiselect = nc.isMultiSelect();
556 } else {
557 Object[] names = this.inputValueNames.toArray();
558 name = names[names.length - 1].toString();
559 }
560
561 log.debug("Name of attribute: " + name);
562 Element selectNode = ArtifactXMLUtilities.createXFormElement(
563 document, multiselect ? "select" : "select1");
564 selectNode.setAttribute("ref", name);
565
566 Element lableNode = ArtifactXMLUtilities.createXFormElement(
567 document, "label");
568 lableNode.setTextContent(RessourceFactory.getInstance()
569 .getRessource(callMeta.getLanguages(), name, name));
570 Element choiceNode = ArtifactXMLUtilities.createXFormElement(
571 document, "choices");
572
573 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o;
574 Iterator<KeyValueDescibeData> resultIt = values.iterator();
575 while (resultIt.hasNext()) {
576 KeyValueDescibeData result = resultIt.next();
577
578 if (result.isSelected()) {
579 Element itemNode = ArtifactXMLUtilities.createXFormElement(
580 document, "item");
581
582 itemNode.setAttribute("selected", "true");
583
584 Element choiceLableNode =
585 ArtifactXMLUtilities.createXFormElement(
549 document, "label"); 586 document, "label");
550 lableNode.setTextContent(RessourceFactory.getInstance() 587 choiceLableNode.setTextContent(result.getValue());
551 .getRessource(callMeta.getLanguages(), name, name)); 588 itemNode.appendChild(choiceLableNode);
552 Element choiceNode = xmlutilities.createXFormElement( 589
553 document, "choices"); 590 Element choicValueNode =
554 591 ArtifactXMLUtilities.createXFormElement(
555 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o;
556 Iterator<KeyValueDescibeData> resultIt = values.iterator();
557 while (resultIt.hasNext()) {
558 KeyValueDescibeData result = resultIt.next();
559 Element itemNode = xmlutilities.createXFormElement(
560 document, "item");
561
562 if (result.isSelected()) {
563 itemNode.setAttribute("selected", "true");
564 }
565
566 Element choiceLableNode = xmlutilities
567 .createXFormElement(document, "label");
568 choiceLableNode.setTextContent(result.getValue());
569 itemNode.appendChild(choiceLableNode);
570
571 Element choicValueNode = xmlutilities
572 .createXFormElement(document, "value");
573 choicValueNode.setTextContent("" + result.getKey());
574 itemNode.appendChild(choicValueNode);
575 choiceNode.appendChild(itemNode);
576 }
577 selectNode.appendChild(lableNode);
578 selectNode.appendChild(choiceNode);
579
580 if (!it.hasNext() && this.dataName != null) {
581 dynamic.appendChild(selectNode);
582 } else {
583 staticNode.appendChild(selectNode);
584 }
585
586 } else if (o instanceof MinMaxDescribeData) {
587 MinMaxDescribeData minMaxDescibeData = (MinMaxDescribeData) o;
588 Object min = minMaxDescibeData.getMinValue();
589 Object max = minMaxDescibeData.getMaxValue();
590 if (min instanceof GregorianCalendar) {
591 Date d = ((GregorianCalendar) min).getTime();
592 min = DateUtils.getPatternedDateAmer(d);
593 }
594
595 if (max instanceof GregorianCalendar) {
596 Date d = ((GregorianCalendar) max).getTime();
597 max = DateUtils.getPatternedDateAmer(d);
598 }
599
600 Element groupNode = xmlutilities.createXFormElement(
601 document, "group");
602 groupNode.setAttribute("ref", minMaxDescibeData.getName());
603 Element groupNodeLableNode = xmlutilities
604 .createXFormElement(document, "label");
605 groupNodeLableNode.setTextContent(RessourceFactory
606 .getInstance().getRessource(
607 callMeta.getLanguages(),
608 minMaxDescibeData.getName(),
609 minMaxDescibeData.getName()));
610 groupNode.appendChild(groupNodeLableNode);
611
612 Element inputMinNode = xmlutilities.createXFormElement(
613 document, "input");
614 inputMinNode.setAttribute("ref", MINVALUEFIELDNAME);
615 Element inputMinLableNode = xmlutilities
616 .createXFormElement(document, "label");
617 inputMinLableNode.setTextContent(RessourceFactory
618 .getInstance().getRessource(
619 callMeta.getLanguages(), MINVALUEFIELDNAME,
620 MINVALUEFIELDNAME));
621 inputMinNode.appendChild(inputMinLableNode);
622
623 Element inputMinValueNode = xmlutilities
624 .createXFormElement(document, "value");
625 inputMinValueNode.setTextContent(min.toString());
626 inputMinNode.appendChild(inputMinValueNode);
627
628 Element inputMaxNode = xmlutilities.createXFormElement(
629 document, "input");
630 inputMaxNode.setAttribute("ref", MAXVALUEFIELDNAME);
631 Element inputMaxLableNode = xmlutilities
632 .createXFormElement(document, "label");
633 inputMaxLableNode.setTextContent(RessourceFactory
634 .getInstance().getRessource(
635 callMeta.getLanguages(), MAXVALUEFIELDNAME,
636 MAXVALUEFIELDNAME));
637 inputMaxNode.appendChild(inputMaxLableNode);
638
639 Element inputMaxValueNode = xmlutilities
640 .createXFormElement(document, "value");
641 inputMaxValueNode.setTextContent(max.toString());
642 inputMaxNode.appendChild(inputMaxValueNode);
643
644 groupNode.appendChild(inputMinNode);
645 groupNode.appendChild(inputMaxNode);
646
647 if (!it.hasNext() && this.dataName != null) {
648 dynamic.appendChild(groupNode);
649 } else {
650 staticNode.appendChild(groupNode);
651 }
652 } else if (o instanceof SingleValueDescribeData) {
653
654 SingleValueDescribeData svdb = (SingleValueDescribeData) o;
655
656 Element groupNode = xmlutilities.createXFormElement(
657 document, "group");
658 groupNode.setAttribute("ref", svdb.getName());
659 Element groupNodeLableNode = xmlutilities
660 .createXFormElement(document, "label");
661 groupNodeLableNode.setTextContent(RessourceFactory
662 .getInstance().getRessource(
663 callMeta.getLanguages(),
664 svdb.getName(),
665 svdb.getName()));
666 groupNode.appendChild(groupNodeLableNode);
667
668 Element inputNode = xmlutilities.createXFormElement(
669 document, "input");
670 inputNode.setAttribute("ref", svdb.getName());
671
672 Element inputLableNode = xmlutilities.createXFormElement(
673 document, "label");
674 inputLableNode.setTextContent("");
675 inputNode.appendChild(inputLableNode);
676
677 Element inputValueNode = xmlutilities.createXFormElement(
678 document, "value"); 592 document, "value");
679 inputValueNode.setTextContent(svdb.getValue()); 593 choicValueNode.setTextContent("" + result.getKey());
680 inputNode.appendChild(inputValueNode); 594 itemNode.appendChild(choicValueNode);
681 595 choiceNode.appendChild(itemNode);
682 groupNode.appendChild(inputNode); 596 }
683 if (!it.hasNext() && this.dataName != null) { 597 }
684 dynamic.appendChild(groupNode); 598 selectNode.appendChild(lableNode);
685 } else { 599 selectNode.appendChild(choiceNode);
686 staticNode.appendChild(groupNode); 600
687 } 601 staticNode.appendChild(selectNode);
688 } 602 }
689 603 else if (o instanceof MinMaxDescribeData) {
690 } 604 appendMinMaxDescribeData(
691 } 605 document,
606 staticNode,
607 callMeta,
608 o);
609 }
610 else if (o instanceof SingleValueDescribeData) {
611 appendSingleValueDescribeData(
612 document,
613 staticNode,
614 callMeta,
615 o);
616 }
617 }
618
619
620 protected void appendToDynamicNode(
621 Document document,
622 Node dynamicNode,
623 CallMeta callMeta,
624 Object o
625 ) {
626 if (o instanceof Collection<?>) {
627 String name = null;
628 boolean multiselect = false;
629 if (o instanceof NamedCollection<?>) {
630 NamedCollection<?> nc = ((NamedCollection<?>) o);
631 name = nc.getName();
632 multiselect = nc.isMultiSelect();
633 } else {
634 Object[] names = this.inputValueNames.toArray();
635 name = names[names.length - 1].toString();
636 }
637
638 Element selectNode = ArtifactXMLUtilities.createXFormElement(
639 document, multiselect ? "select" : "select1");
640 selectNode.setAttribute("ref", name);
641
642 Element lableNode = ArtifactXMLUtilities.createXFormElement(
643 document, "label");
644 lableNode.setTextContent(RessourceFactory.getInstance()
645 .getRessource(callMeta.getLanguages(), name, name));
646 Element choiceNode = ArtifactXMLUtilities.createXFormElement(
647 document, "choices");
648
649 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o;
650 Iterator<KeyValueDescibeData> resultIt = values.iterator();
651 while (resultIt.hasNext()) {
652 KeyValueDescibeData result = resultIt.next();
653 Element itemNode = ArtifactXMLUtilities.createXFormElement(
654 document, "item");
655
656 if (result.isSelected()) {
657 itemNode.setAttribute("selected", "true");
658 }
659
660 Element choiceLableNode =
661 ArtifactXMLUtilities.createXFormElement(document, "label");
662 choiceLableNode.setTextContent(result.getValue());
663 itemNode.appendChild(choiceLableNode);
664
665 Element choicValueNode = ArtifactXMLUtilities.createXFormElement(
666 document, "value");
667 choicValueNode.setTextContent("" + result.getKey());
668 itemNode.appendChild(choicValueNode);
669 choiceNode.appendChild(itemNode);
670 }
671 selectNode.appendChild(lableNode);
672 selectNode.appendChild(choiceNode);
673
674 dynamicNode.appendChild(selectNode);
675 }
676 else if (o instanceof MinMaxDescribeData) {
677 appendMinMaxDescribeData(
678 document,
679 dynamicNode,
680 callMeta,
681 o);
682 }
683 else if (o instanceof SingleValueDescribeData) {
684 appendSingleValueDescribeData(
685 document,
686 dynamicNode,
687 callMeta,
688 o);
689 }
690 }
691
692
693 protected void appendMinMaxDescribeData(
694 Document document,
695 Node node,
696 CallMeta callMeta,
697 Object o
698 ) {
699 MinMaxDescribeData minMaxDescibeData = (MinMaxDescribeData) o;
700 Object min = minMaxDescibeData.getMinValue();
701 Object max = minMaxDescibeData.getMaxValue();
702 if (min instanceof GregorianCalendar) {
703 Date d = ((GregorianCalendar) min).getTime();
704 min = DateUtils.getPatternedDateAmer(d);
705 }
706
707 if (max instanceof GregorianCalendar) {
708 Date d = ((GregorianCalendar) max).getTime();
709 max = DateUtils.getPatternedDateAmer(d);
710 }
711
712 Element groupNode = ArtifactXMLUtilities.createXFormElement(
713 document, "group");
714 groupNode.setAttribute("ref", minMaxDescibeData.getName());
715 Element groupNodeLableNode =
716 ArtifactXMLUtilities.createXFormElement(document, "label");
717 groupNodeLableNode.setTextContent(RessourceFactory
718 .getInstance().getRessource(
719 callMeta.getLanguages(),
720 minMaxDescibeData.getName(),
721 minMaxDescibeData.getName()));
722 groupNode.appendChild(groupNodeLableNode);
723
724 Element inputMinNode = ArtifactXMLUtilities.createXFormElement(
725 document, "input");
726 inputMinNode.setAttribute("ref", MINVALUEFIELDNAME);
727 Element inputMinLableNode = ArtifactXMLUtilities
728 .createXFormElement(document, "label");
729 inputMinLableNode.setTextContent(RessourceFactory
730 .getInstance().getRessource(
731 callMeta.getLanguages(), MINVALUEFIELDNAME,
732 MINVALUEFIELDNAME));
733 inputMinNode.appendChild(inputMinLableNode);
734
735 Element inputMinValueNode = ArtifactXMLUtilities.createXFormElement(
736 document, "value");
737 inputMinValueNode.setTextContent(min.toString());
738 inputMinNode.appendChild(inputMinValueNode);
739
740 Element inputMaxNode = ArtifactXMLUtilities.createXFormElement(
741 document, "input");
742 inputMaxNode.setAttribute("ref", MAXVALUEFIELDNAME);
743 Element inputMaxLableNode = ArtifactXMLUtilities.createXFormElement(
744 document, "label");
745 inputMaxLableNode.setTextContent(RessourceFactory
746 .getInstance().getRessource(
747 callMeta.getLanguages(), MAXVALUEFIELDNAME,
748 MAXVALUEFIELDNAME));
749 inputMaxNode.appendChild(inputMaxLableNode);
750
751 Element inputMaxValueNode = ArtifactXMLUtilities.createXFormElement(
752 document, "value");
753 inputMaxValueNode.setTextContent(max.toString());
754 inputMaxNode.appendChild(inputMaxValueNode);
755
756 groupNode.appendChild(inputMinNode);
757 groupNode.appendChild(inputMaxNode);
758
759 node.appendChild(groupNode);
760 }
761
762
763
764 protected void appendSingleValueDescribeData(
765 Document document,
766 Node node,
767 CallMeta callMeta,
768 Object o
769 ) {
770 SingleValueDescribeData svdb = (SingleValueDescribeData) o;
771
772 Element groupNode = ArtifactXMLUtilities.createXFormElement(
773 document, "group");
774 groupNode.setAttribute("ref", svdb.getName());
775 Element groupNodeLableNode = ArtifactXMLUtilities.createXFormElement(
776 document, "label");
777 groupNodeLableNode.setTextContent(RessourceFactory
778 .getInstance().getRessource(
779 callMeta.getLanguages(),
780 svdb.getName(),
781 svdb.getName()));
782 groupNode.appendChild(groupNodeLableNode);
783
784 Element inputNode = ArtifactXMLUtilities.createXFormElement(
785 document, "input");
786 inputNode.setAttribute("ref", svdb.getName());
787
788 Element inputLableNode = ArtifactXMLUtilities.createXFormElement(
789 document, "label");
790 inputLableNode.setTextContent("");
791 inputNode.appendChild(inputLableNode);
792
793 Element inputValueNode = ArtifactXMLUtilities.createXFormElement(
794 document, "value");
795 inputValueNode.setTextContent(svdb.getValue());
796 inputNode.appendChild(inputValueNode);
797
798 groupNode.appendChild(inputNode);
799
800 node.appendChild(groupNode);
692 } 801 }
693 802
694 /** 803 /**
695 * @see de.intevation.gnv.state.State#getDescibeData() 804 * @see de.intevation.gnv.state.State#getDescibeData()
696 */ 805 */

http://dive4elements.wald.intevation.org