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 200691

Summary: New SPI to enable J2SE Project extension specific properties to be stored properly when modified in Project Properties dialog
Product: java Reporter: Petr Somol <psomol>
Component: ProjectAssignee: Petr Somol <psomol>
Status: RESOLVED FIXED    
Severity: normal CC: apireviews, dkonecny
Priority: P3 Keywords: API, API_REVIEW_FAST
Version: 7.1   
Hardware: All   
OS: All   
URL: http://wiki.netbeans.org/NB71_J2SEProjectAPI#J2SECustomPropertySaver
Issue Type: ENHANCEMENT Exception Reporter:
Bug Depends on:    
Bug Blocks: 199283, 219827    
Attachments: proposed patch
updated patch proposal
test

Description Petr Somol 2011-08-05 08:49:04 UTC
The problem to be solved is as follows. WebStart module and JavaFX 2.0 module both extend standard J2SE Project by adding new properties and accordingly modifying Project Properties dialog contents. In Project Properties it may be desirable to add, remove or replace categories (panels) as well as modify (extend) existing ones, to expose properties not present in standard J2SE Project. The problem is in saving correctly the changes made by user in various panels (to *.properties file, etc.) when OK is pressed. 

for details of the problem and the proposed solution see
http://wiki.netbeans.org/NB71_J2SEProjectAPI#J2SECustomPropertySaver
Comment 1 Petr Somol 2011-08-05 09:23:36 UTC
Created attachment 109810 [details]
proposed patch

proposed patch
Comment 2 Tomas Zezula 2011-08-08 08:38:48 UTC
TZ01: The new friend API does similar thing as the Category.setStoreListener(). What is the relation to it?
TZ02: Should not the save() method have the Project being saved as a parameter.
Comment 3 Petr Somol 2011-08-08 10:04:15 UTC
PS01 (Re TZ01): Category.setStoreListener() is successfully used in WebStart module, but this is only because all WebStart specific properties are modifyable from a single panel only. Thus either the user does not access it and nothing needs to be saved, or she accesses it and the panel gets created and the listener registered and everything works OK.
With JFX the situation is different, it is not possible to rely on a listener in any single category panel. JFX specific properties can be modified from several new category panels + modified JSE panels. Listeners in each of the new panels would cause the properties store() to be called redundantly, while in case of modified JSE panels the store listener is already occupied by JSE project.

With a project extension like JFX, where extension properties are spread across various category panels, it seems better to centralize the reaction to the save action (triggered by OK button) in one place.

PS02 (Re TZ02): Project indeed is needed to be passed to provider implementation. As the proposal above relies on @ProjectServiceProvider, the Project reference can be obtained through constructor parameter. On the other hand it is true that including Project in the save call makes things look clearer and avoids the need to store Project variable inside the provider. So I do not object to define:

public interface J2SECustomPropertySaver {
    void save(Project p);
}
Comment 4 Tomas Zezula 2011-08-09 08:16:42 UTC
OK, thanks.
Comment 5 Petr Somol 2011-08-09 12:00:51 UTC
Created attachment 109885 [details]
updated patch proposal

added Project parameter to save()
Comment 6 Jaroslav Tulach 2011-08-15 19:25:20 UTC
Y01 Re. "storeListener called redundantly" - can't you tighten the API specification to say that each instance of the listener will be called just once?

Y02 Try to write a test to permanently specify the new behavior.
Comment 7 Petr Somol 2011-08-16 08:10:20 UTC
PS03 (Re Y01) "storeListener called redundantly" - it is not the listeners that would be called redundantly. The API defining Category.setStoreListener() has itself a well defined meaning. I mentioned it only because it has been utilized in WebStart for the purpose of storing WebStart specific properties and as such it was worth investigating whether the same can be done for JavaFX2. The problem is that JavaFX2 specific properties are spread across several Categories. Clearly each affected Category would need a StoreListener() registered. The seemingly viable approach is then to have a store() method (in the class that maintains JFX specific properties), that would be called from each such StoreListener(). Such store() method is not part of any API and could be implemented to detect redundant calls of itself, but this still would not overcome the other problem - the problem with extended JSEProject categories. The property panel extension mechanism (#200704, being extension of previous SPI defined by J2SERunConfigProvider) makes it possible to add properties to JSEProject panels - but there seems to be no clear way of registering an additional StoreListener() for just the extended properties while not affecting the JSEProject panel code. Any possible workaround needed to achieve this together with the necessity to register listeners for several Categories seems much less straightforward than registering one central service provider as suggested here.
Comment 8 Petr Somol 2011-08-16 12:51:24 UTC
Created attachment 110009 [details]
test

Re Y02

If no other objections appear I plan to close this issue on We 17 Aug morning.
Comment 10 Quality Engineering 2011-08-18 13:51:17 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/b4d787206ac8
User: Petr Somol <psomol@netbeans.org>
Log: #200691 SPI to enable J2SE Project extension properties to be stored properly