Bug 254976 - [ds tooling] Service Component wizard: Add checkbox for generating lifecycle methods
Summary: [ds tooling] Service Component wizard: Add checkbox for generating lifecycle ...
Status: RESOLVED WONTFIX
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Chris Aniszczyk CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: bugday
Depends on:
Blocks:
 
Reported: 2008-11-11 23:07 EST by Simon Archer CLA
Modified: 2019-10-09 07:03 EDT (History)
1 user (show)

See Also:


Attachments
Done! (12.21 KB, patch)
2008-11-28 15:03 EST, Rafael Oliveira Nóbrega CLA
no flags Details | Diff
New Patch (12.21 KB, patch)
2008-11-28 15:27 EST, Rafael Oliveira Nóbrega CLA
no flags Details | Diff
Stack trace. (6.97 KB, text/plain)
2008-11-28 22:47 EST, Simon Archer CLA
no flags Details
DS Wizard updates (14.67 KB, patch)
2008-12-02 13:51 EST, Rafael Oliveira Nóbrega CLA
no flags Details | Diff
Patch (13.66 KB, patch)
2008-12-04 10:11 EST, Rafael Oliveira Nóbrega CLA
caniszczyk: iplog+
Details | Diff
org.eclipse.pde.ds.ui.patch (12.86 KB, patch)
2008-12-04 11:25 EST, Chris Aniszczyk CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Archer CLA 2008-11-11 23:07:43 EST
Using Eclipse 3.5M3. Extracted from bug 253635.

It might be helpful to have the following checkbox below the Class field:

     [x] Generate lifecycle methods.

If this checkbox is checked, and it should be checked by default, the component class will have the following methods added, if they do not already exist:

  protected void activate(ComponentContext context) {
  }

  protected void deactivate(ComponentContext context) {
  }

The state of the checkbox should probably also be persisted (see bug 254970). The context parameter is of type org.osgi.service.component.ComponentContext.
Comment 1 Simon Archer CLA 2008-11-19 14:52:57 EST
The "Generate lifecycle methods" checkbox should be enabled only when:

- The class specified in the Class field exists, and,
- The class does NOT contain the method activate(ComponentContext) or the method deactivate(ComponentContext).

Since the Class field is empty by default, the checkbox should therefore be disabled by default, and only becoming enabled when a valid class name is entered in the field and the class does not contain both of the lifecycle methods.
Comment 2 Rafael Oliveira Nóbrega CLA 2008-11-28 15:03:05 EST
Created attachment 119044 [details]
Done!

CheckBox added. 
CheckBox Enable/Disable based on Implementation Class and Methods existence.
CheckBox persisted in the plugin settings.
if(checkbox.isSelected) ->  addMethods and import clause
Comment 3 Rafael Oliveira Nóbrega CLA 2008-11-28 15:27:28 EST
Created attachment 119052 [details]
New Patch

Changed the import clause to: "org.osgi.service.component.ComponentContext"
Comment 4 Simon Archer CLA 2008-11-28 17:17:32 EST
Thanks Rafael, I shall try out the patch and let you know.

RFC 0134, "Declarative Services Update" (http://www.osgi.org/download/osgi-4.2-early-draft.pdf) has content that is related to the activate/deactivate methods. See section 3.2, "Bug 244: Extend SCR to allow alternate activate and deactivate method signatures". Also see the OSGi bug report https://www.osgi.org/members/bugzilla/show_bug.cgi?id=244. Rest assured, that I'll open other PDE bug reports to address these new requirements.
Comment 5 Simon Archer CLA 2008-11-28 22:46:07 EST
I have tested the patch and although it basically works I have uncovered the following issues:

1. I experienced an NPE while creating a new service component. See the attached file for the entire stack trace.

java.lang.NullPointerException
	at org.eclipse.pde.internal.ds.ui.wizards.DSFileWizardPage.updateCreateMethodsButton(DSFileWizardPage.java:400)
	at org.eclipse.pde.internal.ds.ui.wizards.DSFileWizardPage.isPageComplete(DSFileWizardPage.java:347)
	at org.eclipse.pde.internal.ds.ui.wizards.DSFileWizardPage$1.modifyText(DSFileWizardPage.java:184)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:167)

This was easily fixed by moving the call to setComponentName() in org.eclipse.pde.internal.ds.ui.wizards.DSFileWizardPage.createAdvancedControls(Composite) down to just before the call to validatePage(). This is a case of building all the controls before performing behavior that causes the controls to be updated. Simple enough.

