Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
BenKenobie31415 committed Mar 10, 2024
1 parent bb05602 commit 4204127
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ public class CopyPositionableViewModelElementAction extends Action {
boolean run() throws GeckoException {
CopyPositionableViewModelElementVisitor visitor = new CopyPositionableViewModelElementVisitor(geckoViewModel);

Set<PositionableViewModelElement<?>> copyQueue = geckoViewModel.getCurrentEditor().getSelectionManager().getCurrentSelection();
Set<Element> elementToCopy = copyQueue.stream().map(PositionableViewModelElement::getTarget).collect(Collectors.toSet());
Set<PositionableViewModelElement<?>> copyQueue =
geckoViewModel.getCurrentEditor().getSelectionManager().getCurrentSelection();
Set<Element> elementToCopy =
copyQueue.stream().map(PositionableViewModelElement::getTarget).collect(Collectors.toSet());
for (Edge edge : geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getAutomaton().getEdges()) {
if (elementToCopy.contains(edge.getSource()) && elementToCopy.contains(edge.getDestination())) {
copyQueue.add(geckoViewModel.getViewModelElement(edge));
}
}
for (SystemConnection connection : geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getConnections()) {
for (SystemConnection connection : geckoViewModel.getCurrentEditor()
.getCurrentSystem()
.getTarget()
.getConnections()) {
System sourceSystem = geckoViewModel.getGeckoModel().getSystemWithVariable(connection.getSource());
System destinationSystem = geckoViewModel.getGeckoModel().getSystemWithVariable(connection.getDestination());
System destinationSystem =
geckoViewModel.getGeckoModel().getSystemWithVariable(connection.getDestination());
if (elementToCopy.contains(sourceSystem) && elementToCopy.contains(destinationSystem)) {
copyQueue.add(geckoViewModel.getViewModelElement(connection));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public Void visit(RegionViewModel regionViewModel) {

@Override
public Void visit(EdgeViewModel edgeViewModel) {
Set<PositionableViewModelElement<?>> selection = geckoViewModel.getCurrentEditor().getSelectionManager().getCurrentSelection();
Set<PositionableViewModelElement<?>> selection =
geckoViewModel.getCurrentEditor().getSelectionManager().getCurrentSelection();
if (selection.contains(edgeViewModel.getSource()) && selection.contains(edgeViewModel.getDestination())) {
Edge original = edgeViewModel.getTarget();
Edge copy = geckoViewModel.getGeckoModel().getModelFactory().copyEdge(original);
Expand All @@ -98,7 +99,8 @@ public Void visit(EdgeViewModel edgeViewModel) {
@Override
public Void visit(StateViewModel stateViewModel) {
State original = stateViewModel.getTarget();
Pair<State, Map<Contract, Contract>> copyResult = geckoViewModel.getGeckoModel().getModelFactory().copyState(original);
Pair<State, Map<Contract, Contract>> copyResult =
geckoViewModel.getGeckoModel().getModelFactory().copyState(original);
State copy = copyResult.getKey();
originalToClipboard.putAll(copyResult.getValue());
originalToClipboard.put(original, copy);
Expand All @@ -113,9 +115,18 @@ public Void visit(PortViewModel portViewModel) {

@Override
public Void visit(SystemConnectionViewModel systemConnectionViewModel) {
Set<PositionableViewModelElement<?>> selection = geckoViewModel.getCurrentEditor().getSelectionManager().getCurrentSelection();
SystemViewModel sourceSystemViewModel = (SystemViewModel) geckoViewModel.getViewModelElement(geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getChildSystemWithVariable(systemConnectionViewModel.getTarget().getSource()));
SystemViewModel destinationSystemViewModel = (SystemViewModel) geckoViewModel.getViewModelElement(geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getChildSystemWithVariable(systemConnectionViewModel.getTarget().getDestination()));
Set<PositionableViewModelElement<?>> selection =
geckoViewModel.getCurrentEditor().getSelectionManager().getCurrentSelection();
SystemViewModel sourceSystemViewModel = (SystemViewModel) geckoViewModel.getViewModelElement(
geckoViewModel.getCurrentEditor()
.getCurrentSystem()
.getTarget()
.getChildSystemWithVariable(systemConnectionViewModel.getTarget().getSource()));
SystemViewModel destinationSystemViewModel = (SystemViewModel) geckoViewModel.getViewModelElement(
geckoViewModel.getCurrentEditor()
.getCurrentSystem()
.getTarget()
.getChildSystemWithVariable(systemConnectionViewModel.getTarget().getDestination()));
if (selection.contains(sourceSystemViewModel) && selection.contains(destinationSystemViewModel)) {
SystemConnection original = systemConnectionViewModel.getTarget();
SystemConnection copy = geckoViewModel.getGeckoModel().getModelFactory().copySystemConnection(original);
Expand Down Expand Up @@ -149,7 +160,8 @@ private void savePositionRecursively(System original) {
savePositionRecursively(child);
}
}
private void savePositionAndSize(Element key,PositionableViewModelElement<?> positionSource) {

private void savePositionAndSize(Element key, PositionableViewModelElement<?> positionSource) {
elementToPosAndSize.put(key, new Pair<>(positionSource.getPosition(), positionSource.getSize()));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.gecko.actions;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javafx.geometry.Point2D;
import org.gecko.exceptions.GeckoException;
Expand Down Expand Up @@ -30,7 +29,8 @@ boolean run() throws GeckoException {
return false;
}

PastePositionableViewModelElementVisitor pasteVisitor = new PastePositionableViewModelElementVisitor(geckoViewModel, copyVisitor);
PastePositionableViewModelElementVisitor pasteVisitor =
new PastePositionableViewModelElementVisitor(geckoViewModel, copyVisitor);
for (Element element : copyVisitor.getOriginalToClipboard().values()) {
element.accept(pasteVisitor);
}
Expand All @@ -42,7 +42,8 @@ boolean run() throws GeckoException {
}
}
pastedElements.addAll(pasteVisitor.getPastedElements());
Action selectAction = geckoViewModel.getActionManager().getActionFactory().createSelectAction(pastedElements, true);
Action selectAction =
geckoViewModel.getActionManager().getActionFactory().createSelectAction(pastedElements, true);
geckoViewModel.getActionManager().run(selectAction);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public class PastePositionableViewModelElementVisitor implements ElementVisitor
@Getter
private final Set<Element> unsuccessfulPastes;

PastePositionableViewModelElementVisitor(GeckoViewModel geckoViewModel, CopyPositionableViewModelElementVisitor copyVisitor) {
PastePositionableViewModelElementVisitor(
GeckoViewModel geckoViewModel, CopyPositionableViewModelElementVisitor copyVisitor) {
this.geckoViewModel = geckoViewModel;
this.copyVisitor = copyVisitor;
pastedElements = new HashSet<>();
Expand All @@ -48,23 +49,27 @@ public class PastePositionableViewModelElementVisitor implements ElementVisitor

@Override
public void visit(State stateFromClipboard) throws ModelException {
Pair<State, Map<Contract, Contract>> copyResult = geckoViewModel.getGeckoModel().getModelFactory().copyState(stateFromClipboard);
Pair<State, Map<Contract, Contract>> copyResult =
geckoViewModel.getGeckoModel().getModelFactory().copyState(stateFromClipboard);
State stateToPaste = copyResult.getKey();
clipboardToPasted.putAll(copyResult.getValue());
geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getAutomaton().addState(stateToPaste);
StateViewModel stateViewModel = geckoViewModel.getViewModelFactory().createStateViewModelFrom(stateToPaste);
stateViewModel.setPosition(copyVisitor.getElementToPosAndSize().get(stateFromClipboard).getKey().add(pasteOffset));
stateViewModel.setPosition(
copyVisitor.getElementToPosAndSize().get(stateFromClipboard).getKey().add(pasteOffset));
stateViewModel.setSize(copyVisitor.getElementToPosAndSize().get(stateFromClipboard).getValue());
clipboardToPasted.put(stateFromClipboard, stateToPaste);
pastedElements.add(stateViewModel);
}

@Override
public void visit(Contract contract) {}
public void visit(Contract contract) {
}

@Override
public void visit(SystemConnection connectionFromClipboard) throws MissingViewModelElementException {
SystemConnection connectionToPaste = geckoViewModel.getGeckoModel().getModelFactory().copySystemConnection(connectionFromClipboard);
SystemConnection connectionToPaste =
geckoViewModel.getGeckoModel().getModelFactory().copySystemConnection(connectionFromClipboard);
Variable pastedSource = (Variable) clipboardToPasted.get(connectionFromClipboard.getSource());
Variable pastedDestination = (Variable) clipboardToPasted.get(connectionFromClipboard.getDestination());
if (pastedSource == null || pastedDestination == null) {
Expand All @@ -78,13 +83,18 @@ public void visit(SystemConnection connectionFromClipboard) throws MissingViewMo
throw new RuntimeException(e);
}
geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().addConnection(connectionToPaste);
SystemConnectionViewModel systemConnectionViewModel = geckoViewModel.getViewModelFactory().createSystemConnectionViewModelFrom(connectionToPaste);
SystemConnectionViewModel systemConnectionViewModel =
geckoViewModel.getViewModelFactory().createSystemConnectionViewModelFrom(connectionToPaste);
pastedElements.add(systemConnectionViewModel);
}

@Override
public void visit(Variable variableFromClipboard) throws ModelException {
if (!geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getVariables().contains(variableFromClipboard)) {
if (!geckoViewModel.getCurrentEditor()
.getCurrentSystem()
.getTarget()
.getVariables()
.contains(variableFromClipboard)) {
return;
}
Variable variableToPaste = geckoViewModel.getGeckoModel().getModelFactory().copyVariable(variableFromClipboard);
Expand All @@ -100,7 +110,8 @@ public void visit(System systemFromClipboard) throws ModelException {
if (systemFromClipboard.getParent() != null) {
return;
}
Pair<System, Map<Element, Element>> copyResult = geckoViewModel.getGeckoModel().getModelFactory().copySystem(systemFromClipboard);
Pair<System, Map<Element, Element>> copyResult =
geckoViewModel.getGeckoModel().getModelFactory().copySystem(systemFromClipboard);
System systemToPaste = copyResult.getKey();
clipboardToPasted.putAll(copyResult.getValue());
geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().addChild(systemToPaste);
Expand All @@ -119,12 +130,19 @@ private void createRecursiveSystemViewModels(System systemToPaste) {
}
for (State state : systemToPaste.getAutomaton().getStates()) {
StateViewModel stateViewModel = geckoViewModel.getViewModelFactory().createStateViewModelFrom(state);
stateViewModel.setPosition(copyVisitor.getElementToPosAndSize().get(clipboardToPasted.inverse().get(state)).getKey().add(pasteOffset));
stateViewModel.setPosition(copyVisitor.getElementToPosAndSize()
.get(clipboardToPasted.inverse().get(state))
.getKey()
.add(pasteOffset));
}
for (Region region : systemToPaste.getAutomaton().getRegions()) {
try {
RegionViewModel regionViewModel = geckoViewModel.getViewModelFactory().createRegionViewModelFrom(region);
regionViewModel.setPosition(copyVisitor.getElementToPosAndSize().get(clipboardToPasted.inverse().get(region)).getKey().add(pasteOffset));
RegionViewModel regionViewModel =
geckoViewModel.getViewModelFactory().createRegionViewModelFrom(region);
regionViewModel.setPosition(copyVisitor.getElementToPosAndSize()
.get(clipboardToPasted.inverse().get(region))
.getKey()
.add(pasteOffset));
} catch (MissingViewModelElementException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -154,7 +172,8 @@ public void visit(Region regionFromClipboard) throws ModelException, MissingView
clipboardToPasted.put(regionFromClipboard, regionToPaste);
geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getAutomaton().addRegion(regionToPaste);
RegionViewModel regionViewModel = geckoViewModel.getViewModelFactory().createRegionViewModelFrom(regionToPaste);
regionViewModel.setPosition(copyVisitor.getElementToPosAndSize().get(regionFromClipboard).getKey().add(pasteOffset));
regionViewModel.setPosition(
copyVisitor.getElementToPosAndSize().get(regionFromClipboard).getKey().add(pasteOffset));
regionViewModel.setSize(copyVisitor.getElementToPosAndSize().get(regionFromClipboard).getValue());
pastedElements.add(regionViewModel);
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/gecko/model/ModelFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public Pair<System, Map<Element, Element>> copySystem(@NonNull System system) th
return copySystem(system, new HashMap<>());
}

public Pair<System, Map<Element, Element>> copySystem(@NonNull System system, Map<Element, Element> originalToCopy) throws ModelException {
public Pair<System, Map<Element, Element>> copySystem(@NonNull System system, Map<Element, Element> originalToCopy)
throws ModelException {
int id = getNewElementId();
System copy;
try {
Expand Down Expand Up @@ -152,8 +153,9 @@ public Pair<System, Map<Element, Element>> copySystem(@NonNull System system, Ma
childSystem.setParent(copy);
}
for (SystemConnection connection : system.getConnections()) {
SystemConnection copiedConnection = copySystemConnection(connection, (Variable) originalToCopy.get(connection.getSource()),
(Variable) originalToCopy.get(connection.getDestination()));
SystemConnection copiedConnection =
copySystemConnection(connection, (Variable) originalToCopy.get(connection.getSource()),
(Variable) originalToCopy.get(connection.getDestination()));
copy.addConnection(copiedConnection);
originalToCopy.put(connection, copiedConnection);
}
Expand Down Expand Up @@ -233,7 +235,8 @@ public SystemConnection copySystemConnection(SystemConnection connection) {
}
}

public SystemConnection copySystemConnection(SystemConnection connection, Variable copiedSource, Variable copiedDestination) {
public SystemConnection copySystemConnection(
SystemConnection connection, Variable copiedSource, Variable copiedDestination) {
SystemConnection result = copySystemConnection(connection);
try {
result.setSource(copiedSource);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/gecko/view/views/EditorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public EditorView(
StringProperty tabName = new SimpleStringProperty("Error_Name");
tabName.bind(Bindings.createStringBinding(() -> {
String name = viewModel.getCurrentSystem().getName();
return name + (viewModel.isAutomatonEditor() ? " (" + ResourceHandler.getString("View", "automaton") + ")"
: " (" + ResourceHandler.getString("View", "system") + ")");
return name + (viewModel.isAutomatonEditor() ? " (" + ResourceHandler.getString("View", "automaton") + ")" :
" (" + ResourceHandler.getString("View", "system") + ")");
}, viewModel.getCurrentSystem().getNameProperty()));

Label tabLabel = new Label();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.gecko.exceptions.ModelException;
import org.gecko.model.Element;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.gecko.viewmodel;

import org.gecko.exceptions.ModelException;

/**
* Represents a visitor pattern for performing operations on {@link PositionableViewModelElement}s. Concrete visitors
* must implement this interface to define specific behavior for each {@link PositionableViewModelElement}.
Expand Down

0 comments on commit 4204127

Please sign in to comment.