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

Bug 109052

Summary: Exposure of workbench part controls to clients
Product: [Eclipse Project] Platform Reporter: amehrega
Component: UIAssignee: Kim Horne <eclipse>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: bokowski, eclipse, hkyleung, Kevin_Haaland, mfaraj, michaelvanmeekeren, sluiman
Version: 3.2   
Target Milestone: 3.2 RC1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 126580    
Attachments:
Description Flags
Candidate plugin none

Description amehrega CLA 2005-09-08 10:19:03 EDT
In order to better enable automated GUI testing in the Eclipse platform, a
public API should be made available that exposes the controls of a workbench
part.  Currently, to get around this, clients need to use three internal APIs:

import org.eclipse.ui.internal.EditorSite;
import org.eclipse.ui.internal.PartPane;
import org.eclipse.ui.internal.PartSite;

The method invocations that allow clients to get the controls of a workbench
part are as follows:

For views:

IViewPart part = ...;
IWorkbenchPartSite site = part.getSite();
PartPane pane = ((PartSite) site).getPane();
Control c = pane.getControl();

For Editors:

IEditorPart part = ...
part .getEditorSite();
PartPane pane = ((EditorSite) site).getPane();
Control c = pane.getControl();

It would be great if the controls of the part were exposed either through the
IWorkbenchPart or IWorkbenchPartSite interface.
Comment 1 Kim Horne CLA 2005-09-09 10:58:55 EDT
You can already do this for your parts.  Workbench parts implement IAdaptable.  You could subclass 
getAdapter() return your part control when asked for the Control adapter.  As a rule we don't want to be 
adding testing methods to commonly used public interfaces. 
Comment 2 amehrega CLA 2005-09-12 10:39:44 EDT
Yes, that would be possible for as long as I have access to the workbench part
code and I could enforce clients to use the version that I would like them to use. 
The reason why I need a public API is because testing tools are expected to work
with any existing view/editor within the Eclipse platform (e.g. such as the
package explorer).

I had a short chat with Kim, and they are unwilling for exposing something like
this (seeing it as something dangerous, which I can understand).  

Harm,

We can either swallow this and go with the internal API usage or we can build a
better argument that convinces the Eclipse folks.
Comment 3 Kim Horne CLA 2005-09-12 10:49:33 EDT
Well, the default implementation of getAdapter() on WorkbenchPart delegates to the platform adapter 
manager.  You don't need direct access to the parts - you could could supply an adapter factory that uses 
the internal API for parts that don't explicitly supply an adapter for Control.
Comment 4 amehrega CLA 2005-09-12 10:59:45 EDT
Thanks for the suggestion Kim but this still doesn't avoid the original problem
for which I opened this defect for (i.e. avoiding internal APIs all together).
Comment 5 Kim Horne CLA 2005-09-12 11:09:34 EDT
Quite right, sorry.  Coffee isn't fully digested yet.
Comment 6 amehrega CLA 2005-09-26 11:16:06 EDT
I spoke with Kevin Haaland about this and he was okay with re-opening this
enhancement with the following changes:

May be there is another approach that could be implemented instead of the
getControl() accessor which I understand has unpleasant side effects that would
enable TPTP to get a testing interface for parts. (e.g. ITestableWorkbenchPart)

It will be great if the adapter that Kim suggested below was provided
internally.  The adapter would be implemented for views and editors and would be
used as follows:

IWorkbenchPart view = [some view]
ITestableWorkbenchPart testableView = (ITestableWorkbenchPart) view.getAdapter
(ITestableWorkbenchPart.class);
Control control = testableView.getControl();


The purpose of the new API (i.e. ITestableWorkbenchPart) would be to verify the
state that a particular editor or view is in.  Many automated GUI recorder tools
include verification mechanisms that allow them to extract specific controls
from a shell to be able to verify that their values equal to expected results.  

For example, to verify the presence of a text box that displays an error in a
view, the recorder will need to:

1) Extract the controls of the view (this is where the new API will be required)
2) Walk through the controls in (1) and find the desired text box
3) Assert that its value is equaled to the expected value specified by the user.

Without the presence of a public API that does step (1), the verification
mechanism will have to resort to internal APIs.
Comment 7 Kim Horne CLA 2005-09-27 10:27:26 EDT
Would it be acceptable if we provided this functionality in a separately downloaded workbench fragment 
(that we would support, of course)?  
Comment 8 amehrega CLA 2005-09-27 13:16:57 EDT
I got a thumbs up from Harm Sluiman about providing this as a separate package
fragment.  If you prefer you can host it in TPTP's CVS for as long as it is
maintained by the Eclipse developers.
Comment 9 Kim Horne CLA 2005-09-28 09:19:48 EDT
Created attachment 27610 [details]
Candidate plugin