2. I found was that when the activate/deactivate methods are generated the complication unit is NOT saved. A wizard should not leave a file unsaved.

3. Upon saving the compliation unit the activate/deactivate methods introduce a dependency upon org.osgi.service.component.ComponentContext, so you get a compilation error if you don't have the bundle org.eclipse.osgi.services as one of your Plug-in Dependencies.  In the perfect world a wizard should not result in compilation errors, so I would like to see this bundle automatically added to the the Plug-in Project's Automated Management of Dependencies list. For example, the project's build.properties file should be updated:

  additional.bundles = org.eclipse.osgi.services

But, of course, it's never as simple as that since you need to be respectful of the additional.bundle property already existing, and the org.eclipse.osgi.services bundle already listed as part of the property's value. I am not aware of PDE automatically updating additional.bundles today, and I'm sure Chris will have an opinion to share. ;-)

4. While using the wizard the "Generate lifecycle methods" checkbox behaved strangely in that it often became automatically checked, even after I had manually unchecked it.  For example, try unchecking it and then change the value of the "File Name:" field. While the checkbox should be checked by default, and while (I think) the state of the checkbox should be persisted, the wizard should not change the state of the checkbox after the user has already changed it.  Clearly this is not working as intended.

I hope this helps.
Comment 6 Simon Archer CLA 2008-11-28 22:47:14 EST
Created attachment 119063 [details]
Stack trace.
Comment 7 Rafael Oliveira Nóbrega CLA 2008-12-02 13:51:33 EST
Created attachment 119300 [details]
DS Wizard updates

I did all changes asked by Simon, except number3.

For some reason I can't use:
IBundlePluginModelBase.getBuildModel().getBuild() or  IBundlePluginModelBase.getBuildModel().getFactory() ...

...to add new entries. It says the model isn't editable.

Any idea?

So I commented this part of the code, and sent the patch.
Comment 8 Simon Archer CLA 2008-12-02 14:48:55 EST
I have tested the patch and issues 1 and 4 are working great.

But I am still seeing issue 2: when the activate/deactivate methods are generated the complication unit is NOT saved. A wizard should not leave a file unsaved.

You might also consider adding an ALT accelerator to the checkbox label "Generate lifecycle methods.", for example:

 * ALT+G: &Generate lifecycle methods.
 * ALT+L: Generate &lifecycle methods.

I would think ALT+L would be the most logical.

Regarding issue 3, yes that is tricky! Maybe Brian Bauman will be able to help, since he worked on PDE when the AMD support was added.

<wishList>I have wished for a long time that the New Plug-in Project wizard supported populating the Automated Management of Dependencies list in some way.  I am thinking of a wizard page that contains a single list to which you can "Add..." and "Remove" bundles that you want on the additional.bundles list. You should also be able to move entries "Up" and "Down" since order matters. The list should probably default to org.eclipse.osgi.services and org.eclipse.osgi (in that order). This list should also be persisted since it is common for bundles in an application to have the same list of additional bundles against which to compile. But this is sounding like a whole new bug report.</wishList>
Comment 9 Chris Aniszczyk CLA 2008-12-02 18:09:28 EST
Let's leave out issue #3 for now, we should be fine by adding the proper import package statement and not use AMD.
Comment 10 Rafael Oliveira Nóbrega CLA 2008-12-04 10:11:42 EST
Created attachment 119508 [details]
Patch

I removed the commented code from issue #3, added ALT accelarator and updated the save function.
Comment 11 Chris Aniszczyk CLA 2008-12-04 11:25:41 EST
Created attachment 119521 [details]
org.eclipse.pde.ds.ui.patch

Updated patch.
Comment 12 Chris Aniszczyk CLA 2008-12-04 11:29:26 EST
One thing that is missing currently is the Import-Package statement on

"org.osgi.service.component"

If this isn't there, there will be a compile error. I suggest modifying the MANIFEST.MF to add the "org.osgi.service.component" to the Import-Package list if it isn't there already.
Comment 13 Simon Archer CLA 2008-12-04 12:17:25 EST
I have tested the patch that is attached to comment 11 and it works well.

When the lifecycle methods were added to the component's implementation class I was expecting the class to be opened in the Java editor, but it was not -- I'm not sure what the convention here is.  It's not really a big deal, but it would communicate that the class has changed.
Comment 14 Eclipse Genie CLA 2019-04-14 15:53:43 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 15 Lars Vogel CLA 2019-10-09 07:03:01 EDT
This bug was marked as stalebug a while ago. Marking as wontfix.

If this report is still relevant for the current release, please
reopen and remove the stalebug whiteboard tag.