Guest User

Untitled

a guest
Aug 10th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. Editor not getting ListBox changes
  2. VIEW:
  3.  
  4. /** ThisEditor is a sub-section of ParentEditor (the Form) and contains a
  5. MyWidget (custom listbox). */
  6. public class ThisEditor extends Composite implements Editor<ThisProxy>, ThisView {
  7. ... //rfeDriver interface defined and created here
  8.  
  9. @UiField
  10. MyWidget my; //getMy and setMy methods in ThisProxy
  11.  
  12. ... //other field declarations
  13.  
  14. public ThisEditor() {
  15. initWidget(binder.createAndBindUi(this));
  16. }
  17.  
  18. @Override
  19. public MyView getMy() {
  20. return my;
  21. }
  22. ... //other methods
  23. }
  24.  
  25. /** This is the View interface that MyWidget implements */
  26. public interface MyView extends HasOptions, HasValue<MyProxy>, Focusable {
  27. interface Presenter {
  28. ...
  29. }
  30. ...
  31. }
  32.  
  33. public class MyWidget extends Composite implements MyView,
  34. IsEditor<LeafValueEditor<MyProxy>> {
  35. ...
  36. @UiField
  37. ListBox listBox; //single-select dropdown
  38. ...
  39.  
  40. public MyWidget() {
  41. initWidget(binder.createAndBindUi(this));
  42. addChangeHandler(); //listen to changes to listBox and setSelectedIndex (?)
  43. }
  44. ...
  45. @Override
  46. public int getSelectedIndex() {
  47. return listBox.getSelectedIndex();
  48. }
  49.  
  50. @Override
  51. public void setSelectedIndex(int index) {
  52. listBox.setSelectedIndex(index);
  53. }
  54. ...
  55.  
  56. /**
  57. * Called by the TakesValueEditor on rfeDriver.edit.
  58. */
  59. @Override
  60. public MyProxy getValue() {
  61. //ask presenter for the MyProxy object -- presenter calls
  62. //getSelectedIndex() on this widget and returns the object associated
  63. //with the index
  64. return presenter.getValue();
  65. }
  66.  
  67. /**
  68. * Called by the TakesValueEditor on rfeDriver.flush.
  69. */
  70. @Override
  71. public void setValue(MyProxy value) {
  72. //pass the value to the presenter to parse and set the index that corresponds
  73. //to this object
  74. presenter.setValue(value);
  75. }
  76.  
  77. PRESENTER
  78.  
  79. public class MyPresenter implements MyView.Presenter,
  80. ValueLookupCompleteEventHandler {
  81. ...
  82. protected HasOptions view;
  83. private List<MyProxy> myList;
  84.  
  85. public MyPresenter(ParentPresenter parent) {
  86. //setParent for this child presenter
  87. }
  88.  
  89. ... //methods to set view and create association between view and presenter
  90.  
  91. @Override
  92. public MyProxy getValue() {
  93. //identify the current selection
  94. String selectedId = view.getValue(view.getSelectedIndex());
  95.  
  96. if (selectedId != null) {
  97. //iterate myList to find the MyProxy object whose id.equals(selectedId)
  98. for (Iterator<MyProxy> i = myList.iterator(); i.hasNext();) {
  99. MyProxy value = i.next();
  100. if (selectedId.equals(value.getCode().toString())) {
  101. return value;
  102. }
  103. }
  104. }
  105. return null;
  106. }
  107.  
  108. @Override
  109. public void setValue(MyProxy value) {
  110. //handle null value
  111. String selectedId = value.getCode().toString();
  112. ... //verify the value is in myList
  113.  
  114. //traverse dropdown list and set selected index corresponding to value object
  115. for (int i = 0; i < view.getItemCount(); ++i) {
  116. if (selectedId.equals(view.getValue(i))) {
  117. view.setSelectedIndex(i);
  118. }
  119. }
  120. }
  121. }
Add Comment
Please, Sign In to add comment