From cbb41e4344772c8a147fdd6ebe12764e582baf81 Mon Sep 17 00:00:00 2001 From: Maxime Porhel Date: Thu, 4 Apr 2024 14:01:13 +0200 Subject: [PATCH] #121 Avoid NPE for transitions launched from a Capella model without project This can occur when the project is a Team for Capella connected project for example. --- .../FilteredOutputModelRenderer.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plugins/org.polarsys.capella.transition.system2subsystem.ui/src/org/polarsys/capella/transition/system2subsystem/ui/preferences/FilteredOutputModelRenderer.java b/plugins/org.polarsys.capella.transition.system2subsystem.ui/src/org/polarsys/capella/transition/system2subsystem/ui/preferences/FilteredOutputModelRenderer.java index 82e6294e..fb79041e 100644 --- a/plugins/org.polarsys.capella.transition.system2subsystem.ui/src/org/polarsys/capella/transition/system2subsystem/ui/preferences/FilteredOutputModelRenderer.java +++ b/plugins/org.polarsys.capella.transition.system2subsystem.ui/src/org/polarsys/capella/transition/system2subsystem/ui/preferences/FilteredOutputModelRenderer.java @@ -1,5 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2022, 2024 THALES GLOBAL SERVICES. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Thales - initial API and implementation + *******************************************************************************/ package org.polarsys.capella.transition.system2subsystem.ui.preferences; +import java.util.Optional; + import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.emf.ecore.resource.Resource; @@ -19,15 +33,15 @@ public class FilteredOutputModelRenderer extends OutputModelRenderer { class NoSourceProjectViewerFilter extends ViewerFilter { - private IProject toFilterCapellaProject; + private Optional toFilterCapellaProject; public NoSourceProjectViewerFilter(Resource toFilterCapellaProject) { - this.toFilterCapellaProject = EcoreUtil2.getFile(toFilterCapellaProject).getProject(); + this.toFilterCapellaProject = Optional.ofNullable(EcoreUtil2.getFile(toFilterCapellaProject)).map(f -> f.getProject()); } @Override public boolean select(Viewer viewer, Object parentElement, Object element) { - return element instanceof IResource && !this.toFilterCapellaProject.equals(element); + return element instanceof IResource && !(this.toFilterCapellaProject.isPresent() && this.toFilterCapellaProject.get().equals(element)); } }