Search in sources :

Example 1 with CreateEndToEndFlowSpecificationTool

use of org.osate.ge.aadl2.ui.internal.tools.CreateEndToEndFlowSpecificationTool 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;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) EndToEndFlow(org.osate.aadl2.EndToEndFlow) CreateFlowImplementationTool(org.osate.ge.aadl2.ui.internal.tools.CreateFlowImplementationTool) Optional(java.util.Optional) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FlowImplementationSelectionDialog(org.osate.ge.aadl2.ui.internal.editor.FlowContributionItemUtil.FlowImplementationSelectionDialog) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) UiService(org.osate.ge.internal.services.UiService) CreateEndToEndFlowSpecificationTool(org.osate.ge.aadl2.ui.internal.tools.CreateEndToEndFlowSpecificationTool) FlowSpecification(org.osate.aadl2.FlowSpecification) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) NamedElement(org.osate.aadl2.NamedElement)

Example 2 with CreateEndToEndFlowSpecificationTool

use of org.osate.ge.aadl2.ui.internal.tools.CreateEndToEndFlowSpecificationTool in project osate2 by osate.

the class CreateEndToEndFlowSpecificationHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final InternalDiagramEditor editor = (InternalDiagramEditor) HandlerUtil.getActiveEditor(event);
    AgeHandlerUtil.activateTool(event, new CreateEndToEndFlowSpecificationTool(editor));
    return null;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) CreateEndToEndFlowSpecificationTool(org.osate.ge.aadl2.ui.internal.tools.CreateEndToEndFlowSpecificationTool)

Aggregations

CreateEndToEndFlowSpecificationTool (org.osate.ge.aadl2.ui.internal.tools.CreateEndToEndFlowSpecificationTool)2 List (java.util.List)1 Optional (java.util.Optional)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Button (org.eclipse.swt.widgets.Button)1 ComponentImplementation (org.osate.aadl2.ComponentImplementation)1 EndToEndFlow (org.osate.aadl2.EndToEndFlow)1 FlowSpecification (org.osate.aadl2.FlowSpecification)1 NamedElement (org.osate.aadl2.NamedElement)1 FlowImplementationSelectionDialog (org.osate.ge.aadl2.ui.internal.editor.FlowContributionItemUtil.FlowImplementationSelectionDialog)1 CreateFlowImplementationTool (org.osate.ge.aadl2.ui.internal.tools.CreateFlowImplementationTool)1 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)1 UiService (org.osate.ge.internal.services.UiService)1 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)1