Hi,

Thanks for the answer. However I did not succeed to make this working by 
managing with the layout. I don't know what I am doing wrong. Could any one of 
you have a quick look on my attached file( .java. For your help,  css is not 
having any entry related to this ) and help me out to get rid of this issue.

I know everybody time is precious but I am doing this as of now I have no 
option. My code is simple , don't know why this is not giving the required 
behaviour.

Every single idea is precious for me at this time.

Regards,
Manish
 
  ----- Original Message ----- 
  From: Matías Costa 
  To: [email protected] 
  Sent: Thursday, February 19, 2009 3:38 PM
  Subject: Re: working with % for gwt/gwtext widget(Panel) height


  I had to think twice to understand you want to set height in percentage.

  The size of any widget is affected by the layout is contained in. You can do 
setHeight("50%"), add to the parent container setLayout(new FitLayout()), or 
just use any of the many layouts available and use panel.add(widget, 
layoutdata). ej: rowlayout / rowdata

  Have you tried setStyle, or a custom css?


  On Thu, Feb 19, 2009 at 5:31 AM, Manish Kumar <[email protected]> wrote:

    Hi All,

    Could I please expect any talk on this? Every single contribution will be 
appreciated well as I am now on dead-end where I need to say yes or no. 

    Regards,
    Manish
      ----- Original Message ----- 
      From: Manish Kumar 
      To: [email protected] 
      Sent: Wednesday, February 18, 2009 2:19 PM
      Subject: working with % forgwt/gwtext widget(Panel) height


      Hi All,

      I am trying to use % with GWT/GWText widget(Panel). But this does not 
work.Could i know how to do or if any work around for this.

      Regards,
      Manish





  

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

package pm.gwt.hub.explorer.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.gwtext.client.widgets.Panel;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.URL;
import com.gwtext.client.widgets.layout.AnchorLayout;
import com.gwtext.client.widgets.layout.BorderLayout;
import com.gwtext.client.widgets.layout.BorderLayoutData;
import com.gwtext.client.widgets.tree.TreeNode;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.core.RegionPosition;
import com.gwtext.client.data.ArrayReader;
import com.gwtext.client.data.FieldDef;
import com.gwtext.client.data.MemoryProxy;
import com.gwtext.client.data.Record;
import com.gwtext.client.data.RecordDef;
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StringFieldDef;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.Request;
import com.gwtext.client.widgets.MessageBox;
import com.google.gwt.xml.client.XMLParser;
import com.google.gwt.xml.client.Node;
import com.google.gwt.xml.client.NamedNodeMap;
import com.google.gwt.xml.client.NodeList;
import com.google.gwt.xml.client.Document;
import com.gwtext.client.widgets.tree.TreePanel;
import com.gwtext.client.widgets.tree.event.TreePanelListenerAdapter;
import com.gwtext.client.widgets.layout.FitLayout;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.RootPanel;
import com.gwtext.client.core.XTemplate;
import com.gwtext.client.widgets.DataView;
import com.gwtext.client.widgets.event.DataViewListenerAdapter;
import java.util.*;

public class PMExplorer implements EntryPoint 
{
	Panel contentPanel;
	String PMServer;
	String rootName;
	TreePanel treePanel;
	Panel appContentPanel;	
	String treePnlWidth = "15%";
	private Object[][] data; 
	private HashMap treeNodeMap;
	private TreeNode currSelectedNode;	
	TreeNode root;
	
	private static RecordDef recordDef = new RecordDef(
         	new FieldDef[]{
         	
         	new StringFieldDef("object"),
         	new StringFieldDef("name"),
         	new StringFieldDef("type"),
            new StringFieldDef("url"),
         }
	);
 
	private static ArrayReader reader = new ArrayReader( recordDef );
		
	public void onModuleLoad() 
	{
		try
        {
			final Panel mainpanel = new Panel();
			mainpanel.setId("main-panel");
			mainpanel.setBorder(true);
			mainpanel.setTitle("Process Master Library");
	       	mainpanel.setAutoWidth( true );
	       	
	       	mainpanel.setHeight( com.google.gwt.user.client.Window.getClientHeight() - 10 );
	        mainpanel.setLayout(new BorderLayout());	  
	       		       	     
	        PMServer = "http://"+com.google.gwt.user.client.Window.Location.getHost()+ "/";	        
	        	
	        String rootDir = com.google.gwt.user.client.Window.Location.getParameter("ROOT_DIR");
        
	        PMServer = PMServer + rootDir; 
	        
	        if(rootDir.endsWith("/"))
	        {
	        	rootDir = rootDir.substring(0, rootDir.lastIndexOf("/"));
	        	rootName = rootDir.substring( rootDir.lastIndexOf("/") + 1);
	        }
	        else
	        	rootName = rootDir.substring( rootDir.lastIndexOf("/") + 1);      
	       
	       doRequestPMHub( PMServer, mainpanel );    						
		}
        catch(Exception re)
        {	
        	MessageBox.alert(re.getLocalizedMessage());
        	GWT.log(re.getMessage(), re);
        }
	}
	
