wbp-component.xml and generics

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

wbp-component.xml and generics

Postby mkornatzki » Wed Apr 28, 2010 11:04 pm

Hi,

i have made a superclass called ValueField which extends JTextField.
My component for the palette is a StringValueField which extends ValueField like this: StringValueField extends ValueField<String>.
I have a method in ValueField like: setValue(T newValue)

The ComponentEditor in SwingDesigner works perfect except for setValue. In this propertyfield i can not enter a value for the String.
Can you help me what i have to write in the wbp-component.xml that the editor knows that setValue requires a String?

I have tried to give swingdesigner a hint and add the following in the wbp-component.xml
Code: Select all
<property id="setValue(java.lang.String)">
</property>


Should i set an editor? But which editor do i have to set for String?

cheers,
michael
mkornatzki
 
Posts: 121
Joined: Wed Oct 15, 2008 3:57 am

Re: wbp-component.xml and generics

Postby Konstantin.Scheglov » Sat May 01, 2010 1:37 am

Only solution which will work now it overriding getValue()/setValue() methods in each specialization.

I've checked again if we can support such generic properties, but I see, that this would require too much changes.
For example, we can not work just with Method now (i.e. use just declaration class), we have to pass also actual Class, or even worse - resolver for type variables, if class specialization is done in "new" statement in Java source.

Code: Select all
public class ValueField<T> extends JTextField {
   private static final long serialVersionUID = 1L;
   public T getValue() {
      return null;
   }
   public void setValue(T value) {
      setText(value.toString());
   }
}


Code: Select all
public class StringValueField extends ValueField<String> {
   private static final long serialVersionUID = 1L;
   public StringValueField() {
      setText("default");
   }
   @Override
   public String getValue() {
      return getText();
   }
   @Override
   public void setValue(String value) {
      super.setValue(value);
   }
}
Konstantin.Scheglov
Moderator
 
Posts: 186
Joined: Tue Oct 18, 2005 8:11 pm
Location: Russian Federation, Lipetsk

Re: wbp-component.xml and generics

Postby mkornatzki » Mon May 03, 2010 12:54 am

It's a pity. I hoped that there was a solution with the component.xml.

I tried your suggestion and now in th properties-list in swingdesigner i see two value-entries.
Image
The reason is that i wanted to show the value as preferrend entry in the properties-list.
If i remove "value" from properties-preferred names than i get only one entry. But i want to see it bold.

My StringValueField.wbp-component.xml looks like this:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<component xmlns="http://www.instantiations.com/D2/WBPComponent">
   <description>Eingabefeld f&#x00FC;r eine Zeichenkette
      <ul>
         <li>value = Objekt vom Typ String</li>
      </ul>   
   </description>
   
   <!-- CREATION -->
   <creation>
      <source><![CDATA[new de.parcit.guibase.swing.text.valuefield.StringValueField(true)]]></source>
   </creation>
   
    <!-- CONSTRUCTORS -->
    <constructors>
       <constructor>
          <parameter type="boolean" property="setNullAllowed(boolean)"/>
       </constructor>   
    </constructors>
   
   <!-- PROPERTIES -->
   <properties-preferred names="backgroundText nullAllowed value" />
   <properties-hidden names="text" />
</component>


Also the type (java.lang.String) is shown at the property. Can i hide this?

The more classes i extend i get increasingly more entries for value:
Image


I have some more problems.
Like the StringValueField i have some more Fields.
IntegerValueField: if i enter a value in the property "value" then there is no integer set but an int even the SingDesigner "knows" the type
LongValueField: here the property value didn't get shown in the properties-list
ShortValueField: the same behaviour as for LongValueField
DecimalValueField: (java.lang.Double) the same behaviour as for LongValueField
DateValueField: (java.util.Date) the same behaviour as for LongValueField

Do i have to make somewhere an entry that the right type was used and the value-property get displayed in the properties-list?

