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();
}
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);
}
});
}
Aggregations