	private void doRequestPMHub( final String url, final Panel mainpanel) throws RequestException
	{
		root = new TreeNode(rootName);
		
		root.setAttribute("location", PMServer);	 	
		
	 	treePanel = new TreePanel();
	 	
	 	treePanel.setAutoScroll(true);							
		treePanel.setBorder(true);
		treePanel.setRootNode(root);                    
        treePanel.setContainerScroll(true);        
        treePanel.setRootVisible(true);
        treePanel.setUseArrows(true);	
        treePanel.setWidth(treePnlWidth);
        
        treePanel.addListener(new TreePanelListenerAdapter()
       	{
           public void onClick(TreeNode self, EventObject e) {            	
            	try
            	{
            		onExpandTreeNode( self );
            	}
            	catch(RequestException re)
            	{
            		MessageBox.alert( re.getLocalizedMessage() );
            	}
			}
            public void onExpandNode(TreeNode self) {                	
            	try
            	{
            		onExpandTreeNode( self );
            	}
            	catch(RequestException re)
            	{
            		MessageBox.alert( re.getLocalizedMessage() );
            	}
			}
            public void onCollapseNode(TreeNode node) {
            	try
            	{
            		onExpandTreeNode( node );
            	}
            	catch(RequestException re)
            	{
            		MessageBox.alert( re.getLocalizedMessage() );
            	}
            }
            public void onDblClick(TreeNode self, EventObject e) {
            	
            	try
            	{
            		onExpandTreeNode( self );
            	}
            	catch(RequestException re)
            	{
            		MessageBox.alert( re.getLocalizedMessage() );
            	}
			}
        });	
        
        appContentPanel = new Panel();	
        appContentPanel.setId("data-view-container-panel");
        appContentPanel.setAutoWidth(true);
        
        //appContentPanel.setHeight(com.google.gwt.user.client.Window.getClientHeight() - 43 );
        
        appContentPanel.setFrame(true);
	    appContentPanel.setBodyBorder(true);
	    appContentPanel.setBorder(true);
	    appContentPanel.setLayout(new FitLayout());		
	            
        contentPanel = new Panel();
	    contentPanel.setId("data-view-panel");
	    contentPanel.setAutoWidth(true);	    
	    contentPanel.setAutoScroll(true);	    
	    contentPanel.setHeader(true);
	    contentPanel.setLayout(new FitLayout());		     
		
	    root.setExpandable(true);
	    
		RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
		
		builder.setCallback(new RequestCallback()
		{    
			public void onError(Request request, Throwable exception) 
			{ 
				MessageBox.alert(exception.getLocalizedMessage());
			}
			public void onResponseReceived(Request request, Response response) 
			{		
				if ( 200 == response.getStatusCode() ) 
				{
					buildTreeNode( response.getText(),root );					
					
					appContentPanel.add((new PMHubViewPanel(root.getText())).getDataView());
					
					RootPanel.get().add( showViewPanel( mainpanel ));
					
					root.expand();
					currSelectedNode = root;								
				}
			}
		});
		builder.send();       
	}
	
	private void buildTreeNode( String messageXML, final TreeNode currNode ) 
	{  
		int nodeCnt = 0;			
						
		Document responseDom = XMLParser.parse( messageXML.trim() );
		
		//Must do this if you ever use a raw node list that you expect to be all elements.
		
		XMLParser.removeWhitespace( responseDom );
		
		NodeList responseElements = responseDom.getElementsByTagName("result");
		
		data = new String[responseElements.getLength()][4];
		
		treeNodeMap = new HashMap();	
		
		while( nodeCnt < responseElements.getLength() ) 
		{
			Node resultNode = responseElements.item( nodeCnt );
			
			NamedNodeMap itemAttrMap =  resultNode.getAttributes();
			
			final String itemName = itemAttrMap.getNamedItem("name").getNodeValue();		
			
			final TreeNode childTreeNode = new TreeNode( itemName );
			
			final String itmType = itemAttrMap.getNamedItem("type").getNodeValue();
						
			if(itmType.equalsIgnoreCase("folder"))
			{
				data[nodeCnt][0] = "<span>"+ itemName +"</span>"; //<img src=\"folder.gif\"></img>  
			}
			else
			{
				data[nodeCnt][0] = "<span>"+ itemName +"</span>"; //<img src=\"file.png\"></img>  
			}
			
			data[nodeCnt][1] = itemName;
			data[nodeCnt][2] = itmType;
			
			final String itmPath = itemAttrMap.getNamedItem("url").getNodeValue();
			
			data[nodeCnt][3] = itmPath;		
				
			final boolean isFolder = (itmType != null && itmType.equalsIgnoreCase("folder"));			
			boolean isNodeExist = false;			
			
			if( isFolder )
			{
				childTreeNode.setExpandable(true);					
				childTreeNode.setAttribute("isFolder", "yes");
				
				com.gwtext.client.data.Node[] nodes = currNode.getChildNodes();
				for(int cnt=0; cnt < nodes.length; cnt++)
				{
					String nodeTxt = ((TreeNode)nodes[cnt]).getText();
					
					if( nodeTxt.equalsIgnoreCase(itemName) )
					{
						isNodeExist = true;
					}
				}
				if( !isNodeExist )
				{
					currNode.appendChild( childTreeNode );	
				}
			}
			else
			{
				childTreeNode.setAttribute("isFolder", "no");
			}
			
			childTreeNode.setAttribute("location", itmPath);
			
			treeNodeMap.put( itemName, childTreeNode );
			
			nodeCnt++;
		}
	}
	
