Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 230842 - [Help] new Toc(IToc ...) does not copy over the linkTo field
Summary: [Help] new Toc(IToc ...) does not copy over the linkTo field
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: User Assistance (show other bugs)
Version: 3.3.2   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: 3.5 M6   Edit
Assignee: platform-ua-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-07 05:13 EDT by James Blackburn CLA
Modified: 2009-02-11 14:16 EST (History)
1 user (show)

See Also:


Attachments
Patch to setLinkTo when IToc is converted to Toc in TocManager (980 bytes, patch)
2008-05-08 03:39 EDT, James Blackburn CLA
cgold: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description James Blackburn CLA 2008-05-07 05:13:45 EDT
Build ID: 3.3.2 (and seems to also still be broken in HEAD)

Steps To Reproduce:
As described in this News Posting:
http://dev.eclipse.org/newslists/news.eclipse.platform.ua/msg00176.html
(I couldn't find a bug filed...)

The LinkTo field is not copied over when the IToc is converted to a Toc in TocManager.java:211
IToc toc = contrib[j].getToc();
contribution.setToc(toc instanceof Toc ? (Toc)toc : (Toc)UAElementFactory.newElement(toc));
contributions.add(contribution);

The Toc constructor does this:
	public Toc(IToc src) {
		super(NAME, src);
		setHref(src.getHref());
		setLabel(src.getLabel());
		ITopic topic = src.getTopic(null);
		if (topic != null) {
			setTopic(topic.getHref());
		}
		appendChildren(src.getChildren());
	}

It should probably also have a setLinkTo(src.getLinkTo()) as well.

More information:
The workaround for integrators is to have, in their ITocContribution implementation:


	public IToc getToc() {
		Toc t =  new Toc(...);
		t.setLinkTo(getLinkTo());
		return t;
	}

but this requires referencing internal classes
Comment 1 Chris Goldthorpe CLA 2008-05-07 13:01:48 EDT
I agree that this was an oversight and easy to fix. I will target RC1 for this bug because it is incorrectly functioning API and is easy to fix.
Comment 2 Chris Goldthorpe CLA 2008-05-07 14:05:56 EDT
This is not as easy to fix as I had first though, IToc does not have a getLinkTo() function. Fixing this will have to wait until Eclipse 3.5.
Comment 3 James Blackburn CLA 2008-05-08 03:39:53 EDT
Created attachment 99230 [details]
Patch to setLinkTo when IToc is converted to Toc in TocManager

Woops, as my class implemented both IToc and ITocContribution, must have missed setLinkTo in IToc...

Attached is a patch containing an alternative solution -- setLinkTo when the Toc is created by TocManager.
Comment 4 Chris Goldthorpe CLA 2008-12-29 16:54:24 EST
I'm looking at fixing this bug for the next milestone. In order to fix this in a way that allows user to use only API classes (org.eclipse.help.internal.toc.Toc is internal) the API needs to be extended slightly. We have a similar situation with the new "icon" attricute in Toc and Topic and more attributes could be added in the future. 

My proposal is to create a new interface IUAElement2 which would allow access to the attributes. If your class which implemented IToc also implements IUAElement2 then the link_to attribute will get copied. Would this solution work for you?

Here's what the new interface would look like.

package org.eclipse.help;

/**
 * Interface which extends IUAElement to allow access to attributes. This
 * enables copy operations to preserve all attributes when user defined 
 * classes are used to implement IToc etc.
 */

public interface IUAElement2 extends IUAElement {
	
	/**
	 * @param name the name of the attribute
	 * @return the attribute value, or if the attribute is undefined the empty string.
	 */
	String getAttribute(String name);

}
Comment 5 Chris Goldthorpe CLA 2009-02-11 14:16:49 EST
The patch is good, I committed the patch and added a new JUnit test to verify the behavior.