Announcement

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

    Problem setting different icon for node type

    Hello, I am using SmartGWTEE 2.2 to build a user management component. I am customizing the SmartGWTEE showcase example. I need help getting a different icon image to indicate that a user is of a certain role. For example, I would like it to default to person.png, although if it's a manager, have it change to manager.png. Can someone assist me?

    Here is the relevant code so far:
    EntryPoint:
    Code:
     treeGrid.setDataSource(DataSource.get("employees"));
            treeGrid.setNodeIcon("icons/16/person.png");
            treeGrid.setFolderIcon("icons/16/person.png");
            treeGrid.setCanReorderRecords(true);
            treeGrid.setCanDragRecordsOut(true);
            treeGrid.setCanAcceptDroppedRecords(true);
            treeGrid.setAutoFetchData(true);
            treeGrid.setShowOpenIcons(false);
            treeGrid.setDropIconSuffix("into");
            treeGrid.setClosedIconSuffix("");
    employees.ds.xml:
    Code:
    <field name="partyId" title="Party ID" type="text"  primaryKey="true"  required="true"/>
    <field name="managerPartyId" title="Manager" type="text"  required="true" foreignKey="partyId"  rootValue="MY_INC" detail="true"/>
    <field name="roleTypeIdTo" title="roleTypeIdTo"  hidden="false" type="text" length="128"/>
    Sample Data Output (expressed in XML)
    Code:
    <List>
    	<employee>
    		<partyId>TRONIX</partyId>
    		<managerPartyId>MY_INC</managerPartyId>
    		<roleTypeIdTo>DEPARTMENT</roleTypeIdTo>
    	</employee>
    	<employee>
    		<partyId>JohnSmith</partyId>
    		<managerPartyId>MY_INC</managerPartyId>
    		<roleTypeIdTo>EMPLOYEE</roleTypeIdTo>
    	</employee>
    	<employee>
    		<partyId>JaneDoe</partyId>
    		<managerPartyId>MY_INC</managerPartyId>
    		<roleTypeIdTo>MANAGER</roleTypeIdTo>
    	</employee>
    </List>
    Regards,
    Brant

    #2
    You can use an override of TreeGrid.getIcon():

    http://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/widgets/tree/TreeGrid.html#getIcon%28com.smartgwt.client.data.Record,%20boolean%29

    Comment


      #3
      Thanks for getting back to me. Could you please be more specific. Could you please give me some example code of how I would accomplish this.

      Regards,
      Brant

      Comment


        #4
        Please note that I am using SmartGWTEE/DMI and am using an object on the session. Here is the full employees.ds.xml:

        Code:
        <DataSource
            ID="employees"
            serverType="generic"
        >
            <fields>
             <field name="partyId"      title="Party ID"     type="text"  primaryKey="true"  required="true"/>
                <field name="managerPartyId"       title="Manager"         type="text"  required="true" 
                       foreignKey="partyId"  rootValue="MY_INC" detail="true"/>
                <field name="firstName" title="First Name"    hidden="true"  type="text"     length="128"/>
        <field name="lastName"            title="Last Name" hidden="true"    type="text"     length="128"/>
        <field name="suffix" title="Suffix"    hidden="true"        type="text"     length="128"/>
        <field name="fullName" title="Name"    type="text"     length="128"/>
        <field name="userLoginId" title="userLoginId"    hidden="true"        type="text"     length="128"/>
        <field name="roleTypeIdTo" title="roleTypeIdTo"    hidden="false"        type="text"     length="128"/>
        
         <field name="reviewerPartyId" title="reviewerPartyId"    hidden="true"        type="text"     length="128"/>
          <field name="managerName" title="managerName"    hidden="true"        type="text"     length="128"/>
           <field name="reviewerName" title="reviewerName"    hidden="true"        type="text"     length="128"/>
            <field name="reviewer" title="reviewer"    hidden="true"        type="text"     length="128"/>
                <field name="email"           title="Email"           type="text"     length="128"/>
                <field name="department"         title="Department"        type="text"     length="128"/>
                 <field name="subdept" title="Sub-Department"    hidden="true"        type="text"     length="128"/>
            </fields>
            <serverObject lookupStyle="attribute" attributeScope="session" attributeName="EmployeesDMI" className="EmployeesDMI"/>
            
        </DataSource>

        Comment


          #5
          You'd add an override like this to your TreeGrid instance:

          Code:
          public String getIcon (Record node, boolean defaultState) {
             if ("MANAGER".equals(node.getAttribute("roleTypeIdTo"))) {
                 return "manager.png";
             }
              return "employee.png";
          }
          Last edited by Isomorphic; 18 Aug 2010, 13:42.

          Comment


            #6
            Okay, I think this gets me close although I have a couple questions.

            1) Would I put this code in my EntryPoint or do I make a new class?
            2) In your sample code, it has record.getAttribute("roleTypeIdTo"), this gives me an error regarding the "record" definition.

            Originally posted by Isomorphic
            You'd add an override like this to your TreeGrid instance:

            Code:
            public String getIcon (Record node, boolean defaultState) {
               if ("MANAGER".equals(record.getAttribute("roleTypeIdTo"))) {
                   return "manager.png";
               }
                return "employee.png";
            }

            Comment


              #7
              Like any method override in Java, you need to create a subclass.

              Yes, the variable should have been "node" not "record".

              Comment


                #8
                I got it going, thank you very much for your help!

                Regards,
                Brant

                Comment

                Working...
                X