cheers, michael
mkornatzki
 
Posts: 121
Joined: Wed Oct 15, 2008 3:57 am

Re: wbp-component.xml and generics

Postby Konstantin.Scheglov » Mon May 03, 2010 4:31 am

mkornatzki wrote:It's a pity. I hoped that there was a solution with the component.xml.

I tried your suggestion and now in th properties-list in swingdesigner i see two value-entries.
Image
The reason is that i wanted to show the value as preferrend entry in the properties-list.
If i remove "value" from properties-preferred names than i get only one entry. But i want to see it bold.


Code: Select all
<properties-preferred names="setValue(java.lang.String)"/>


You can use method signature to specify property exactly.
Name of property is just convenient shortcut, which works in most cases, but not in this one.


mkornatzki wrote:I have some more problems.
Like the StringValueField i have some more Fields.
IntegerValueField: if i enter a value in the property "value" then there is no integer set but an int even the SingDesigner "knows" the type
LongValueField: here the property value didn't get shown in the properties-list
ShortValueField: the same behaviour as for LongValueField
DecimalValueField: (java.lang.Double) the same behaviour as for LongValueField
DateValueField: (java.util.Date) the same behaviour as for LongValueField

Do i have to make somewhere an entry that the right type was used and the value-property get displayed in the properties-list?


I don't want to guess how these classes look. ;-)
Just show exact example.
Konstantin.Scheglov
Moderator
 
Posts: 186
Joined: Tue Oct 18, 2005 8:11 pm
Location: Russian Federation, Lipetsk

Re: wbp-component.xml and generics

Postby mkornatzki » Mon May 03, 2010 4:34 am

they look like exact the same as in your example. Only changed the type.
Code: Select all
public class TestLongValueField
   extends TestValueField<Long> {

   @Override
   public Long getValue() {
      return super.getValue();
   }

   @Override
   public void setValue(Long newValue) {
      super.setValue(newValue);
   }
}

and maybe you can check this also for integer:
Code: Select all
public class TestIntegerValueField
   extends TestValueField<Integer> {

   @Override
   public Integer getValue() {
      return super.getValue();
   }

   @Override
   public void setValue(Integer newValue) {
      super.setValue(newValue);
   }
}

and give me a hint what i have to do that the swingdesigner generate code like:
Code: Select all
integerValueField.setValue(new Integer(123));

and not
Code: Select all
integerValueField.setValue(123);

because the type is an integer and not an int
mkornatzki
 
Posts: 121
Joined: Wed Oct 15, 2008 3:57 am

Re: wbp-component.xml and generics

Postby Konstantin.Scheglov » Mon May 03, 2010 5:02 am

mkornatzki wrote:and give me a hint what i have to do that the swingdesigner generate code like:
Code: Select all
integerValueField.setValue(new Integer(123));

and not
Code: Select all
integerValueField.setValue(123);

because the type is an integer and not an int


Code: Select all
integerValueField.setValue(123);
is correct behavior, because in Java5+ it works with help of auto-boxing.

There are no editor for "Long" or "Short" now, these types never were used in any of standard components in toolkits which we support now.

"Date" editing is supported, but you need to configure editor for your toolkit (we use it for GWT).
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<component xmlns="http://www.instantiations.com/D2/WBPComponent">
   <!-- PROPERTIES -->
   <properties-preferred names="setValue(java.util.Date)"/>
   <property id='setValue(java.util.Date)'>
      <editor id='customDate'>
         <parameter name='functions'>import java.text.SimpleDateFormat;</parameter>
         <parameter name='toString'>(new SimpleDateFormat("dd.MM.yyyy")).format(value)</parameter>
         <parameter name='toDate'>(new SimpleDateFormat("dd.MM.yyyy")).parse(value)</parameter>
         <parameter name='source'>new java.text.SimpleDateFormat("dd.MM.yyyy").parse("%value%", new java.text.ParsePosition(0))</parameter>
      </editor>
   </property>