	private void onExpandTreeNode(final TreeNode self ) throws RequestException
	{
		
		RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode( self.getAttribute("location") ));
		builder.setCallback(new RequestCallback()
		{    
			public void onError(Request request, Throwable exception) 
			{ 
				MessageBox.alert( exception.getLocalizedMessage() );
			}
			public void onResponseReceived(Request request, Response response) 
			{      
				if (200 == response.getStatusCode()) 
				{   
					appContentPanel.clear();
					
					buildTreeNode ( response.getText(), self );	
					
					appContentPanel.add((new PMHubViewPanel(self.getText())).getDataView());
					
					currSelectedNode = self;
					
					appContentPanel.doLayout();
				} 
				else 
				{       
					MessageBox.alert(response.getStatusCode() +" : "+ response.getStatusText() +":"+ response.getText() );
				}    
			}
		});
		
		builder.send();	
	}
	
	public Panel showViewPanel(final Panel mainpanel) 
	{
		BorderLayoutData centerData = new BorderLayoutData( RegionPosition.CENTER );
        centerData.setMargins(3, 0, 3, 3);

        BorderLayoutData westData = new BorderLayoutData( RegionPosition.WEST );
        westData.setSplit(true);
        westData.setMargins(3, 3, 0, 3);
                
        mainpanel.add(treePanel, westData);
        mainpanel.add(appContentPanel, centerData);   
               
        return mainpanel;
    }
	
	public class PMHubViewPanel {
	   
	   protected Store store;
	   String title;
	   	   
	   public PMHubViewPanel(String title) {	
		   contentPanel.clear();
		   this.title = title;
	   }
	   
	   public Panel getDataView() {
		   
		   contentPanel.setTitle(this.title);
		   
		   MemoryProxy proxy = new MemoryProxy( data );
		   		   
	       store = new Store(proxy, reader);
	       store.load();	        
       	    
	       XTemplate template = new XTemplate(new String[]{
	    		   "<table>",
	    		   "<tpl for='.'>",
	    		   "<tr><td>",
	    		   "<div class='thumb-wrap'>",
                   "<div class='thumb'>{object} </div>", 
                   "</div>",
                   "</td></tr>",
                   "</tpl>",
                   "<div class='x-clear'></div>",
                   "</table>",
           });
                      
           final DataView dataView = new DataView("div.thumb-wrap") {
               public void prepareData(Data data) {                   
               }
           };  
          
           dataView.setStore(store);
           dataView.setTpl(template);           
           dataView.setSingleSelect(true);
           dataView.setEmptyText("No Folders/Files to display.");     
          
           contentPanel.add(dataView);    
                    
           dataView.addListener(new DataViewListenerAdapter() {

               /**
                * This method is called when a selection is made changing the previous
                * selection
                * @params view the view that this selection is for
                * @params selections a list of all selected items.  There should only be
                * one as we only allow 1 selection.
                */
               
        	   public void onSelectionChange(DataView component,
                                             Element[] selections) {            	  
               }               
                
               public void onClick(DataView source, int index, Element node, EventObject e) 
               {            	   
            	   try
            	   {
	            	   Record[] records = dataView.getSelectedRecords(); 
	            	   String fileTitle = records[0].getAsString("name");            	          	   
	            	   String location = records[0].getAsString("url"); 
	            	   String type = records[0].getAsString("type"); 
	            	   	
	            	   if( type != null && type.equalsIgnoreCase("folder"))
	            	   {  		   
	            		   onExpandTreeNode( (TreeNode)treeNodeMap.get( fileTitle ) );
	            	   }
	            	   else if( type != null && ( type.equalsIgnoreCase("xbp") || type.equalsIgnoreCase("xml") ))
	            	   {	            		   
	            	   }
	            	   else 
	            	   {
	            		   com.google.gwt.user.client.Window.open( location, "", "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes" );	  
	            	   }
	               }
            	   catch(RequestException re)
            	   {
            		   MessageBox.alert(re.getLocalizedMessage());
            	   }
		        } 
           });
           contentPanel.doLayout();
                   
		  return contentPanel;
	   }
	   
	}
}

Reply via email to