Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Ext GWT Premium Member
    Join Date
    Jun 2010
    Location
    Kyrksæterøra, Norway
    Posts
    70
    Vote Rating
    2
    stigrv is on a distinguished road

      0  

    Default TreeStore hasRecord

    TreeStore hasRecord


    The TreeStore object inherits the hasRecord method of the Store class. As it is now, this record will always return "false", as the records map in the superclass has no content if subclassed by the TreeStore object. I think this method should be overriden in the TreeStore object and return a valid value in that context.

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,734
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    ListStore also doesn't extend any *record methods, but records work correctly for them. How are you using the Record objects that the TreeStore doesn't have any?

    Here's a quick sample, that runs through and makes changes to records, then allows interactive testing:
    Code:
    public class Test implements EntryPoint {
    
      public void onModuleLoad() {
        SampleDataProperties props = GWT.create(SampleDataProperties.class);
    
        final TreeStore<SampleData> treeStore = new TreeStore<SampleData>(props.id());
    
        final SampleData root = new SampleData("Root", "The top of the tree");
        SampleData parentAndChild = new SampleData("parent and child", "The first child of root, has children");
        SampleData leafNodeA = new SampleData("Leaf Node A", "The only 3rd tier child in this tree");
        SampleData leafNodeB = new SampleData("Leaf Node B", "Last entry in the tree");
    
        treeStore.add(root);
        treeStore.add(root, parentAndChild);
        treeStore.add(root, leafNodeB);
        treeStore.add(parentAndChild, leafNodeA);
    
        //first, test before changes
        System.out.println("Has any modified records (false)? " + (treeStore.getModifiedRecords().size() != 0));
        System.out.println("Root records (false)? " + treeStore.hasRecord(root));
        System.out.println();
    
        //request (i.e. create) a record
        Store<SampleData>.Record record = treeStore.getRecord(root);
    
        //verify that record exists, has no changes
        System.out.println("Has any modified records (true)? " + (treeStore.getModifiedRecords().size() != 0));
        System.out.println("Root records (true)? " + treeStore.hasRecord(root));
        if (treeStore.hasRecord(root)) {
          System.out.println("  Has Changes (false)? " + treeStore.getRecord(root).isDirty());
        }
        System.out.println();
    
        //modify a record
        record.addChange(props.description(), "THE TOP OF THE TREE");
    
        //verify that a record exists, verify that it has changes
        System.out.println("Has any modified records (true)? " + (treeStore.getModifiedRecords().size() != 0));
        System.out.println("Root records (true)? " + treeStore.hasRecord(root));
        if (treeStore.hasRecord(root)) {
          System.out.println("  Has Changes (true)? " + treeStore.getRecord(root).isDirty());
        }
        System.out.println();
    
        //commit record - but once a record exists, it stays around for use later, though it isn't dirty
        //single version:
        record.commit(true);
        //whole store version:
    //    treeStore.commitChanges();
    
        //verify that no records exist
        System.out.println("Has any modified records (false)? " + (treeStore.getModifiedRecords().size() != 0));
        System.out.println("Root records (true)? " + treeStore.hasRecord(root));
        if (treeStore.hasRecord(root)) {
          System.out.println("  Has Changes (false)? " + treeStore.getRecord(root).isDirty());
        }
        System.out.println();
    
    
    
        //Okay, build a TreeGrid and let the user verify all of these via UI
        ColumnConfig<SampleData, String> name = new ColumnConfig<SampleData, String>(props.name(), 200, "Name");
        ColumnConfig<SampleData, String> description = new ColumnConfig<SampleData, String>(props.description(), 200, "Description");
    
        ColumnModel<SampleData> columns = new ColumnModel<SampleData>(Arrays.<ColumnConfig<SampleData, ?>>asList(name, description));
        TreeGrid<SampleData> treeGrid = new TreeGrid<SampleData>(treeStore, columns, name);
    
        //set up simple editors
        GridInlineEditing<SampleData> editing = new GridInlineEditing<Test.SampleData>(treeGrid);
        editing.addEditor(name, new TextField());
        editing.addEditor(description, new TextField());
    
        //Size and draw
        treeGrid.setPixelSize(500, 500);
        RootPanel.get().add(treeGrid);
        
        //make some buttons to reset all and commit all
        RootPanel.get().add(new TextButton("Reset", new SelectHandler() {
          @Override
          public void onSelect(SelectEvent event) {
            treeStore.rejectChanges();
          }
        }));
        RootPanel.get().add(new TextButton("Save", new SelectHandler() {
          @Override
          public void onSelect(SelectEvent event) {
            treeStore.commitChanges();
          }
        }));
    
        //finally, add a button to confirm the above tests
        RootPanel.get().add(new TextButton("Print results to IDE console", new SelectHandler() {
          @Override
          public void onSelect(SelectEvent event) {
            System.out.println("Has any modified records? " + (treeStore.getModifiedRecords().size() != 0));
            System.out.println("Root records? " + treeStore.hasRecord(root));
            if (treeStore.hasRecord(root)) {
              System.out.println("Has Changes? " + treeStore.getRecord(root).isDirty());
            }
            System.out.println();
          }
        }));
      }
    
      public interface SampleDataProperties extends PropertyAccess<SampleData> {
        ModelKeyProvider<SampleData> id();
    
        ValueProvider<SampleData, String> name();
        ValueProvider<SampleData, String> description();
      }
      public static class SampleData {
        private static int nextId = 0;
    
        private final int id = nextId++;
    
        private String name;
        private String description;
    
        public SampleData(String name, String description) {
          setName(name);
          setDescription(description);
        }
    
        public int getId() {
          return id;
        }
    
        public String getName() {
          return name;
        }
    
        public void setName(String name) {
          this.name = name;
        }
    
        public String getDescription() {
          return description;
        }
    
        public void setDescription(String description) {
          this.description = description;
        }
    
      }
    }
    Can you clarify your bug, or provide a working test case that reproduces the issue?

  3. #3
    Ext GWT Premium Member
    Join Date
    Jun 2010
    Location
    Kyrksæterøra, Norway
    Posts
    70
    Vote Rating
    2
    stigrv is on a distinguished road

      0  

    Default


    What I need to do, is to determine if a model exists somewhere in the tree. My first instinct was to use the hasRecord method, but that did not give the expected result. I am now getting all elements in the tree using the getAll method, and iterating through it. I could also have used the findModelWithKey method. No matter which of the methods I use, I will need to fetch the key provider from the store in order to get the model key. I would prefer to have a contains method or similar which accepts a model object.

  4. #4
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,734
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Is it sufficient to know if the item is *visible*, or do you want to know if the item is there, filtered or not?

    If you know the item is present, you can check if it is visible or not by asking for its index in its parent - TreeStore.indexOf(M). As with most other methods, this will break an assertion if the item isn't present.

    Otherwise, Store.findModel(M) exists as a simple way of saying Store.findModelWithKey(Store.getKeyProvider().getKey(model)). This will easily then tell you if there is any model in the store that matches the key in the model passed in (so the models don't need to be the same instance, or even match .equals, but just have the same matching key). Is that what you are looking for?

  5. #5
    Ext GWT Premium Member
    Join Date
    Jun 2010
    Location
    Kyrksæterøra, Norway
    Posts
    70
    Vote Rating
    2
    stigrv is on a distinguished road

      0  

    Default


    Yes, the findModel method solves the problem. Thanks.

Thread Participants: 1