/*******************************************************************************
 * Copyright (c) 2011 Red Hat, Inc.
 *  All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Red Hat, Inc. - initial API and implementation
 *
 * @author Bob Brodt
 ******************************************************************************/

package org.eclipse.bpmn2.modeler.ui.property;

import org.eclipse.bpmn2.BaseElement;
import org.eclipse.bpmn2.Process;
import org.eclipse.bpmn2.di.BPMNDiagram;
import org.eclipse.bpmn2.modeler.core.features.AbstractBpmn2CreateConnectionFeature;
import org.eclipse.bpmn2.modeler.core.features.AbstractBpmn2CreateFeature;
import org.eclipse.bpmn2.modeler.core.utils.ModelUtil;
import org.eclipse.bpmn2.modeler.core.utils.PropertyUtil;
import org.eclipse.bpmn2.modeler.ui.diagram.BPMNFeatureProvider;
import org.eclipse.bpmn2.modeler.ui.editor.BPMN2Editor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.features.IFeature;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.ui.services.GraphitiUi;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

/**
 * @author Bob Brodt
 *
 */
public class PropertyLabelProvider extends LabelProvider {

	@Override
	public Image getImage(Object element) {
		EObject be = PropertyUtil.getBusinessObjectForSelection((ISelection)element);
        BPMN2Editor editor = BPMN2Editor.getEditor( be );
        
        if (editor!=null) {
		    BPMNFeatureProvider fp = (BPMNFeatureProvider)editor.getDiagramTypeProvider().getFeatureProvider();
			PictogramElement pe = PropertyUtil.getPictogramElementForSelection((ISelection)element);
		    IFeature cf = fp.getCreateFeatureForPictogramElement(pe);
			if (cf instanceof AbstractBpmn2CreateFeature) {
				return GraphitiUi.getImageService().getImageForId(
						((AbstractBpmn2CreateFeature)cf).getCreateImageId());
			}
			if (cf instanceof AbstractBpmn2CreateConnectionFeature) {
				return GraphitiUi.getImageService().getImageForId(
						((AbstractBpmn2CreateConnectionFeature)cf).getCreateImageId());
			}
        }
		return super.getImage(element);
	}

	@Override
	public String getText(Object element) {
		EObject be = PropertyUtil.getBusinessObjectForSelection((ISelection)element);
		if (be!=null) {
			BaseElement bpmnElement = ((BPMNDiagram)be).getPlane().getBpmnElement();
			if (bpmnElement instanceof Process) {
				be = bpmnElement;
			}
			return ModelUtil.getDisplayName(be);
		}
		return super.getText(element);
	}
}

@@ -2590,16 +2590,54 @@
 ull) %7B%0D%0A
+%09%09%09if (be instanceof BPMNDiagram) %7B%0D%0A%09
 %09%09%09BaseE
@@ -2704,24 +2704,25 @@
 ment();%0D%0A%09%09%09
+%09
 if (bpmnElem
@@ -2752,16 +2752,17 @@
  %7B%0D%0A%09%09%09%09
+%09
 be = bpm
@@ -2772,16 +2772,23 @@
 ement;%0D%0A
+%09%09%09%09%7D%0D%0A
 %09%09%09%7D%0D%0A%09%09

Fix class cast exception bug in PropertyLabelProvider, introduced with previous commit