Search in sources :

Example 26 with ModeInstance

use of org.osate.aadl2.instance.ModeInstance in project osate2 by osate.

the class SOMChooserDialog method configureViewer.

private void configureViewer() {
    final Tree tree = viewer.getTree();
    TableLayout tableLayout = new TableLayout();
    tree.setLayout(tableLayout);
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    new TreeColumn(tree, SWT.LEFT).setText(COLUMN_COMPONENT_INSTANCE);
    new TreeColumn(tree, SWT.LEFT).setText(COLUMN_MODE_INSTANCE);
    tableLayout.addColumnData(new ColumnWeightData(2, true));
    tableLayout.addColumnData(new ColumnWeightData(1, true));
    viewer.setColumnProperties(new String[] { COLUMN_COMPONENT_INSTANCE, COLUMN_MODE_INSTANCE });
    viewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
    class ComponentAndModeLabelProvider extends LabelProvider implements ITableLabelProvider {

        @Override
        public Image getColumnImage(Object element, int columnIndex) {
            if (columnIndex == 0) {
                return baseLabelProvider.getImage(element);
            } else if (columnIndex == 1) {
                final ComponentInstance component = (ComponentInstance) element;
                if (componentExistsInCurrentMode(component)) {
                    if (selectedModes.containsKey(component)) {
                        if (selectedModes.get(component) == null) {
                            return OsateUiPlugin.getImageDescriptor(MODE_NOT_SET_ICON).createImage();
                        } else {
                            return OsateUiPlugin.getImageDescriptor(MODE_SET_ICON).createImage();
                        }
                    } else {
                        return null;
                    }
                } else {
                    return OsateUiPlugin.getImageDescriptor(NONEXISTENT_ICON).createImage();
                }
            }
            return null;
        }

        @Override
        public String getColumnText(Object element, int columnIndex) {
            if (columnIndex == 0) {
                return baseLabelProvider.getText(element);
            } else if (columnIndex == 1) {
                final ComponentInstance component = (ComponentInstance) element;
                if (componentExistsInCurrentMode(component)) {
                    if (selectedModes.containsKey(component)) {
                        if (selectedModes.get(component) == null) {
                            return "Mode Not Set";
                        } else {
                            return selectedModes.get(component).getName();
                        }
                    } else {
                        return null;
                    }
                } else {
                    return "Component Does Not Exist In Current Mode";
                }
            }
            return null;
        }
    }
    viewer.setLabelProvider(new ComponentAndModeLabelProvider());
    viewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof ComponentInstance) {
                for (ComponentInstance component : ((ComponentInstance) element).getAllComponentInstances()) {
                    if (component.getModeInstances().size() > 0) {
                        return true;
                    }
                }
            }
            return false;
        }
    });
    viewer.setCellEditors(new CellEditor[] { null, new ComboBoxCellEditor(tree, new String[0], SWT.READ_ONLY) });
    viewer.setCellModifier(new ICellModifier() {

        @Override
        public void modify(Object element, String property, Object value) {
            int selection = ((Integer) value).intValue();
            if (selection != -1) {
                selectedModes.put((ComponentInstance) ((TreeItem) element).getData(), ((ComponentInstance) ((TreeItem) element).getData()).getModeInstances().get(selection));
                updateOkEnabled();
                viewer.refresh();
                viewer.getTree().redraw();
            }
        }

        @Override
        public Object getValue(Object element, String property) {
            final ModeInstance mode = selectedModes.get(element);
            if (mode != null) {
                return new Integer(((ComponentInstance) element).getModeInstances().indexOf(mode));
            } else {
                return new Integer(-1);
            }
        }

        @Override
        public boolean canModify(Object element, String property) {
            if (viewer.getSelection() instanceof IStructuredSelection && ((IStructuredSelection) viewer.getSelection()).size() == 1) {
                final ComponentInstance selectedComponent = (ComponentInstance) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
                final ArrayList<String> modeNames = new ArrayList<String>();
                for (ModeInstance mode : selectedComponent.getModeInstances()) {
                    modeNames.add(mode.getName());
                }
                ((ComboBoxCellEditor) viewer.getCellEditors()[1]).setItems(modeNames.toArray(new String[0]));
            }
            final ComponentInstance component = (ComponentInstance) element;
            return property.equals(COLUMN_MODE_INSTANCE) && (selectedModes.containsKey(component) && (component instanceof SystemInstance || componentExistsInCurrentMode(component)));
        }
    });
    viewer.setInput(systemInstance.eResource());
    viewer.expandAll();
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ModeInstance(org.osate.aadl2.instance.ModeInstance) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeItem(org.eclipse.swt.widgets.TreeItem) ArrayList(java.util.ArrayList) AdapterFactoryContentProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SystemInstance(org.osate.aadl2.instance.SystemInstance) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ICellModifier(org.eclipse.jface.viewers.ICellModifier) Tree(org.eclipse.swt.widgets.Tree) TableLayout(org.eclipse.jface.viewers.TableLayout) AdapterFactoryLabelProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 27 with ModeInstance

