+ private void createIntervalElements(Composite parent) {
+
+ Label label = new Label(parent, SWT.NONE);
+ label.setText("Generic");
+ intervalText = new Text(parent, SWT.BORDER);
+ addSelectionListener(intervalText);
+
+ disableUpdatesButton = new Button(parent, SWT.CHECK);
+ disableUpdatesButton.setText("Disable updates");
+ addSelectionListener(disableUpdatesButton);
+
+ resetVisualisationButton = new Button(parent, SWT.CHECK);
+ resetVisualisationButton.setText("Reset Visualisation");
+ addSelectionListener(resetVisualisationButton);
+
+ hoveringVertexEnabledButton = new Button(parent, SWT.CHECK);
+ hoveringVertexEnabledButton.setText("Vertex Key Variables on Hover");
+ addSelectionListener(hoveringVertexEnabledButton);
+
+ hoveringEdgesEnabledButton = new Button(parent, SWT.CHECK);
+ hoveringEdgesEnabledButton.setText("Edge Key Variables on Hover");
+ addSelectionListener(hoveringEdgesEnabledButton);
+ }
+
+ private void initializeHideElements(Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setText("Hide Elements");
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+ GridLayoutFactory.fillDefaults().numColumns(8).margins(5, 5).applyTo(group);
+
+ createHideElements(group);
+ }
+
+ private void createHideElements(Composite parent) {
+
+ hideEdgesButton = new Button(parent, SWT.CHECK);
+ hideEdgesButton.setText("Edges");
+ addSelectionListener(hideEdgesButton);
+
+ hidePointsButton = new Button(parent, SWT.CHECK);
+ hidePointsButton.setText("Points");
+ addSelectionListener(hidePointsButton);
+
+ hideConsumersButton = new Button(parent, SWT.CHECK);
+ hideConsumersButton.setText("Consumers");
+ addSelectionListener(hideConsumersButton);
+
+ hideProducersButton = new Button(parent, SWT.CHECK);
+ hideProducersButton.setText("Producers");
+ addSelectionListener(hideProducersButton);
+
+ hideValvesButton = new Button(parent, SWT.CHECK);
+ hideValvesButton.setText("Valves");
+ addSelectionListener(hideValvesButton);
+
+ hidePumpingStationsButton = new Button(parent, SWT.CHECK);
+ hidePumpingStationsButton.setText("Pumping Stations");
+ addSelectionListener(hidePumpingStationsButton);
+ }
+
+ private void initializeStaticProperties(Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setText("Static Properties");
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+ GridLayoutFactory.fillDefaults().numColumns(8).margins(5, 5).applyTo(group);
+
+ createStaticProperties(group);
+ }
+
+ private void createStaticProperties(Composite parent) {
+
+ networkBranchesStaticPropertiesButton = new Button(parent, SWT.CHECK);
+ networkBranchesStaticPropertiesButton.setText("Network Branches");
+ addSelectionListener(networkBranchesStaticPropertiesButton);
+
+ pointsStaticPropertiesButton = new Button(parent, SWT.CHECK);
+ pointsStaticPropertiesButton.setText("Points");
+ addSelectionListener(pointsStaticPropertiesButton);
+
+ consumersStaticPropertiesButton = new Button(parent, SWT.CHECK);
+ consumersStaticPropertiesButton.setText("Consumers");
+ addSelectionListener(consumersStaticPropertiesButton);
+
+ }
+
+ private void initializeDynamicSymbols(Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setText("Dynamic Symbols");
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+ GridLayoutFactory.fillDefaults().numColumns(8).margins(5, 5).applyTo(group);
+
+ createDynamicSymbols(group);
+ }
+
+ private void createDynamicSymbols(Composite parent) {
+
+ dynamicSymbolsEdgesButton = new Button(parent, SWT.CHECK);
+ dynamicSymbolsEdgesButton.setText("Shutoff Valves in Pipes");
+ addSelectionListener(dynamicSymbolsEdgesButton);
+
+ dynamicSymbolsProducersButton = new Button(parent, SWT.CHECK);
+ dynamicSymbolsProducersButton.setText("Producers");
+ addSelectionListener(dynamicSymbolsProducersButton);
+
+ dynamicSymbolsValvesButton = new Button(parent, SWT.CHECK);
+ dynamicSymbolsValvesButton.setText("Valves");
+ addSelectionListener(dynamicSymbolsValvesButton);
+
+ dynamicSymbolsPumpingStationsButton = new Button(parent, SWT.CHECK);
+ dynamicSymbolsPumpingStationsButton.setText("Pumping Stations");
+ addSelectionListener(dynamicSymbolsPumpingStationsButton);
+ }
+
+ private void initializeEdgeArrows(Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setText("Edge Arrows");
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+ GridLayoutFactory.fillDefaults().numColumns(6).margins(5, 5).applyTo(group);
+
+ createEdgeArrowsHeaderRow(group);
+
+ edgeArrowSuppliers = new ArrayList<>();
+ {
+ try {
+ Collection<DynamicArrowObject> result = Simantics.getSession().syncRequest(new UniqueRead<Collection<DynamicArrowObject>>() {
+
+ @Override
+ public Collection<DynamicArrowObject> perform(ReadGraph graph) throws DatabaseException {
+ return DynamicVisualisationsContributions.dynamicEdgeArrowObjects(graph);
+ }
+ });
+
+ for (DynamicArrowObject object : result) {
+ edgeArrowSuppliers.add(createEdgeArrowRow(group, object));
+ }
+ } catch (DatabaseException e) {
+ LOGGER.error("Could not create coloring objecst", e);
+ }
+ }
+ }
+
+
+ private void createEdgeArrowsHeaderRow(Composite parent) {
+
+ Label label = new Label(parent, SWT.NONE);
+ label.setText("Label");
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+
+ label = new Label(parent, SWT.NONE);
+ label.setText("Used");
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+
+ label = new Label(parent, SWT.NONE);
+ label.setText("Variable");
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+
+ label = new Label(parent, SWT.NONE);
+ label.setText("Gain");
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+
+ label = new Label(parent, SWT.NONE);
+ label.setText("Bias");
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+
+ label = new Label(parent, SWT.NONE);
+ label.setText("Default");
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+ }
+
+ private Supplier<Pair<String, DynamicArrowContribution>> createEdgeArrowRow(Composite parent, DynamicArrowObject object) {
+
+ Map<String, DynamicArrowContribution> arrowContributions = object.getArrowContributions();
+ if (arrowContributions.isEmpty()) {
+ // ok, no point in showing empty combo boxes
+ return null;
+ }
+
+ Label label = new Label(parent, SWT.NONE);
+ label.setText(object.getArrowObject().getName());
+ GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(label);
+
+ Button usedButton = new Button(parent, SWT.CHECK);
+ GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(usedButton);
+ addSelectionListener(usedButton);
+
+ Combo variableCombo = new Combo(parent, SWT.READ_ONLY);
+ variableCombo.setItems(arrowContributions.keySet().toArray(new String[arrowContributions.size()]));
+
+ GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo);
+
+ Text gainText = new Text(parent, SWT.BORDER);
+ GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(gainText);
+ addSelectionListener(gainText);
+
+ Text biasText = new Text(parent, SWT.BORDER);
+ GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(biasText);
+ addSelectionListener(biasText);
+
+ Button defaultButton = new Button(parent, SWT.CHECK);
+ GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
+ defaultButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ int index = variableCombo.getSelectionIndex();
+ if (index >= 0) {
+ String key = variableCombo.getItem(index);
+ DynamicArrowContribution cont = arrowContributions.get(key);
+
+ gainText.setText(Double.toString(cont.getDefaultGain()));
+ gainText.setEnabled(!defaultButton.getSelection());
+ biasText.setText(Double.toString(cont.getDefaultBias()));
+ biasText.setEnabled(!defaultButton.getSelection());
+
+ }
+ }
+ });
+ addSelectionListener(defaultButton);
+
+ variableCombo.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ // handle update for others
+ String key = variableCombo.getItem(variableCombo.getSelectionIndex());
+ DynamicArrowContribution cont = arrowContributions.get(key);
+
+ if (gainText.getText().isEmpty()) {
+ gainText.setText(Double.toString(cont.getDefaultGain()));
+ }
+ if (biasText.getText().isEmpty()) {
+ biasText.setText(Double.toString(cont.getDefaultBias()));
+ }
+
+ defaultButton.setSelection(true);
+ }
+ });
+ addSelectionListener(variableCombo);
+
+ arrowRows.put(object.getArrowObject().getName(), new ArrowObjectRow(label, usedButton, variableCombo, gainText, biasText, defaultButton));
+
+ return new Supplier<Pair<String, DynamicArrowContribution>>() {
+
+ @Override
+ public Pair<String, DynamicArrowContribution> get() {
+ int selectionIndex = variableCombo.getSelectionIndex();
+ if (selectionIndex >= 0) {
+ String key = variableCombo.getItem(selectionIndex);
+ DynamicArrowContribution cont = arrowContributions.get(key);
+ if (cont != null) {
+ String label = variableCombo.getItem(variableCombo.getSelectionIndex());
+
+ double gain = cont.getDefaultGain();
+ String gainS = gainText.getText();
+ if (gainS != null && !gainS.isEmpty()) {
+ gain = Double.parseDouble(gainS);
+ }
+ double bias = cont.getDefaultBias();
+ String biasS = biasText.getText();
+ if (biasS != null && !biasS.isEmpty()) {
+ bias = Double.parseDouble(biasText.getText());
+ }
+
+ DynamicArrowContribution dsc = new DynamicArrowContribution(label, cont.getModuleName(), cont.getAttributeName(), gain, bias);
+ dsc.setUsed(usedButton.getSelection());
+ dsc.setUseDefault(defaultButton.getSelection());
+
+ return Pair.make(object.getArrowObject().getName(), dsc);
+ }
+ }
+ return null;
+ }
+ };
+ }
+