Using custom component-factory

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

Using custom component-factory

Postby vidaj » Wed Apr 09, 2008 2:20 am

Hello

I'm using SwingDesigner with a component factory. The factory follows your specification, i.e. ComponentFactory.getInstance().createXXX();

The major problem I have is that SwingDesigner always throws an exception if my createXXX-method accepts other parameters than String, int and void. Example:

ComponentFactory.getInstance().createTextfield(); // This works perfectly.
ComponentFactory.getInstance().createTextfield(int columns); // This works perfectly.
ComponentFactory.getInstance().createTextfield(String string); // This works perfectly.
ComponentFactory.getInstance().createTextfield(ValueModel model); // This throws an exception

(ValueModel is an interface in the JGoodies Binding Framework. For the record: all methods have the same content: return new JTextField();)

The error-log is as follows:
java.lang.NullPointerException
at com.swtdesigner.model.swing.component.ComponentBeanInfo.applyProperties(ComponentBeanInfo.java:829)
at com.swtdesigner.model.swing.component.ComponentBeanInfo.createControl0(ComponentBeanInfo.java:775)
at com.swtdesigner.model.swing.component.ComponentBeanInfo.createControl(ComponentBeanInfo.java:708)
at com.swtdesigner.model.swing.component.ContainerBeanInfo.createSingleComponent(ContainerBeanInfo.java:835)
at com.swtdesigner.model.swing.component.ContainerBeanInfo.createControl(ContainerBeanInfo.java:658)
at com.swtdesigner.model.swing.component.ComponentBeanInfo.prepareControl(ComponentBeanInfo.java:615)
at com.swtdesigner.model.swing.component.ContainerBeanInfo.createControl(ContainerBeanInfo.java:674)
at com.swtdesigner.model.swing.component.ComponentBeanInfo.prepareControl(ComponentBeanInfo.java:615)
at com.swtdesigner.model.swing.component.ContainerBeanInfo.createControl(ContainerBeanInfo.java:674)
at com.swtdesigner.model.swing.component.ComponentBeanInfo.prepareControl(ComponentBeanInfo.java:615)
at com.swtdesigner.model.swing.component.ComponentBeanInfo.createGUIComponent(ComponentBeanInfo.java:601)
at com.swtdesigner.model.JavaInfo$18.execute(JavaInfo.java:5610)
at com.swtdesigner.model.swing.properties.custom.DesignTimeHelper.execute(DesignTimeHelper.java:54)
at com.swtdesigner.model.JavaInfo.notifyPropertyChanged(JavaInfo.java:5605)
at com.swtdesigner.model.JavaInfo.notifyPropertyChanged(JavaInfo.java:5586)
at com.swtdesigner.gef.common.property.DesignerEditorPropertyComposite.handleRootNodeSelected(DesignerEditorPropertyComposite.java:665)
at com.swtdesigner.gef.common.property.DesignerEditorPropertyComposite.updatePropertyComposite(DesignerEditorPropertyComposite.java:872)
at com.swtdesigner.gef.DesignerEditor.parseCompilationUnit(DesignerEditor.java:1202)
at com.swtdesigner.gef.DesignerEditor$17.execute(DesignerEditor.java:1100)
at com.swtdesigner.model.swing.properties.custom.DesignTimeHelper.execute(DesignTimeHelper.java:54)
at com.swtdesigner.gef.DesignerEditor.handleActivate(DesignerEditor.java:1094)
at com.swtdesigner.gef.DesignerEditor.handleActivate(DesignerEditor.java:1085)
at com.swtdesigner.editors.MultiPageEditor.showDesignEditor(MultiPageEditor.java:391)
at com.swtdesigner.editors.MultiPageEditor$2.widgetSelected(MultiPageEditor.java:178)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:227)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:962)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:947)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:706)
at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3227)
at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:2005)
at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:316)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3682)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3293)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:169)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
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:508)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)
at org.eclipse.equinox.launcher.Main.run(Main.java:1173)


Is this a bug, or will SwingDesigner intentionally only parse methods with basic type parameters, regardless of their content?
vidaj
 
Posts: 2
Joined: Wed Mar 26, 2008 6:35 am

Re: Using custom component-factory

Postby Eric Clayberg » Wed Apr 09, 2008 8:13 am

vidaj wrote:I'm using SwingDesigner with a component factory. The factory follows your specification, i.e. ComponentFactory.getInstance().createXXX();
The major problem I have is that SwingDesigner always throws an exception if my createXXX-method accepts other parameters than String, int and void....
Is this a bug, or will SwingDesigner intentionally only parse methods with basic type parameters, regardless of their content?

The factory support in Swing Designer will work with any arguments. It is not limited to simple arugments like Strings and ints.

For example:

Code: Select all
package test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.swing.JTextField;

public class ComponentFactory {
   public static List createList(String a, String b, String c) {
      List elements = new ArrayList();
      elements.add(a);
      elements.add(b);
      elements.add(c);
      return elements;
   }
   public static JTextField creaTextField() {
      return new JTextField();
   }
   public static JTextField creaTextField(List list) {
      JTextField textField = new JTextField();
      String text = "";
      for (Iterator I = list.iterator(); I.hasNext();) {
         String s = (String) I.next();
         if (!text.isEmpty()) {
            text += " ";
         }
         text += s;
      }
      textField.setText(text);
      return textField;
   }
}

Code: Select all
package test;

import java.awt.BorderLayout;
import java.util.Collections;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JTextField;

public class JFrame_1 extends JFrame {
   /**
    * Launch the application
    * @param args
    */
   public static void main(String args[]) {
      try {
         JFrame_1 frame = new JFrame_1();
         frame.setVisible(true);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
   /**
    * Create the frame
    */
   public JFrame_1() {
      super();
      setBounds(100, 100, 500, 375);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      //
      {
         JTextField textField = ComponentFactory.creaTextField();
         getContentPane().add(textField, BorderLayout.NORTH);
      }
      {
         List list = ComponentFactory.createList("aaa", "bbb", "ccc");
         JTextField textField = ComponentFactory.creaTextField(list);
         getContentPane().add(textField, BorderLayout.SOUTH);
      }
   }
}

The exception you listed is a downstream side effect of an earlier exception. We need to see an actual test case and your entire Eclipse ".log" file to determine what the actual problem is.
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