use of org.osate.aadl2.instance.ModeInstance in project osate2 by osate.

the class ShowElementsInModeHandler method enableInModeNodes.

private void enableInModeNodes(final BusinessObjectProviderHelper bopHelper, final BusinessObjectNode boTree, final BusinessObjectContext selectedMode) {
    final BusinessObjectNode parentNode = getParentNode(boTree, selectedMode.getParent());
    bopHelper.getChildBusinessObjects(parentNode).forEach(childBo -> {
        if (childBo instanceof ModalElement) {
            final ModeFeature modeFeature = getModeFeature(selectedMode);
            final List<ModeFeature> modeFeatures = AadlModalElementUtil.getAllInModesOrTransitions((ModalElement) childBo);
            // Enable if ModalElement is in selected mode
            enableInModeChild(bopHelper, modeFeatures, childBo, modeFeature, parentNode);
        } else if (childBo instanceof InstanceObject) {
            final ModalElement modalElement = AadlInstanceObjectUtil.getModalElement((InstanceObject) childBo);
            if (modalElement != null) {
                final List<ModeFeature> modeFeatures = AadlModalElementUtil.getAllInModesOrTransitions(modalElement);
                // Get ModeFeature from ModeInstance or ModeTransitionInstance
                final ModeFeature modeFeature = getModeFeature(selectedMode);
                // Enable if ModalElement is in selected mode
                enableInModeChild(bopHelper, modeFeatures, childBo, modeFeature, parentNode);
            } else if (childBo instanceof NamedElement && !(childBo instanceof ModeInstance || childBo instanceof ModeTransitionInstance)) {
                // Child with no mode should be enabled
                enableChild(bopHelper, selectedMode, childBo, parentNode);
            }
        } else if (childBo instanceof NamedElement && !(childBo instanceof ModeFeature)) {
            // Child with no mode should be enabled
            enableChild(bopHelper, selectedMode, childBo, parentNode);
        }
    });
}
Also used : BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) InstanceObject(org.osate.aadl2.instance.InstanceObject) ModeInstance(org.osate.aadl2.instance.ModeInstance) LinkedList(java.util.LinkedList) List(java.util.List) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) ModeFeature(org.osate.aadl2.ModeFeature) NamedElement(org.osate.aadl2.NamedElement) ModalElement(org.osate.aadl2.ModalElement)

Aggregations

ModeInstance (org.osate.aadl2.instance.ModeInstance)24 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)12 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)11 Mode (org.osate.aadl2.Mode)9 SystemInstance (org.osate.aadl2.instance.SystemInstance)6 ArrayList (java.util.ArrayList)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)4 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)4 Context (org.osate.aadl2.Context)3 FeatureGroup (org.osate.aadl2.FeatureGroup)3 ModeTransition (org.osate.aadl2.ModeTransition)3 ConnectionReference (org.osate.aadl2.instance.ConnectionReference)3 ModeTransitionInstance (org.osate.aadl2.instance.ModeTransitionInstance)3 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)2 NotificationChain (org.eclipse.emf.common.notify.NotificationChain)2 BasicEList (org.eclipse.emf.common.util.BasicEList)2 AccessConnection (org.osate.aadl2.AccessConnection)2 Connection (org.osate.aadl2.Connection)2 Feature (org.osate.aadl2.Feature)2 FeatureGroupConnection (org.osate.aadl2.FeatureGroupConnection)2