Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Label Decorators Trace - Common Navigator for Xtext-based Project(Label Decorator Trace disappears in custom CNF)
Label Decorators Trace - Common Navigator for Xtext-based Project [message #915999] Tue, 18 September 2012 11:35
Sandra Shklyaeva is currently offline Sandra ShklyaevaFriend
Messages: 16
Registered: July 2012
Junior Member
I am developing custom common navigator for my Xtext-based Project.
I use Eclipse Common Navigator Framework as usual.
To define I do the following:

 <extension
       point="org.eclipse.ui.navigator.viewer">
    <viewerContentBinding
          viewerId="org.eclipse.ui.navigator.ProjectExplorer">
       <includes>
          <contentExtension
                pattern="com.mydsl.ui.navigator.MyDslNavigator">
          </contentExtension>
       </includes>
    </viewerContentBinding>
 </extension>
 <extension
       point="org.eclipse.ui.navigator.navigatorContent">
    <navigatorContent
          activeByDefault="true"
          appearsBefore="org.eclipse.ui.navigator.resourceContent"
          contentProvider="com.mydsl.ui.navigator.MyDslNavigatorContentProvider"
          icon="icons/maple-icon.png"
          id="com.mydsl.ui.navigator.MyDslNavigator"
          labelProvider="com.mydsl.ui.navigator.MyDslNavigatorLabelProvider"
          name="MyDsl Project"
          priority="higher">
          	<triggerPoints>
				<or>
       <adapt
             type="org.eclipse.core.resources.IProject">
       </adapt>
       <adapt
             type="org.eclipse.core.resources.IResource">
       </adapt>
     <adapt
           type="org.eclipse.core.resources.IFolder">
     </adapt>
     <adapt
           type="org.eclipse.core.resources.IFile">
     </adapt>
 				</or>
			</triggerPoints>
           <possibleChildren>
              <or>
                 <adapt
                       type="org.eclipse.core.resources.IProject">
                 </adapt>
                 <adapt
                       type="org.eclipse.core.resources.IResource">
                 </adapt>
                 <adapt
                       type="org.eclipse.core.resources.IFolder">
                 </adapt>
                 <adapt
                       type="org.eclipse.core.resources.IFile">
                 </adapt>
              </or>
           </possibleChildren>
           </actionProvider>   
    </navigatorContent>
 </extension>


In the MyDslNavigatorLabelProvider I want to apply custom icons for folders using getImage(Object element).

If I just return image from the super implementation of the method, decorators (errors, warnings) work as expected:

index.php/fa/11539/0/

	public Image getImage(Object element) {
		return super.getImage(element);
	}


If I return custom icons for folders, decorators trace disappear:

index.php/fa/11540/0/

	public Image getImage(Object element) {
if(element instanceof IFolder){
return Images.MY_ICON.createImage();
}
	return super.getImage(element);	
	}


I tried to dig deeper and found implementation of LabelProvider (DecoratingLabelProvider) for ResourceNavigator.
So, I copied getImage() from DecoratingLabelProvider.


private ILabelDecorator decorator;

	public MyDslNavigatorLabelProvider() {
		this.decorator = PlatformUI.getWorkbench().getDecoratorManager()
				.getLabelDecorator();
	}

public Image getImage(Object element) {
		Image image = super.getImage(element);
		System.out.println(element.getClass().toString());
		if (decorator != null) {
			System.out.println("I AM HERE");
			if (decorator instanceof LabelDecorator) {
				System.out.println("I AM LabelDecorator");
				LabelDecorator ld2 = (LabelDecorator) decorator;
				Image decorated = ld2.decorateImage(image, element,
						DecorationContext.DEFAULT_CONTEXT);
				if (decorated != null) {
					System.out.println("I AM NOT NULL");
					return decorated;
				}
			} else {
				System.out.println("I AM NOT LabelDecorator");
				Image decorated = decorator.decorateImage(image, element);
				if (decorated != null) {
					System.out.println("I AM NOT NULL");
					return decorated;
				}
			}
		}
		System.out.println("I AM NULL");
		return Images.MY_ICON.createImage();
	}


Finally, I found that I always go to "I AM LabelDecorator" sysout and decorated image is always NULL and there is still no decorators.

What I am doing wrong?
Probably Xtext has custom LabelProvider for Common Navigator that I can implement and bind.

Regards,
Sandra
  • Attachment: exists.png
    (Size: 3.90KB, Downloaded 654 times)
  • Attachment: disappear.png
    (Size: 4.68KB, Downloaded 650 times)
Previous Topic:How to embed new line character in string in xtend?
Next Topic:Spell checking in Xdoc
Goto Forum:
  


Current Time: Thu Dec 18 10:42:35 GMT 2014

Powered by FUDForum. Page generated in 0.02936 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software