Commit 8d59ebf4 authored by Liana Soima's avatar Liana Soima
Browse files

GSNPropertySection



Modified property section of argument elements.
Signed-off-by: Liana Soima's avatarLiana Soima <soima@fortiss.org>
Issue-Ref: 3986
parent 7083a196
......@@ -323,6 +323,9 @@
<contextMenuContribution
contributor="org.fortiss.af3.safetycases.ui.commands.SCElementIsImpacted">
</contextMenuContribution>
<contextMenuContribution
contributor="org.fortiss.af3.safetycases.ui.commands.ConnectToSystemModelElements">
</contextMenuContribution>
</extension>
<extension
point="org.eclipse.ui.views">
......
/*-------------------------------------------------------------------------+
| Copyright 2020 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.action;
import static org.fortiss.af3.allocation.utils.AllocationUtils.getAllocationTables;
import static org.fortiss.af3.safetycases.ui.utils.AF3SelectionDialogUtils.selectMultipleReferences;
import static org.fortiss.af3.safetycases.ui.utils.Utils.alreadyReferencedElements;
import static org.fortiss.tooling.kernel.service.IPersistencyService.getInstance;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getRootElements;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.swt.widgets.Shell;
import org.fortiss.af3.allocation.model.AllocationTable;
import org.fortiss.af3.component.model.Component;
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.mode.model.Mode;
import org.fortiss.af3.platform.model.IPlatformArchitectureElement;
import org.fortiss.af3.platform.model.PlatformArchitecture;
import org.fortiss.af3.platform.model.allocation.ComponentToExecutionUnitAllocationTable;
import org.fortiss.af3.safetycases.model.ArgumentElement;
import org.fortiss.af3.state.model.State;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.model.IProjectRootElement;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
/**
* This class implements the action of designating a System model element to the selected
* {@link ArgumentElement}.
*
* @author liana soima
*/
public class ConnectToSystemModelElementsAction extends EObjectActionBase<ArgumentElement> {
/** The selected argument element. */
private ArgumentElement selectedArgumentElement = null;
/** Represents the existing reference. */
private List<EObject> alreadyReferenced;
/** The current shell. */
private Shell shell;
/** Constructor. */
public ConnectToSystemModelElementsAction(ArgumentElement target, String text, Shell shell) {
super(target, text);
setTarget(target);
this.shell = shell;
selectedArgumentElement = target;
}
/** {@inheritDoc} */
@Override
public void run() {
final ITopLevelElement topLevel =
getInstance().getTopLevelElementFor(selectedArgumentElement);
topLevel.runAsCommand(new Runnable() {
private List<?> elements;
@Override
public void run() {
if(selectedArgumentElement != null) {
Collection<Class<? extends IProjectRootElement>> roots =
new ArrayList<Class<? extends IProjectRootElement>>();
List<ComponentToExecutionUnitAllocationTable> ca2hwList = getAllocationTables(
selectedArgumentElement, ComponentToExecutionUnitAllocationTable.class);
roots.add(Analysis.class);
roots.add(ComponentArchitecture.class);
roots.add(PlatformArchitecture.class);
List<EObject> analysisList =
new ArrayList<>(getRootElements(selectedArgumentElement, roots));
analysisList.addAll(ca2hwList);
alreadyReferenced = alreadyReferencedElements(selectedArgumentElement);
elements = selectMultipleReferences(shell, analysisList, alreadyReferenced,
selectedArgumentElement);
if(elements != null) {
List<EObject> removedItems = alreadyReferenced.stream()
.filter(x -> !(elements.contains(x))).collect(Collectors.toList());
removeIfNotContained(selectedArgumentElement, removedItems);
elements = elements.stream().filter(x -> !(alreadyReferenced.contains(x)))
.collect(Collectors.toList());
if(!elements.isEmpty()) {
for(Object element : elements) {
if(element instanceof Requirement) {
if(selectedArgumentElement
.getReferencedRequirements() != null) {
selectedArgumentElement.getReferencedRequirements()
.add((Requirement)element);
}
} else if(element instanceof Component) {
if(selectedArgumentElement.getReferencedComponents() != null) {
selectedArgumentElement.getReferencedComponents()
.add((Component)element);
}
} else if(element instanceof State) {
if(selectedArgumentElement.getReferencedStates() != null) {
selectedArgumentElement.getReferencedStates()
.add((State)element);
}
} else if(element instanceof AllocationTable) {
if(selectedArgumentElement.getReferencedDeployments() != null) {
selectedArgumentElement.getReferencedDeployments()
.add((AllocationTable)element);
}
} else if(element instanceof Mode) {
if(selectedArgumentElement.getReferencedModes() != null) {
selectedArgumentElement.getReferencedModes()
.add((Mode)element);
}
} else if(element instanceof IPlatformArchitectureElement) {
if(selectedArgumentElement.getReferencedPTA() != null) {
selectedArgumentElement.getReferencedPTA()
.add((IPlatformArchitectureElement)element);
}
}
}
}
}
}
}
});
}
/**
* TODO (CC, 4-1)
* If an Argument element is de-selected in the ConnectToSystemElement dialog, then it has
* to be deleted from the list.
*/
private void removeIfNotContained(ArgumentElement argElem, List<EObject> removedElements) {
argElem.getReferencedComponents().removeIf(x -> removedElements.contains(x));
argElem.getReferencedDeployments().removeIf(x -> removedElements.contains(x));
argElem.getReferencedModes().removeIf(x -> removedElements.contains(x));
argElem.getReferencedPTA().removeIf(x -> removedElements.contains(x));
argElem.getReferencedRequirements().removeIf(x -> removedElements.contains(x));
argElem.getReferencedStates().removeIf(x -> removedElements.contains(x));
}
}
/*-------------------------------------------------------------------------+
| Copyright 2020 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.commands;
import static java.util.Collections.emptyList;
import static org.fortiss.af3.safetycases.ui.utils.AF3SelectionDialogUtils.selectSystemModelElement;
import static org.fortiss.af3.safetycases.ui.utils.Utils.alreadyReferencedElements;
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.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.Display;
import org.eclipse.swt.widgets.Shell;
import org.fortiss.af3.safetycases.model.ArgumentElement;
import org.fortiss.af3.safetycases.model.AwayArgumentElement;
import org.fortiss.af3.safetycases.ui.AF3SafetyCasesUIActivator;
import org.fortiss.af3.safetycases.ui.action.ConnectToSystemModelElementsAction;
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;
import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
/**
*
* This class implements the feature of referencing a System Model Element from any
* {@link ArgumentElement}. The feature is compound of 2 buttons: one button for referencing a new
* System Model Element (implemented in the ConnectToSystemModelElements class, and a button for
* showing the already referenced items.
*
* Icons made by <a href="https://www.flaticon.com/authors/becris" title="Becris">Becris</a> from
* <a href="https://www.flaticon.com/" title="Flaticon"> www.flaticon.com</a>
* https://icons8.com/icons/set/connect
*
* @author soima liana
*/
public class ConnectToSystemModelElements implements IContextMenuContributor {
/** {@inheritDoc} */
@Override
public List<IContributionItem> getContributedItems(EObject selection,
ContextMenuContextProvider contextProvider) {
if(selection instanceof ArgumentElement) {
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
if(selection instanceof AwayArgumentElement) {
return emptyList();
}
contributionItems.add(new ActionContributionItem(
new ReferenceSystemModelElements((ArgumentElement)selection)));
ArgumentElement argElement = (ArgumentElement)selection;
List<EObject> existingReferences = alreadyReferencedElements(argElement);
if(!existingReferences.isEmpty()) {
contributionItems.add(new ActionContributionItem(
new ShowReferenceSystemModelElements(argElement)));
}
return contributionItems;
}
return emptyList();
}
/** {@inheritDoc} */
@Override
public String getMenuSectionID() {
return AFTER_GLOBAL_MENU_SECTION_ID;
}
/** The action to Reference a System Model Element. */
private class ReferenceSystemModelElements extends Action {
/** The selected argument element. */
private ArgumentElement selectedArgumentElement = null;
/** Constructor. */
ReferenceSystemModelElements(ArgumentElement selectedArgumentElement) {
super("Connect To System Model",
AF3SafetyCasesUIActivator.getImageDescriptor("icons/connection.png"));
this.selectedArgumentElement = selectedArgumentElement;
}
/** {@inheritDoc} */
@Override
public void run() {
new ConnectToSystemModelElementsAction(selectedArgumentElement, "",
Display.getCurrent().getActiveShell()).run();
}
}
/** This class opens a dialog containing all the referenced System Model Elements. */
private class ShowReferenceSystemModelElements extends Action {
/** The selected argument element. */
private ArgumentElement selectedArgumentElement = null;
/** The current shell. */
private Shell shell;
/** Constructor. */
ShowReferenceSystemModelElements(ArgumentElement selectedArgumentElement) {
super("Show System Model Reference",
AF3SafetyCasesUIActivator.getImageDescriptor("icons/selectConnection.png"));
this.selectedArgumentElement = selectedArgumentElement;
this.shell = Display.getCurrent().getActiveShell();
}
/** {@inheritDoc} */
@Override
public void run() {
final ITopLevelElement topLevel =
getInstance().getTopLevelElementFor(selectedArgumentElement);
topLevel.runAsCommand(new Runnable() {
private List<EObject> elements;
@Override
public void run() {
elements = alreadyReferencedElements(selectedArgumentElement);
EObject option =
selectSystemModelElement(shell, elements, selectedArgumentElement);
if(option != null) {
IModelEditorBindingService.getInstance().openInEditor(option);
}
}
});
}
}
}
......@@ -54,7 +54,6 @@ import org.fortiss.af3.mode.model.Mode;
import org.fortiss.af3.mode.model.ModeAutomaton;
import org.fortiss.af3.platform.model.PlatformArchitecture;
import org.fortiss.af3.platform.model.allocation.ComponentToExecutionUnitAllocationTable;
import org.fortiss.af3.safetycases.model.ArgumentElement;
import org.fortiss.af3.safetycases.model.ArgumentElementBase;
import org.fortiss.af3.safetycases.model.AwayArgumentElement;
import org.fortiss.af3.safetycases.model.AwaySolution;
......@@ -160,9 +159,8 @@ public class ArgumentElementPropertySection extends PropertySectionBase {
public void widgetSelected(SelectionEvent e) {
if(currentlySelectedGSNElement.getDocumentReference() != null &&
currentlySelectedGSNElement.getDocumentReference() != "") {
String message = "This element already has a document reference. " +
"Are you sure you want to replace the reference to this document?";
boolean go = openConfirm(getCurrent().getActiveShell(), "", message);
boolean go = openConfirm(getCurrent().getActiveShell(), "",
"This element already has a document reference. Are you sure you want to replace the reference to this document?");
if(!go) {
return;
}
......@@ -231,24 +229,6 @@ public class ArgumentElementPropertySection extends PropertySectionBase {
addDocumentReferenceButton.setEnabled(false);
removeDocumentReferenceButton.setEnabled(false);
documentReferenceExplText.setEnabled(false);
if(currentlySelectedGSNElement instanceof AwayArgumentElement) {
AwayArgumentElement awayArgumentElement =
(AwayArgumentElement)currentlySelectedGSNElement;
ArgumentElement pointsTo = awayArgumentElement.getPointsTo();
if(pointsTo != null) {
String newClaimText = pointsTo.getTextualInformation();
final ITopLevelElement topLevel =
getInstance().getTopLevelElementFor(currentlySelectedGSNElement);
topLevel.runAsCommand(new Runnable() {
@Override
public void run() {
((ArgumentElement)currentlySelectedGSNElement)
.setTextualInformation(newClaimText);
}
});
}
}
claimText.setEnabled(false);
} else {
addDocumentReferenceButton.setEnabled(true);
......@@ -257,15 +237,15 @@ public class ArgumentElementPropertySection extends PropertySectionBase {
claimText.setEnabled(true);
}
// code for binding GSN id.
// code for binding GSN id
performComplexTextBinding(dbc, idText,
observeValue(currentlySelectedGSNElement, ARGUMENT_ELEMENT_BASE__GSN_ID), null,
null, new StringToGsnIdValidator(currentlySelectedGSNElement), null);
// code for binding claim.
// code for binding claim
performComplexTextBinding(dbc, claimText,
observeValue(currentlySelectedGSNElement, ARGUMENT_ELEMENT__TEXTUAL_INFORMATION),
null, null, new StringToClaimValidator(), null);
// code for binding document reference explanation.
// code for binding document reference explanation
performComplexTextBinding(dbc, documentReferenceExplText,
observeValue(currentlySelectedGSNElement,
ARGUMENT_ELEMENT_BASE__INFO_DOCUMENT_REFERENCE),
......
......@@ -63,7 +63,7 @@ public class AwayEntityPropertySection extends PropertySectionBase {
referencedModuleIDText.setEnabled(false);
String gsnID = "";
if(currentlySelectedAwayEntity.getPointsTo() != null) {
gsnID = currentlySelectedAwayEntity.getPointsTo().getModule().getGsnID();
gsnID = (currentlySelectedAwayEntity.getPointsTo()).getModule().getGsnID();
}
if(gsnID != "" && gsnID != null) {
referencedModuleIDText.setText(gsnID);
......
......@@ -19,6 +19,7 @@ import static org.fortiss.af3.safetycases.model.SafetyCasesPackage.Literals.SAFE
import static org.fortiss.af3.safetycases.model.SafetyCasesPackage.Literals.SAFETY_CASES_CONNECTION__MULTIPLICITY_EXPLANATION;
import static org.fortiss.tooling.kernel.service.IPersistencyService.getInstance;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.observeText;
import static org.fortiss.tooling.kernel.ui.util.ObservableUtils.observeValue;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.swt.SWT;
......@@ -32,7 +33,6 @@ import org.fortiss.af3.safetycases.model.ArgumentModule;
import org.fortiss.af3.safetycases.model.SafetyCasesConnection;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.ui.extension.base.PropertySectionBase;
import org.fortiss.tooling.kernel.ui.util.ObservableUtils;
/**
* Property section of {@link SafetyCasesConnection}s.
......@@ -98,28 +98,36 @@ public class ConnectionPropertySection extends PropertySectionBase {
currentlySelectedConnection = (SafetyCasesConnection)input;
}
/** {@inheritDoc} */
/**
* {@inheritDoc}
*
* <p>
* Sub-classes may override, but must call super.refresh() first.
*/
@SuppressWarnings("unchecked")
@Override
public void refresh() {
super.refresh();
if(!(currentlySelectedConnection.eContainer() instanceof ArgumentModule)) {
multiplicityText.setEnabled(false);
multiplicityExplText.setEnabled(false);
} else {
multiplicityText.setEnabled(true);
multiplicityExplText.setEnabled(true);
}
if(currentlySelectedConnection.isOptional()) {
isOptionalButton.setSelection(true);
} else {
isOptionalButton.setSelection(false);
}
IObservableValue<?> modelObservableMultiplicity = ObservableUtils
.observeValue(currentlySelectedConnection, SAFETY_CASES_CONNECTION__MULTIPLICITY);
dbc.bindValue(observeText(multiplicityText, SWT.Modify), modelObservableMultiplicity, null,
IObservableValue<?> modelObservableMultiplicity =
observeValue(currentlySelectedConnection, SAFETY_CASES_CONNECTION__MULTIPLICITY);
dbc.bindValue(observeText(multiplicityText, SWT.None), modelObservableMultiplicity, null,
null);
IObservableValue<?> modelObservableMultiplicityExpl = ObservableUtils.observeValue(
IObservableValue<?> modelObservableMultiplicityExpl = observeValue(
currentlySelectedConnection, SAFETY_CASES_CONNECTION__MULTIPLICITY_EXPLANATION);
dbc.bindValue(observeText(multiplicityExplText, SWT.Modify),
modelObservableMultiplicityExpl, null, null);
dbc.bindValue(observeText(multiplicityExplText, SWT.None), modelObservableMultiplicityExpl,
null, null);
}
}
/*-------------------------------------------------------------------------+
| Copyright 2020 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 static org.fortiss.af3.safetycases.model.maintenanceStatus.ACTUALLY_IMPACTED;
import static org.fortiss.af3.safetycases.model.maintenanceStatus.CHALLENGED;
import static org.fortiss.af3.safetycases.model.maintenanceStatus.POTENTIALLY_IMPACTED;
import static org.fortiss.af3.safetycases.ui.utils.MaintenanceUtils.getActualMaintainanceStatus;
import static org.fortiss.af3.safetycases.ui.utils.Utils.cannotBeInstantiated;
import static org.fortiss.af3.safetycases.ui.utils.Utils.setToPrivateOrPublic;
import static org.fortiss.af3.safetycases.ui.utils.Utils.setUndevelopedEntity;
import static org.fortiss.tooling.kernel.service.IPersistencyService.getInstance;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.fortiss.af3.safetycases.model.ArgumentElement;
import org.fortiss.af3.safetycases.model.Context;
import org.fortiss.af3.safetycases.model.Goal;
import org.fortiss.af3.safetycases.model.Solution;
import org.fortiss.af3.safetycases.model.Strategy;
import org.fortiss.af3.safetycases.model.VISIBILITY;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.ui.extension.base.PropertySectionBase;
/**
* Property section of an {@link ArgumentElement} which describes the properties that an element can
* have (can be private, instantiated, challenged, potentially/actually impacted or undeveloped.
*
*
* @author soima
*/
public class GSNStatesPropertySection extends PropertySectionBase {
/** Check-box which tells whether the selected element is instantiated. */
private Button isInstantiatedCheckbox;
/** Check-box which tells whether the selected element is challenged. */
private Button isChallengedCheckbox;
/** Check-box which tells whether the selected element is set as undeveloped. */
private Button isUndevelopedCheckbox;
/** Check-box which tells whether the selected element is private. */
private Button isPrivateCheckbox;
/** Check-box which tells whether the selected element is private. */
private Button isPotentiallyImpactedCheckbox;
/** Check-box which tells whether the selected element is private. */
private Button isActuallyImpactedCheckbox;
/** The currently selected {@link ArgumentElement}. */
private ArgumentElement currentlySelectedSection;
/** {@link Label} to display the explanation of the {@link GSNStatesPropertySection}. */
private Label state;
/** {@inheritDoc} */
@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
state = getWidgetFactory().createLabel(composite, "State");
state.setToolTipText("The state of the GSN element");
getWidgetFactory().createLabel(composite, "");
isChallenged();
isPotentiallyImpacted();
isActuallyImpacted();
isInstantiated();
// change order of buttons so that it looks better on the GUI
if(currentlySelectedSection instanceof Solution) {
isPrivateCheckbox = getWidgetFactory().createButton(composite, "Is Private", SWT.CHECK);
isPrivate();
isUndevelopedCheckbox =
getWidgetFactory().createButton(composite, "Is Developed", SWT.CHECK);
isUndeveloped();
} else {
isUndevelopedCheckbox =
getWidgetFactory().createButton(composite, "Is Developed", SWT.CHECK);
isPrivateCheckbox = getWidgetFactory().createButton(composite, "Is Private", SWT.CHECK);
isUndeveloped();
isPrivate();
}
}
/**
* This method adds to an {@link ArgumentElement} a check-box to set the argument
* as instantiated or uninstantiated.
*/
private void isInstantiated() {