Search in sources :

Example 1 with ModeFeatureReference

use of org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference in project osate2 by osate.

the class ModeContributionItem method refresh.

void refresh() {
    final ComboViewer comboViewer = getComboViewer();
    final SortedSet<ModeFeatureReference> modeFeatureReferences = new TreeSet<>((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
    if (comboViewer != null) {
        final ModeFeatureReference nullValue = AadlModalElementUtil.createModeFeatureReference(getNullValueString(), null, null);
        modeFeatureReferences.add(nullValue);
        Object selectedValue = nullValue;
        final String selectedModeName = editor == null ? null : editor.getPartProperty(SELECTED_MODE_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) {
                queryService.getResults(MODE_CONTAINER_QUERY, diagram, null).stream().flatMap(modeContainer -> {
                    // If container contains a modal element
                    if (AadlModalElementUtil.getModalElement(modeContainer.getBusinessObjectContext()) != null) {
                        // Get qualified modes to add to the drop-down
                        return Stream.concat(getModeBindingFeatureReferences((DiagramNode) modeContainer.getBusinessObjectContext()), getModeFeatureReferences((DiagramNode) modeContainer.getBusinessObjectContext()));
                    }
                    return Stream.empty();
                }).forEach(modeFeatureRef -> {
                    modeFeatureReferences.add(modeFeatureRef);
                });
                // Find ComboViewer selection
                final Optional<ModeFeatureReference> tmpSelectedValue = modeFeatureReferences.stream().filter(tmpKey -> tmpKey.getName().equalsIgnoreCase(selectedModeName)).findAny();
                if (tmpSelectedValue.isPresent()) {
                    selectedValue = tmpSelectedValue.get();
                }
                comboViewer.setLabelProvider(new LabelProvider() {

                    @Override
                    public String getText(final Object element) {
                        final ModeFeatureReference mf = (ModeFeatureReference) element;
                        return mf.getName();
                    }
                });
                comboViewer.setInput(modeFeatureReferences);
            }
        }
        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) SortedSet(java.util.SortedSet) ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComboViewer(org.eclipse.jface.viewers.ComboViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TreeSet(java.util.TreeSet) ModeFeatureReference(org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference) ModelChangeNotifier(org.osate.ge.internal.services.ModelChangeNotifier) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) Composite(org.eclipse.swt.widgets.Composite) ComboContributionItem(org.osate.ge.internal.ui.editor.ComboContributionItem) Subcomponent(org.osate.aadl2.Subcomponent) Objects(com.google.common.base.Objects) IEditorPart(org.eclipse.ui.IEditorPart) ChangeListener(org.osate.ge.internal.services.ModelChangeNotifier.ChangeListener) AadlClassifierUtil(org.osate.ge.aadl2.internal.util.AadlClassifierUtil) AadlInstanceObjectUtil(org.osate.ge.aadl2.internal.util.AadlInstanceObjectUtil) Collectors(java.util.stream.Collectors) Mode(org.osate.aadl2.Mode) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) Stream(java.util.stream.Stream) UiUtil(org.osate.ge.internal.ui.util.UiUtil) QueryService(org.osate.ge.services.QueryService) AadlModalElementUtil(org.osate.ge.aadl2.internal.util.AadlModalElementUtil) Optional(java.util.Optional) 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) ModeFeatureReference(org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ComboViewer(org.eclipse.jface.viewers.ComboViewer) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) QueryService(org.osate.ge.services.QueryService) TreeSet(java.util.TreeSet) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 2 with ModeFeatureReference

use of org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference in project osate2 by osate.

the class ModeContributionItem method onSelection.

@Override
protected void onSelection(final Object value) {
    if (editor != null && !editor.isDisposed() && value != null) {
        final ModeFeatureReference mf = (ModeFeatureReference) value;
        ContributionUtil.getColoringService(editor).setHighlightedMode(mf.getNamedElement(), mf.getContainer());
    }
}
Also used : ModeFeatureReference(org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference)

Example 3 with ModeFeatureReference

use of org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference in project osate2 by osate.

the class ModeContributionItem method saveModeSelection.

private void saveModeSelection() {
    // Save the current mode selection
    final ComboViewer comboViewer = getComboViewer();
    if (comboViewer != null && editor != null) {
        final Object firstSelection = comboViewer.getStructuredSelection().getFirstElement();
        final ModeFeatureReference mf = (ModeFeatureReference) firstSelection;
        final String selectionStr = firstSelection != null ? (String) mf.getName() : null;
        editor.setPartProperty(SELECTED_MODE_PROPERTY_KEY, selectionStr);
    }
}
Also used : ModeFeatureReference(org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference) ComboViewer(org.eclipse.jface.viewers.ComboViewer)

Aggregations

ModeFeatureReference (org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference)3 ComboViewer (org.eclipse.jface.viewers.ComboViewer)2 Objects (com.google.common.base.Objects)1 List (java.util.List)1 Optional (java.util.Optional)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Composite (org.eclipse.swt.widgets.Composite)1 Control (org.eclipse.swt.widgets.Control)1 IEditorPart (org.eclipse.ui.IEditorPart)1 ComponentImplementation (org.osate.aadl2.ComponentImplementation)1 Mode (org.osate.aadl2.Mode)1 NamedElement (org.osate.aadl2.NamedElement)1 Subcomponent (org.osate.aadl2.Subcomponent)1 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)1 AadlClassifierUtil (org.osate.ge.aadl2.internal.util.AadlClassifierUtil)1