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

Bug 346608

Summary: Usage of ItemProvider of AbstractDiffExtension should be possible
Product: [Modeling] EMFCompare Reporter: Mikaël Barbero <mikael.barbero>
Component: CoreAssignee: EMF Compare <emf.compare-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: laurent.goubet, mikael.barbero
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

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.