Announcement

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

    Creating a custom pickList

    Hi,

    I want a drop down list to be populated based on what is in the datasource xml (more or less like the valueMap declaration).
    However, the values in the drop down list should be greyed-out based on an updateFlag.

    In the case the forUpdate flag is "false", user is not allowed to select the value, but he/she is able to see this value (greyed-out).

    I know you guys are going to suggest "optionDataSource" (sooner or later).
    Howver, these drop down lists are always static and generated based on the logged in user (security),
    so it makes no sense to go fetch these values if I have them in my ds xml (datasource xml has user security applied to it as well).

    So, based on the discussions I had on the forum over the past few days...
    I guess I need to implement the picklist properties for my custom comboBoxItem (we want to re-use most of the functionality of the existing ComboBoxItem).
    At first sight, grid seems to support what I want to do eg. "getRecordCanSelectProperty()" (allow selection based on updateFlag).

    So, first thought was to implement the "getClientPickListData()" on my custom editor.
    Sadly enough there is no example of such an implementation anywhere and I haven't been able to get this working so far.
    I'm thinking that the absence of both optionDataSource AND valueMap is maybe causing this?
    But that's just a wild guess.

    Any thoughts on how this could be realised would be greatly appreciated. I'll post an example later today of what I have so far.

    Originally posted by javaDoc
    getClientPickListData()

    Returns the set of data to be displayed in this item's PickList.

    This method will be called for non-databound form items implementing the PickList interface.
    The default implementation will derive data from the item's valueMap - can be overridden to allow a custom set of options to be displayed.

    Note that for PickLists that filter data based on user input 'ComboBox'), this method should return the data before filtering.

    Overrides: getClientPickListData() in ComboBoxItem
    Returns:
    Array of record objects to be displayed in the pickList. Note that when a user picks a record from the list,
    the value of the field matching item.valueField will be picked. Also note that the fields to be displayed can be customized via item.pickListFields
    Regards,
    Bart
    Last edited by bade; 11 Mar 2011, 02:02.

    #2
    Alright... seems like all my effort did pay off. I was to quick to dismiss the optionDataSource.

    I have developed the followig:

    "ClientOnly" DataSource which caches data directly set by setCacheData(...).
    PickListProperties grid using this datasource as an OptionDataSource.
    setRecordCanSelectProperty("forUpdate") so that it reacts to the data that is there.
    ComboBoxItem using this pickListProperties.

    What I'm seeing now, is that indeed 'Green' (where forUpdate='false') is not highlighted in the drop down list,
    but you can click on it and the value is SET in the comboBoxItem.

    According to me that is something that should not be possible, so I tried to find a workaround for this...
    So, I added a recordClickHandler... but then you can't select anything anymore?

    I inlcuded a standalone test case below.

    FireFox 3.6.15
    SC_SNAPSHOT-2011-03-09/EVAL Deployment

    Code:
    public class Standalone implements EntryPoint {
    		
    	private static Canvas masterPanel = null;
    	
    	public void onModuleLoad() {
    		   		
    		//masterPanel should be a Layout
    		masterPanel = new Canvas(); 
    		masterPanel.setHeight100();
    		masterPanel.setWidth100();
    		masterPanel.setStyleName("pageBackground"); //background style from skin
    		
    		masterPanel.addChild(testCase10());
    		masterPanel.draw();	
    	}
    
       public VLayout testCase10() {
        	
        	VLayout test = new VLayout();
        	test.setWidth100();
        	test.setHeight100();
            	
            //static data for this comboBox
            ListGridRecord[] records = new ListGridRecord[3];
            records[0] = new ListGridRecord();
            records[0].setAttribute("enumeration_id", 1);
            records[0].setAttribute("enumerationValue", "Red");
            records[0].setAttribute("forUpdate", true);
            records[1] = new ListGridRecord();
            records[1].setAttribute("enumeration_id", 2);
            records[1].setAttribute("enumerationValue", "Green");
           //selecting green is not allowed
            records[1].setAttribute("forUpdate", false);
            records[2] = new ListGridRecord();
            records[2].setAttribute("enumeration_id", 3);
            records[2].setAttribute("enumerationValue", "Blue");
            records[2].setAttribute("forUpdate", true);
      	  	
            DataSourceIntegerField pkDS = new DataSourceIntegerField("enumeration_id");    
            pkDS.setPrimaryKey(true);
      	  	
            DataSourceTextField enumValueDS = new DataSourceTextField("enumerationValue");
            
            DataSourceBooleanField forUpdateDS = new DataSourceBooleanField("forUpdate");
      	  	
           DataSource datasource = new DataSource();
          datasource.setID("testDS");
          datasource.setFields(pkDS, enumValueDS, forUpdateDS);
          datasource.setCacheData(records);
          datasource.setClientOnly(true);  	    
      	    	        
          ListGrid pickListProperties = new ListGrid();
          pickListProperties.setAutoFetchData(false);
          pickListProperties.setWidth(500);
          pickListProperties.setHeight(300);
          pickListProperties.setDataSource(datasource);
          pickListProperties.setEmptyMessage("No data");
          pickListProperties.setRecordCanSelectProperty("forUpdate");
          pickListProperties.setShowHeader(false);
    
          pickListProperties.setCellFormatter(new CellFormatter() {   
    
                public String format(Object value, ListGridRecord record, int rowNum, int colNum) {   
                	
                    Boolean forUpdate = record.getAttributeAsBoolean("forUpdate");   
                    String enumValue = record.getAttribute("enumerationValue");
                    if(forUpdate)//blue
                    	return "<span style='color:#113377'>" + enumValue + "</span>";
                    else//grey
                    	return "<i><span style='color:#aaaaaa'>" + enumValue + "</span></i>";
                    	
                }   
            });
    
    
    //        This is also blocking the selection of allowed values, for some reason
    //        pickListProperties.addRecordClickHandler(new RecordClickHandler() {
    //			
    //			public void onRecordClick(RecordClickEvent event) {
    //				 Boolean forUpdate = event.getRecord().getAttributeAsBoolean("forUpdate");
    //				 if(!forUpdate) event.cancel();
    //			}
    //		});
           
          ListGridField idField1 = new ListGridField("enumeration_id");
          ListGridField valueField1 = new ListGridField("enumerationValue");
            
          ComboBoxItem combo =new ComboBoxItem("enumeration_id");
          combo.setPickListWidth(450);
          combo.setOptionDataSource(datasource);   
          combo.setValueField("enumeration_id");   
          combo.setDisplayField("enumerationValue");   
          combo.setPickListProperties(pickListProperties);
          combo.setPickListFields(valueField1);
          combo.setAddUnknownValues(false);
          combo.setCompleteOnTab(true);
                   
           DynamicForm form = new DynamicForm();   
           form.setHeight(300);   
           form.setWidth(500);
           form.setFields(combo);
           test.addMember(form);
           return test;
        }
    
    }
    Last edited by bade; 11 Mar 2011, 06:38.

    Comment


      #3
      Any news on this?

      Comment


        #4
        Just cancel the ChangeEvent to reject the change.

        Comment


          #5
          Only one problem with that, the changeEvent doesn't give you the Record.
          Remember it's the Record that holds the "forUpdate" flag, not the item.
          Last edited by bade; 16 Mar 2011, 01:13.

          Comment


            #6
            This just means you'll need to make the record available, eg, as a "final" variable in the place where you add your change handler.

            Comment

            Working...
            X