Commit 7ad5c9e0 authored by Carmen Carlan's avatar Carmen Carlan

Any argument element can reference a list of requirements

Issue-ref: 3765
Signed-off-by: Carmen Carlan's avatarCarmen Carlan <carlan@fortiss.org>
parent 9e62ed68
......@@ -346,7 +346,7 @@
contributor="org.fortiss.af3.safetycases.ui.commands.DeleteRequirementReference">
</contextMenuContribution>
<contextMenuContribution
contributor="org.fortiss.af3.safetycases.ui.commands.ReferenceRequirement">
contributor="org.fortiss.af3.safetycases.ui.commands.ReferenceRequirements">
</contextMenuContribution>
<contextMenuContribution
contributor="org.fortiss.af3.safetycases.ui.commands.GoToReferencedDocument">
......@@ -450,15 +450,6 @@
type="org.fortiss.af3.safetycases.model.Goal">
</input>
</propertySection>
<propertySection
afterSection="org.fortiss.af3.safetycases.ui.properties.GoalPropertySection"
class="org.fortiss.af3.safetycases.ui.properties.RequirementLinkPropertySection"
id="org.fortiss.af3.safetycases.ui.properties.RequirementLinkPropertySection"
tab="org.fortiss.tooling.kernel.ui.property.tab.general">
<input
type="org.fortiss.af3.safetycases.model.Goal">
</input>
</propertySection>
<propertySection
afterSection="org.fortiss.af3.safetycases.ui.properties.RequirementLinkPropertySection"
class="org.fortiss.af3.safetycases.ui.properties.QuantitativeEvaluationPropertySection"
......
......@@ -3,17 +3,17 @@ package org.fortiss.af3.safetycases.ui.action;
import static org.eclipse.jface.dialogs.MessageDialog.openError;
import static org.eclipse.ui.plugin.AbstractUIPlugin.imageDescriptorFromPlugin;
import static org.fortiss.af3.safetycases.ui.AF3SafetyCasesUIActivator.PLUGIN_ID;
import static org.fortiss.af3.safetycases.ui.utils.AF3SelectionDialogUtils.openSR;
import static org.fortiss.af3.safetycases.ui.utils.AF3SelectionDialogUtils.selectMultipleRequirements;
import static org.fortiss.tooling.kernel.service.IPersistencyService.getInstance;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getRootElements;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.swt.widgets.Shell;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.model.ExternalRelation;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.safetycases.model.ArgumentElement;
import org.fortiss.af3.safetycases.model.Goal;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
......@@ -24,13 +24,12 @@ import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
*
* @author carlan
*/
public class ConnectGoalToSafetyRequirementAction extends EObjectActionBase<Goal> {
public class ConnectElementToRequirementsAction extends EObjectActionBase<ArgumentElement> {
/** The default shell. */
private final Shell shell;
/** Constructor. */
public ConnectGoalToSafetyRequirementAction(Goal editedObject, Shell shell) {
public ConnectElementToRequirementsAction(ArgumentElement editedObject, Shell shell) {
super("ConnectSRToGoal", imageDescriptorFromPlugin(PLUGIN_ID, "Icon_Requirement.png"));
setTarget(editedObject);
this.shell = shell;
......@@ -44,32 +43,22 @@ public class ConnectGoalToSafetyRequirementAction extends EObjectActionBase<Goal
openError(shell, "Requirements Analysis", "Cannot find Requirements Analysis!");
return;
}
Requirement selected = null;
if(getTarget().getSafetyRequirement() != null) {
selected = getTarget().getSafetyRequirement();
EList<Requirement> alreadyReferencedRequirements = null;
if(getTarget().getReferencedRequirements() != null) {
alreadyReferencedRequirements = getTarget().getReferencedRequirements();
}
final Requirement sr = openSR(shell.getShell(), analysisList, selected);
if(sr == null || sr == selected) {
final EList<Requirement> selectedRequirements = selectMultipleRequirements(shell.getShell(),
analysisList, alreadyReferencedRequirements);
if(selectedRequirements == null || selectedRequirements == alreadyReferencedRequirements) {
return;
}
final ITopLevelElement topLevelAnalysis =
getInstance().getTopLevelElementFor(sr.getContainer());
final ITopLevelElement topLevelAnalysis = getInstance().getTopLevelElementFor(getTarget());
topLevelAnalysis.runAsCommand(new Runnable() {
@Override
public void run() {
getTarget().setSafetyRequirement(sr);
if(sr.getDescription() != null) {
getTarget().setTextualInformation(sr.getDescription());
}
if(sr.getName() != null) {
getTarget().setName("Goal: " + sr.getName());
}
for(ExternalRelation er : sr.getExternalRelation()) {
if(er.getExternalRelationSpecification().getSpecificationOf() != null &&
er.getExternalRelationSpecification()
.getSpecificationOf() instanceof Component) {
getTarget().setAf3Element(
er.getExternalRelationSpecification().getSpecificationOf());
if(!selectedRequirements.isEmpty()) {
for(int i = 0; i < selectedRequirements.size(); i++) {
getTarget().getReferencedRequirements().add(selectedRequirements.get(i));
}
}
}
......
......@@ -18,28 +18,30 @@ package org.fortiss.af3.safetycases.ui.commands;
import static java.util.Collections.emptyList;
import static org.eclipse.jface.dialogs.MessageDialog.openConfirm;
import static org.eclipse.swt.widgets.Display.getCurrent;
import static org.fortiss.af3.safetycases.ui.utils.AF3SelectionDialogUtils.selectMultipleRequirements;
import static org.fortiss.tooling.kernel.service.IPersistencyService.getInstance;
import static org.fortiss.tooling.kernel.ui.service.IContextMenuService.AFTER_GLOBAL_MENU_SECTION_ID;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.swt.widgets.Shell;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.safetycases.model.ArgumentElement;
import org.fortiss.af3.safetycases.model.Goal;
import org.fortiss.af3.safetycases.model.Solution;
import org.fortiss.af3.safetycases.model.SpinalElement;
import org.fortiss.af3.safetycases.ui.AF3SafetyCasesUIActivator;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor;
import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
/**
* This class implements the action of disconnecting a {@link Requirement} from a {@link Goal} or
* from a {@link Solution}.
* This class implements the action of deleting the reference(s) from {@link ArgumentElement} to
* {@link Requirement}(s).
*
* @author carlan
*/
......@@ -49,19 +51,14 @@ public class DeleteRequirementReference implements IContextMenuContributor {
@Override
public List<IContributionItem> getContributedItems(EObject selection,
ContextMenuContextProvider contextProvider) {
if(selection instanceof Goal && ((Goal)selection).getSafetyRequirement() != null) {
if(selection instanceof ArgumentElement &&
((ArgumentElement)selection).getReferencedRequirements() != null &&
!((Goal)selection).getReferencedRequirements().isEmpty()) {
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(new ActionContributionItem(
new DeleteRequirementReferenceAction((Goal)selection)));
return contributionItems;
}
if(selection instanceof Solution && ((Solution)selection).getSafetyRequirement() != null) {
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(new ActionContributionItem(
new DeleteRequirementReferenceAction((Solution)selection)));
return contributionItems;
}
return emptyList();
}
......@@ -71,15 +68,18 @@ public class DeleteRequirementReference implements IContextMenuContributor {
return AFTER_GLOBAL_MENU_SECTION_ID;
}
/** The action. */
/** The action to delete the referenced {@link Requirement}(s). */
private class DeleteRequirementReferenceAction extends Action {
/** The selected {@link Goal}. */
private SpinalElement selectedElement;
/** The default shell. */
private final Shell shell = new Shell();
/** The selected {@link ArgumentElement}. */
private ArgumentElement selectedElement;
/** Constructor. */
DeleteRequirementReferenceAction(SpinalElement selected) {
super("Delete Reference 2 Requirement",
DeleteRequirementReferenceAction(ArgumentElement selected) {
super("Delete Reference 2 Requirement(s)",
AF3SafetyCasesUIActivator.getImageDescriptor("icons/delete.png"));
this.selectedElement = selected;
}
......@@ -88,43 +88,31 @@ public class DeleteRequirementReference implements IContextMenuContributor {
@Override
public void run() {
final ITopLevelElement topLevel = getInstance().getTopLevelElementFor(selectedElement);
if(selectedElement instanceof Goal) {
Goal selectedGoal = ((Goal)selectedElement);
topLevel.runAsCommand(new Runnable() {
@Override
public void run() {
boolean go = openConfirm(getCurrent().getActiveShell(), "",
"Are you sure you want to delete the reference to " +
selectedGoal.getId() + "?");
if(!go) {
return;
}
selectedGoal.setSafetyRequirement(null);
selectedGoal.setAf3Element(null);
selectedGoal.setName("Goal");
selectedGoal.setTextualInformation("");
}
});
EList<Requirement> referencedRequirements = selectedElement.getReferencedRequirements();
EList<Requirement> option =
selectMultipleRequirements(shell.getShell(), referencedRequirements, null);
String selectedRequirementsID = "";
if(option != null) {
for(int i = 0; i < option.size(); i++) {
selectedRequirementsID = selectedRequirementsID + " " + option.get(i).getId();
}
}
if(selectedElement instanceof Solution) {
Solution selectedSolution = ((Solution)selectedElement);
topLevel.runAsCommand(new Runnable() {
@Override
public void run() {
boolean go = openConfirm(getCurrent().getActiveShell(), "",
"Are you sure you want to delete the reference to " +
selectedSolution.getId() + "?");
if(!go) {
return;
final String s = selectedRequirementsID;
topLevel.runAsCommand(new Runnable() {
@Override
public void run() {
boolean go = openConfirm(getCurrent().getActiveShell(), "",
"Are you sure you want to delete the reference to" + s + "?");
if(!go) {
return;
}
if(option != null) {
if(!referencedRequirements.isEmpty()) {
selectedElement.getReferencedRequirements().removeAll(option);
}
selectedSolution.setSafetyRequirement(null);
selectedSolution.setAf3Element(null);
selectedSolution.setTextualInformation("");
}
});
}
}
});
}
}
}
package org.fortiss.af3.safetycases.ui.commands;
import static java.util.Collections.emptyList;
import static org.fortiss.af3.safetycases.ui.utils.AF3SelectionDialogUtils.selectRequirement;
import static org.fortiss.tooling.kernel.ui.service.IContextMenuService.AFTER_GLOBAL_MENU_SECTION_ID;
import static org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService.getInstance;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.swt.widgets.Shell;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.safetycases.model.ArgumentElement;
import org.fortiss.af3.safetycases.model.Goal;
import org.fortiss.af3.safetycases.ui.AF3SafetyCasesUIActivator;
import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor;
import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
/**
* This class implements the action of opening the editor of the safety {@link Requirement} which is
* referenced by an instance of type {@link Goal}.
* This class implements the action of opening the editor of a {@link Requirement} that is
* referenced by an instance of type {@link ArgumentElement}.
*
* @author carlan
*/
......@@ -29,10 +33,12 @@ public class GoToReferencedRequirement implements IContextMenuContributor {
@Override
public List<IContributionItem> getContributedItems(EObject selection,
ContextMenuContextProvider contextProvider) {
if(selection instanceof Goal && ((Goal)selection).getSafetyRequirement() != null) {
Goal g = (Goal)selection;
if(selection instanceof ArgumentElement &&
((ArgumentElement)selection).getReferencedRequirements() != null &&
!((Goal)selection).getReferencedRequirements().isEmpty()) {
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
GoToReferencedRequirementAction action = new GoToReferencedRequirementAction(g);
GoToReferencedRequirementAction action =
new GoToReferencedRequirementAction((ArgumentElement)selection);
contributionItems.add(new ActionContributionItem(action));
return contributionItems;
}
......@@ -45,25 +51,29 @@ public class GoToReferencedRequirement implements IContextMenuContributor {
return AFTER_GLOBAL_MENU_SECTION_ID;
}
/** The action. */
/** The action to go to a selected referenced {@link Requirement}. */
private class GoToReferencedRequirementAction extends Action {
/** The selected goal. */
private Goal selectedGoal;
/** The default shell. */
private final Shell shell = new Shell();
/** The selected {@link ArgumentElement}. */
private ArgumentElement selectedElement;
/** Constructor. */
GoToReferencedRequirementAction(Goal selected) {
super("Go To Referenced Safety Requirement",
GoToReferencedRequirementAction(ArgumentElement selected) {
super("Go To Referenced Requirement",
AF3SafetyCasesUIActivator.getImageDescriptor("icons/Icon_Requirement.png"));
this.selectedGoal = selected;
this.selectedElement = selected;
}
/** {@inheritDoc} */
@Override
public void run() {
Requirement sr = selectedGoal.getSafetyRequirement();
if(sr != null) {
getInstance().openInEditor(sr);
EList<Requirement> sr = selectedElement.getReferencedRequirements();
Requirement option = selectRequirement(shell.getShell(), sr, null);
if(option != null) {
getInstance().openInEditor(option);
}
}
}
......
......@@ -16,11 +16,7 @@
package org.fortiss.af3.safetycases.ui.commands;
import static java.util.Collections.emptyList;
import static org.eclipse.jface.dialogs.MessageDialog.openError;
import static org.fortiss.af3.safetycases.ui.utils.AF3SelectionDialogUtils.openSR;
import static org.fortiss.tooling.kernel.service.IPersistencyService.getInstance;
import static org.fortiss.tooling.kernel.ui.service.IContextMenuService.AFTER_GLOBAL_MENU_SECTION_ID;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getRootElements;
import java.util.ArrayList;
import java.util.List;
......@@ -30,17 +26,12 @@ import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.model.ExternalRelation;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.safetycases.model.ArgumentElement;
import org.fortiss.af3.safetycases.model.Goal;
import org.fortiss.af3.safetycases.model.Solution;
import org.fortiss.af3.safetycases.ui.AF3SafetyCasesUIActivator;
import org.fortiss.af3.safetycases.ui.action.ConnectGoalToSafetyRequirementAction;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.af3.safetycases.ui.action.ConnectElementToRequirementsAction;
import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor;
import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
......@@ -50,22 +41,16 @@ import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
*
* @author carlan
*/
public class ReferenceRequirement implements IContextMenuContributor {
public class ReferenceRequirements implements IContextMenuContributor {
/** {@inheritDoc} */
@Override
public List<IContributionItem> getContributedItems(EObject selection,
ContextMenuContextProvider contextProvider) {
if(selection instanceof Goal) {
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(
new ActionContributionItem(new ReferenceRequirementAction((Goal)selection)));
return contributionItems;
}
if(selection instanceof Solution) {
if(selection instanceof ArgumentElement) {
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(new ActionContributionItem(
new ReferenceSolutionRequirementAction((Solution)selection)));
new ReferenceRequirementsAction((ArgumentElement)selection)));
return contributionItems;
}
return emptyList();
......@@ -78,79 +63,23 @@ public class ReferenceRequirement implements IContextMenuContributor {
}
/** The action. */
private class ReferenceRequirementAction extends Action {
private class ReferenceRequirementsAction extends Action {
/** The selected goal. */
private Goal selectedGoal;
/** The selected {@link ArgumentElement}. */
private ArgumentElement selectedElement;
/** Constructor. */
ReferenceRequirementAction(Goal selected) {
super("Connect 2 Requirement",
ReferenceRequirementsAction(ArgumentElement selected) {
super("Connect 2 Requirement(s)",
AF3SafetyCasesUIActivator.getImageDescriptor("icons/Icon_Requirement.png"));
this.selectedGoal = selected;
this.selectedElement = selected;
}
/** {@inheritDoc} */
@Override
public void run() {
new ConnectGoalToSafetyRequirementAction(selectedGoal,
new ConnectElementToRequirementsAction(selectedElement,
Display.getCurrent().getActiveShell()).run();
}
}
/** The action. */
private class ReferenceSolutionRequirementAction extends Action {
/** The selected goal. */
private Solution selectedSolution;
/** The current shell. */
private Shell shell;
/** Constructor. */
ReferenceSolutionRequirementAction(Solution selected) {
super("Connect 2 Requirement",
AF3SafetyCasesUIActivator.getImageDescriptor("icons/Icon_Requirement.png"));
this.selectedSolution = selected;
this.shell = Display.getCurrent().getActiveShell();
}
/** {@inheritDoc} */
@Override
public void run() {
List<Analysis> analysisList = getRootElements(selectedSolution, Analysis.class);
if(analysisList.isEmpty()) {
openError(shell, "Requirements Analysis", "Cannot find Requirements Analysis!");
return;
}
Requirement selected = null;
if(selectedSolution.getSafetyRequirement() != null) {
selected = selectedSolution.getSafetyRequirement();
}
final Requirement sr = openSR(shell.getShell(), analysisList, selected);
if(sr == null || sr == selected) {
return;
}
final ITopLevelElement topLevelAnalysis =
getInstance().getTopLevelElementFor(sr.getContainer());
topLevelAnalysis.runAsCommand(new Runnable() {
@Override
public void run() {
selectedSolution.setSafetyRequirement(sr);
if(sr.getDescription() != null) {
selectedSolution.setTextualInformation(sr.getDescription());
}
if(sr.getName() != null) {
selectedSolution.setName("Solution: " + sr.getName());
}
for(ExternalRelation er : sr.getExternalRelation()) {
IModelElement erSpecification =
er.getExternalRelationSpecification().getSpecificationOf();
if(erSpecification != null && erSpecification instanceof Component) {
selectedSolution.setAf3Element(erSpecification);
}
}
}
});
}
}
}
/*-------------------------------------------------------------------------+
| Copyright 2018 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.safetycases.ui.properties;
import java.util.List;
import org.conqat.ide.commons.ui.jface.TreeContentProviderBase;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.ECollections;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.RequirementsContainer;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.af3.safetycases.model.Goal;
import org.fortiss.af3.safetycases.model.Solution;
import org.fortiss.af3.safetycases.model.SpinalElement;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.dialog.ElementTreeSingleSelectDialog;
import org.fortiss.tooling.kernel.model.IProjectRootElement;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import org.fortiss.tooling.kernel.ui.extension.base.PropertySectionBase;
import org.fortiss.tooling.kernel.ui.presentation.ModelElementLabelProvider;
/**
* Class specifying the UI machinery to populate links from suitable safety elements and
* requirements.
*
* @author vivek
*/
public class RequirementLinkPropertySection extends PropertySectionBase {
/** Currently selected {@link Goal}. */
private SpinalElement currentlySelectedSpinal;
/** Button for creating reference. */
private Button addRequirement;
/** Label for referenced button section. */
private Label requirementLabel;
/** Link for referenced button section. */
private Link requirementLink;
/** Button for eliminating reference. */
private Button deleteRequirementlButton;
/** {@inheritDoc} */
@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
createModelElementLabel();
createAddRequirementButton();
createDeleteModelButton();
}
/** {@inheritDoc} */
@Override
protected void setSectionInput(Object input) {
currentlySelectedSpinal = (SpinalElement)input;
setRequirementLink();
}
/**
* Sets the requirement link label
*/
private void setRequirementLink() {
if(currentlySelectedSpinal instanceof Goal) {
Requirement safRequirement = ((Goal)currentlySelectedSpinal).getSafetyRequirement();
requirementLink.setText(getLabelName(safRequirement));
requirementLink.setToolTipText(getToolTipText(safRequirement));
}