Skip to content

Commit

Permalink
[565568] [Filtering]Performing a derivation having as target a folder in
Browse files Browse the repository at this point in the history
the source project causes an infinite loop

Bug 565568

Change-Id: I3127556c19503e22b4610dc19419d9afc4792df5
Signed-off-by: Ali AKAR <[email protected]>
  • Loading branch information
aliakar82 authored and minhtutonthat committed Aug 6, 2020
1 parent db5fba1 commit 8b7fbbf
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -108,7 +107,7 @@ protected WizardNewProjectCreationPage createLocalProjectDescriptionPage() {
*/
@Override
protected ProjectContentsLocationArea handleDefaultProjectLocation(Composite parent) {
return new CapellaProjectContentsLocationArea(getErrorReporter(), parent);
return new FilteringProjectContentsLocationArea(getErrorReporter(), parent);
}

/**
Expand Down

0 comments on commit 8b7fbbf

Please sign in to comment.