</component>
Konstantin.Scheglov
Moderator
 
Posts: 186
Joined: Tue Oct 18, 2005 8:11 pm
Location: Russian Federation, Lipetsk

Re: wbp-component.xml and generics

Postby mkornatzki » Mon May 03, 2010 5:11 am

is correct behavior, because in Java5+ it works with help of auto-boxing.

sure, java can do that but in our projects it is not allowed. If you didn't think of the problems which autoboxing can bring then you can get errors and this we want to prevent.

i will try to set the dateeditor as you described.

Can i write my own propertyeditor and register it for long and short like any other beanpropertyeditor?
mkornatzki
 
Posts: 121
Joined: Wed Oct 15, 2008 3:57 am

Re: wbp-component.xml and generics

Postby Konstantin.Scheglov » Mon May 03, 2010 5:21 am

mkornatzki wrote:
is correct behavior, because in Java5+ it works with help of auto-boxing.

sure, java can do that but in our projects it is not allowed. If you didn't think of the problems which autoboxing can bring then you can get errors and this we want to prevent.


Hm...
I will need to add preference for this.

How do you disable this? Using some option in Eclipse? Or?...


mkornatzki wrote:Can i write my own propertyeditor and register it for long and short like any other beanpropertyeditor?


This is better to do on our side.
I will do this in next several days.
Konstantin.Scheglov
Moderator
 
Posts: 186
Joined: Tue Oct 18, 2005 8:11 pm
Location: Russian Federation, Lipetsk

Re: wbp-component.xml and generics

Postby mkornatzki » Mon May 03, 2010 5:25 am

How do you disable this? Using some option in Eclipse? Or?...

It is a compiler preference from eclipse "Boxing and unboxing conversions":
Image
mkornatzki
 
Posts: 121
Joined: Wed Oct 15, 2008 3:57 am

Re: wbp-component.xml and generics

Postby Konstantin.Scheglov » Tue May 04, 2010 3:40 am

1. Now we will check not only for Java5+, but also this compiler option. It should be "ignore" to allow us to use auto-boxing.

2. I've added editors for Byte, Short and Long types. Update to the latest build.
Konstantin.Scheglov
Moderator
 
Posts: 186
Joined: Tue Oct 18, 2005 8:11 pm
Location: Russian Federation, Lipetsk

Re: wbp-component.xml and generics

Postby mkornatzki » Tue May 04, 2010 5:14 am

Great, it works :)

thank you
mkornatzki
 
Posts: 121
Joined: Wed Oct 15, 2008 3:57 am

Re: wbp-component.xml and generics

Postby Eric Clayberg » Tue May 04, 2010 5:33 am

Glad we could help.
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: wbp-component.xml and generics

Postby mkornatzki » Wed May 05, 2010 3:23 am

can you give me a hint what i have to do to use sun.beans.editors.DoubleEditor for Double-values in the property editor?

regards,
michael
mkornatzki
 
Posts: 121
Joined: Wed Oct 15, 2008 3:57 am

Re: wbp-component.xml and generics

Postby Konstantin.Scheglov » Wed May 05, 2010 4:04 am

mkornatzki wrote:can you give me a hint what i have to do to use sun.beans.editors.DoubleEditor for Double-values in the property editor?


You will need to write BeanInfo.
But why do you want to use it at all?
Swing Designer already includes editor for "double" primitive type.
Konstantin.Scheglov
Moderator
 
Posts: 186
Joined: Tue Oct 18, 2005 8:11 pm
Location: Russian Federation, Lipetsk

Re: wbp-component.xml and generics

Postby mkornatzki » Wed May 05, 2010 7:06 am

thank you, so i am on the right direction.

The Problem is that need Objects and no primitives. The value can be null and not only 0
mkornatzki
 
Posts: 121
Joined: Wed Oct 15, 2008 3:57 am

Next

Return to Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest