diff --git a/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/actions/FilteringProjectContentsLocationArea.java b/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/actions/FilteringProjectContentsLocationArea.java new file mode 100644 index 00000000..19f2b1b0 --- /dev/null +++ b/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/actions/FilteringProjectContentsLocationArea.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2020 THALES GLOBAL SERVICES. + * All rights reserved. This program and the accompanying materials + * are 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: + * Thales - initial API and implementation + *******************************************************************************/ +package org.polarsys.capella.filtering.tools.actions; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.ISelectionService; +import org.eclipse.ui.PlatformUI; +import org.polarsys.capella.common.helpers.EcoreUtil2; +import org.polarsys.capella.core.platform.sirius.ui.project.internal.CapellaProjectContentsLocationArea; + +public class FilteringProjectContentsLocationArea extends CapellaProjectContentsLocationArea { + + public FilteringProjectContentsLocationArea(IErrorMessageReporter reporter, Composite composite) { + super(reporter, composite); + } + + @Override + public String checkValidLocation() { + String isValid = super.checkValidLocation(); + if(isValid == null) { + IProject project = getSelectedProject(); + if(project != null) { + String selectedPrjloc = project.getLocation().toOSString(); + String trgtPrjLoc = getProjectLocation(); + if(trgtPrjLoc.startsWith(selectedPrjloc)) { + return "Generation is not allowed inside the source project"; + } + } + } + return isValid; + } + + private IProject getSelectedProject() { + ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService(); + ISelection sel = selectionService.getSelection("capella.project.explorer"); + Object selectedObject = sel; + if (sel instanceof IStructuredSelection) { + selectedObject = ((IStructuredSelection) sel).getFirstElement(); + if(selectedObject instanceof EObject) { + return EcoreUtil2.getProject((EObject)selectedObject); + } + else if (selectedObject instanceof IAdaptable) { + IResource res = (IResource) ((IAdaptable) selectedObject).getAdapter(IResource.class); + return res.getProject(); + } + } + return null; + } +} diff --git a/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/actions/FilteringProjectWizard.java b/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/actions/FilteringProjectWizard.java index dfebae32..d0108d8e 100644 --- a/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/actions/FilteringProjectWizard.java +++ b/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/actions/FilteringProjectWizard.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018 THALES GLOBAL SERVICES. + * Copyright (c) 2018, 2020 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -41,7 +41,6 @@ import org.polarsys.capella.common.tools.report.util.IReportManagerDefaultComponents; import org.polarsys.capella.core.data.capellacore.NamedElement; import org.polarsys.capella.core.model.handler.helpers.CapellaProjectHelper.ProjectApproach; -import org.polarsys.capella.core.platform.sirius.ui.project.internal.CapellaProjectContentsLocationArea; import org.polarsys.capella.core.platform.sirius.ui.project.internal.ProjectContentsLocationArea; import org.polarsys.capella.core.platform.sirius.ui.project.internal.WizardNewProjectCreationPage; import org.polarsys.capella.core.platform.sirius.ui.project.operations.ProjectSessionCreationHelper; @@ -108,7 +107,7 @@ protected WizardNewProjectCreationPage createLocalProjectDescriptionPage() { */ @Override protected ProjectContentsLocationArea handleDefaultProjectLocation(Composite parent) { - return new CapellaProjectContentsLocationArea(getErrorReporter(), parent); + return new FilteringProjectContentsLocationArea(getErrorReporter(), parent); } /**