Provided is a plugin that provides an adapter on the part SITE (not the part)
for IWorkbenchPartTestable.  The source for the plugin is include.  

Example usage:
ViewPart partToTest = ...;
IWorkbenchPartTestable testable =
(IWorkbenchPartTestable)partToTest.getSite().getAdapter(IWorkbenchPartTestable.class);

Composite partComposite = testable.getControl();

The control returned by getControl() will always be the composite passed to
createView/EditorPart();

We've yet to iron out where this plugin will live in the eclipse ecosystem.
Comment 10 Kim Horne CLA 2005-09-28 09:27:07 EDT
I should also mention that this required a small change to PartSite which I've checked into HEAD.  The 
attached plugin won't work until next weeks integration build unless you want to brave a nightly build or 
play with what's in HEAD..
Comment 11 amehrega CLA 2006-02-07 11:41:04 EST
Kim,

Can we please finalize this defect and determine where the plug-in will be hosted?  
I have a defect that's blocking the release of TPTP because of the internal APIs that I'm forced to use.

Maybe we'll be better off if we can provide this as part of the platform (marked as a provisional API) as opposed to hosting it as a separate download.  The plug-in only has 3 classes and it seems like an overkill to create a completely separate plug-in.  Hosting it as a separate download will cause confusion amongst users and developers (for maintenance and configuration management reasons).

I also noticed that the plug-in never registers its adapter factory with the platform’s adapter manager.  I created a plug-in activator class and added the following to the ‘start’ method of the plug-in:

Platform.getAdapterManager().registerAdapters(new TestableAdapterFactory(), IWorkbenchPartSite.class);


Any how, TPTP requires this to be resolved as soon as possible.
I'll appreciate your quick response.
Comment 12 Kim Horne CLA 2006-02-07 13:28:35 EST
Everyone who can give me answers regarding this issue is currently out of town.  I wouldn't expect that this would be resolved before the API freeze next week.
Comment 13 Kim Horne CLA 2006-02-10 09:40:14 EST
I've talked with MvM and neither of us are comfortable with the idea of putting this into the SDK release.  We don't have enough time to fully consider the implications and today is the last day before the API freeze.  We're willing to host the plug-in on the Platform-UI update site and maintain the source code, however.  We'd also be willing to hand it over to you to include in your builds which might make it easier for you to manage the dependency problem.  In either case we'd be willing to make it a friend of the org.eclipse.ui.internal package in org.eclipse.ui.workbench to clean up plug-in boundary issues.

(Also, you shouldn't have had to add that registration to the bundle activator - the org.eclipse.core.runtime.adapter extension in the plug-in XML should've been sufficient.  You might need to activate the bundle, however, because as I understand it the adapter mechanism is lazy under certain circumstances).

If this is sufficient for your immediate needs we should plan on talking after 3.2 ships to discuss this and whatever other requirements you might have with regard to testing frameworks within the workbench.
Comment 14 amehrega CLA 2006-02-10 10:40:42 EST
Thanks Kim for your quick response.

For now we can have the plugin hosted on Eclipse's CVS (under /cvsroot/eclipse).  Hubert (who does TPTP's builds) has agreed to download the plugin from your CVS using an anonymous account and build it as part of TPTP's build.  At least this way, we'll be able to keep the user unaware of the extra Eclipse plugin needed.

For Hubert to build the plug-in successfully, he needs to also have a *feature* included with the plug-in.  Please include both a feature and the plug-in under your CVS.

Comment 15 Kim Horne CLA 2006-02-10 13:14:57 EST
I've checked the source for the plug-in and accompanying feature into CVS.  they may be found at

dev.eclipse.org/cvsroot/eclipse/platform-ui-home/testing/org.eclipse.ui.testing
dev.eclipse.org/cvsroot/eclipse/platform-ui-home/testing/org.eclipse.ui.testing-feature

Please let me know if this is okay. 
Comment 16 amehrega CLA 2006-04-03 16:42:12 EDT
The plug-in is working fine.
Thanks Kim for following upon this.  You can go ahead with closing this enhancement
Comment 17 Kim Horne CLA 2006-04-03 16:44:17 EDT
Will verify at our end for RC1.
Comment 18 Kim Horne CLA 2006-09-19 10:27:22 EDT
Finally marking as verified.  My bad.