Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGL Development Tools » Can you create a GridLayout widget dynamically?
Can you create a GridLayout widget dynamically? [message #1016205] Tue, 05 March 2013 08:36 Go to next message
Richard Moulton is currently offline Richard Moulton
Messages: 92
Registered: August 2011
Location: Devon, UK
Member
Using EDT 0.8.2

I was building a set of widgets 'on the fly' and was looking to use a GridLayout widget to achieve the result I was after, rather than a series of boxes.

Should the following work?

package client;

import org.eclipse.edt.rui.widgets.Div;
import org.eclipse.edt.rui.widgets.GridLayout;
import org.eclipse.edt.rui.widgets.GridLayoutData;
import org.eclipse.edt.rui.widgets.HTML;
import eglx.ui.rui.RUIHandler;

handler TestGridLayout type RUIhandler{initialUI =[ui], onConstructionFunction = start}

    ui Div{children =[]};

    function start()
    	grid GridLayout = new GridLayout{ rows=2, columns=3, children=[] };
    	grid.appendChild( new HTML{text="R1C1", layoutData = new GridLayoutData{row=1, column=1} } );
    	ui.appendChild(grid);
    end
end


If I do the following then this does work ...

package client;

import org.eclipse.edt.rui.widgets.Div;
import org.eclipse.edt.rui.widgets.GridLayout;
import org.eclipse.edt.rui.widgets.GridLayoutData;
import org.eclipse.edt.rui.widgets.HTML;
import eglx.ui.rui.RUIHandler;

handler TestGridLayout type RUIhandler{initialUI =[ui], onConstructionFunction = start}

    ui Div{children =[]};

    function start()
    	grid GridLayout = new GridLayout{ rows=2, columns=3, 
    		children=[ new HTML{text="R1C1", layoutData = new GridLayoutData{row=1, column=1} } ] };
    	ui.appendChild(grid);
    end
end


If I do the following then I still get R1C1 but not R1C21 ...

package client;

import org.eclipse.edt.rui.widgets.Div;
import org.eclipse.edt.rui.widgets.GridLayout;
import org.eclipse.edt.rui.widgets.GridLayoutData;
import org.eclipse.edt.rui.widgets.HTML;
import eglx.ui.rui.RUIHandler;

handler TestGridLayout type RUIhandler{initialUI =[ui], onConstructionFunction = start}

    ui Div{children =[]};

    function start()
    	grid GridLayout = new GridLayout{ rows=2, columns=3, 
    		children=[ new HTML{text="R1C1", layoutData = new GridLayoutData{row=1, column=1} } ] };
        grid.appendChild( new HTML{text="R1C2", layoutData = new GridLayoutData{row=1, column=2} } );
    	ui.appendChild(grid);
    end
end


Richard
Re: Can you create a GridLayout widget dynamically? [message #1017472 is a reply to message #1016205] Mon, 11 March 2013 18:20 Go to previous messageGo to next message
Paul Harmon is currently offline Paul Harmon
Messages: 11
Registered: July 2009
Junior Member
Richard,

The answer is YES you can!

When you dynamically update the children in the GridLayout, you will need to force it to recompute the layout. You can do this by simply invoking
grid.layout();
after you do grid.appendChild(...). Alternatively, you can use:

grid.children = grid.children;

(I offer this alternative, because I am not able to test with EDT at the moment, so if the first one doesnt work, you can try this strange looking approach Smile ).

Hope this works for you!

Paul
Re: Can you create a GridLayout widget dynamically? [message #1017948 is a reply to message #1017472] Tue, 12 March 2013 16:43 Go to previous message
Richard Moulton is currently offline Richard Moulton
Messages: 92
Registered: August 2011
Location: Devon, UK
Member
Paul,

Both solutions worked.

I expanded my example slightly to prove the point, the create button creates a new GridLayout and the refresh button performs the grid.layout() function.

package client;

import org.eclipse.edt.rui.widgets.Box;
import org.eclipse.edt.rui.widgets.Button;
import org.eclipse.edt.rui.widgets.Div;
import org.eclipse.edt.rui.widgets.GridLayout;
import org.eclipse.edt.rui.widgets.GridLayoutData;
import org.eclipse.edt.rui.widgets.HTML;
import eglx.ui.rui.Event;
import eglx.ui.rui.RUIHandler;
import eglx.ui.rui.Widget;

handler TestGridLayout type RUIhandler{initialUI =[ui], onConstructionFunction = start}

    ui Div{children =[ box, create, refresh ]};
    box Box{};
    create Button{ text="Create Grid", onClick ::= create_onClick };
    refresh Button{ text="Refresh Grid", onClick ::= refresh_onClick };
    
    function start()
    end

    function createGrid()
    	grid GridLayout = new GridLayout{ rows=2, columns=3, children=[] };
    	grid.appendChild( new HTML{text="R1C1", layoutData = new GridLayoutData{row=1, column=1} } );
	box.appendChild( grid );
    end
    
    
    function create_onClick(event Event in)
    	createGrid();
    end
    
    function refresh_onClick(event Event in)
    	w widget[] = box.children;
    	for ( i int from 1 to w.getSize())
    		if ( w[i] isa GridLayout )
    			g GridLayout = w[i] as GridLayout;
    			//g.children = g.children;
    			g.layout();
    		end
    	end
    end

end


Many Thanks
Richard
Previous Topic:Is the mobile widget set compatible with the standard set of Dojo widgets?
Next Topic:DojoMobileDatePicker problem
Goto Forum:
  


Current Time: Fri Aug 01 02:04:46 EDT 2014

Powered by FUDForum. Page generated in 0.02475 seconds