/******************************************************************************* | |
* Copyright (c) 2016 Fundación Tecnalia Research & Innovation. | |
* | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v2.0 | |
* which accompanies this distribution, and is available at | |
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html | |
* | |
* SPDX-License-Identifier: EPL-2.0 | |
* | |
* Contributors: | |
* Huascar Espinoza - initial API and implementation | |
* Alejandra Ruíz - initial API and implementation | |
* Idoya Del Río - initial API and implementation | |
* Mari Carmen Palacios - initial API and implementation | |
* Angel López - initial API and implementation | |
*******************************************************************************/ | |
/* | |
* | |
*/ | |
package org.eclipse.opencert.pkm.refframework.refframework.diagram.sheet; | |
import org.eclipse.core.runtime.IAdaptable; | |
import org.eclipse.gmf.runtime.emf.type.core.IElementType; | |
import org.eclipse.gmf.runtime.notation.View; | |
import org.eclipse.jface.viewers.BaseLabelProvider; | |
import org.eclipse.jface.viewers.ILabelProvider; | |
import org.eclipse.jface.viewers.IStructuredSelection; | |
import org.eclipse.swt.graphics.Image; | |
import org.eclipse.opencert.pkm.refframework.refframework.diagram.navigator.RefframeworkNavigatorGroup; | |
import org.eclipse.opencert.pkm.refframework.refframework.diagram.part.RefframeworkVisualIDRegistry; | |
import org.eclipse.opencert.pkm.refframework.refframework.diagram.providers.RefframeworkElementTypes; | |
/** | |
* @generated | |
*/ | |
public class RefframeworkSheetLabelProvider extends BaseLabelProvider implements | |
ILabelProvider { | |
/** | |
* @generated | |
*/ | |
public String getText(Object element) { | |
element = unwrap(element); | |
if (element instanceof RefframeworkNavigatorGroup) { | |
return ((RefframeworkNavigatorGroup) element).getGroupName(); | |
} | |
IElementType etype = getElementType(getView(element)); | |
return etype == null ? "" : etype.getDisplayName(); | |
} | |
/** | |
* @generated | |
*/ | |
public Image getImage(Object element) { | |
IElementType etype = getElementType(getView(unwrap(element))); | |
return etype == null ? null : RefframeworkElementTypes.getImage(etype); | |
} | |
/** | |
* @generated | |
*/ | |
private Object unwrap(Object element) { | |
if (element instanceof IStructuredSelection) { | |
return ((IStructuredSelection) element).getFirstElement(); | |
} | |
return element; | |
} | |
/** | |
* @generated | |
*/ | |
private View getView(Object element) { | |
if (element instanceof View) { | |
return (View) element; | |
} | |
if (element instanceof IAdaptable) { | |
return (View) ((IAdaptable) element).getAdapter(View.class); | |
} | |
return null; | |
} | |
/** | |
* @generated | |
*/ | |
private IElementType getElementType(View view) { | |
// For intermediate views climb up the containment hierarchy to find the one associated with an element type. | |
while (view != null) { | |
int vid = RefframeworkVisualIDRegistry.getVisualID(view); | |
IElementType etype = RefframeworkElementTypes.getElementType(vid); | |
if (etype != null) { | |
return etype; | |
} | |
view = view.eContainer() instanceof View ? (View) view.eContainer() | |
: null; | |
} | |
return null; | |
} | |
} |