+
+ private void openDebugSetHighLevelStateShell(ViewModel model)
+ {
+ Shell debugShell = new Shell();
+ debugShell.setLayout(new GridLayout(2, false));
+ new Label(debugShell, SWT.NONE).setText("Target component: ");
+ Combo componentSelector = new Combo(debugShell, SWT.DROP_DOWN | SWT.READ_ONLY);
+ componentSelector.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ List<GUIComponent> componentsByItemIndex = new ArrayList<>();
+ model.addComponentAddedListener(c -> recalculateComponentSelector(componentsByItemIndex, componentSelector, model));
+ model.addComponentRemovedListener(c -> recalculateComponentSelector(componentsByItemIndex, componentSelector, model));
+ recalculateComponentSelector(componentsByItemIndex, componentSelector, model);
+ new Label(debugShell, SWT.NONE).setText("Target state ID: ");
+ Text stateIDText = new Text(debugShell, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
+ stateIDText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ new Label(debugShell, SWT.NONE).setText("Value type: ");
+ Composite radioGroup = new Composite(debugShell, SWT.NONE);
+ radioGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ GridLayout radioGroupLayout = new GridLayout(2, false);
+ radioGroupLayout.marginHeight = 0;
+ radioGroupLayout.marginWidth = 0;
+ radioGroup.setLayout(radioGroupLayout);
+ Button radioBit = new Button(radioGroup, SWT.RADIO);
+ radioBit.setText("Single bit");
+ Button radioBitVector = new Button(radioGroup, SWT.RADIO);
+ radioBitVector.setText("Bitvector");
+ new Label(debugShell, SWT.NONE).setText("Value string representation: \n(Bit vectors: MSBit...LSBit)");
+ Text valueText = new Text(debugShell, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
+ valueText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ Button send = new Button(debugShell, SWT.PUSH);
+ send.setText("Send!");
+ Button get = new Button(debugShell, SWT.PUSH);
+ get.setText("Get!");
+ Text output = new Text(debugShell, SWT.READ_ONLY);
+ output.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+ Listener sendAction = e ->
+ {
+ try
+ {
+ int componentIndex = componentSelector.getSelectionIndex();
+ if (componentIndex < 0 || componentIndex >= componentsByItemIndex.size())
+ throw new RuntimeException("No component selected");
+ GUIComponent target = componentsByItemIndex.get(componentIndex);
+ String valueString = valueText.getText();
+ Object value;
+ if (radioBit.getSelection())
+ value = Bit.parse(valueString);
+ else if (radioBitVector.getSelection())
+ value = BitVector.parseMSBFirst(valueString);
+ else
+ throw new RuntimeException("No value type selected");
+ target.setHighLevelState(stateIDText.getText(), value);
+ output.setText("Success!");
+ }
+ catch (Exception x)
+ {
+ output.setText(x.getClass().getSimpleName() + (x.getMessage() == null ? "" : ": " + x.getMessage()));
+ }
+ };
+ Listener getAction = e ->
+ {
+ try
+ {
+ if (componentSelector.getSelectionIndex() >= componentsByItemIndex.size())
+ throw new RuntimeException("No valid component selected");
+ output.setText("Success! Value: \r\n"
+ + componentsByItemIndex.get(componentSelector.getSelectionIndex()).getHighLevelState(stateIDText.getText()));
+ }
+ catch (Exception x)
+ {
+ output.setText(x.getClass().getSimpleName() + (x.getMessage() == null ? "" : ": " + x.getMessage()));
+ }
+ };
+ send.addListener(SWT.Selection, sendAction);
+ valueText.addListener(SWT.DefaultSelection, sendAction);
+ get.addListener(SWT.Selection, getAction);
+ stateIDText.addListener(SWT.DefaultSelection, getAction);
+ debugShell.open();
+ }
+
+ private void recalculateComponentSelector(List<GUIComponent> componentsByItemIndex, Combo componentSelector, ViewModel model)
+ {
+ componentsByItemIndex.clear();
+ componentSelector.setItems();
+ addComponentSelectorItems(componentsByItemIndex, "", componentSelector, model);
+ }
+
+ private void addComponentSelectorItems(List<GUIComponent> componentsByItemIndex, String base, Combo componentSelector, ViewModel model)
+ {
+ for (GUIComponent c : model.getComponents())
+ if (!(c instanceof WireCrossPoint || c instanceof SubmodelInterface))
+ {
+ String item = base + c.getClass().getSimpleName();
+ componentsByItemIndex.add(c);
+ componentSelector.add(item);
+ if (c instanceof SubmodelComponent)
+ addComponentSelectorItems(componentsByItemIndex, item + " -> ", componentSelector, ((SubmodelComponent) c).submodel);
+ }
+ }
+