Announcement

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

    Canvas.addChild() won't except Label (TypeError)

    Hello Isomorphic and whoever might be able to help me,
    I'm using GWT 2.7 and SmartGWT (build from 24/08/16).
    I'm trying to create the showcase "Snap-to-grid drag and drop" from your showcases on my computer, but it just won't work. I've copy-pasted the code into the hello-world example in the LGPL download of SmartGWT.
    My helloworld.java looks like this:

    Code:
    package com.mycompany.client;
    
    import com.smartgwt.client.types.Alignment;  
    import com.smartgwt.client.types.DragAppearance;  
    import com.smartgwt.client.types.Overflow;  
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.Label;
    import com.smartgwt.client.widgets.form.DynamicForm;  
    import com.smartgwt.client.widgets.form.fields.CheckboxItem;  
    import com.smartgwt.client.widgets.form.fields.RadioGroupItem;  
    import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;  
    import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;  
    import com.smartgwt.client.widgets.layout.VLayout;  
     
    import java.util.LinkedHashMap;
    
    import com.google.gwt.core.client.EntryPoint;
    
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class HelloWorld implements EntryPoint {
        
        /**
         * This is the entry point method.
         */
        public void onModuleLoad() {
            final Canvas gridCanvas = new Canvas();  
            gridCanvas.setBorder("1px solid blue");  
            gridCanvas.setWidth(400);  
            gridCanvas.setHeight(300);  
            gridCanvas.setChildrenSnapResizeToGrid(true);  
            gridCanvas.setChildrenSnapToGrid(true);  
            gridCanvas.setOverflow(Overflow.HIDDEN);  
            gridCanvas.setShowSnapGrid(true);  
        
            Label label = new Label();  
            label.setWidth(80);  
            label.setHeight(40);  
            label.setAlign(Alignment.CENTER);  
            label.setContents("Drag or Resize me");  
            label.setBackgroundColor("white");  
            label.setShowEdges(true);  
            label.setCanDragReposition(true);  
            label.setCanDragResize(true);  
            label.setDragAppearance(DragAppearance.TARGET);  
            label.setKeepInParentRect(true);  
              
            gridCanvas.addChild(label);  
              
            DynamicForm gridForm = new DynamicForm();  
            gridForm.setWidth(400);  
            gridForm.setNumCols(4);  
              
            CheckboxItem snapDrag = new CheckboxItem();  
            snapDrag.setValue(true);  
            snapDrag.setTitle("Enable Snap-To-Grid Move");  
            snapDrag.addChangedHandler(new ChangedHandler() {  
      
                @Override  
                public void onChanged(ChangedEvent event) {  
                    gridCanvas.setProperty("childrenSnapToGrid", !gridCanvas.getChildrenSnapToGrid());  
                }  
                  
            });  
            CheckboxItem snapResize = new CheckboxItem();  
            snapResize.setValue(true);  
            snapResize.setTitle("Enable Snap To Grid Resize");  
            snapResize.addChangedHandler(new ChangedHandler() {  
      
                @Override  
                public void onChanged(ChangedEvent event) {  
                    gridCanvas.setProperty("childrenSnapResizeToGrid", !gridCanvas.getChildrenSnapResizeToGrid());  
                }  
                  
            });  
      
            RadioGroupItem radioGroupHGap = new RadioGroupItem();  
            radioGroupHGap.setTitle("Horizontal snap-to gap");  
            LinkedHashMap<Integer,String> hGapMap = new LinkedHashMap<Integer,String>();  
            hGapMap.put(10, "10 pixels");  
            hGapMap.put(20, "20 pixels");  
            hGapMap.put(50, "50 pixels");  
            radioGroupHGap.setValueMap(hGapMap);  
            radioGroupHGap.setDefaultValue(20);  
            radioGroupHGap.addChangedHandler(new ChangedHandler() {  
      
                @Override  
                public void onChanged(ChangedEvent event) {  
                    gridCanvas.setProperty("snapHGap", Integer.parseInt(String.valueOf(event.getValue())));  
                }  
                  
            });  
            RadioGroupItem radioGroupVGap = new RadioGroupItem();  
            radioGroupVGap.setTitle("Vertical snap-to gap");  
            LinkedHashMap<Integer,String> vGapMap = new LinkedHashMap<Integer,String>();  
            vGapMap.put(10, "10 pixels");  
            vGapMap.put(20, "20 pixels");  
            vGapMap.put(50, "50 pixels");  
            radioGroupVGap.setValueMap(vGapMap);  
            radioGroupVGap.setDefaultValue(20);  
            radioGroupVGap.addChangedHandler(new ChangedHandler() {  
      
                @Override  
                public void onChanged(ChangedEvent event) {  
                    gridCanvas.setProperty("snapVGap", Integer.parseInt(String.valueOf(event.getValue())));  
                }  
                  
            });  
            gridForm.setFields(snapDrag,snapResize,radioGroupHGap,radioGroupVGap);  
              
            VLayout vl = new VLayout();  
            vl.setMembersMargin(10);  
            vl.addMember(gridCanvas);  
            vl.addMember(gridForm);  
      
            vl.draw();  
        }  
    
    }
    and throws this error:
    http://prntscr.com/ca94ti

    I've already commented the gridCanvas.addChild(label) and vl.addMember(gridCanvas). It works fine with that, well, at least it shows the radiobuttons and so on.
    However, the whole Canvas will not work and I really don't know why.
    All the tests were run after a GWT Compile. Also tried with java compliance 1.7 and jre7 instead of jre8_101 and 1.8. The error occurs in Firefox 24 and in Internet Explorer in ClassicDevMode, SuperDevMode and normal web application. I've also tried to run it on two different computers, windows 10 and windows 7.

    What can I do to fix the errors? Why won't it work?

    I'm thankful for any help!

    Kind regards,


    Chris

    //Edit:

    Of course I meant "accept" in the title. Sorry for that
    Last edited by Chrisz0rian; 25 Aug 2016, 05:35.

    #2
    See the FAQ: for any JavaScript error, you want to look in the SmartGWT Developer Console for warnings and for a stack trace of the error. This is usually best done in compiled mode or at least SuperDevMode.

    If you find a stack trace and it doesn't lead you to a solution, post it here.

    Comment


      #3
      Thank you for your advice! I managed to print the entire stacktrace and fix my problem.
      Apparently, the drawing module from GWT is not loading automatically and you have to add it to the base xml file.
      The following post was helpful to me: http://forums.smartclient.com/forum/...ne-in-sgwt-3-0

      Long story short:
      I added
      Code:
       <inherits name="com.smartgwt.Drawing"/>
      right after (!!)
      Code:
      <inherits name="com.smartgwt.SmartGwt"/>

      Comment

      Working...
      X