| /***************************************************************************** |
| * Copyright (c) 2020 CEA LIST. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are property of the CEA, their use is subject to specific agreement |
| * with the CEA. |
| * |
| * Project: Papyrus Robotics |
| * |
| * Contributors: |
| * CEA LIST - Initial API and implementation |
| * |
| *****************************************************************************/ |
| /* com.cea.sophia.fha.table.config.provider PartHeaderLabelProvider.java */ |
| |
| package org.eclipse.papyrus.robotics.safety.riskanalysis.table; |
| |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; |
| import org.eclipse.papyrus.infra.emf.nattable.provider.EMFEObjectHeaderLabelProvider; |
| import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EObjectAxis; |
| import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis; |
| import org.eclipse.papyrus.infra.nattable.model.nattable.nattablelabelprovider.ILabelProviderConfiguration; |
| import org.eclipse.papyrus.infra.nattable.model.nattable.nattablelabelprovider.ObjectLabelProviderConfiguration; |
| import org.eclipse.papyrus.infra.nattable.utils.ILabelProviderContextElementWrapper; |
| import org.eclipse.papyrus.infra.nattable.utils.LabelProviderCellContextElementWrapper; |
| import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; |
| import org.eclipse.uml2.uml.Class; |
| import org.eclipse.uml2.uml.Property; |
| |
| |
| |
| /** |
| * |
| * PartHeaderLabelProvider Class is dedicated exclusively to customizing the |
| * header label of the Function that have Hazardous Events in a HARA Table. |
| * |
| */ |
| public class PartHazardAnalysisHeaderLabelProvider extends EMFEObjectHeaderLabelProvider { |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.papyrus.infra.emf.nattable.provider. |
| * EMFEObjectHeaderLabelProvider#accept(java.lang.Object) |
| */ |
| @Override |
| public boolean accept(Object element) { |
| if (element instanceof ILabelProviderContextElementWrapper) { |
| Object object = ((ILabelProviderContextElementWrapper) element).getObject(); |
| if (object instanceof IAxis) { |
| object = ((IAxis) object).getElement(); |
| } |
| if (object instanceof Property) { |
| return ((Property) object) |
| .getAppliedStereotype("TaskBasedRiskAnalysis::HazardAnalysis") != null; |
| } |
| } |
| return false; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.papyrus.infra.emf.nattable.provider. |
| * EMFEObjectHeaderLabelProvider#getText(java.lang.Object) |
| */ |
| @Override |
| public String getText(Object element) { |
| ILabelProviderContextElementWrapper context = (ILabelProviderContextElementWrapper) element; |
| EObject object = (EObject) ((ILabelProviderContextElementWrapper) element).getObject(); |
| if (object instanceof EObjectAxis) { |
| object = ((EObjectAxis) object).getElement(); |
| } |
| final IConfigRegistry configRegistry = context.getConfigRegistry(); |
| final LabelProviderService serv = getLabelProviderService(configRegistry); |
| ILabelProviderConfiguration conf = null; |
| if (element instanceof LabelProviderCellContextElementWrapper) { |
| conf = getLabelConfiguration((LabelProviderCellContextElementWrapper) element); |
| } |
| if (conf instanceof ObjectLabelProviderConfiguration |
| && !((ObjectLabelProviderConfiguration) conf).isDisplayLabel()) { |
| return ""; //$NON-NLS-1$ |
| } |
| |
| String label = ""; //$NON-NLS-1$ |
| if (object instanceof Property) { |
| object = object.eContainer(); |
| if (object instanceof Property) { |
| label = ((Property) object).getType().getName() + ":" + serv.getLabelProvider(object).getText(object); //$NON-NLS-1$ |
| } else if (object instanceof Class) { |
| label = serv.getLabelProvider(object).getText(object); |
| } |
| } |
| |
| return label; |
| } |
| |
| } |