Announcement

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

    Timeline and Dynamic Lanes

    Hi, fellas!

    Is it possible to use a timeline with dynamic lanes(i.e. bringing them from a datasource)?

    I really did a deep research about that and can't figure out a working solution.

    I'm using SmartGWT 3.1 and trying something like below, but the lanes don't show up on the page:

    Code:
    public class Module implements EntryPoint {
    	
    	public static Lane[] lanes;
    	
    	/**
    	 * This is the entry point method.
    	 */
    	public void onModuleLoad() {
    		
    		
    		AnyDS.getInstance().fetchData(null, new DSCallback() {
    			
    			@Override
    			public void execute(DSResponse response, Object rawData, DSRequest request) {
    				
    				Record[] rs = response.getData()
    				lanes = new Lane[rs.length]
    						
    				for(int i = 0 ; i < rs.length ; i++){
    					Record r  = rs[i];
    					lanes[i] = new Lane(r.getAttribute("x"), r.getAttribute("y"));
    				}					
    			}
    		});
    
    		Timeline timeline = new Timeline();  
    		timeline.setLanes(lanes);
                    timeline.setDataSource(OtherDS.getInstance());
    		timeline.draw();
    	}
    }

    Thanks in advance

    #2
    No tips so far, guys?

    Didn't anyone understand my question? Is it a little bit strange?

    Or just a few people is really using the Timeline widget and nobody worked on something similar up to now?


    Thanks again

    Comment


      #3
      The Timeline is being created before the fetch returns, so there are no lanes to set - just move all of the Timeline creation code into the callback from the fetchData, right after the for loop. Note that setLanes() won't presently work *after* initial draw(). This is queued to be addressed.

      Comment


        #4
        Thanks for answers, Isomorphic guys!

        After some more research e brain activity :), I was getting closer to what you said.

        But thinking even more about all that, I came up with the solution below:

        Is this a good approach?

        Code:
        public class PlanilhaTimeline extends Timeline {
        
        	private static DataSource anyDS;
        	private static DataSource otherDS;
        	
        	public PlanilhaTimeline() {
        		anyDS = AnyDS.getInstance();
        		otherDS = OtherDS.getInstance();
        
        		...
        		setDataSource(anyDS);
        				
        		AdvancedCriteria criteria = new AdvancedCriteria(...);
        		setInitialCriteria(criteria);
        		
        		setAutoFetchData(true);
        		
        	}
        	
        	@Override
        	public void draw() {
        		
        		otherDS.fetchData(null, new DSCallback() {
        			
        			@Override
        			public void execute(DSResponse response, Object rawData, DSRequest request) {
        
        				Record[] rs = response.getData();
        						
        				for(int i = 0 ; i < rs.length ; i++){
        					Record r  = rs[i];
        					addLane(new Lane(r.getAttribute("x"),r.getAttribute("y")));
        				}					
        			}
        		});
        		
        		super.draw();
        	}
        
        }

        Comment


          #5
          No, not really. Adding lanes after the Timeline draws is vastly more expensive than providing all the lanes up front, before the Timeline draws.

          Comment


            #6
            Just a quick note that we've fixed setLanes() being called after draw() and the fixes will hit nightly builds of 3.1p and 4.0d from February 10 (see smartclient.com/builds).

            Note that it is still most efficient to setLanes() before setData() or fetchData() and draw(), but it will now work in any case.

            Comment

            Working...
            X