Bug 162999 - [CommonNavigator] Problem with clashing overrides for non-nested action provider
Summary: [CommonNavigator] Problem with clashing overrides for non-nested action provider
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Windows XP
: P1 critical (vote)
Target Milestone: 3.3 M7   Edit
Assignee: Michael D. Elder CLA
QA Contact:
URL:
Whiteboard: awaitingfeedback
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2006-10-31 16:34 EST by Brian Fitzpatrick CLA
Modified: 2007-06-06 07:48 EDT (History)
1 user (show)

See Also:


Attachments
Patch that includes proposed change (1.03 KB, patch)
2007-03-16 12:36 EDT, Brian Fitzpatrick CLA
no flags Details | Diff
Provides a fix to allow multiple non-nested action providers to be invoked. (7.48 KB, patch)
2007-03-30 00:26 EDT, Michael D. Elder CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Fitzpatrick CLA 2006-10-31 16:34:20 EST
I've run into an issue where we have an action provider that provides a Refresh action in the Data Source Explorer for DTP. This Refresh is meant to be overridden. We have a case already where that is done within the framework for some of the objects in the tree. However, now I'm attempting to add a second override for this non-nested action provider. And when it goes to load the action providers, I get a NPE when it attempts to compare the two overriding action providers, since neither has a priority. 

In the inner CommonActionProviderDescriptorCompator in CommonActionProviderDescriptor, the compare methods looks like this:

		public int compare(Object o1, Object o2) {
			CommonActionProviderDescriptor lvalue= null, rvalue= null;
			
			if(o1 instanceof CommonActionProviderDescriptor)
				lvalue = (CommonActionProviderDescriptor) o1;
			
			if(o2 instanceof CommonActionProviderDescriptor)
				rvalue = (CommonActionProviderDescriptor) o2;
			
			if(lvalue == null || rvalue == null)
				return LESS_THAN;
			if(lvalue.equals(rvalue))
				return EQUALS;
			int comparison = lvalue.getPriority().getValue() - rvalue.getPriority().getValue();
			if(comparison == 0) 
				return lvalue.getDefinedId().compareTo(rvalue.getDefinedId());
			return comparison;
			
		}

Somehow we need to account for the fact that non-nested action providers don't have a priority. Now... I added this line:

			if(lvalue.getPriority() == null || lvalue.getPriority() == null)
				return LESS_THAN;

However, my second overriding action doesn't get loaded. It does take care of the NPE though. 

Any ideas? I can't believe that we'd be the only folks to attempt to override non-nested providers.
Comment 1 Brian Fitzpatrick CLA 2006-10-31 17:46:01 EST
Another possible fix is to add the priority attribute to the Navigator action provider extension to only be used if it's a non-nested provider
Comment 2 Brian Fitzpatrick CLA 2006-11-30 19:10:35 EST
This issue with the priority being null is a critical one for us in DTP and in Sybase products using DTP. We need a patch or fix for this. I don't want to have to do a one-off copy of the org.eclipse.ui.navigator plug-in for fear of causing issues with other things, but we may have to do just that.
Comment 3 Brian Fitzpatrick CLA 2006-11-30 19:11:00 EST
Upping the priority to P1 - Critical.
Comment 4 John Graham CLA 2007-03-16 12:13:26 EDT
This will cause problems for DTP Europa and DTP adopters if not addressed in 3.3. 
Comment 5 Brian Fitzpatrick CLA 2007-03-16 12:36:56 EDT
Created attachment 61122 [details]
Patch that includes proposed change

This patch includes the two line fix that I'm proposing to fix this issue.
Comment 6 Michael D. Elder CLA 2007-03-29 23:37:56 EDT
When you override a single provider with two providers, which of the two providers do you expect to be invoked? Or do you expect both?
Comment 7 Michael D. Elder CLA 2007-03-30 00:26:02 EDT
Created attachment 62459 [details]
Provides a fix to allow multiple non-nested action providers to be invoked.

This patch prototypes one possible fix where all overriding action providers are allowed.
Comment 8 Michael D. Elder CLA 2007-03-30 00:26:27 EDT
Please verify if the latest patch satisfies your requirements.
Comment 9 Brian Fitzpatrick CLA 2007-04-02 12:01:55 EDT
(In reply to comment #8)
> Please verify if the latest patch satisfies your requirements.

Interesting. Ok. So you're proposing that we go in order of plug-in ID? (Sorry I didn't respond sooner, I was on vacation all week last week.)

I don't think this is the best way to go based on what I've seen. The issue is that the nested action provider has a priority attribute, but the non-nested one doesn't, so there's nothing to compare against. Using the plug-in ID will make for some entertaining and possibly unexpected results. 

I would think that adding an optional priority attribute to the non-nested action provider would be the better way to go and then use the plug-in ID to resolve cases where more than one provider has the same priority. 
Comment 10 Michael D. Elder CLA 2007-04-09 23:44:41 EDT
The patch actually supports multiple providers; so the priority/order of invocation shouldn't really matter as they should contribute to the menu independently. 

Can you describe the use case you're expecting to handle with this? Do you expect all contributions to appear or that one of the overriding action providers would win out?
Comment 11 Brian Fitzpatrick CLA 2007-04-10 10:57:27 EDT
The use case is pretty simple. For example, let's say we have our generic JDBC connection profile in DTP. It has its own refresh action provider, which can be overridden for specific instances. A DTP adopter writes their own connection profile for their particular database and wants to override the Refresh action provider to do their own specific thing. Within the context of that enablement or target, their provider should win for that particular provider. That's why I was suggesting the priority more than just sorting them by IDs. 
Comment 12 Michael D. Elder CLA 2007-04-23 23:53:54 EDT
Okay. I think this should handle your use case. There's a test (grab org.eclipse.ui.tests.navigator when you apply the patch). In the test case:

Open the "Test Navigator Viewer".
Create a project, a folder, two resources, one of which ends with ".txt"
Right click on the project and folder to see "overrideABLE"
Right click on non-.txt file to see "overridING1" and on the .txt file for overridING2. 

The two overriding extensions have priorities and both enable on IResource, with one enabling on IResource && extension == .txt. 

McQ approved the new attribute on actionProvider with a +1 on the PMC mailing list. 
Comment 13 Michael D. Elder CLA 2007-04-24 21:58:19 EDT
Fixed for > 20070424.