Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 346608 - Usage of ItemProvider of AbstractDiffExtension should be possible
Summary: Usage of ItemProvider of AbstractDiffExtension should be possible
Status: CLOSED FIXED
Alias: None
Product: EMFCompare
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: EMF Compare CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-20 05:05 EDT by Mikaël Barbero CLA
Modified: 2011-05-23 10:36 EDT (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 Mikaël Barbero CLA 2011-05-20 05:05:47 EDT
I'd like to define the label/image of my AbstractDiffExtension within their generated ItemProvider, but it seems it is impossible. Here is a possible workaround: 

Generated AbstractDiffExtension subclasses should return null on call to getText() getImage() (manual change in the generated code) and the ModelStructureLabelProvider of ModelStructureMergeViewer should be changed to :

@Override
public Image getImage(Object object) {
	Image image = null;
	if (object instanceof AbstractDiffExtension) {
		image = (Image)((AbstractDiffExtension)object).getImage();
	} else if (object instanceof IFile) {
		image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
	} 

	// fallback to ItemProvider	
	if (image == null) {
		image = adapterProvider.getImage(object);
	}
	
	return image;
}

@Override
public String getText(Object object) {
	String text = null;
	if (object instanceof AbstractDiffExtension) {
		text = ((AbstractDiffExtension)object).getText();
	} else if (object instanceof IFile) {
		text = ((IFile)object).getName();
	} else if (object instanceof Resource) {
		text = ((Resource)object).getURI().lastSegment();
	}
	
	// fallback to ItemProvider
	if (text == null || "".equals(text)) { //$NON-NLS-1$
		text = adapterProvider.getText(object);
	}

	return text;
}

It does not change the behavior of existing code, it just change the logic to fallback to the ItemProvider instead of returning <null>.
Comment 1 Laurent Goubet CLA 2011-05-23 10:36:50 EDT
Changing the generated code can not be done as it simply is what EMF does (you generate the code of a "derived" reference, you have to manually code it; by default it throws an UnsupportedOperationException.) and changing it now would break the contract of this API.

As for the rest, the ModelStructureMergeViewer now properly falls back to the adapter factory.