Community
Participate
Working Groups
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.
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.
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
Created attachment 119052 [details] New Patch Changed the import clause to: "org.osgi.service.component.ComponentContext"
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.
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.
Created attachment 119063 [details] Stack trace.
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.
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>
Let's leave out issue #3 for now, we should be fine by adding the proper import package statement and not use AMD.
Created attachment 119508 [details] Patch I removed the commented code from issue #3, added ALT accelarator and updated the save function.
Created attachment 119521 [details] org.eclipse.pde.ds.ui.patch Updated patch.
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.
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.
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.
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.