Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes2 #190

Merged
merged 5 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ tasks.jacocoTestReport {
}))
}

pmd {
// Disabling build failure on rule violations
isIgnoreFailures = true
}

application {
mainClass.set("org.gecko.application.Main")
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/gecko/actions/ActionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public ChangeTypePortViewModelElementAction createChangeTypePortViewModelElement
return new ChangeTypePortViewModelElementAction(portViewModel, newType);
}

public ChangeVariableValuePortViewModelAction createChangeVariableValuePortViewModelAction(
PortViewModel portViewModel, String newValue) {
return new ChangeVariableValuePortViewModelAction(portViewModel, newValue);
}

public ChangeVisibilityPortViewModelAction createChangeVisibilityPortViewModelAction(
PortViewModel portViewModel, Visibility visibility) {
return new ChangeVisibilityPortViewModelAction(geckoViewModel, portViewModel, visibility);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.gecko.actions;

import org.gecko.exceptions.ModelException;
import org.gecko.viewmodel.PortViewModel;

public class ChangeVariableValuePortViewModelAction extends Action {
private final PortViewModel portViewModel;
private String newValue;
private final String oldValue;

ChangeVariableValuePortViewModelAction(PortViewModel portViewModel, String newValue) {
this.portViewModel = portViewModel;
this.newValue = newValue;
this.oldValue = portViewModel.getValue();
}

@Override
boolean run() throws ModelException {
if (newValue == null || newValue.isEmpty()) {
newValue = null;
}
portViewModel.setValue(newValue);
portViewModel.updateTarget();
return true;
}

@Override
Action getUndoAction(ActionFactory actionFactory) {
return actionFactory.createChangeVariableValuePortViewModelAction(portViewModel, oldValue);
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/gecko/view/GeckoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ private void onUpdateCurrentEditorToViewModel(

private void focusCenter(EditorViewModel editorViewModel) {
// Evaluate the center of all elements by calculating the average position
if (editorViewModel.getPositionableViewModelElements().isEmpty()) {
editorViewModel.setPivot(new Point2D(0, 0));
return;
}

Point2D center = editorViewModel.getPositionableViewModelElements()
.stream()
.map(PositionableViewModelElement::getCenter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,15 @@ public ContextMenu build() {
// Edge editing commands:
Menu changeKindMenu = new Menu(ResourceHandler.getString("Buttons", "change_kind"));

MenuItem hitMenuItem = new MenuItem(Kind.HIT.name());
hitMenuItem.setOnAction(
e -> actionManager.run(actionManager.getActionFactory().createChangeKindAction(edgeViewModel, Kind.HIT)));
for (Kind kind : Kind.values()) {
MenuItem kindMenuItem = createKindMenuItem(kind);

MenuItem missMenuItem = new MenuItem(Kind.MISS.name());
missMenuItem.setOnAction(
e -> actionManager.run(actionManager.getActionFactory().createChangeKindAction(edgeViewModel, Kind.MISS)));
if (edgeViewModel.getKind() == kind) {
kindMenuItem.setDisable(true);
}

MenuItem failMenuItem = new MenuItem(Kind.FAIL.name());
failMenuItem.setOnAction(
e -> actionManager.run(actionManager.getActionFactory().createChangeKindAction(edgeViewModel, Kind.FAIL)));

changeKindMenu.getItems().addAll(hitMenuItem, missMenuItem, failMenuItem);
changeKindMenu.getItems().add(kindMenuItem);
}

MenuItem deleteMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "delete"));
deleteMenuItem.setOnAction(e -> actionManager.run(
Expand All @@ -55,4 +51,11 @@ public ContextMenu build() {
edgeContextMenu.getItems().addAll(dataTransferToEdgeEditingSeparator, changeKindMenu, deleteMenuItem);
return edgeContextMenu;
}

private MenuItem createKindMenuItem(Kind kind) {
MenuItem kindMenuItem = new MenuItem(kind.name());
kindMenuItem.setOnAction(
e -> actionManager.run(actionManager.getActionFactory().createChangeKindAction(edgeViewModel, kind)));
return kindMenuItem;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.gecko.view.inspector.builder;

import org.gecko.actions.ActionManager;
import org.gecko.view.ResourceHandler;
import org.gecko.view.inspector.element.InspectorSeparator;
import org.gecko.view.inspector.element.container.InspectorTypeLabel;
import org.gecko.view.inspector.element.container.InspectorVisibilityPicker;
import org.gecko.view.inspector.element.label.InspectorLabel;
import org.gecko.view.inspector.element.textfield.InspectorVariableValueField;
import org.gecko.viewmodel.PortViewModel;

/**
Expand All @@ -24,5 +27,9 @@ public VariableBlockInspectorBuilder(ActionManager actionManager, PortViewModel

// Type
addInspectorElement(new InspectorTypeLabel(actionManager, viewModel));

// Value
addInspectorElement(new InspectorLabel(ResourceHandler.getString("Inspector", "variable_value")));
addInspectorElement(new InspectorVariableValueField(actionManager, viewModel));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public InspectorAddVariableButton(
setPrefWidth(WIDTH);
setOnAction(event -> {
actionManager.run(actionManager.getActionFactory().createCreatePortViewModelElementAction(systemViewModel));
//TODO this (hopyfully) gets the added port. This should be replaced by something not as hacky.
// Newly added port is the last in the list.
PortViewModel addedPort = systemViewModel.getPortsProperty().getLast();
//This is not an action because it should not be undoable.
// This is not an action because it should not be undoable.
addedPort.setVisibility(visibility);
try {
addedPort.updateTarget();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected InspectorTextField(StringProperty stringProperty, ActionManager action
});
}

private void updateText() {
protected void updateText() {
if (getText().isEmpty()) {
setText(stringProperty.get());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.gecko.view.inspector.element.textfield;

import org.gecko.actions.Action;
import org.gecko.actions.ActionManager;
import org.gecko.viewmodel.PortViewModel;

/**
* A concrete representation of an {@link InspectorTextField} for a {@link PortViewModel}, through which the value of
* the variable can be changed.
*/
public class InspectorVariableValueField extends InspectorTextField {
private final ActionManager actionManager;
private final PortViewModel portViewModel;

public InspectorVariableValueField(ActionManager actionManager, PortViewModel portViewModel) {
super(portViewModel.getValueProperty(), actionManager);
this.actionManager = actionManager;
this.portViewModel = portViewModel;
}

@Override
protected Action getAction() {
return actionManager.getActionFactory().createChangeVariableValuePortViewModelAction(portViewModel, getText());
}

@Override
protected void updateText() {
getParent().requestFocus();
if (getText() != null && getText().equals(portViewModel.getValue())) {
return;
}
actionManager.run(getAction());
setText(portViewModel.getValue());
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/gecko/view/views/FloatingUIBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public Node buildSearchWindow(EditorView editorView) {
searchBar.getItems().addAll(closeButton, searchTextField, backwardButton, forwardButton, matchesLabel);

searchTextField.setOnAction(e -> {
// TODO: Deselect current selection.
editorViewModel.getSelectionManager().deselectAll();
List<PositionableViewModelElement<?>> oldSearchMatches = new ArrayList<>(matches);
oldSearchMatches.forEach(matches::remove);
matches.addAll(editorViewModel.getElementsByName(searchTextField.getText()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ private void onVisibilityChanged(
if (oldValue == newValue) {
return;
}
//TODO this is ugly
PortViewModel portViewModel =
portsProperty.stream().filter(pvm -> pvm.getVisibilityProperty() == observable).findFirst().orElseThrow();
PortViewElement portViewElement =
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/gecko/viewmodel/PortViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
public class PortViewModel extends BlockViewModelElement<Variable> {
private final Property<Visibility> visibilityProperty;
private final StringProperty typeProperty;
private final StringProperty valueProperty;

private final Property<Point2D> systemPortPositionProperty;
private final Property<Point2D> systemPortSizeProperty;
Expand All @@ -32,6 +33,7 @@ public PortViewModel(int id, @NonNull Variable target) {
super(id, target);
this.visibilityProperty = new SimpleObjectProperty<>(target.getVisibility());
this.typeProperty = new SimpleStringProperty(target.getType());
this.valueProperty = new SimpleStringProperty(target.getValue());
this.sizeProperty.setValue(DEFAULT_PORT_SIZE);
this.systemPortPositionProperty = new SimpleObjectProperty<>(Point2D.ZERO);
this.systemPortSizeProperty = new SimpleObjectProperty<>(Point2D.ZERO);
Expand Down Expand Up @@ -61,11 +63,20 @@ public void setType(@NonNull String type) {
typeProperty.setValue(type);
}

public String getValue() {
return valueProperty.getValue();
}

public void setValue(String value) {
valueProperty.setValue(value);
}

@Override
public void updateTarget() throws ModelException {
super.updateTarget();
target.setVisibility(getVisibility());
target.setType(getType());
target.setValue(getValue());
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/Inspector_de_DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ target=Ziel
region_plural=Regionen
code=Code
rename_root_system=Root-System umbenennen
variable_value=Value
3 changes: 2 additions & 1 deletion src/main/resources/lang/Inspector_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ source=Source
target=Target
region_plural=Regions
code=Code
rename_root_system=Rename root system
rename_root_system=Rename root system
variable_value=Value
4 changes: 3 additions & 1 deletion src/test/java/org/gecko/io/SaveAndLoadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public class ProjectFileSerializerTest {
private static GeckoViewModel treeGeckoViewModel;
private static ObjectMapper mapper;
static String EMPTY_GECKO_JSON =
"{\"model\":{\"id\":0,\"name\":\"Element_0\",\"code\":null,\"automaton\":{\"startState\":null,\"regions\":[],\"states\":[],\"edges\":[]},\"children\":[],\"connections\":[],\"variables\":[]},\"startStates\":[],\"viewModelProperties\":[]}";
"{\"model\":{\"id\":0,\"name\":\"Element_0\",\"code\":null,\"automaton\":{\"startState\":null,\"regions\""
+ ":[],\"states\":[],\"edges\":[]},\"children\":[],\"connections\":[],\"variables\":[]},\"startStates"
+ "\":[],\"viewModelProperties\":[]}";
static String NON_NULL_AUTOMATON_JSON = "\"automaton\":{";
static String NON_NULL_START_STATE_JSON = "\"startState\":{";
static String NON_NULL_REGIONS_JSON = "\"regions\":[{";
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/org/gecko/model/ContractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

Expand All @@ -12,15 +13,13 @@
import org.junit.jupiter.api.Test;

public class ContractTest {
static Contract contract;
private static Contract contract;

@BeforeAll
static void setUp() {
Condition preCondition = null;
Condition postCondition = null;

// TODO: Contracts accept null pre-/postConditions, because setter onMethod instead of onParam

try {
preCondition = new Condition("pre");
postCondition = new Condition("post");
Expand Down
1 change: 0 additions & 1 deletion src/test/java/org/gecko/tools/CursorToolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ private void start(Stage stage) throws ModelException {

// @Test
// void select(FxRobot robot) {
// assertTrue(true);
// assertEquals(geckoView.getCurrentView().getCurrentViewElements().size(), 4);
//
// for (ViewElement<?> viewElement : geckoView.getCurrentView().getCurrentViewElements()) {
Expand Down
Loading