Codegeneration

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

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

Codegeneration

Postby doc » Tue Jul 07, 2009 1:58 am

I activated the switch "statement generation" -> "lazy" in the options of the swing builder plugin.
Therefore I get a separate private getXXX() statement for each component.
After definition of bindings the related getXXX() statement is filled up with a initDataBindings() call at the end.
Next the reparsing of the class fails. Manual removal of the call leads to successful reparsing of the source.

The initDataBindings() method should be called once in my init method and should not automatically generated in each getXXX() method.

best regards
doc
 
Posts: 14
Joined: Thu Jun 25, 2009 1:52 am

Re: Codegeneration

Postby Eric Clayberg » Tue Jul 07, 2009 6:51 pm

Please give this a try using the very latest Swing Designer v7.1 build.
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: Codegeneration

Postby doc » Wed Jul 08, 2009 1:54 am

The same effect...
The reparsing after definition of binding causes the following exception (taken from logfile):

Code: Select all
!ENTRY com.instantiations.designer.core 4 4 2009-07-08 11:30:59.028
!MESSAGE Designer [7.1.0.200907072354]: 0 (Wrapper).
!STACK 0
com.instantiations.designer.core.utils.exception.DesignerException: 0 (Wrapper).
   at com.instantiations.designer.core.model.JavaInfo$9.postVisit(JavaInfo.java:1202)
   at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
   at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2548)
   at org.eclipse.jdt.core.dom.MethodInvocation.accept0(MethodInvocation.java:245)
   at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2478)
   at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2525)
   at org.eclipse.jdt.core.dom.ExpressionStatement.accept0(ExpressionStatement.java:144)
   at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2478)
   at com.instantiations.designer.core.eval.ExecutionFlowUtils.visitStatement0(ExecutionFlowUtils.java:330)
   at com.instantiations.designer.core.eval.ExecutionFlowUtils.visitStatement(ExecutionFlowUtils.java:244)
   at com.instantiations.designer.core.eval.ExecutionFlowUtils.visitStatement0(ExecutionFlowUtils.java:263)
   at com.instantiations.designer.core.eval.ExecutionFlowUtils.visitStatement(ExecutionFlowUtils.java:244)
   at com.instantiations.designer.core.eval.ExecutionFlowUtils.visit(ExecutionFlowUtils.java:199)
   at com.instantiations.designer.core.eval.ExecutionFlowUtils.visit(ExecutionFlowUtils.java:162)
   at com.instantiations.designer.core.model.JavaInfo.refresh_create(JavaInfo.java:1240)
   at com.instantiations.designer.core.model.ObjectInfo.refreshCreate0(ObjectInfo.java:420)
   at com.instantiations.designer.core.model.ObjectInfo.access$000(ObjectInfo.java:24)
   at com.instantiations.designer.core.model.ObjectInfo$4.run(ObjectInfo.java:390)
   at com.instantiations.designer.core.utils.execution.ExecutionUtils.runDesignTime(ExecutionUtils.java:87)
   at com.instantiations.designer.core.model.ObjectInfo.refresh(ObjectInfo.java:388)
   at com.instantiations.designer.core.model.ObjectInfo.endEdit(ObjectInfo.java:355)
   at com.instantiations.designer.core.utils.execution.ExecutionUtils.run(ExecutionUtils.java:241)
   at com.instantiations.designer.core.model.util.ObjectInfoAction$1.run(ObjectInfoAction.java:66)
   at com.instantiations.designer.core.utils.execution.ExecutionUtils.runLog(ExecutionUtils.java:52)
   at com.instantiations.designer.core.model.util.ObjectInfoAction.run(ObjectInfoAction.java:63)
   at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
   at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:583)
   at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:500)
   at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
   at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
   at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
   at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
   at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
   at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2384)
   at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2348)
   at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2200)
   at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:495)
   at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
   at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:490)
   at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
   at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
   at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
   at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
   at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
   at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
   at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
   at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
   at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
Caused by: com.instantiations.designer.core.utils.exception.DesignerException: 0 (Wrapper).
   at com.instantiations.designer.core.model.JavaInfoEvaluationHelper.evaluate(JavaInfoEvaluationHelper.java:484)
   at com.instantiations.designer.core.model.JavaInfo$9.postVisit(JavaInfo.java:1194)
   ... 52 more
