Inheritence and Design View

GWT Designer allows you to quickly create the modules, composites, panels, remote services and other elements that comprise Google Web Tookit applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Inheritence and Design View

Postby allioop70 » Fri Mar 09, 2007 8:56 am

I have an abstract base class that extends Composite. I then have created a number of classes that extend the base class.

I see an intermittent problem where sometimes my extended class can be edited from the WYSIWYG Design tab and something they cant and the editor tells me that the window type is not recognizable.

Any ideas?
allioop70
 
Posts: 13
Joined: Mon Jan 29, 2007 2:57 pm
Location: Colorado

Re: Inheritence and Design View

Postby Eric Clayberg » Fri Mar 09, 2007 10:46 am

allioop70 wrote:I have an abstract base class that extends Composite. I then have created a number of classes that extend the base class. I see an intermittent problem where sometimes my extended class can be edited from the WYSIWYG Design tab and something they cant and the editor tells me that the window type is not recognizable.

Send us a test case and your complete Eclipse ".log" file.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Inheritence and Design View

Postby allioop70 » Thu Mar 29, 2007 1:01 pm

So I finally had a little time to look at the log and play with this and this is what I found.

I have a class called BaseWidget which extends Composite and sets a private variable to my service, then has a public method which uses the service.

class BaseWidget extends Composite
{
private final UserServiceAsync myService = UserService.Util.getInstance();

public boolean isUserLoggedIn()
{
<This method uses the service>
}
}

Then I have a class called BasePanel which extends BaseWidget. This class just has additional methods just for my panels.

class BasePanel extends BaseWidget
{}

Here is a panel signature:

class LoginPanel extends BasePanel
{
}

This setup is crashing Designer when I try to view a panel in design view.

If I extend BasePanel from Composite, the problem goes away. Is there something in GWT or Designer that doesn't support this inheriting this way?

There are two errors in the stack trace, the full package name has been removed.

!ENTRY com.swtdesigner 4 4 2007-03-29 14:34:45.027
!MESSAGE Designer internal error [6.2.0.20070306143804]: com.swtdesigner.properties.PropertyException: java.lang.NoSuchMethodException: web.client.services.UserService.<init>()
!STACK 0
org.apache.commons.lang.exception.NestableError: com.swtdesigner.properties.PropertyException: java.lang.NoSuchMethodException: web.client.services.UserService.<init>()
at com.swtdesigner.model.swing.properties.custom.DesignTimeHelper.execute(DesignTimeHelper.java:56)
at com.swtdesigner.model.JavaInfo.notifyPropertyChanged(JavaInfo.java:5566)
at com.swtdesigner.model.JavaInfo.notifyPropertyChanged(JavaInfo.java:5548)
at com.swtdesigner.gef.common.property.DesignerEditorPropertyComposite.handleRootNodeSelected(DesignerEditorPropertyComposite.java:588)
at com.swtdesigner.gef.common.property.DesignerEditorPropertyComposite.updatePropertyComposite(DesignerEditorPropertyComposite.java:789)
at com.swtdesigner.gef.DesignerEditor.parseCompilationUnit(DesignerEditor.java:1128)
at com.swtdesigner.gef.DesignerEditor$17.execute(DesignerEditor.java:1040)
at com.swtdesigner.model.swing.properties.custom.DesignTimeHelper.execute(DesignTimeHelper.java:54)
at com.swtdesigner.gef.DesignerEditor.handleActivate(DesignerEditor.java:1034)
at com.swtdesigner.gef.DesignerEditor.handleActivate(DesignerEditor.java:1028)
at com.swtdesigner.editors.MultiPageEditor.showDesignEditor(MultiPageEditor.java:413)
at com.swtdesigner.editors.MultiPageEditor$2.widgetSelected(MultiPageEditor.java:183)


!ENTRY com.swtdesigner 4 4 2007-03-29 14:34:46.481
!MESSAGE Designer internal error [6.2.0.20070306143804]: web.client.services.UserService.<init>()
!STACK 0
java.lang.NoSuchMethodException: web.client.services.UserService.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getDeclaredConstructor(Unknown Source)
at com.google.gwt.core.client.GWT.create(Unknown Source)
at web.client.services.UserService$Util.getInstance(UserService.java:95)
at web.client.panels.BaseWidget.<init>(BaseWidget.java:39)
at web.client.panels.BasePanel.<init>(BasePanel.java:26)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at com.swtdesigner.gwt.model.widgets.UIObjectInfo.createWidgetInstance(UIObjectInfo.java:242)
at com.swtdesigner.gwt.model.widgets.UIObjectInfo.createBeanInstance(UIObjectInfo.java:88)
at com.swtdesigner.gwt.model.widgets.WidgetInfo.createBeanInstance(WidgetInfo.java:138)
at com.swtdesigner.model.swing.JavaBeanInfo.ensureBeanInstance(JavaBeanInfo.java:1134)
at com.swtdesigner.model.swing.JavaBeanInfo.getChildAccessedBy(JavaBeanInfo.java:596)
at com.swtdesigner.gwt.model.widgets.UIObjectInfo.getChildAccessedBy(UIObjectInfo.java:186)
at com.swtdesigner.model.swing.JavaBeanInfo.getChildAccessedBy(JavaBeanInfo.java:678)
at com.swtdesigner.model.swing.JavaBeanInfo.createPropertyFromPropertyDescriptor(JavaBeanInfo.java:1865)
at com.swtdesigner.model.swing.JavaBeanInfo.getProperty(JavaBeanInfo.java:1816)
at com.swtdesigner.model.swing.JavaBeanInfo.addPropertiesFromPropertyDescriptors(JavaBeanInfo.java:1776)
at com.swtdesigner.model.swing.JavaBeanInfo.getPropertyList(JavaBeanInfo.java:1732)
at com.swtdesigner.gwt.model.widgets.UIObjectInfo.getPropertyList(UIObjectInfo.java:161)
at com.swtdesigner.gwt.model.widgets.WidgetInfo.getPropertyList(WidgetInfo.java:123)
at com.swtdesigner.model.JavaInfo.getProperties(JavaInfo.java:968)
at com.swtdesigner.gef.actions.nls.NLSSupport.prepareSources(NLSSupport.java:93)
at com.swtdesigner.gef.actions.nls.NLSSupport.<init>(NLSSupport.java:77)
at com.swtdesigner.gef.actions.nls.NLSSupport.get(NLSSupport.java:36)
at com.swtdesigner.gef.actions.nls.ExternalizeStringsContributionItem.updateLocalesList(ExternalizeStringsContributionItem.java:139)
at com.swtdesigner.gef.actions.nls.ExternalizeStringsContributionItem.createLocalesCombo(ExternalizeStringsContributionItem.java:101)
at com.swtdesigner.gef.actions.nls.ExternalizeStringsContributionItem.fill(ExternalizeStringsContributionItem.java:39)
at com.swtdesigner.gef.DesignerEditor.addExternalizeStringsItem(DesignerEditor.java:1637)
at com.swtdesigner.gef.DesignerEditor.updatePalette(DesignerEditor.java:1573)
at com.swtdesigner.gef.DesignerEditor.updateSelectionActions(DesignerEditor.java:1670)
at com.swtdesigner.gef.DesignerEditor$17.execute(DesignerEditor.java:1044)
at com.swtdesigner.model.swing.properties.custom.DesignTimeHelper.execute(DesignTimeHelper.java:54)
at com.swtdesigner.gef.DesignerEditor.handleActivate(DesignerEditor.java:1034)
at com.swtdesigner.gef.DesignerEditor.handleActivate(DesignerEditor.java:1028)
at com.swtdesigner.editors.MultiPageEditor.showDesignEditor(MultiPageEditor.java:413)
at com.swtdesigner.editors.MultiPageEditor$2.widgetSelected(MultiPageEditor.java:183)
allioop70
 
Posts: 13
Joined: Mon Jan 29, 2007 2:57 pm
Location: Colorado

Re: Inheritence and Design View

Postby Eric Clayberg » Thu Mar 29, 2007 2:27 pm

If you look at the log, you can see that the exception is in the code for the UserService class rather than in Designer code...

Code: Select all
java.lang.NoSuchMethodException: web.client.services.UserService.<init>()
   at java.lang.Class.getConstructor0(Unknown Source)
   at java.lang.Class.getDeclaredConstructor(Unknown Source)
   at com.google.gwt.core.client.GWT.create(Unknown Source)
   at web.client.services.UserService$Util.getInstance(UserService.java:95)
   at web.client.panels.BaseWidget.<init>(BaseWidget.java:39)
   at web.client.panels.BasePanel.<init>(BasePanel.java:26)

RemoteServices are a runtime-only construct that can't be used at design time. See the earlier discussion on this topic here.

You will need to isolate any code using a RemoteService with an isDesignTime() check. Here's an example of how to use it...

Code: Select all
public class MyComposite extends Composite {
        public MyComposite() {
                final AbsolutePanel absolutePanel = new AbsolutePanel();
                initWidget(absolutePanel);
                //
                final Button button = new Button();
                absolutePanel.add(button, 30, 34);
                button.setText("New Button");
                //
                if (!isDesignTime()) {
                        final CheckBox checkBox = new CheckBox();
                        absolutePanel.add(checkBox, 54, 99);
                        checkBox.setText("New CheckBox");
                }
        }
        // Implement the following method exactly as-is
        private static final boolean isDesignTime() {
                return false;
        }
}
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Inheritence and Design View

Postby allioop70 » Fri Mar 30, 2007 7:24 am

Eric Clayberg wrote:You will need to isolate any code using a RemoteService with an isDesignTime() check. Here's an example of how to use it...


Why is this necessary only when inheriting a service and not when a service is instantiated and used directly in a widget itself? What's the difference?

Using the example I presented earlier. If the LoginPanel, or any of our panels for that matter, instantiate a service themselves, we do not see this problem.

Code: Select all
class LoginPanel extends BasePanel
{
  CommonServiceAsync commonService =
    CommonService.Util.getInstance();

<Use common service code here>
}


Designer will only fail on the inherited service. Using the example I used previously. If I extend BasePanel from Composite, thereby removing the inherited service from the BaseWidget, I have no errors and no problems using Designer, no matter now many services I use in the same widget.
allioop70
 
Posts: 13
Joined: Mon Jan 29, 2007 2:57 pm
Location: Colorado

Re: Inheritence and Design View

Postby Eric Clayberg » Fri Mar 30, 2007 8:52 am

It's necessary for any class that is instantiated at design time. That inclues Composites used in a panel or superclasses of a panel.

It isn't an issue for the class being edited as that class is not instantiated. It is parsed and the parser can ignore the service classes.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Inheritence and Design View

Postby allioop70 » Fri Mar 30, 2007 12:12 pm

Eric Clayberg wrote:It's necessary for any class that is instantiated at design time. That inclues Composites used in a panel or superclasses of a panel.

It isn't an issue for the class being edited as that class is not instantiated. It is parsed and the parser can ignore the service classes.


Okay, so I've rewritten my BaseWidget as follows and it still fails with the same message:

Code: Select all
BaseWidget extends Composite
{
  UserServiceAsync userService = null;

  BaseWidget()
  {
    if (!isDesignTime())
    {
      userService = UserService.Util.getInstance();
    }
  }

  doSomeStuff()
  {
    if (!isDesignTime())
    {
      userService.stuff();
    }
  }
}


Any other ideas?
allioop70
 
Posts: 13
Joined: Mon Jan 29, 2007 2:57 pm
Location: Colorado

Re: Inheritence and Design View

Postby Eric Clayberg » Fri Mar 30, 2007 2:15 pm

Where is the isDesignTime() method?
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to GWT Designer

Who is online

Users browsing this forum: No registered users and 3 guests