Bug 232268 - [Viewers] TreeViewer and TableViewer have to be subclassable
Summary: [Viewers] TreeViewer and TableViewer have to be subclassable
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-15 06:37 EDT by Martin Aeschlimann CLA
Modified: 2022-01-11 16:47 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2008-05-15 06:37:21 EDT
3.4 I20080513-2000

TreeViewer and TableViewer are marked as 'This class is not intended to be subclassed by clients.'

Maybe this was always marked as this and I never realized, but it dosen't make sense to have this restriction. There are also at least 20 subtypes of TreeViewer in SDK alone.

One reason to subclass the viewers is to implement
  protected void handleLabelProviderChanged(LabelProviderChangedEvent event)

Label changes are broadcasted in terms of resources, but the viewer might show model elements like Java elements and has to do a mapping to evaluate the elements to update.

Other use cases are fine tuning of
protected void handleInvalidSelection(...) 

See the CommonViewer for more use cases.
Comment 1 Boris Bokowski CLA 2008-05-15 10:12:41 EDT
(In reply to comment #0)
> Maybe this was always marked as this and I never realized

Yes it was always marked like this. :-)
Comment 2 Dani Megert CLA 2008-10-21 08:30:06 EDT
Boris, any chance we get this for 3.5? Every class in the TableViewer hierarchy allows subclassing except ColumnViewer and TableViewer. I can understand this for the ColumnViewer which is an implementation detail but subclassing TableViewer is really needed.

NOTE: ColumnViewer is missing the correct API tooling tags.
Comment 3 Boris Bokowski CLA 2008-10-21 14:13:51 EDT
The problem with this is, while I realize that there are advanced use cases that currently require subclassing, I don't want to encourage clients to create subclasses gratuitously. For example, the Javadoc for TableViewer does not explain the interface for subclassers.

It would be easier for me to say yes to a more narrow API. How about something like this:

TableViewer.setViewerStrategy(ViewerStrategy strategy)

public abstract class ViewerStrategy {
  protected ... handleLabelProviderChanged(...);
  protected ... handleInvalidSelection(...)
}

How many methods are we talking about? How much control over what happens do you need in methods like handleInvalidSelection (firing of events?) - would you be able to move what you are doing today into a separate class without access to protected methods?
Comment 4 Dani Megert CLA 2008-10-22 10:32:29 EDT
There are lots of methods: look e.g. at org.eclipse.jdt.internal.ui.browsing.PackagesViewTableViewer and all its super classes in the hierarchy. org.eclipse.search.internal.ui.SearchResultViewer is even worse. The strategy also has performance impacts as it introduces indirections.

TreeViewer has many more subclasses than TableViewer and each of them overrides/extends other features i.e. the strategy will be quite big.

I think we can't expect that all the owners of those classes go and refactor their code, so I guess either we open up the Tree/TableViewer or we say no and clients will most likely live with that fact and see the warning in their code.
Comment 5 Remy Suen CLA 2008-10-30 06:12:20 EDT
Per bug 234345 comment 4, please extend this discussion to include the protected internalRefresh(Widget, Object, boolean, boolean) and the internalRemove(Object[]) methods in AbstractTreeViewer (which is not marked with @noextend) that are currently tagged with:

"EXPERIMENTAL. Not to be used except by JDT. This method was added to support JDT's explorations into grouping by working sets, which requires viewers to support multiple equal elements. See bug 76482 for more details. This support will likely be removed in Eclipse 3.2 in favor of proper support for multiple equal elements."

I myself am pretty neutral about this topic since the generic viewers have been "good enough" for me so far. We did have somebody on IRC a few weeks ago express the desire to subclass TreeViewer and I couldn't really give a good response to that outside of saying "the javadocs says you shouldn't do that".
Comment 6 Boris Bokowski CLA 2009-11-26 09:46:47 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 7 Eclipse Webmaster CLA 2019-09-06 16:11:11 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.
Comment 8 Eclipse Genie CLA 2022-01-11 16:47:57 EST
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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.