Caused by: org.apache.commons.lang.exception.NestableError: getScrollPaneTest()
   at com.instantiations.designer.core.eval.ASTEvaluationEngine.evaluate(ASTEvaluationEngine.java:52)
   at com.instantiations.designer.core.model.JavaInfoEvaluationHelper.evaluateExpression(JavaInfoEvaluationHelper.java:538)
   at com.instantiations.designer.core.model.JavaInfoEvaluationHelper.evaluate(JavaInfoEvaluationHelper.java:427)
   ... 53 more
Caused by: com.instantiations.designer.core.utils.exception.DesignerException: 306 (Local instance method invocation). getScrollPaneTest()
   at com.instantiations.designer.core.eval.evaluators.InvocationEvaluator.evaluateLocalMethodInvocation(InvocationEvaluator.java:145)
   at com.instantiations.designer.core.eval.evaluators.InvocationEvaluator.evaluate(InvocationEvaluator.java:110)
   at com.instantiations.designer.core.eval.evaluators.InvocationEvaluator.evaluate(InvocationEvaluator.java:67)
   at com.instantiations.designer.core.eval.ASTEvaluationEngine.evaluate0(ASTEvaluationEngine.java:96)
   at com.instantiations.designer.core.eval.ASTEvaluationEngine.evaluate(ASTEvaluationEngine.java:42)
   ... 55 more



Next notice on this behavior:
If I delete the generated message call to "initDataBindings()" from the method "getScrollPaneTest()" manually, the reparsing (switching from source to design view) causes no error but the design view is empty. No further log entries.
After closing and reopening of the java file the parsing is successful and the design view is filled correctly.
doc
 
Posts: 14
Joined: Thu Jun 25, 2009 1:52 am

Re: Codegeneration

Postby Eric Clayberg » Wed Jul 08, 2009 6:19 am

You do need to remove the extra calls to initDataBindings().

The fix only applies to newly generated code and should prevent the initDataBindings() calls from being put in the wrong place.

Are you still seeing the initDataBindings() regenerated in the wrong place when you edit the data bindings?
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: Codegeneration

Postby doc » Wed Jul 08, 2009 6:34 am

Yes, the case shown above was generated after removing all redundant initDataBindings() calls.
doc
 
Posts: 14
Joined: Thu Jun 25, 2009 1:52 am

Re: Codegeneration

Postby Eric Clayberg » Wed Jul 08, 2009 7:22 am

We are unable to reproduce the code generation issue using the latest build, so that exception is probably unrelated.

Please post a test case that we can use to reproduce the exception you are getting.
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: Codegeneration

Postby doc » Mon Aug 10, 2009 12:26 am

Hi,
after serveral trials to build a test case I got one:
Initial situation is to create a view for a list of Abc objects:


Code: Select all
public class Abc
{
  String something = new String("something");
 
  public Abc()
  {
  }
  public String getSomething()
  {
    return something;
  }
  public void setSomething(String something)
  {
    this.something = something;
  }
}


Simple view (based on simple JFrame):

Code: Select all
import java.awt.EventQueue;


public class Test extends JFrame
{
  private List<Abc> abc = new ArrayList<Abc>();
  private JPanel contentPane;
  private JTable table;
  private JScrollPane scrollPane;

  public void init()
  {
    initDataBindings();
  }
 
