use of org.osate.ge.aadl2.ui.internal.tools.CreateFlowImplementationTool in project osate2 by osate.
the class CreateFlowImplementationHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final InternalDiagramEditor editor = (InternalDiagramEditor) HandlerUtil.getActiveEditor(event);
AgeHandlerUtil.activateTool(event, new CreateFlowImplementationTool(editor));
return null;
}
use of org.osate.ge.aadl2.ui.internal.tools.CreateFlowImplementationTool 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