use of org.osate.ge.aadl2.ui.internal.editor.FlowContributionItemUtil.FlowImplementationSelectionDialog in project osate2 by osate.
the class DeleteFlowContributionItem method createControl.
@Override
protected Control createControl(final Composite parent) {
deleteFlowBtn = new Button(parent, SWT.PUSH);
deleteFlowBtn.setImage(deleteImage);
deleteFlowBtn.setToolTipText("Delete");
updateButton();
deleteFlowBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
if (editor != null && selectedFlow != null) {
final AadlModificationService aadlModificationService = Objects.requireNonNull((AadlModificationService) editor.getAdapter(AadlModificationService.class), "Unable to retrieve modification service");
getFlowToRemove().ifPresent(ne -> aadlModificationService.modify(ne, EcoreUtil::remove));
}
}
/**
* Get the flow to modify/remove
* @return the flow to modify/remove
*/
private Optional<NamedElement> getFlowToRemove() {
final NamedElement selectedFlowSegment = selectedFlow.getFlowSegment();
final BusinessObjectContext container = selectedFlow.getContainer();
final ComponentImplementation componentImpl = FlowContributionItemUtil.getComponentImplementation(container);
if (selectedFlowSegment instanceof EndToEndFlow) {
final ComponentImplementation endToEndFlowContainer = AgeEmfUtil.resolveOrNull(selectedFlowSegment.getContainingComponentImpl(), ComponentImplementation.class, componentImpl.eResource().getResourceSet());
return Optional.of(AgeEmfUtil.resolveOrNull(selectedFlowSegment, EndToEndFlow.class, endToEndFlowContainer.eResource().getResourceSet()));
} else if (selectedFlowSegment instanceof FlowSpecification) {
final FlowSpecification flowSpecification = AgeEmfUtil.resolveOrNull(selectedFlowSegment, FlowSpecification.class, componentImpl.eResource().getResourceSet());
// If there are multiple flow implementations for the flow spec, choose desired one.
final List<FlowImplementation> flowImpls = componentImpl.getOwnedFlowImplementations().stream().filter(fi -> fi.getSpecification() == flowSpecification).collect(Collectors.toList());
return getFlowImplementation(flowImpls);
} else {
throw new RuntimeException("Unexpected flow type: " + selectedFlow.getFlowSegment());
}
}
private Optional<NamedElement> getFlowImplementation(final List<FlowImplementation> flowImpls) {
if (flowImpls.size() == 1) {
return Optional.of(flowImpls.get(0));
} else {
final FlowImplementationSelectionDialog dlg = new FlowImplementationSelectionDialog(Display.getCurrent().getActiveShell(), flowImpls, "Select", "Choose the flow implementation to delete.");
if (dlg.open() == Window.OK) {
return Optional.ofNullable(dlg.getSelectedFlowImplementation());
}
}
return Optional.empty();
}
});
return deleteFlowBtn;
}
use of org.osate.ge.aadl2.ui.internal.editor.FlowContributionItemUtil.FlowImplementationSelectionDialog in project osate2 by osate.
the class EditFlowContributionItem method createControl.
@Override
protected Control createControl(final Composite parent) {
editFlowBtn = new Button(parent, SWT.PUSH);
editFlowBtn.setImage(editIcon.createImage());
editFlowBtn.setToolTipText("Edit...");
updateButton();
editFlowBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
segmentNodes.clear();
final DiagramElement container = selectedHighlightableFlow.getDiagramElementContainer();
final NamedElement flowSegment = AgeAadlUtil.getRootRefinedElement(selectedHighlightableFlow.getFlowSegment());
final ComponentImplementation ci = FlowContributionItemUtil.getComponentImplementation(container.getBusinessObject());
// Set focus to editor for activating create flow tool
editor.setFocus();
editor.selectDiagramNodes(Collections.singletonList(editor.getDiagram()));
final UiService uiService = Adapters.adapt(editor, UiService.class);
// Create dialog and activate appropriate flow tool
if (flowSegment instanceof EndToEndFlow) {
final EndToEndFlow endToEndFlow = AgeEmfUtil.resolveOrNull(flowSegment, EndToEndFlow.class, ci.eResource().getResourceSet());
// Activate tool
uiService.activateTool(new CreateEndToEndFlowSpecificationTool(editor, container, endToEndFlow));
} else if (flowSegment instanceof FlowSpecification) {
final FlowSpecification fs = AgeEmfUtil.resolveOrNull(flowSegment, FlowSpecification.class, ci.eResource().getResourceSet());
getFlowImplementation(ci, fs).ifPresent(fi -> {
uiService.activateTool(new CreateFlowImplementationTool(editor, container, fi));
});
} else {
throw new RuntimeException("Unsupported flow type.");
}
}
private Optional<FlowImplementation> getFlowImplementation(final ComponentImplementation ci, final FlowSpecification flowSpec) {
final List<FlowImplementation> flowImpls = ci.getAllFlowImplementations().stream().filter(fi -> fi.getSpecification() == flowSpec).collect(Collectors.toList());
if (flowImpls.size() == 1) {
return Optional.of(flowImpls.get(0));
} else {
final FlowImplementationSelectionDialog dlg = new FlowImplementationSelectionDialog(Display.getCurrent().getActiveShell(), flowImpls, "Select", "Choose the flow implementation to edit.");
if (dlg.open() == Window.OK) {
return Optional.ofNullable(dlg.getSelectedFlowImplementation());
}
}
return Optional.empty();
}
});
return editFlowBtn;
}
Aggregations