Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    #16
    oh

    Likely because I am a fool.

    Ok, let me try just fetching the data.

    I will get records back I assume and I can do some sort of add records to a treegrid?

    Evan

    Comment


      #17
      Sorry to bring this up again, but it really, really seems like you haven't read the Tree Data Binding overview. Here's a direct link. No, no adding of records to the TreeGrid involved is normal tree data binding.

      Comment


        #18
        settings to tree

        Hello,

        If I just fetch the data and don't use a tree or result tree then I am not sure where I indicate the "tree setttings". Thinkgs like what the parent is, what the id is, ...

        Currently I fetch as follows.

        Would I use a "resultset" instead and then what would I set the ids (parent self, root, ...) on?

        Evan

        private void myFetchDataTreeGrid() {
        Tree rTree = new Tree();
        rTree.setModelType(TreeModelType.PARENT);
        rTree.setIdField("entkey");
        rTree.setParentIdField("parentkey");
        rTree.setShowRoot(false);
        rTree.setRootValue(0);
        rTree.setReportCollisions(false);

        treeGrid.setData(rTree);
        treeGrid.setVisible(false);

        // Where we expand the first two levels or all if less than 20 (which may have bugs, if
        // forces sql on each node ...
        DataArrivedHandler dataArrivedHandler = new DataArrivedHandler() {
        @Override
        public void onDataArrived(com.smartgwt.client.widgets.tree.events.DataArrivedEvent event) {
        // the following does expand all the nodes, however it also forces a new query on each leaf node!! not what we wanted
        Tree t = treeGrid.getData();
        t.openAll();
        showGrid();
        }
        };
        treeGrid.addDataArrivedHandler(dataArrivedHandler);


        CellContextClickHandler cellContextClickHandler = new CellContextClickHandler() {
        @Override
        public void onCellContextClick(CellContextClickEvent event) {
        System.out.print("context click");
        }
        };
        treeGrid.addCellContextClickHandler(cellContextClickHandler);

        String strSearchText = textItem.getValueAsString();
        AdvancedCriteria crit = new AdvancedCriteria(new Criterion("searchsyn", currentOperatorId, strSearchText));

        // fires only if server contact was needed, thus if have data already would want to do "shrink" after filterdata call
        DSCallback dsCallback = new DSCallback() {
        @Override
        public void execute(DSResponse response, Object rawData, DSRequest request) {
        showGrid();
        }

        };
        // treeGrid.fetchData(crit, dsCallback);
        treeGrid.fetchData(crit, dsCallback);
        }

        Comment


          #19
          You set these things in the data returned from the server.

          The Tree Data Binding overview links to samples showing this..

          Comment


            #20
            Hmm

            Yes, I agree I am confused. But really I am reading (over and over again) your documentation. I could use some examples to point me along. But regardless one thing at a time.

            I understand that no tree or resulttree is what I need.

            Lets talk about the .ds.xml and the parent/id fields. If I do not use the tree (or resulttree) type then it is not clear how to set these items.


            My data source does not have the same names for the id fields.

            I will just quote the doumentation and we can talk about it I guess.


            so yes I think my data clearly is "parent linked" as it the doc says

            "If you have a dataset that is "parent-linked", that is, every node has a unique ID (the idField) and also has a property with the unique ID of it's parent node (the parentIdField) the tree can load child nodes by simply sending a DSRequest with appropriate Criteria. Given a parent node with ID "225" in a tree where the parentIdField is called "parentId", the criteria would be: "

            However, I do not have a "parentId" field. I could redesign my columns and .ds.xml to have this, but it seems likely not needed.

            So this is what I want then
            "ree relationship in your DataSource: the tree will automatically use your primaryKey field as the idField. To declare the parentIdField, declare a foreignKey field with the name of the primaryKey field. "

            I currently have the following in my data source .ds.xml
            serverType="sql">
            <fields>
            <field primaryKey="true" name="entkey" type="integer"></field>
            <field name="parentkey" type="integer"></field>

            How should it change?

            Evan

            Comment


              #21
              You need to add a declaration of a foreignKey so that the DataSource knows how to form a tree structure from your records.

              Comment


                #22
                ok

                Hello,

                So looking at the examples the following seem the closest to what I want. And not sure how to have it use a .ds.xml file.

                If I put in the .ds.xml the parent and id fields, that is cool. But then where do I set the "root" of the tree id?

                However I have a .ds.xml file

                Is there an example using one of these? One that has the field settings? I did not see one.

                Evan


                public class EmployeeXmlDS extends DataSource {

                private static EmployeeXmlDS instance = null;

                public static EmployeeXmlDS getInstance() {
                if (instance == null) {
                instance = new EmployeeXmlDS("employeesDS");
                }
                return instance;
                }

                public EmployeeXmlDS(String id) {

                setID(id);
                setTitleField("Name");
                setRecordXPath("/List/employee");
                DataSourceTextField nameField = new DataSourceTextField("Name", "Name", 128);

                DataSourceIntegerField employeeIdField = new DataSourceIntegerField("EmployeeId", "Employee ID");
                employeeIdField.setPrimaryKey(true);
                employeeIdField.setRequired(true);

                DataSourceIntegerField reportsToField = new DataSourceIntegerField("ReportsTo", "Manager");
                reportsToField.setRequired(true);
                reportsToField.setForeignKey(id + ".EmployeeId");
                reportsToField.setRootValue("1");

                DataSourceTextField jobField = new DataSourceTextField("Job", "Title", 128);
                DataSourceTextField emailField = new DataSourceTextField("Email", "Email", 128);
                DataSourceTextField statusField = new DataSourceTextField("EmployeeStatus", "Status", 40);
                DataSourceFloatField salaryField = new DataSourceFloatField("Salary", "Salary");
                DataSourceTextField orgField = new DataSourceTextField("OrgUnit", "Org Unit", 128);
                DataSourceTextField genderField = new DataSourceTextField("Gender", "Gender", 7);
                genderField.setValueMap("male", "female");
                DataSourceTextField maritalStatusField = new DataSourceTextField("MaritalStatus", "Marital Status", 10);

                setFields(nameField, employeeIdField, reportsToField, jobField, emailField,
                statusField, salaryField, orgField, genderField, maritalStatusField);

                setDataURL("ds/test_data/employees.data.xml");
                setClientOnly(true);
                }
                }

                Comment


                  #23
                  .ds.xml file

                  This is what I have come up with.

                  But I have been unable to find any documentation (really an example) of a .ds.xml file for a tree that shows me the attributes.

                  Questions:
                  1. is the foreignkey below the correct way to say where the "id" is. And do I just use the field name for this?
                  2. Is there a "rootValue" setting and do I put it with the parent?
                  3. otherwise are the attributes legal and where in the documentation is a list of these attributes and settings?

                  Thanks,
                  Evan


                  <DataSource schema="relayBDLive" dbName="Mysql" tableName="parents_search_entities"
                  ID="parents_search_entities" dataSourceVersion="1" generatedBy="Evan Smith"
                  serverType="sql">
                  <fields>
                  <field primaryKey="true" name="entkey" type="integer" title="id"></field>
                  <field name="parentkey" type="integer" title="parent" foreignKey="entkey" rootValue="0"></field>
                  <field name="numchildren" type="integer"></field>
                  ...

                  Comment


                    #24
                    documentation

                    http://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/data/DataSourceField.html#getForeignKey%28%29

                    Is helpful, but is not showing .ds.xml settings so am unsure still of the exact settings and looking for an example of setting root.

                    Evan

                    Comment


                      #25
                      fetchData

                      Hello,

                      The treeGrid.fetchData(crit, dsCallback)

                      My criteria does not get passed back to the server. What is the right way to fetch data on the treeGrid?

                      Evan

                      Comment


                        #26
                        fetchData not passing criteria

                        Hello,

                        How do I have the fetch not go get the whole tree on the first call? And instead use my fetch criteria. Is this the demand mode? What setting do I need to change below?


                        private void setupTreeGrid() {
                        treeGrid.setHeight(iMaxListGridHeight);
                        treeGrid.setWidth(iWidthListGrid);
                        treeGrid.setLeft(100);
                        treeGrid.setHeaderHeight(0);
                        treeGrid.setDataFetchMode(FetchMode.LOCAL);
                        treeGrid.setCascadeSelection(true);
                        treeGrid.setShowSelectedStyle(false);
                        treeGrid.setShowPartialSelection(true);
                        treeGrid.setShowSelectedStyle(false);
                        treeGrid.setShowPartialSelection(true);
                        treeGrid.setCascadeSelection(true);
                        treeGrid.setShowHeader(false);
                        treeGrid.setShowAllColumns(true);
                        treeGrid.setShowAllRecords(true); // try this out ...
                        DataSource ds = DataSource.get(DataSourceInfo.PARENTS_SEARCH_ENITITES_DATASOURCE_MYSQL);
                        treeGrid.setDataSource(ds);
                        treeGrid.setKeepParentsOnFilter(true); // so mode defaults to local now
                        treeGrid.setLoadDataOnDemand(true);

                        treeGrid.setAutoFetchData(false);
                        treeGrid.setSortFoldersBeforeLeaves(true);
                        treeGrid.setSortField("entsyn");
                        treeGrid.setCanMultiSort(false);
                        treeGrid.setShowSortArrow(SortArrow.NONE);
                        treeGrid.setShowEdges(true);
                        treeGrid.setEdgeSize(2);
                        treeGrid.setShowEmptyMessage(true);
                        treeGrid.setAlternateRecordStyles(true);
                        treeGrid.setCanHover(true);
                        treeGrid.setShowHover(true);
                        treeGrid.setHoverWidth(150);
                        treeGrid.setFolderIcon("folder.gif");
                        treeGrid.setShowConnectors(true);
                        treeGrid.setShowBackgroundComponent(true);

                        treeGrid.setHoverCustomizer(new HoverCustomizer() {
                        @Override
                        public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
                        Integer i = record.getAttributeAsInt("entfieldskey");
                        String strTreeLoc = record.getAttributeAsString("treeloc");
                        String str = "";
                        try {
                        str = EntityEnumType.getHoverFromEntFieldsKey(i);
                        str += " [" + strTreeLoc + "]";
                        } catch (Exception e) {
                        }
                        return str;
                        }
                        });
                        treeGrid.setCellFormatter(getFormatter());

                        TreeGridField fieldSyn = new TreeGridField("entsyn", "Syn");
                        TreeGridField selectMe = new TreeGridField("selectme", "selectme");
                        selectMe.setType(ListGridFieldType.BOOLEAN);
                        selectMe.setCanEdit(true);
                        selectMe.setPrompt("Click to select item");

                        if (AppUtilsShared.RCCodeMultipleSearchHeads) {
                        treeGrid.setFields(fieldSyn, selectMe);
                        treeGrid.setSelectionType(SelectionStyle.MULTIPLE);
                        } else {
                        treeGrid.setFields(fieldSyn);
                        }

                        DataArrivedHandler dataArrivedHandler = new DataArrivedHandler() {
                        @Override
                        public void onDataArrived(com.smartgwt.client.widgets.tree.events.DataArrivedEvent event) {
                        // the following does expand all the nodes, however it also forces a new query on each leaf node!! not what we wanted
                        Tree t = treeGrid.getData();
                        t.openAll();
                        showGrid();
                        }
                        };
                        treeGrid.addDataArrivedHandler(dataArrivedHandler);

                        CellContextClickHandler cellContextClickHandler = new CellContextClickHandler() {
                        @Override
                        public void onCellContextClick(CellContextClickEvent event) {
                        System.out.print("context click");
                        }
                        };
                        treeGrid.addCellContextClickHandler(cellContextClickHandler);

                        }

                        private void myFetchDataTreeGrid() {
                        String strSearchText = textItem.getValueAsString();
                        AdvancedCriteria crit = new AdvancedCriteria(new Criterion("searchsyn", currentOperatorId, strSearchText));

                        // fires only if server contact was needed, thus if have data already would want to do "shrink" after filterdata call
                        DSCallback dsCallback = new DSCallback() {
                        @Override
                        public void execute(DSResponse response, Object rawData, DSRequest request) {
                        showGrid();
                        }

                        };
                        // treeGrid.fetchData(crit, dsCallback);
                        treeGrid.fetchData(crit, dsCallback);
                        }


                        and the data source

                        <fields>
                        <field primaryKey="true" name="entkey" type="integer" title="id"></field>
                        <field name="parentkey" type="integer" title="parent" foreignKey="entkey" rootValue="0"></field>
                        <field name="numchildren" type="integer"></field>

                        Comment


                          #27
                          hmm

                          The documentation says
                          "ResultTrees are created for you by the TreeGrid when you set dataSource, but you can pass an initial dataset to a databound TreeGrid by setting initialData. "

                          So I should not be setting the data source on the tree, and I assume that is what is getting me.

                          So setInitialData looks correct to use. But that takes a TreeNode array as an argument.

                          How do I load an array of tree nodes? What data structure do I bind to my data source to get a array of tree nodes.

                          Thanks,
                          Evan

                          Comment


                            #28
                            hmm

                            Well TreeNode is derived from a ListGridRecord

                            So perhaps ResultSet is the way to go.

                            Any examples of this?

                            evan

                            Comment


                              #29
                              first try

                              So here I am trying to "get the data on my own" instead of using tree and result tree.

                              I thought a result set might work. But once I get the data back I don't know how to put it in to the treenode array so I can set initial data.

                              Am I going down the right track here?

                              Evan


                              private void myFetchDataTreeGrid() {
                              String strSearchText = textItem.getValueAsString();
                              AdvancedCriteria crit = new AdvancedCriteria(new Criterion("searchsyn", currentOperatorId, strSearchText));
                              DataSource ds = DataSource.get(DataSourceInfo.PARENTS_SEARCH_ENITITES_DATASOURCE_MYSQL);
                              final ResultSet rs = new ResultSet();
                              rs.setDataSource(ds);
                              rs.setCriteria(crit);
                              rs.setFetchMode(FetchMode.LOCAL);
                              com.smartgwt.client.data.events.DataArrivedHandler dhand = new com.smartgwt.client.data.events.DataArrivedHandler() {
                              @Override
                              public void onDataArrived(com.smartgwt.client.data.events.DataArrivedEvent event) {
                              TreeNode treenodes[] = new TreeNode[rs.getLength()];
                              for (int i = event.getStartRow(); i < event.getEndRow(); i++) {
                              //treenodes[i].set
                              // = rs.get(i);

                              }
                              treeGrid.setInitialData(treenodes);
                              showGrid();
                              }
                              };
                              rs.addDataArrivedHandler(dhand);
                              rs.getLength(); // force a fetch
                              }

                              Comment


                                #30
                                result set

                                Hello,

                                Well I thought the following fetch code would do it.

                                But ... the record length on data arrived is always 0.
                                And the criteria I define is not being passed into the payload. Which is really confusing to me. Why is the criteria for this code not going to the payload?

                                Here is the code and the console for the payload.

                                Thanks,
                                Evan

                                private void myFetchDataTreeGrid() {
                                String strSearchText = textItem.getValueAsString();
                                AdvancedCriteria crit = new AdvancedCriteria(new Criterion("searchsyn", currentOperatorId, strSearchText));
                                DataSource ds = DataSource.get(DataSourceInfo.PARENTS_SEARCH_ENITITES_DATASOURCE_MYSQL);
                                final ResultSet rs = new ResultSet();
                                rs.setDataSource(ds);
                                rs.setCriteria(crit);
                                rs.setFetchMode(FetchMode.LOCAL);
                                com.smartgwt.client.data.events.DataArrivedHandler dhand = new com.smartgwt.client.data.events.DataArrivedHandler() {
                                @Override
                                public void onDataArrived(com.smartgwt.client.data.events.DataArrivedEvent event) {
                                int ilen = rs.getLength();
                                TreeNode treenodes[] = new TreeNode[ilen];
                                for (int i = event.getStartRow(); i < event.getEndRow(); i++) {
                                TreeNode n = new TreeNode();
                                Record r = rs.get(i);
                                n.setAttribute("id", r.getAttributeAsInt("entkey"));
                                n.setAttribute("parentd", r.getAttributeAsInt("entkey"));
                                n.setAttribute("entsyn", r.getAttributeAsString("entsyn"));
                                treenodes[i] = n;
                                }
                                treeGrid.setInitialData(treenodes);
                                showGrid();
                                }
                                };
                                rs.addDataArrivedHandler(dhand);
                                // force fetch?
                                Record r = rs.get(0);
                                }


                                === 2013-05-16 21:14:18,216 [l0-2] DEBUG XML - Parsed XML from (in memory stream): 15ms
                                === 2013-05-16 21:14:18,232 [l0-2] DEBUG RPCManager - Processing 1 requests.
                                === 2013-05-16 21:14:18,232 [l0-2] DEBUG RPCManager - Request #1 (DSRequest) payload: {
                                criteria:{
                                },
                                operationConfig:{
                                dataSource:"parents_search_entities",
                                operationType:"fetch"
                                },
                                componentId:"(created directly)",
                                appID:"builtinApplication",
                                operation:"parents_search_entities_fetch",
                                oldValues:null
                                }
                                === 2013-05-16 21:14:18,232 [l0-2] INFO IDACall - Performing 1 operation(s)
                                === 2013-05-16 21:14:18,232 [l0-2] DEBUG DeclarativeSecurity - Processing security checks for DataSource null, field null
                                === 2013-05-16 21:14:18,232 [l0-2] DEBUG DeclarativeSecurity - DataSource parents_search_entities is not in the pre-checked list, processing...

                                Comment

                                Working...
                                X