Search in sources :

Example 16 with QueryService

use of org.osate.ge.services.QueryService 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)

Example 17 with QueryService

use of org.osate.ge.services.QueryService in project osate2 by osate.

the class CreateModeTransitionPaletteCommand method getPotentialOwnersByMode.

private static List<ComponentClassifier> getPotentialOwnersByMode(final BusinessObjectContext modeBoc, final QueryService queryService) {
    final Mode mode = (Mode) modeBoc.getBusinessObject();
    final String modeName = mode.getName();
    if (modeName == null) {
        return Collections.emptyList();
    }
    final BusinessObjectContext containerBoc = getOwnerBoc(modeBoc, queryService);
    if (containerBoc == null) {
        return Collections.emptyList();
    }
    final Element bo = (Element) containerBoc.getBusinessObject();
    return AadlUiUtil.getPotentialComponentClassifiers(bo).stream().filter(tmpBo -> tmpBo instanceof ComponentClassifier && !(tmpBo.isDerivedModes())).filter(cc -> hasModeWithName(cc, modeName)).collect(Collectors.toList());
}
Also used : Element(org.osate.aadl2.Element) BusinessObjectAndExtra(org.osate.ge.operations.BusinessObjectAndExtra) GetCreateConnectionOperationContext(org.osate.ge.palette.GetCreateConnectionOperationContext) ModeTransitionTrigger(org.osate.aadl2.ModeTransitionTrigger) ComponentClassifier(org.osate.aadl2.ComponentClassifier) BusinessObjectContext(org.osate.ge.BusinessObjectContext) AadlImages(org.osate.ge.aadl2.internal.AadlImages) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) AadlUiUtil(org.osate.ge.aadl2.ui.internal.AadlUiUtil) ModeTransition(org.osate.aadl2.ModeTransition) Aadl2Package(org.osate.aadl2.Aadl2Package) Subcomponent(org.osate.aadl2.Subcomponent) ModeTransitionTriggerSelectionDialog(org.osate.ge.aadl2.ui.internal.dialogs.ModeTransitionTriggerSelectionDialog) Operation(org.osate.ge.operations.Operation) Collectors(java.util.stream.Collectors) Mode(org.osate.aadl2.Mode) List(java.util.List) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) QueryService(org.osate.ge.services.QueryService) AadlCategories(org.osate.ge.aadl2.AadlCategories) ModeTransitionTriggerInfo(org.osate.ge.aadl2.ui.internal.dialogs.ModeTransitionTriggerSelectionDialog.ModeTransitionTriggerInfo) Optional(java.util.Optional) AadlNamingUtil(org.osate.ge.aadl2.internal.AadlNamingUtil) ExecutableQuery(org.osate.ge.query.ExecutableQuery) Collections(java.util.Collections) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Mode(org.osate.aadl2.Mode) Element(org.osate.aadl2.Element) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 18 with QueryService

use of org.osate.ge.services.QueryService in project osate2 by osate.

the class FlowSpecificationCreationUtil method getPotentialOwnersByFeature.

public static List<ComponentType> getPotentialOwnersByFeature(BusinessObjectContext featureBoc, final QueryService queryService) {
    final Context context = getContext(featureBoc, queryService);
    final Feature feature = (Feature) featureBoc.getBusinessObject();
    final String childName = context == null ? feature.getName() : context.getName();
    if (childName == null) {
        return Collections.emptyList();
    }
    final BusinessObjectContext containerBoc = getFlowSpecificationOwnerBoc(featureBoc, queryService);
    if (containerBoc == null) {
        return Collections.emptyList();
    }
    final Element bo = (Element) containerBoc.getBusinessObject();
    return AadlUiUtil.getPotentialClassifierTypesForEditing(bo).stream().filter(tmpBo -> canOwnFlowSpecification(tmpBo)).map(ComponentType.class::cast).filter(ct -> hasFeatureWithName(ct, childName)).collect(Collectors.toList());
}
Also used : BusinessObjectContext(org.osate.ge.BusinessObjectContext) Context(org.osate.aadl2.Context) Element(org.osate.aadl2.Element) SystemType(org.osate.aadl2.SystemType) Feature(org.osate.aadl2.Feature) AbstractFeature(org.osate.aadl2.AbstractFeature) Port(org.osate.aadl2.Port) ProcessorType(org.osate.aadl2.ProcessorType) DataAccess(org.osate.aadl2.DataAccess) ComponentClassifier(org.osate.aadl2.ComponentClassifier) ThreadType(org.osate.aadl2.ThreadType) BusinessObjectContext(org.osate.ge.BusinessObjectContext) SubprogramGroupType(org.osate.aadl2.SubprogramGroupType) ComponentType(org.osate.aadl2.ComponentType) DirectionType(org.osate.aadl2.DirectionType) AadlUiUtil(org.osate.ge.aadl2.ui.internal.AadlUiUtil) Subcomponent(org.osate.aadl2.Subcomponent) Context(org.osate.aadl2.Context) FeatureGroup(org.osate.aadl2.FeatureGroup) ProcessType(org.osate.aadl2.ProcessType) DirectedFeature(org.osate.aadl2.DirectedFeature) DeviceType(org.osate.aadl2.DeviceType) Collectors(java.util.stream.Collectors) VirtualProcessorType(org.osate.aadl2.VirtualProcessorType) AadlFeatureUtil(org.osate.ge.aadl2.internal.util.AadlFeatureUtil) List(java.util.List) QueryService(org.osate.ge.services.QueryService) Parameter(org.osate.aadl2.Parameter) AadlNamingUtil(org.osate.ge.aadl2.internal.AadlNamingUtil) AbstractType(org.osate.aadl2.AbstractType) ThreadGroupType(org.osate.aadl2.ThreadGroupType) ExecutableQuery(org.osate.ge.query.ExecutableQuery) Collections(java.util.Collections) DataType(org.osate.aadl2.DataType) SubprogramType(org.osate.aadl2.SubprogramType) ComponentType(org.osate.aadl2.ComponentType) Element(org.osate.aadl2.Element) Feature(org.osate.aadl2.Feature) AbstractFeature(org.osate.aadl2.AbstractFeature) DirectedFeature(org.osate.aadl2.DirectedFeature) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Aggregations

QueryService (org.osate.ge.services.QueryService)18 BusinessObjectContext (org.osate.ge.BusinessObjectContext)16 Collectors (java.util.stream.Collectors)4 Subcomponent (org.osate.aadl2.Subcomponent)4 QueryResult (org.osate.ge.query.QueryResult)4 List (java.util.List)3 Optional (java.util.Optional)3 ExecutableQuery (org.osate.ge.query.ExecutableQuery)3 Objects (com.google.common.base.Objects)2 Collections (java.util.Collections)2 Stream (java.util.stream.Stream)2 ComboViewer (org.eclipse.jface.viewers.ComboViewer)2 LabelProvider (org.eclipse.jface.viewers.LabelProvider)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 Composite (org.eclipse.swt.widgets.Composite)2 Control (org.eclipse.swt.widgets.Control)2 IEditorPart (org.eclipse.ui.IEditorPart)2 ComponentClassifier (org.osate.aadl2.ComponentClassifier)2 ComponentImplementation (org.osate.aadl2.ComponentImplementation)2 Element (org.osate.aadl2.Element)2