/**
 * This program and the accompanying materials
 * are made available under the terms of the License
 * which accompanies this distribution in the file LICENSE.txt
 */
package com.archimatetool.editor.propertysections;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.graphics.Image;

import com.archimatetool.editor.ui.ArchiLabelProvider;
import com.archimatetool.editor.utils.StringUtils;
import com.archimatetool.model.IArchimateConcept;



/**
 * Properties Label Provider
 * 
 * @author Phillip Beauvoir
 */
public class PropertiesLabelProvider implements ILabelProvider {

    @Override
    public Image getImage(Object object) {
        if(!(object instanceof IStructuredSelection)) {
            return null;
        }
        
        object = ((IStructuredSelection)object).getFirstElement();
        
        if(object instanceof IAdaptable) {
            object = ((IAdaptable)object).getAdapter(object.getClass());
        }
        
        return ArchiLabelProvider.INSTANCE.getImage(object);
    }

    @Override
    public String getText(Object object) {
        if(!(object instanceof IStructuredSelection)) {
            return " "; //$NON-NLS-1$
        }
        
        object = ((IStructuredSelection)object).getFirstElement();
        
        if(object instanceof IAdaptable) {
            object = ((IAdaptable)object).getAdapter(object.getClass());
        }

        object = ArchiLabelProvider.INSTANCE.getWrappedElement(object);
        
        // An Archimate Concept is a special text
        if(object instanceof IArchimateConcept) {
            return getArchimateConceptText((IArchimateConcept)object);
        }

        // Check the main label provider
        String text = ArchiLabelProvider.INSTANCE.getLabel(object);
        
        return normalise(text);
    }
    
    String getArchimateConceptText(IArchimateConcept archimateConcept) {
        String name = normalise(archimateConcept.getName());
        
        String typeName = ArchiLabelProvider.INSTANCE.getDefaultName(archimateConcept.eClass());
        
        if(StringUtils.isSet(name)) {
            return name + " (" + typeName + ")"; //$NON-NLS-1$ //$NON-NLS-2$
        }
        
        return typeName;
    }
    
    private String normalise(String text) {
        if(StringUtils.isSet(text)) {
            // Remove Ampersands as well as newlines
            return StringUtils.normaliseNewLineCharacters(StringUtils.escapeAmpersandsInText(text));
        }
        
        return " "; // Ensure the title bar is displayed //$NON-NLS-1$
    }
    
    @Override
    public void addListener(ILabelProviderListener listener) {
    }

    @Override
    public void dispose() {
    }

    @Override
    public boolean isLabelProperty(Object element, String property) {
        return false;
    }

    @Override
    public void removeListener(ILabelProviderListener listener) {
    }

}

@@ -2002,34 +2002,66 @@
 );%0D%0A        
-%0D%0A
+if(StringUtils.isSet(text)) %7B%0D%0A   
         
 return norma
@@ -2040,32 +2040,33 @@
 ) %7B%0D%0A           
+ 
 return normalise
@@ -2070,24 +2070,117 @@
 ise(text);%0D%0A
+        %7D%0D%0A        %0D%0A        return %22 %22; // Ensure the title bar is displayed //$NON-NLS-1$%0D%0A
     %7D%0D%0A    %0D
@@ -2619,146 +2619,113 @@
     
-private String normalise(String text) %7B%0D%0A        if(StringUtils.isSet(text)) %7B%0D%0A            // Remove Ampersands as well as newlines%0D%0A    
+/**%0D%0A     * Remove Ampersands as well as newlines%0D%0A     */%0D%0A    private String normalise(String text) %7B%0D%0A
     
@@ -2822,101 +2822,8 @@
 );%0D%0A
-        %7D%0D%0A        %0D%0A        return %22 %22; // Ensure the title bar is displayed //$NON-NLS-1$%0D%0A
     

Normalise object text fix PropertiesLabelProvider