Announcement

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

    Conditionally show a RollOverCanvas

    SmartGWT Pro 2.3
    GWT 2.0.3
    Tested with Firefox 3.6, IE7 and Chrome 6.0.472.62
    DevMode

    I've been trying to produce something very similar to the ListGrid roll-over controls show in http://www.smartclient.com/smartgwt/showcase/#grid_appearance_rollover_controls, but with 1 little twist: I only want to show the rollover if the record the user is hovering over has data in a specific field.

    The use case for this is that some of the records may have a ticket number in an external ticket system - if this is the case, I want to show a little icon that they can click to directly open that ticket; but if they don't, then I don't show the icon.

    At first, I naively tried this:

    Code:
    protected ListGridField rtTicketNumberField;
    protected Layout emptyCanvas;
    protected Layout rtTicketNumberCanvas;
    protected ImgButton rtTicketNumberImgButton;
    
    ....
    
    rtTicketNumberField = new ListGridField(DIDOrderField.RT_TICKET_NUMBER.getName(), DIDOrderField.RT_TICKET_NUMBER.getDisplayTitle(), 100);
    
    rtTicketNumberCanvas = new HLayout(3);
    rtTicketNumberCanvas.setSnapTo("TR");
    rtTicketNumberCanvas.setHeight(18);
    rtTicketNumberCanvas.setWidth(13);
    	
    rtTicketNumberImgButton = new ImgButton();
    rtTicketNumberImgButton.setShowDown(false);
    rtTicketNumberImgButton.setShowRollOver(false);
    rtTicketNumberImgButton.setSrc("icons/misc/helpdesk.png");
    rtTicketNumberImgButton.setWidth(13);
    rtTicketNumberImgButton.setHeight(16);
    rtTicketNumberImgButton.setPrompt("Open Ticket in RT");
    		
    rtTicketNumberCanvas.setMembers(rtTicketNumberImgButton);
    
    ...
    
    
    @Override  
    	protected Canvas getRollOverCanvas(Integer rowNum, Integer colNum) {  
    		ListGridRecord rollOverRecord = this.getRecord(rowNum);
    		if(rollOverRecord.getAttribute(DIDOrderField.RT_TICKET_NUMBER.getName())!= null)
    		{
    				return rtTicketNumberCanvas;		
    		}
    		else
    		{
    			return emptyCanvas;
    		}
    			
    		
    	}
    The problem with that was that while the rtTicketNumber canvas showed just fine on any record that had data in the rtTicketNumberField, the canvas would not disappear when you moved the mouse off. I'm not entirely sure why - something about the fact that I'm conditionally returning a different canvas based on the record data seems to throw off this behavior, because when I removed the conditional check and always returned the rtTicketNumberCanvas...

    Code:
    @Override  
    	protected Canvas getRollOverCanvas(Integer rowNum, Integer colNum) {  
    		return rtTicketNumberCanvas;		
    		
    		
    	}
    ... it worked fine, exactly as in the show case.

    I ended up solving it by doing this:

    Code:
    @Override  
    	protected Canvas getRollOverCanvas(Integer rowNum, Integer colNum) {  
    		ListGridRecord rollOverRecord = this.getRecord(rowNum);
    		if(rollOverRecord.getAttribute(DIDOrderField.RT_TICKET_NUMBER.getName())!= null)
    		{
    				rtTicketNumberCanvas.setVisibility(Visibility.VISIBLE);
    				return rtTicketNumberCanvas;		
    		}
    		else
    		{
    			rtTicketNumberCanvas.setVisibility(Visibility.HIDDEN);
    			return emptyCanvas;
    		}
    			
    		
    	}
    With this set, it works fine - I just wonder if this is indeed the correct approach?
Working...
X