Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 89834

Summary: [Presentations] Allow for unanticipated parameters for part appearance and behavior
Product: [Eclipse Project] Platform Reporter: Chris Gross <schtoo>
Component: UIAssignee: Paul Webster <pwebster>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: emoffatt, Mike_Wilson, n.a.edgar
Version: 3.1Keywords: helpwanted
Target Milestone: 3.3 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
part Properties v01
none
part Properties v02
none
part Properties v03
none
part Properties v04 none

Description Chris Gross CLA 2005-03-31 10:34:27 EST
This is a follow up to bug 86357.  

The presentations API needs to have some capability for custom or otherwise 
unanticipated parameters.  The current list of parameters is limited to just 
name, content description and one image.  While those parameters may be 
sufficient for some or even most situations, they are not sufficient for all.
Comment 1 Chris Gross CLA 2005-08-03 13:02:23 EDT
I would like to add a use case for this.  This is primarily needed for RCP 
applications.  

Consider that our security mechanism may prevent people from having full access 
to different parts of the application.  Sometimes they may be able to see but 
not modify the objects within a certain editor.  I'd like the ability to just 
tell the presentation that this is a read-only part and present that somehow in 
the UI.  Perhaps this is a decorator on the tab, perhaps just a different 
color.  

We are actually doing this right now.  But because there is no way to pass 
parameters to the presentation, we are cramming everything in the content 
description as a delimited string.
Comment 2 Chris Gross CLA 2005-12-08 16:15:21 EST
Possible implementation:

The initial bug I entered for this was bug 86357 that asked for access to the getAdapter method of the underlying part.  This is problematic because the part is not instantiated/activated until after the presentation is established.  But couldn't we just tie it together using the property change listener just like is done with the other properties and toolbar and such.  

IPresentablePart could have a getAdapter method but the method would return null or perhaps throw an exception until after the part was activated.  Once the part is activated a property change event would be thrown with IPresentablePart.PROP_ADAPTER (or whatever).  Thereby alerting the presentation that its safe to call getAdapter.  
Comment 3 Paul Webster CLA 2006-09-28 11:00:56 EDT
There are currently no plans to work on this feature.

PW
Comment 4 Paul Webster CLA 2006-10-10 12:37:29 EDT
Investigating.

PW
Comment 5 Paul Webster CLA 2006-10-10 14:31:09 EDT
What kind of information should be propogated across?

A possible option is to define

interface IWorkbenchPartProperty {
/**
 * Return a user defined property or null if it doesn't exist.
 */
public String getProperty(String key);

/**
 * set a user defined property.  Fires a property change event
 * with PROP_USER. A value of null clears the property.
 */
public void setProperty(String key, String value);
}

and implement it on WorkbenchPart.

Then add
public String getProperty(String key)
to IWorkbenchPartReference and IPresentablePart.  It would return null if the part doesn't exist yet and the reference has not been persisted from a previous session (assuming that is possible).

PW
Comment 6 Chris Gross CLA 2006-10-10 16:32:38 EDT
Ideally I'd like the properties to be Objects but I Strings will do.  I can see the persistance would be messy otherwise.  So, yeah what you have would work for me.
Comment 7 Paul Webster CLA 2006-10-10 20:23:42 EDT
I'm pretty sure that I can persist (String, String) properties from the IWorkbenchPartReference (although that would need more investigation).  That would allow the IPresentablePart access to the properties before the actual IWorkbenchPart was instantiated.

This assumes the properties will be treated like the other properties like title, name, description, icon, tooltip.  I think that's a decent model to work from.

Another option would be to only allow properties that implement IPersistableElement ... that would force them to support saveState(IMemento) and supply an IElementFactory ID for recreation.  I think this design is more restrictive than just using String objects.

Later,
PW


Comment 8 Chris Gross CLA 2006-10-11 09:35:29 EDT
Yea I thought about IPersistableElement too.  Just seems to add more complexity/responsibility and in reality it doesn't make that big a difference to have Objects rather than Strings.  

Another twist, some properties will not be logically persistable.  Take my previous example, where the presentation is trying to show an editor as read only because a user doesn't have rights to it.  That user could be given read/write rights after that read only property is persisted.  So when the workbench is restarted, that value is stale and in fact not correct.  But IMO thats ok.  Persist the latest value and let the editor re-evaluate it when its actually created.  The presentation will just update when the user selects the editor/view.  
Comment 9 Paul Webster CLA 2006-10-11 10:14:11 EDT
(In reply to comment #8)
> [... snip ...]
> thats ok.  Persist the latest value and let the editor re-evaluate it when its
> actually created.  The presentation will just update when the user selects the
> editor/view.  

I think that'll work fine.  When the part is first instantiated, the reference asks the part for all of its latest values ... and fires a property change event if the part returns new values.

PW


Comment 10 Chris Gross CLA 2006-12-20 11:42:44 EST
Paul, is there any movement on this item?
Comment 11 Paul Webster CLA 2006-12-20 14:27:00 EST
Let's see what we can do.

PW
Comment 12 Paul Webster CLA 2007-01-09 15:43:25 EST
Created attachment 56661 [details]
part Properties v01

Draft patch of adding arbitrary properties to a part, saving them in the reference between sessions, and showing them through IPresentablePart.

1) there is no default implementation on IWorkbenchPart, this depends on each part implementing IWorkbenchPart3 if they want to store arbitrary properties

There is also the question of what to do with property change events.  Right now, there are a few defined constants, but they are integers.  That makes it hard for different parts to define arbitrary properties.

One option is to have a mediator that everybody will talk to.  Want your property change id, ask the mediator with your key and it'll give you a number.   The numbers will be consistent for one session, but change between sessions.

With the mediator it might be able to right a base implementation in WorkbenchPart ... but this might be too much overkill.

More anon.

PW
Comment 13 Chris Gross CLA 2007-01-09 17:24:33 EST
It seems strange that the id for the property is a string, but the id for the property event is a int.  Perhaps we could combine them?  Make the property keys be ints?  
Comment 14 Paul Webster CLA 2007-01-09 19:47:12 EST
I thought about making the property keys ints ... but that would make it exceptionally easy for property collision.  With Strings we can have keys tack their plugin id on the front.

I'm gonna stick with Strings for now, but ask some of the other UI committers.  It might be that we just live with constants starting at 0x500, and everybody has to deal with the fact that getProperty(0x500) might return the correct property, a useless String, or null.

PW
Comment 15 Paul Webster CLA 2007-01-13 09:48:37 EST
Another option that avoids dealing with the String to int mapper is to say that all of these properties are user properties, and we'll fire IWorkbenchPartConstants.PROP_USER

Then there's no mapper, but you wouldn't be able to narrow down which user property has changed.

Nick, do you have any opinion about firing the property change event?

PW
Comment 16 Paul Webster CLA 2007-01-13 09:52:01 EST
Of course we could go half way, and just fire the hasCode() for that string key ... it would be consistent within one run of eclipse (but you wouldn't be able to save that int id), and the odds of you checking the incorrect property are very small (but not 0).

PW
Comment 17 Nick Edgar CLA 2007-01-15 11:37:45 EST
Using the hashCode feels like a hack.
In the original design of the presentations mechanism, we deliberately did not provide an open-ended properties mechanism, since that would encourage tight coupling between the presentation and the view/editor implementations.  We felt strongly that parts should be agnostic of which presentation is presenting them.

On the other hand, I do feel that it's nice to have an escape so that use cases that we never envisioned are possible to implement.  Chris' security scenario is definitely a reasonable one, and I know of several RCP apps that require something similar.


Comment 18 Paul Webster CLA 2007-01-15 15:17:07 EST
Created attachment 56930 [details]
part Properties v02

After talking to Nick, here is a draft patch that avoids the int property IDs all together.  Just use JFace PropertyChangeEvents for the arbitrary event set.

This patch still needs some TLC, but it solves the random ID problem and allows me to add a default implementation to WorkbenchPart.

PW
Comment 19 Chris Gross CLA 2007-01-15 15:32:02 EST
Essentially separates the two properties completely.  Sounds good to me.  
Comment 20 Paul Webster CLA 2007-01-16 15:08:25 EST
Created attachment 56982 [details]
part Properties v03

Update javadocs, include view saveState/restoreState.

PW
Comment 21 Paul Webster CLA 2007-01-16 22:09:59 EST
Created attachment 56997 [details]
part Properties v04

Added some extra session tests and improved persistence.

PW
Comment 22 Paul Webster CLA 2007-01-17 08:38:05 EST
Released API and tests >20070117
PW
Comment 23 Paul Webster CLA 2007-02-06 12:27:10 EST
I20070206-0010
PW