Search in sources :

Example 1 with HighlightableFlowInfo

use of org.osate.ge.aadl2.ui.internal.editor.FlowContributionItem.HighlightableFlowInfo in project osate2 by osate.

the class FlowContributionItem method onSelection.

@Override
protected void onSelection(final Object value) {
    if (editor != null && !editor.isDisposed() && value != null) {
        @SuppressWarnings("unchecked") final Map.Entry<String, HighlightableFlowInfo> highlightableFlowsMapEntry = (Entry<String, HighlightableFlowInfo>) value;
        final FlowSegmentReference highlightableFlowElement = highlightableFlowsMapEntry.getValue().highlightableFlowElement;
        NamedElement flowSegmentElement = null;
        BusinessObjectContext container = null;
        if (highlightableFlowElement != null) {
            flowSegmentElement = highlightableFlowElement.flowSegmentElement;
            container = highlightableFlowElement.container;
        }
        ContributionUtil.getColoringService(editor).setHighlightedFlow(flowSegmentElement, container);
    }
}
Also used : Entry(java.util.Map.Entry) FlowSegmentReference(org.osate.ge.aadl2.internal.util.AadlFlowSpecificationUtil.FlowSegmentReference) Map(java.util.Map) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) NamedElement(org.osate.aadl2.NamedElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 2 with HighlightableFlowInfo

use of org.osate.ge.aadl2.ui.internal.editor.FlowContributionItem.HighlightableFlowInfo in project osate2 by osate.

the class FlowContributionItem method refresh.

void refresh() {
    final ComboViewer comboViewer = getComboViewer();
    final Map<String, HighlightableFlowInfo> highlightableFlowElements = new TreeMap<>((o1, o2) -> o1.toLowerCase().compareTo(o2.toLowerCase()));
    if (comboViewer != null) {
        final Map.Entry<String, HighlightableFlowInfo> nullMapEntry = new AbstractMap.SimpleEntry<>(getNullValueString(), new HighlightableFlowInfo(null, FlowSegmentState.COMPLETE));
        highlightableFlowElements.put(nullMapEntry.getKey(), nullMapEntry.getValue());
        Map.Entry<String, HighlightableFlowInfo> selectedValue = nullMapEntry;
        final String selectedFlowName = editor == null ? null : editor.getPartProperty(SELECTED_FLOW_PROPERTY_KEY);
        // Clear the combo box
        comboViewer.setInput(null);
        if (editor == null) {
            return;
        }
        final AgeDiagram diagram = editor.getDiagram();
        if (diagram != null) {
            final QueryService queryService = ContributionUtil.getQueryService(editor);
            if (queryService != null) {
                // Determine which flows have elements contained in the diagram and whether the flow is partial.
                queryService.getResults(FLOW_CONTAINER_QUERY, diagram, null).stream().flatMap(flowContainerQueryable -> {
                    if (flowContainerQueryable.getBusinessObject() instanceof ComponentInstance) {
                        return AadlInstanceObjectUtil.getComponentInstance(flowContainerQueryable.getBusinessObjectContext()).map(ci -> createFlowSegmentReferences(flowContainerQueryable.getBusinessObjectContext(), ci)).orElse(Stream.empty());
                    } else {
                        return AadlClassifierUtil.getComponentImplementation(flowContainerQueryable.getBusinessObjectContext()).map(ci -> createFlowSegmentReferences(flowContainerQueryable.getBusinessObjectContext(), ci)).orElse(Stream.empty());
                    }
                }).map(HighlightableFlowInfo::create).filter(Predicates.notNull()).forEachOrdered(highlightableFlowElement -> {
                    highlightableFlowElements.put(getName(highlightableFlowElement.highlightableFlowElement), highlightableFlowElement);
                });
                // Determine which value should be selected
                final Optional<Entry<String, HighlightableFlowInfo>> tmpSelectedValue = highlightableFlowElements.entrySet().stream().filter(entry -> entry.getKey().equalsIgnoreCase(selectedFlowName)).findAny();
                if (tmpSelectedValue.isPresent()) {
                    selectedValue = tmpSelectedValue.get();
                }
                comboViewer.setInput(highlightableFlowElements.entrySet());
            }
        }
        showFlowContributionItem.updateShowFlowItem(selectedValue.getValue());
        editFlowContributionItem.updateEditFlowItem(selectedValue.getValue());
        deleteFlowContributionItem.updateDeleteFlowItem(selectedValue.getValue());
        final StructuredSelection newSelection = new StructuredSelection(selectedValue);
        if (!Objects.equal(newSelection, comboViewer.getSelection())) {
            comboViewer.setSelection(newSelection);
            onSelection(newSelection.getFirstElement());
        }
    }
}
Also used : ComponentInstance(org.osate.aadl2.instance.ComponentInstance) SwtUtil(org.osate.ge.swt.SwtUtil) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ComponentImplementation(org.osate.aadl2.ComponentImplementation) AadlFlowSpecificationUtil(org.osate.ge.aadl2.internal.util.AadlFlowSpecificationUtil) ComboViewer(org.eclipse.jface.viewers.ComboViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ModelChangeNotifier(org.osate.ge.internal.services.ModelChangeNotifier) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Composite(org.eclipse.swt.widgets.Composite) ComboContributionItem(org.osate.ge.internal.ui.editor.ComboContributionItem) Map(java.util.Map) Predicates(com.google.common.base.Predicates) Subcomponent(org.osate.aadl2.Subcomponent) Objects(com.google.common.base.Objects) IEditorPart(org.eclipse.ui.IEditorPart) ChangeListener(org.osate.ge.internal.services.ModelChangeNotifier.ChangeListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) AadlClassifierUtil(org.osate.ge.aadl2.internal.util.AadlClassifierUtil) AadlInstanceObjectUtil(org.osate.ge.aadl2.internal.util.AadlInstanceObjectUtil) FlowSegmentReference(org.osate.ge.aadl2.internal.util.AadlFlowSpecificationUtil.FlowSegmentReference) Collectors(java.util.stream.Collectors) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) AbstractMap(java.util.AbstractMap) Stream(java.util.stream.Stream) UiUtil(org.osate.ge.internal.ui.util.UiUtil) QueryService(org.osate.ge.services.QueryService) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) Optional(java.util.Optional) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NamedElement(org.osate.aadl2.NamedElement) ExecutableQuery(org.osate.ge.query.ExecutableQuery) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Control(org.eclipse.swt.widgets.Control) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) ComboViewer(org.eclipse.jface.viewers.ComboViewer) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) QueryService(org.osate.ge.services.QueryService) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) Map(java.util.Map) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap)

Aggregations

AbstractMap (java.util.AbstractMap)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 TreeMap (java.util.TreeMap)2 NamedElement (org.osate.aadl2.NamedElement)2 BusinessObjectContext (org.osate.ge.BusinessObjectContext)2 FlowSegmentReference (org.osate.ge.aadl2.internal.util.AadlFlowSpecificationUtil.FlowSegmentReference)2 Objects (com.google.common.base.Objects)1 Predicates (com.google.common.base.Predicates)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Composite (org.eclipse.swt.widgets.Composite)1 Control (org.eclipse.swt.widgets.Control)1 IEditorPart (org.eclipse.ui.IEditorPart)1