I am trying to write Celltree with below requirement.
1) Populate tree based user definded class/datastructure. 
2) User will able to edit leaf node. While editing he will get list of 
available values(SuggestBox). Leaf lavel is composite cell having images 
and InputTextCell.
3) User will click save button. It will create class object again created 
with updated data from tree. 

I am able to implement first 2 steps. but I am not able to get the updated 
data from tree. I created data provider structure similar to class. When I 
click save I get old values only.
Kindly suggest the changes which I need to do. Please find the aatched code.


-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
package com.smg.gwt.selection.client;



/*
 * Copyright 2010 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.AbstractInputCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.CompositeCell;
import com.google.gwt.cell.client.EditTextCell;
import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.cell.client.HasCell;
import com.google.gwt.cell.client.IconCellDecorator;
import com.google.gwt.cell.client.ImageCell;
import com.google.gwt.cell.client.TextButtonCell;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.cell.client.TextInputCell;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.BrowserEvents;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.InputElement;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.TableCellElement;
import com.google.gwt.dom.client.TableElement;
import com.google.gwt.dom.client.TableRowElement;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.safecss.shared.SafeStyles;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.CellTree;
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
import com.google.gwt.user.cellview.client.TreeNode;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.SuggestOracle;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.gwt.view.client.DefaultSelectionEventManager;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.ProvidesKey;
import com.google.gwt.view.client.SelectionModel;
import com.google.gwt.view.client.SingleSelectionModel;
import com.google.gwt.view.client.TreeViewModel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;

import com.smg.gwt.selection.shared.GeoMCIBodyDetails;
import com.smg.gwt.selection.shared.GeometricItemDetails;
import com.smg.gwt.selection.shared.MCIBodyDetails;
import com.smg.gwt.selection.shared.NGDDetails;
import com.smg.gwt.selection.shared.NoteSurfDetails;

 
  /**
   * The model that defines the nodes in the tree.
   */
  public class NoteSurfTreeControl implements TreeViewModel {
    /**
     * This selection model is shared across all leaf nodes. A selection model
     * can also be shared across all nodes in the tree, or each set of child
     * nodes can have its own instance. This gives you flexibility to determine
     * how nodes are selected.
     */
	  
	  /**
	   * The images used for this example.
	   */
	  static interface Images1 extends ClientBundle {
	    ImageResource editTreeItem();
	    ImageResource noimage();
	    ImageResource releaseFlag();
	    ImageResource treeItem();
	    ImageResource treeRoot();
	    ImageResource treeSubItem();
	    ImageResource v4litemblue();
	    ImageResource v4litemrevisionblue(); 
	    ImageResource mcibody();
	    ImageResource warningicon();
	    ImageResource search();
	  }
	  
	  /**
	     * The HTML templates used to render the cell.
	     */
	    interface Templates extends SafeHtmlTemplates {
	      /**
	       * The template for this Cell, which includes styles and a value.
	       * 
	       * @param styles the styles to include in the style attribute of the div
	       * @param value the safe value. Since the value type is {@link SafeHtml},
	       *          it will not be escaped before including it in the template.
	       *          Alternatively, you could make the value type String, in which
	       *          case the value would be escaped.
	       * @return a {@link SafeHtml} instance
	       */
	      @SafeHtmlTemplates.Template("<div style=\"{0}\">{1}</div>")
	      SafeHtml cell(SafeStyles styles, SafeHtml value);
	    }
	    
	  
	private static Images1 images1;
	private final Cell<MCIBodyDetails> GeometricDetailsCell;
	//private final NGDDetails ngddetails;
    private final SingleSelectionModel<MCIBodyDetails> selectionModel;
    ListDataProvider<GeoMCIBodyDetails> geoProvider;
    static int dummy = 0;
    
    
    
    //////////////////////////////////////////////////////
    public class SuggestBoxTextInputCell extends TextInputCell  { 
    	  
    	 MySuggestBox suggestBox; 
    	  
    	 private class MyTextBox extends TextBox { 
    	  public MyTextBox(Element element) { 
    	   super(element); 
    	  } 
    	 } 
    	  
    	 private class MySuggestBox extends SuggestBox { 
    	  public MySuggestBox(SuggestOracle suggestOracle, TextBox textBox) { 
    	   super(suggestOracle, textBox); 
    	  } 
    	  
    	  @Override
    	  public void onAttach() { 
    	   super.onAttach(); 
    	  } 
    	 } 
    	  
    	 public SuggestBoxTextInputCell() { 
    	  super(); 
    	 } 
    	  
    	  
    	 @Override
    	 public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, 
    	   ValueUpdater<String> valueUpdater) {       		 
    	  super.onBrowserEvent(context, parent, value, event, valueUpdater); 
    	  String eventType = event.getType(); 
    	  if (BrowserEvents.FOCUS.equals(eventType)) {
    	   TextBox textBox = new MyTextBox(getInputElement(parent));
    	   parent.getParentElement().focus();
    	   suggestBox = new MySuggestBox(getSuggestOracle(), textBox); 
    	   suggestBox.onAttach();    	
    	  } 
    	 } 
    	 
    	 private SuggestOracle getSuggestOracle() { 
    	        //this does not work without implementation 
    		 MultiWordSuggestOracle oracle = new MultiWordSuggestOracle("-");  
    		    oracle.add("APPLE");
    		    oracle.add("ANT-BOTTLE");
    		    oracle.add("A123-BCough");
    		    oracle.add("ABat-CD45tree");
    		    oracle.add("leathermaterial");
    		    oracle.add("Bold-C2plastic");
    		    oracle.add("B23Charcoal-Doorblack");
    		    oracle.add("12493453-AluminumCover");
    		    oracle.add("34423234-blackleather");
    		    oracle.add("76456433-graydashboard");
    		    oracle.add("87878788-cottonseats");
    		    oracle.add("09809098-glasslamps");
    		    oracle.add("45645645-steelseatbelts");
    		    oracle.add("23423423-blackwheels");
    		    oracle.add("22342342-whitecolorseats");
    		    oracle.add("23423423-reddashboard");
    	        return oracle; 
    	 } 
    	}
    
    /////////////////////////////////////////////////////
    
        
    /**
     * A Cell used to render the LetterCount.
     */
    private static class GeometricItemDetailsCell extends AbstractCell<GeoMCIBodyDetails> {

      @Override
      public void render(Context context, GeoMCIBodyDetails value, SafeHtmlBuilder sb) {
        if (value != null) {
        	sb.append(AbstractImagePrototype.create(images1.v4litemrevisionblue()).getSafeHtml());      	
                  
        	sb.appendEscaped(" " + value.geometricChildId + " -" + value.geometricChildName + "/"+ value.geometricChildRev +" ");
          if(value.getReleaseStatus())
        	  sb.append(AbstractImagePrototype.create(images1.releaseFlag()).getSafeHtml());       
        }
      }
    }
    
 
    public NoteSurfTreeControl( ListDataProvider<GeoMCIBodyDetails> geoListProvider, boolean isEditable) {
    	this.selectionModel = new SingleSelectionModel<MCIBodyDetails>();
        
        if (images1 == null) {
        	images1 = GWT.create(Images1.class);
        }
        //this.ngddetails = null;
        this.geoProvider=geoListProvider;
        
        List<HasCell<MCIBodyDetails, ?>> hasCells = new ArrayList<HasCell<MCIBodyDetails, ?>>();
        
        hasCells.add(new HasCell<MCIBodyDetails, String>() {

            //private EditTextCell cell = new EditTextCell();
            private IconCellDecorator<String> cell = new IconCellDecorator<String>(images1.warningicon(),new TextCell());

            public Cell<String> getCell() {
              return cell;
            }

            public FieldUpdater<MCIBodyDetails, String> getFieldUpdater() {
              return null;
            }

            public String getValue(MCIBodyDetails object) {
              return "";
            }
          });
        if(isEditable)
        {

	        hasCells.add(new HasCell<MCIBodyDetails, String>() {
	
	        	private IconCellDecorator<String> cell = new IconCellDecorator<String>(images1.v4litemblue(),new SuggestBoxTextInputCell());
	        	//private IconCellDecorator<String> cell = new IconCellDecorator<String>(images1.v4litemblue(),new EditTextCell());
	
	            public Cell<String> getCell() {
	              return cell;
	            }
	
	            public FieldUpdater<MCIBodyDetails, String> getFieldUpdater() {
	            	//SelectionControl.rootLogger.log(Level.INFO, "1 new value:");
	              return null;
	            }
	
	            public String getValue(MCIBodyDetails object) {
	              return object.mciBody;
	            }
	          });
	       
        }
        else
        {    
        	
        	 hasCells.add(new HasCell<MCIBodyDetails, String>() {
        			
 	            //private EditTextCell cell = new EditTextCell();
 	            private IconCellDecorator<String> cell = new IconCellDecorator<String>(images1.v4litemblue(),new TextCell());
 	
 	            public Cell<String> getCell() {
 	              return cell;
 	            }
 	
 	            public FieldUpdater<MCIBodyDetails, String> getFieldUpdater() {
 	              return null;
 	            }
 	
 	            public String getValue(MCIBodyDetails object) {
 	              return object.mciBody;
 	            }
 	          }); 	 
        	 
        }        
        
                
        GeometricDetailsCell = new CompositeCell<MCIBodyDetails>(hasCells) {
            @Override
            public void render(Context context, MCIBodyDetails value, SafeHtmlBuilder sb) {
              sb.appendHtmlConstant("<table><tbody><tr>");
              super.render(context, value, sb);             
              sb.appendHtmlConstant("</tr></tbody></table>");
            }

            @Override
            protected Element getContainerElement(Element parent) {
              // Return the first TR element in the table.
              return parent.getFirstChildElement().getFirstChildElement().getFirstChildElement();
            }

            @Override
            protected <X> void render(Context context, MCIBodyDetails value,
                SafeHtmlBuilder sb, HasCell<MCIBodyDetails, X> hasCell) {
              Cell<X> cell = hasCell.getCell();
              sb.appendHtmlConstant("<td>");
              cell.render(context, hasCell.getValue(value), sb);              
              sb.appendHtmlConstant("</td>");
            }
            
            /*
            @Override
        	  public Set<String> getConsumedEvents() {
        	      Set<String> consumedEvents = new HashSet<String>();
        	      consumedEvents.add("CLICK");
        	      return consumedEvents;
        	  }
            
            @Override
            public void onBrowserEvent(Cell.Context context, Element parent, MCIBodyDetails value, NativeEvent event, ValueUpdater<MCIBodyDetails> valueUpdater)
            {
            	switch (DOM.eventGetType((Event)event)) {
    	          case Event.ONCLICK:
    	              // TODO
    	        	  Window.alert("Action Button Image");
    	        	  parent.focus();
    	              break;

    	          default:
    	              break;
    	          }            	
            }
            */
            

          };
        
    }
 // Create a value updater that will be called when the value in a cell changes.
    ValueUpdater<MCIBodyDetails> valueUpdater = new ValueUpdater<MCIBodyDetails>() {
      public void update(MCIBodyDetails newValue) {
        Window.alert("You typed: " + newValue.mciBody);
        SelectionControl.rootLogger.log(Level.INFO, "1 new value:" +newValue.mciBody);
      }
    };
        
        /**
     * Get the {@link NodeInfo} that provides the children of the specified
     * value.
     */
    public <T> NodeInfo<?> getNodeInfo(T value) {
      if (value == null) {
    	  return new DefaultNodeInfo<GeoMCIBodyDetails>(geoProvider, new GeometricItemDetailsCell());    	  
      }
      else if (value instanceof GeoMCIBodyDetails)
      {    	  
    	  return new DefaultNodeInfo<MCIBodyDetails>(((GeoMCIBodyDetails) value).getMciBodyProvider(),  GeometricDetailsCell, selectionModel, valueUpdater);
 
      }

      return null;
    }
    /**
     * Check if the specified value represents a leaf node. Leaf nodes cannot be
     * opened.
     */
      @Override
    public boolean isLeaf(Object value) {
      // The leaf nodes are the songs, which are Strings.
      if (value instanceof MCIBodyDetails) {
        return true;
      }
      return false;

    }
  }


Reply via email to