This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 216775 - Problems with custom property editor, use of setValue and toString/fromString
Summary: Problems with custom property editor, use of setValue and toString/fromString
Status: RESOLVED FIXED
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 7.1.2
Hardware: PC Windows 7
: P2 normal (vote)
Assignee: issues@guibuilder
URL:
Keywords:
: 220504 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-08-13 08:58 UTC by AlvinHong
Modified: 2012-11-27 15:33 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
file for case (2.23 KB, text/plain)
2012-08-13 08:59 UTC, AlvinHong
Details
file for case (5.93 KB, text/plain)
2012-08-13 09:00 UTC, AlvinHong
Details
file for case (1.15 KB, text/plain)
2012-08-13 09:01 UTC, AlvinHong
Details
file for case (1.64 KB, text/plain)
2012-08-13 09:01 UTC, AlvinHong
Details

Note You need to log in before you can comment on or make changes to this bug.
Description AlvinHong 2012-08-13 08:58:41 UTC
I am creating a custom bean that depends on a custom property editor. My custom editor extends PropertyEditorSupport and implements XMLPropertyEditor. The model is an Object for which I've implemented equals, toString, and fromString.

- Java initialization string works (can be verified in the Java code)

- XML serialization works (can be verified in the form)

However:

- The component is not responding to the changes, that is the internal state is not being updated, it appears that setValue is not being called

- The string representation appears correct in the property pane but if changes are made in the cell (not the editor, but the cell in the property pane using the text format) an error is thrown.
Comment 1 AlvinHong 2012-08-13 08:59:17 UTC
Created attachment 123029 [details]
file for case
Comment 2 AlvinHong 2012-08-13 09:00:50 UTC
Created attachment 123030 [details]
file for case
Comment 3 AlvinHong 2012-08-13 09:01:19 UTC
Created attachment 123031 [details]
file for case
Comment 4 AlvinHong 2012-08-13 09:01:37 UTC
Created attachment 123032 [details]
file for case
Comment 5 Tomas Pavek 2012-08-13 16:33:54 UTC
Not sure what setValue call you mean in the first problem. Do you mean that RedBlackTextField.setRedBlackData does not get called with the new instance from the custom property editor panel?

BTW I see you are able to use XMLPropertyEditor, so you could perhaps also try to use ExPropertyEditor: http://bits.netbeans.org/dev/javadoc/org-openide-explorer/org/openide/explorer/propertysheet/ExPropertyEditor.html
and PropertyEnv: http://bits.netbeans.org/dev/javadoc/org-openide-explorer/org/openide/explorer/propertysheet/PropertyEnv.html
This should allow you to get informed when OK button is pressed and set the value in the property editor only at this moment. You can also do some validation at this point.

But otherwise, the property editor (RedBlackEdito) looks correct to me at the first sight. So there might be a bug on NetBeans side, we need to try out and debug. There's some chance it's not exposed when using the ExPropertyEditor.


As for the second problem, you don't mention what error is thrown, but I'd say your property editor is missing getAsText and setAsText methods to allow editing of the value as a String.
Comment 6 AlvinHong 2012-08-15 12:13:50 UTC
Hi, thank you for getting back so soon.

On the first problem, the issue I have is that the paintComponent method in RedBlackTextField is showing blank info for red and black, even after you set RedBlackData in the RedBlackEditor. I would expect that the internal state of RedBlackTextField would be updated.

On the second problem, I have added the following code in the editor:

  /**
   * {@inheritDoc}
   */
  @Override
  public String getAsText() {
    try {
      return getValue().toString();
    } catch (Throwable IDontCare) {
      return "";
    }
  }
  
  /**
   * {@inheritDoc}
   */
  @Override
  public void setAsText(String text) throws IllegalArgumentException {
    try {
      setValue(RecordData.fromString(text));
    } catch (Throwable IDontCare) {
      throw new IllegalArgumentException(IDontCare.getMessage());
    }
  }

and now it works! Thanks for the hint - I look forward to your findings on the component state.
Comment 7 Tomas Pavek 2012-08-16 09:59:47 UTC
OK, I see what the first problem is. The property editor actually works well. The problem is with the RedBlackData property value. The GUI builder gets an instance from the property editor, but needs to create a copy of it to set it to the design view - which it can't in this case.

There are basically two equal instances for each component (RedBlackTextField in your case): one is used as the reference instance in the model (for property sheet, generated code, persistence) and a separate instance is used for the design view. If you invoke a preview of the form, yet another instance gets created. This means that also property values set by the user need to be copied among the components.

The only way GUI builder can make a copy of a custom data type is serialization. So it should work for you if you make RedBlackData Serializable or Externalizable. If the property value type is simple, it should be easy and work just well. It could also be used instead of the XMLPropertyEditor implementation (which is OTOH more suitable for the "long term" persistence in the form file, but you may get along without it if you can keep your data serialization stable).

We should perhaps look into the possibility to share the same instance of the property value for design view as a fallback if it can't be cloned - instead of not setting it at all as it seems happening now.
Comment 8 Tomas Pavek 2012-08-17 15:49:27 UTC
I've changed how the property values cloned for the view are handled if can't be cloned: same instance is used instead of not setting it to the view component.
http://hg.netbeans.org/jet-main/rev/95617f8a01e7

There's a small risk in this change. The previous behavior ensured that same property value instance was never set to multiple components. If could not be copied, it was not set. This was safe. Now some failures could happen, theoretically, if some special properties can't share the value instance between more components and can't have the values serialized. But I think it's rather hypothetical that someone would have a component and rely on that it's property is not set in the design view. Such a component is not suitable for use in GUI builder anyway.

To the reporter: The fix will be available in next NetBeans version. For now you need to make the RedBlackData class Serializable.
Comment 9 Quality Engineering 2012-08-21 15:08:08 UTC
Integrated into 'main-golden', will be available in build *201208211308* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/95617f8a01e7
User: Tomas Pavek <tpavek@netbeans.org>
Log: #216775: if can't clone property value, use the same instance instead of ignoring it
Comment 10 Tomas Pavek 2012-11-27 15:33:27 UTC
*** Bug 220504 has been marked as a duplicate of this bug. ***