  /**
   * Launch the application.
   */
  public static void main(String[] args)
  {
    EventQueue.invokeLater(new Runnable()
    {
      public void run()
      {
        try
        {
          Test frame = new Test();
          frame.init();
          frame.setVisible(true);
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    });
  }

  /**
   * Create the frame.
   */
  public Test()
  {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 1000, 760);
    contentPane = new JPanel();
    contentPane.setLayout(new FormLayout(new ColumnSpec[] {
        FormFactory.RELATED_GAP_COLSPEC,
        ColumnSpec.decode("default:grow"),},
      new RowSpec[] {
        FormFactory.RELATED_GAP_ROWSPEC,
        RowSpec.decode("default:grow"),}));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.add(getScrollPane(), "2, 2, fill, fill");
  }
 
  protected BindingGroup initDataBindings()
  {
    BindingGroup bindingGroup = new BindingGroup();
    return bindingGroup;
  }

  private JTable getTable() {
    if (table == null) {
       table = new JTable();
    }
    return table;
  }
  private JScrollPane getScrollPane() {
    if (scrollPane == null) {
       scrollPane = new JScrollPane();
       scrollPane.setViewportView(getTable());
    }
    return scrollPane;
  }
}


In component view select the JTable -> right mouse click bindings -><Self Object>->abc-List (Self Object)->Column add->Abc(something)->finish

Code: Select all
Local instance method invocation
WindowBuilder can't invoke the local instance method getScrollPane().


Show stack trace.
Hide stack trace.

Stack trace:
com.instantiations.designer.core.utils.exception.DesignerException: 306 (Local instance method invocation). getScrollPane()
   at com.instantiations.designer.core.eval.evaluators.InvocationEvaluator.evaluateLocalMethodInvocation(InvocationEvaluator.java:140)
   at com.instantiations.designer.core.eval.evaluators.InvocationEvaluator.evaluate(InvocationEvaluator.java:105)
   at com.instantiations.designer.core.eval.evaluators.InvocationEvaluator.evaluate(InvocationEvaluator.java:62)
   at com.instantiations.designer.core.eval.ASTEvaluationEngine.evaluate0(ASTEvaluationEngine.java:99)
   at com.instantiations.designer.core.eval.ASTEvaluationEngine.evaluate(ASTEvaluationEngine.java:43)
   at com.instantiations.designer.core.model.JavaInfoEvaluationHelper.evaluateExpression(JavaInfoEvaluationHelper.java:553)
   at com.instantiations.designer.core.model.JavaInfoEvaluationHelper.evaluate(JavaInfoEvaluationHelper.java:428)
   at com.instantiations.designer.core.model.JavaInfo$9.postVisit(JavaInfo.java:1195)
   at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
   at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2548)
   at org.eclipse.jdt.core.dom.MethodInvocation.accept0(MethodInvocation.java:245)
   at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2478)
   at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2525)
   at org.eclipse.jdt.core.dom.ExpressionStatement.accept0(ExpressionStatement.java:144)
   at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2478)
   at com.instantiations.designer.core.eval.ExecutionFlowUtils.visitStatement0(ExecutionFlowUtils.java:330)
   at com.instantiations.designer.core.eval.ExecutionFlowUtils.visitStatement(ExecutionFlowUtils.java:244)
   at com.instantiations.designer.core.eval.ExecutionFlowUtils.visitStatement0(ExecutionFlowUtils.java:263)
   at com.instantiations.designer.core.eval.ExecutionFlowUtils.visitStatement(ExecutionFlowUtils.java:244)
   at com.instantiations.designer.core.eval.ExecutionFlowUtils.visit(ExecutionFlowUtils.java:199)
   at com.instantiations.designer.core.eval.ExecutionFlowUtils.visit(ExecutionFlowUtils.java:162)
   at com.instantiations.designer.core.model.JavaInfo.refresh_create(JavaInfo.java:1241)
   at com.instantiations.designer.core.model.ObjectInfo.refreshCreate0(ObjectInfo.java:420)
   at com.instantiations.designer.core.model.ObjectInfo.access$000(ObjectInfo.java:24)
   at com.instantiations.designer.core.model.ObjectInfo$4.run(ObjectInfo.java:390)


Generaded code:

Code: Select all
import java.awt.EventQueue;


public class Test extends JFrame
{
  private List<Abc> abc = new ArrayList<Abc>();
  private JPanel contentPane;
  private JTable table;
  private JScrollPane scrollPane;

  public void init()
  {
    initDataBindings();
  }
 
  /**
   * Launch the application.
   */
  public static void main(String[] args)
  {
    EventQueue.invokeLater(new Runnable()
    {
      public void run()
      {
        try
        {
          Test frame = new Test();
          frame.init();
          frame.setVisible(true);
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    });
  }

  /**
   * Create the frame.
   */
  public Test()
  {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 1000, 760);
    contentPane = new JPanel();
    contentPane.setLayout(new FormLayout(new ColumnSpec[] {
        FormFactory.RELATED_GAP_COLSPEC,
        ColumnSpec.decode("default:grow"),},
      new RowSpec[] {
        FormFactory.RELATED_GAP_ROWSPEC,
        RowSpec.decode("default:grow"),}));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.add(getScrollPane(), "2, 2, fill, fill");
  }

  private JTable getTable() {
    if (table == null) {
       table = new JTable();
    }
    return table;
  }
  private JScrollPane getScrollPane() {
    if (scrollPane == null) {
       scrollPane = new JScrollPane();
       scrollPane.setViewportView(getTable());
    }
    initDataBindings();
    return scrollPane;
  }
  protected BindingGroup initDataBindings() {
    JTableBinding<Abc, List<Abc>, JTable> jTableBinding = SwingBindings.createJTableBinding(UpdateStrategy.READ, abc, table);
    //
    BeanProperty<Abc, String> abcBeanProperty = BeanProperty.create("something");
    jTableBinding.addColumnBinding(abcBeanProperty).setColumnName("New Column");
    //
    jTableBinding.bind();
    //
    BindingGroup bindingGroup = new BindingGroup();
    //
    bindingGroup.addBinding(jTableBinding);
    return bindingGroup;
  }
}



Important is to use the lazy code generation.

Best regards

- doc
doc
 
Posts: 14
Joined: Thu Jun 25, 2009 1:52 am

Re: Codegeneration

Postby Eric Clayberg » Thu Aug 20, 2009 6:30 am

Please give this a try using the latest Swing Designer v7.1 build.
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: Codegeneration

Postby doc » Sun Aug 23, 2009 11:29 pm

No change concerning the occurring exception, sorry...

Generated code:
Code: Select all
package data;

import java.awt.EventQueue;


public class Test extends JFrame
{
  private List<Abc> abc = new ArrayList<Abc>();
  private JPanel contentPane;
  private JTable table;
  private JScrollPane scrollPane;

  public void init()
  {
    initDataBindings();
  }
 
  /**
   * Launch the application.
   */
  public static void main(String[] args)
  {
    EventQueue.invokeLater(new Runnable()
    {
      public void run()
      {
        try
        {
          Test frame = new Test();
          frame.init();
          frame.setVisible(true);
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    });
  }

  /**
   * Create the frame.
   */
  public Test()
  {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 1000, 760);
    contentPane = new JPanel();
    contentPane.setLayout(new FormLayout(new ColumnSpec[] {
        FormFactory.RELATED_GAP_COLSPEC,
        ColumnSpec.decode("default:grow"),},
      new RowSpec[] {
        FormFactory.RELATED_GAP_ROWSPEC,
        RowSpec.decode("default:grow"),}));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.add(getScrollPane(), "2, 2, fill, fill");
  }

  private JTable getTable() {
    if (table == null) {
       table = new JTable();
    }
    return table;
  }
  private JScrollPane getScrollPane() {
    if (scrollPane == null) {
       scrollPane = new JScrollPane();
       scrollPane.setViewportView(getTable());
    }
    initDataBindings();
    return scrollPane;
  }
  protected BindingGroup initDataBindings() {
    JTableBinding<Abc, List<Abc>, JTable> jTableBinding = SwingBindings.createJTableBinding(UpdateStrategy.READ, abc, getTable(), "Test");
    //
    BeanProperty<Abc, String> abcBeanProperty = BeanProperty.create("something");
    jTableBinding.addColumnBinding(abcBeanProperty).setColumnName("Test");
    //
    jTableBinding.bind();
    //
    BindingGroup bindingGroup = new BindingGroup();
    //
    bindingGroup.addBinding(jTableBinding);
    return bindingGroup;
  }
}
doc
 
Posts: 14
Joined: Thu Jun 25, 2009 1:52 am

Re: Codegeneration

Postby Eric Clayberg » Mon Aug 24, 2009 11:20 am

The exception is now fixed in the latest build.
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 Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest