Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-ui-dev] Question about JFace, wrapped objects, and objectContributions

Hi everybody.  I have a question about the interaction of
objectContributions and selections when dealing with custom models
managed through JFace.  My apologies if this isn't seen as appropriate
for this list, but it seemed that there is a deeper issue here.

I'm using a JFace TreeViewer to provide a view on a model.  As my
model doesn't directly correspond to a tree, I've created a projection
of the model using a structure similar to the TreeParent / TreeObject
as provided by the JFace generated templates.  I've modified my
LabelProvider to unwrap these objects appropriately.

My problem is this: although my wrappers are an internal thing,
meant only to impose a structure, they are bleeding through, becoming
the actual objects exposed to the workbench.  As a result, some of
the workbench's objectContributions are not being properly applied,
such as when building context menus.

For example, some of my model objects are actually JDT IJavaElements.
But because the JDT objectContributions don't specify "adaptable=true"
(e.g. org.eclipse.jdt.internal.ui.compare.JavaReplaceActions and
org.eclipse.jdt.internal.ui.compare.JavaCompareActions), they never
appear in the context menus, even when the wrappers can be adapted.
I think they should apply as my wrapper objects exist only to
support imposing a viewing structure; the `real' objects are the
model objects.

I can't return the actual model objects (e.g. the IJavaElements),
as they may occur multiple places in my model (which causes problems
with implementing ITreeContentProvider.getParent()).

I see three solutions to this problem, but I'm hoping there is a
better way?

 1. My hacked solution for the moment is to explicitly call
    ObjectActionContributorManager.contributeObjectActions() in in
    my menuAboutToShow(IMenuManager) callback and provide an
    explicitly unwrapped selection.  This solves the immediate
    problem, but it's an undesirable, short-term solution.

 2. Subclass TreeViewer and override the getSelection() to do the
    rewrapping.  This seems the better immediate option, but I'm
    not sure about the consequences, and the same problem will occur
    with other types of structured viewers.

 3. Add another level of indirection with an additional method to
    IStructuredContentProvider.getModelObject(), called appropriately?

I apologize if this has been discussed before, but I couldn't find
anything appropriate.

Brian.

-- 
  Brian de Alwis | Software Practices Lab | UBC | http://www.cs.ubc.ca/~bsd/
"There is much pleasure to be gained in useless knowledge." - Bertrand Russell


Back to the top