Skip to content

Commit

Permalink
[1917] Enhance creation and display of Physical Paths.
Browse files Browse the repository at this point in the history
Added selection dialog in case of many possible sources

Bug 1917 

Conflicts:
	core/plugins/org.polarsys.capella.core.sirius.analysis/description/context.odesign
	core/plugins/org.polarsys.capella.core.sirius.analysis/description/logical.odesign
	core/plugins/org.polarsys.capella.core.sirius.analysis/description/physical.odesign
	core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/PhysicalServices.java

Change-Id: I644f40b265087692e259a824df0ff6a19dece598
Signed-off-by: Ali AKAR <ali.akar82@gmail.com>
  • Loading branch information
aliakar82 committed Jul 3, 2018
1 parent b8ab879 commit 106a1ea
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 146 deletions.

Large diffs are not rendered by default.

Expand Up @@ -3864,14 +3864,21 @@
</tools>
</ownedTools>
<ownedTools xsi:type="tool_1:PopupMenu" name="Physical Path">
<menuItemDescription xsi:type="tool_1:OperationAction" name="Create a Physical Path" precondition="aql:self.isValidPhysicalPathSelection(views)">
<view name="views">
<subVariables xsi:type="tool_1:AcceleoVariable" name="source" computationExpression="aql:self.getAvailableSourcesOfPhysicalPath(views)->first()"/>
</view>
<menuItemDescription xsi:type="tool_1:OperationAction" name="Create a Physical Path" precondition="&lt;%isValidPhysicalPathSelection($views)%>">
<view name="views"/>
<initialOperation>
<firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="aql:self.createPhysicalPath(views,source)">
<subModelOperations xsi:type="tool_1:If" conditionExpression="aql:self.oclIsKindOf(cs::PhysicalPath)">
<subModelOperations xsi:type="tool:CreateView" mapping="//@ownedViewpoints[name='System%20Analysis']/@ownedRepresentations[name='System%20Architecture%20Blank']/@defaultLayer/@nodeMappings[name='SAB_PhysicalPathEnd']" containerViewExpression="aql:views->first().getDiagramContainer()"/>
<firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="&lt;% $views%>">
<subModelOperations xsi:type="tool_1:ExternalJavaAction" name="selectSource" id="org.polarsys.capella.core.sirius.analysis.actions.extensions.SelectElementFromListWizard">
<parameters name="context" value="&lt;% $views.nFirst()%>"/>
<parameters name="scope" value="&lt;%getAvailableSourcesOfPhysicalPath($views)%>"/>
<parameters name="resultVariable" value="source"/>
<parameters name="wizardMessage" value="Select the Source of your Physical Path:"/>
<parameters name="displayDialogForOneElement" value="false"/>
</subModelOperations>
<subModelOperations xsi:type="tool_1:ChangeContext" browseExpression="&lt;%createPhysicalPath($views,$source)%>">
<subModelOperations xsi:type="tool_1:If" conditionExpression="&lt;%current.isA(&quot;PhysicalPath&quot;)%>">
<subModelOperations xsi:type="tool:CreateView" mapping="//@ownedViewpoints[name='System%20Analysis']/@ownedRepresentations[name='System%20Architecture%20Blank']/@defaultLayer/@nodeMappings[name='SAB_PhysicalPathEnd']" containerViewExpression="&lt;%$views.nFirst().getDiagramContainer()%>"/>
</subModelOperations>
</subModelOperations>
</firstModelOperations>
</initialOperation>
Expand Down
Expand Up @@ -2427,14 +2427,21 @@
</initialOperation>
</ownedTools>
<ownedTools xsi:type="tool:PopupMenu" name="Physical Path">
<menuItemDescription xsi:type="tool:OperationAction" name="Create a Physical Path" precondition="aql:self.isValidPhysicalPathSelection(views)">
<view name="views">
<subVariables xsi:type="tool:AcceleoVariable" name="source" computationExpression="aql:self.getAvailableSourcesOfPhysicalPath(views)->first()"/>
</view>
<menuItemDescription xsi:type="tool:OperationAction" name="Create a Physical Path" precondition="&lt;%isValidPhysicalPathSelection($views)%>">
<view name="views"/>
<initialOperation>
<firstModelOperations xsi:type="tool:ChangeContext" browseExpression="aql:self.createPhysicalPath(views,source)">
<subModelOperations xsi:type="tool:If" conditionExpression="aql:self.oclIsKindOf(cs::PhysicalPath)">
<subModelOperations xsi:type="tool_1:CreateView" mapping="//@ownedViewpoints[name='Logical%20Architecture']/@ownedRepresentations[name='Logical%20Architecture%20Blank']/@defaultLayer/@nodeMappings[name='LAB_PhysicalPathEnd']" containerViewExpression="aql:views->first().getDiagramContainer()"/>
<firstModelOperations xsi:type="tool:ChangeContext" browseExpression="&lt;% $views%>">
<subModelOperations xsi:type="tool:ExternalJavaAction" name="selectSource" id="org.polarsys.capella.core.sirius.analysis.actions.extensions.SelectElementFromListWizard">
<parameters name="context" value="&lt;% $views.nFirst()%>"/>
<parameters name="scope" value="&lt;%getAvailableSourcesOfPhysicalPath($views)%>"/>
<parameters name="resultVariable" value="source"/>
<parameters name="wizardMessage" value="Select the Source of your Physical Path:"/>
<parameters name="displayDialogForOneElement" value="false"/>
</subModelOperations>
<subModelOperations xsi:type="tool:ChangeContext" browseExpression="&lt;%createPhysicalPath($views,$source)%>">
<subModelOperations xsi:type="tool:If" conditionExpression="&lt;%current.isA(&quot;PhysicalPath&quot;)%>">
<subModelOperations xsi:type="tool_1:CreateView" mapping="//@ownedViewpoints[name='Logical%20Architecture']/@ownedRepresentations[name='Logical%20Architecture%20Blank']/@defaultLayer/@nodeMappings[name='LAB_PhysicalPathEnd']" containerViewExpression="&lt;%$views.nFirst().getDiagramContainer()%>"/>
</subModelOperations>
</subModelOperations>
</firstModelOperations>
</initialOperation>
Expand Down
Expand Up @@ -3001,14 +3001,21 @@
</initialOperation>
</ownedTools>
<ownedTools xsi:type="tool:PopupMenu" name="Physical Path">
<menuItemDescription xsi:type="tool:OperationAction" name="Create a Physical Path" precondition="aql:self.isValidPhysicalPathSelection(views)" forceRefresh="true">
<view name="views">
<subVariables xsi:type="tool:AcceleoVariable" name="source" computationExpression="aql:self.getAvailableSourcesOfPhysicalPath(views)->first()"/>
</view>
<menuItemDescription xsi:type="tool:OperationAction" name="Create a Physical Path" precondition="&lt;%isValidPhysicalPathSelection($views)%>" forceRefresh="true">
<view name="views"/>
<initialOperation>
<firstModelOperations xsi:type="tool:ChangeContext" browseExpression="aql:self.createPhysicalPath(views,source)">
<subModelOperations xsi:type="tool:If" conditionExpression="aql:self.oclIsKindOf(cs::PhysicalPath)">
<subModelOperations xsi:type="tool_1:CreateView" mapping="//@ownedViewpoints[name='Physical%20Architecture']/@ownedRepresentations[name='Physical%20Architecture%20Blank']/@defaultLayer/@nodeMappings[name='PAB_PhysicalPathEnd']" containerViewExpression="aql:views->first().getDiagramContainer()"/>
<firstModelOperations xsi:type="tool:ChangeContext" browseExpression="&lt;% $views%>">
<subModelOperations xsi:type="tool:ExternalJavaAction" name="selectSource" id="org.polarsys.capella.core.sirius.analysis.actions.extensions.SelectElementFromListWizard">
<parameters name="context" value="&lt;% $views.nFirst()%>"/>
<parameters name="scope" value="&lt;%getAvailableSourcesOfPhysicalPath($views)%>"/>
<parameters name="resultVariable" value="source"/>
<parameters name="wizardMessage" value="Select the Source of your Physical Path:"/>
<parameters name="displayDialogForOneElement" value="false"/>
</subModelOperations>
<subModelOperations xsi:type="tool:ChangeContext" browseExpression="&lt;%createPhysicalPath($views,$source)%>">
<subModelOperations xsi:type="tool:If" conditionExpression="&lt;%current.isA(&quot;PhysicalPath&quot;)%>">
<subModelOperations xsi:type="tool_1:CreateView" mapping="//@ownedViewpoints[name='Physical%20Architecture']/@ownedRepresentations[name='Physical%20Architecture%20Blank']/@defaultLayer/@nodeMappings[name='PAB_PhysicalPathEnd']" containerViewExpression="&lt;%$views.nFirst().getDiagramContainer()%>"/>
</subModelOperations>
</subModelOperations>
</firstModelOperations>
</initialOperation>
Expand Down
Expand Up @@ -15,6 +15,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -479,8 +480,8 @@ public EObject createABPhysicalLink(EObject context, DSemanticDecorator sourceVi

public EObject createPhysicalPath(EObject context, List<EObject> views, EObject source) {

if (!views.isEmpty()) {
List<PhysicalLink> newList = new ArrayList<PhysicalLink>();
if (!views.isEmpty() && source != null) {
List<PhysicalLink> newList = new ArrayList<>();
for (EObject aSelectedElement : views) {
if ((aSelectedElement instanceof DEdge) && (((DEdge) aSelectedElement).getTarget() != null)
&& (((DEdge) aSelectedElement).getTarget() instanceof PhysicalLink)) {
Expand All @@ -498,7 +499,7 @@ public EObject createPhysicalPath(EObject context, List<EObject> views, EObject
return PhysicalPathExt.createPhysicalPath(container, newList, sourcePath);

}
return context;
return null;
}

public boolean canBeInvolvedInPhysicalPath(EObject source) {
Expand All @@ -515,8 +516,8 @@ private boolean isLogicalSystemComponent(EObject source) {
}

public List<EObject> getAvailableSourcesOfPhysicalPath(EObject context, List<EObject> views) {
HashMap<Part, Integer> parts = new HashMap<Part, Integer>();
List<EObject> result = new ArrayList<EObject>();
HashMap<Part, Integer> parts = new HashMap<>();
List<EObject> result = new ArrayList<>();
for (EObject aSelectedElement : views) {
if ((aSelectedElement instanceof DEdge) && (((DEdge) aSelectedElement).getTarget() != null)
&& (((DEdge) aSelectedElement).getTarget() instanceof PhysicalLink)) {
Expand Down Expand Up @@ -566,7 +567,7 @@ public boolean canBeInvolvedInPhysicalLink(EObject context) {
}

public boolean isValidPhysicalPathSelection(EObject context, List<EObject> views) {
SimpleOrientedGraph<Part> graph = new SimpleOrientedGraph<Part>();
SimpleOrientedGraph<Part> graph = new SimpleOrientedGraph<>();
if (!views.isEmpty()) {
for (EObject aSelectedElement : views) {
if ((aSelectedElement instanceof DEdge) && (((DEdge) aSelectedElement).getTarget() != null)
Expand All @@ -584,7 +585,7 @@ public boolean isValidPhysicalPathSelection(EObject context, List<EObject> views
return false;
}
}
return graph.isValid();
return graph.isValid() && !getAvailableSourcesOfPhysicalPath(context, views).isEmpty();
}
return false;
}
Expand Down Expand Up @@ -1456,7 +1457,7 @@ public HashMapSet<PhysicalLink, PhysicalPath> getPPDInvolvePhysicalLinkAndPhysic
incoming.retainAll(outgoing);
incoming.removeAll(PhysicalPathExt.getFlatPhysicalLinks(path));

Collection<Part> targetParts = new HashSet<Part>();
Collection<Part> targetParts = new LinkedHashSet<>();
targetParts.addAll(PhysicalPathExt.getFlatPhysicalPathFirstParts(path));
targetParts.addAll(PhysicalPathExt.getFlatPhysicalPathLastParts(path));

Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 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 @@ -70,6 +70,11 @@ public abstract class AbstractExternalJavaAction implements IExternalJavaAction
* Message tag.
*/
protected static final String MESSAGE = "message"; //$NON-NLS-1$

/**
* Parameter to display or not the dialog if one element is to display
*/
protected static final String DISPLAY_DIALOG_FOR_ONE_ELEMENT = "displayDialogForOneElement"; //$NON-NLS-1$

protected static final String EXCHANGE_TYPE = "exchangeType"; //$NON-NLS-1$

Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 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 @@ -35,7 +35,7 @@
*/
public class SelectElementFromListWizard extends AbstractExternalJavaAction {
@SuppressWarnings({ "unchecked", "rawtypes" })
public Object execute(EObject context, List scope_p, String wizardMessage_p, boolean multiple_p) {
public Object execute(EObject context, List scope_p, String wizardMessage_p, boolean multiple, boolean displayDialog) {
String wizardMessage = wizardMessage_p;
List<? extends EObject> scope = scope_p;
if (wizardMessage == null) {
Expand All @@ -44,21 +44,24 @@ public Object execute(EObject context, List scope_p, String wizardMessage_p, boo
if (scope == null) {
scope = Collections.emptyList();
}
if(scope.size() == 1 && !displayDialog){
return scope.get(0);
}
boolean expandViewer = CapellaUIPropertiesPlugin.getDefault().isAllowedExpandSingleViewerContent();
int viewerExpandLevel = expandViewer ? AbstractTreeViewer.ALL_LEVELS : 0;
SelectElementsDialog selectionDialog = new SelectElementsDialog(getShell(),
new CapellaTransfertViewerLabelProvider(TransactionHelper.getEditingDomain(context)),
Messages.SelectElementFromListWizard_Title,
wizardMessage,
new ArrayList<EObject>(scope),
multiple_p,
multiple,
null, viewerExpandLevel);

Object result = WIZARD_CANCELED;
if (Window.OK == selectionDialog.open()) {
List<? extends EObject> selectedElements = selectionDialog.getResult();
result = selectedElements;
if (!multiple_p && !selectedElements.isEmpty()) {
if (!multiple && !selectedElements.isEmpty()) {
// Mono selection case.
result = selectedElements.get(0);
}
Expand All @@ -77,12 +80,14 @@ public void execute(Collection<? extends EObject> selections, Map<String, Object
String wizardMessage = (String) parameters.get(WIZARD_MESSAGE);
String resultVariable = (String) parameters.get(RESULT_VARIABLE);
String sMultiple = (String) parameters.get(MULTIPLE);
String sDisplayDialog = (String) parameters.get(DISPLAY_DIALOG_FOR_ONE_ELEMENT);

Assert.isNotNull(context);
Assert.isNotNull(resultVariable);
boolean multiple = ("true".equals(sMultiple)) ? true : false; //$NON-NLS-1$
boolean displayDialog = sDisplayDialog == null ? true : ("true".equals(sDisplayDialog)) ? true : false;

Object result = execute(context, scope, wizardMessage, multiple);
Object result = execute(context, scope, wizardMessage, multiple, displayDialog);
InterpreterUtil.getInterpreter(context).setVariable(resultVariable, result);
}
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 THALES GLOBAL SERVICES.
* Copyright (c) 2018 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 All @@ -11,30 +11,24 @@
package org.polarsys.capella.test.diagram.common.ju.step.tools;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.EStoreEObjectImpl.EStoreFeatureMap;
import org.eclipse.emf.validation.internal.modeled.model.validation.Feature;
import org.eclipse.sirius.diagram.DDiagramElement;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.junit.Assert;
import org.polarsys.capella.core.data.cs.CsPackage;
import org.polarsys.capella.core.data.cs.PhysicalLink;
import org.polarsys.capella.core.data.cs.PhysicalPath;
import org.polarsys.capella.core.data.fa.FaPackage;
import org.polarsys.capella.core.data.fa.FunctionalExchange;
import org.polarsys.capella.core.data.pa.PaPackage;
import org.polarsys.capella.core.model.helpers.PhysicalLinkExt;
import org.polarsys.capella.test.diagram.common.ju.context.DiagramContext;
import org.polarsys.capella.test.diagram.common.ju.headless.HeadlessResultOpProvider;
import org.polarsys.capella.test.diagram.common.ju.headless.IHeadlessResult;
import org.polarsys.capella.test.diagram.common.ju.wrapper.utils.ArgumentType;

public class CreatePathTool extends AbstractToolStep {
public class CreatePathTool extends AbstractToolStep<Object> {

protected String element;
protected EClass clazz;
Expand All @@ -45,6 +39,20 @@ public CreatePathTool(DiagramContext context, String toolName, String element,
this.element = element;
this.links = links;
}

@Override
protected void preRunTest() {
IHeadlessResult result = new IHeadlessResult (){
@Override
public Object getResult(Collection<? extends EObject> selections, Map<String, Object> parameters) {
@SuppressWarnings("rawtypes")
List scope = (List) parameters.get("scope");
return scope.get(0);
}
};
HeadlessResultOpProvider.INSTANCE.setCurrentOp(result);
super.preRunTest();
}

@Override
protected void initToolArguments() {
Expand Down

0 comments on commit 106a1ea

Please sign in to comment.