Commit 96b2b783 authored by Sarah Grebing's avatar Sarah Grebing
Browse files

planning for conceptual merge of actions

parent b8ec7a67
...@@ -6,6 +6,7 @@ import de.uka.ilkd.key.proof.init.ProofInputException; ...@@ -6,6 +6,7 @@ import de.uka.ilkd.key.proof.init.ProofInputException;
import de.uka.ilkd.key.speclang.Contract; import de.uka.ilkd.key.speclang.Contract;
import edu.kit.formal.gui.ProofScriptDebugger; import edu.kit.formal.gui.ProofScriptDebugger;
import edu.kit.formal.gui.controls.*; import edu.kit.formal.gui.controls.*;
import edu.kit.formal.gui.model.Breakpoint;
import edu.kit.formal.gui.model.InspectionModel; import edu.kit.formal.gui.model.InspectionModel;
import edu.kit.formal.interpreter.Interpreter; import edu.kit.formal.interpreter.Interpreter;
import edu.kit.formal.interpreter.InterpreterBuilder; import edu.kit.formal.interpreter.InterpreterBuilder;
...@@ -42,6 +43,7 @@ import java.net.URL; ...@@ -42,6 +43,7 @@ import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.List; import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
...@@ -128,6 +130,18 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -128,6 +130,18 @@ public class DebuggerMainWindowController implements Initializable {
scriptController.mainScriptProperty().bindBidirectional(statusBar.mainScriptIdentifierProperty()); scriptController.mainScriptProperty().bindBidirectional(statusBar.mainScriptIdentifierProperty());
}
/**
* If the mouse moves other toolbar button, the help text should display in the status bar
*/
private void registerToolbarToStatusBar() {
/*toolbar.getChildrenUnmodifiable().forEach(
n -> n.setOnMouseEntered(statusBar.getTooltipHandler()));
buttonStartInterpreter.setOnMouseEntered(statusBar.getTooltipHandler());
*/
} }
/** /**
...@@ -209,19 +223,26 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -209,19 +223,26 @@ public class DebuggerMainWindowController implements Initializable {
} }
public InspectionViewsController getInspectionViewsController() {
return inspectionViewsController;
}
/** public KeYProofFacade getFacade() {
* If the mouse moves other toolbar button, the help text should display in the status bar return FACADE;
*/ }
private void registerToolbarToStatusBar() {
/*toolbar.getChildrenUnmodifiable().forEach(
n -> n.setOnMouseEntered(statusBar.getTooltipHandler()));
buttonStartInterpreter.setOnMouseEntered(statusBar.getTooltipHandler()); public void showCodeDock(ActionEvent actionEvent) {
*/ if (!javaAreaDock.isDocked()) {
javaAreaDock.dock(dockStation, DockPos.RIGHT);
}
} }
//region Actions: Execution //region Actions: Execution
@FXML
public void executeToBreakpoint() {
}
@FXML @FXML
public void executeScript() { public void executeScript() {
if (proofTreeController.isAlreadyExecuted()) { if (proofTreeController.isAlreadyExecuted()) {
...@@ -256,6 +277,27 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -256,6 +277,27 @@ public class DebuggerMainWindowController implements Initializable {
} }
} }
public File getJavaFile() {
return javaFile.get();
}
//endregion
public void setJavaFile(File javaFile) {
this.javaFile.set(javaFile);
}
public File getKeyFile() {
return keyFile.get();
}
/**
* Reload the KeY environment, to execute the script again
* TODO: reload views
*
* @param file
* @param keyfile
* @return
*/
public Task<Void> reloadEnvironment(File file, boolean keyfile) { public Task<Void> reloadEnvironment(File file, boolean keyfile) {
Task<Void> task = new Task<Void>() { Task<Void> task = new Task<Void>() {
@Override @Override
...@@ -272,25 +314,6 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -272,25 +314,6 @@ public class DebuggerMainWindowController implements Initializable {
return task; return task;
} }
@FXML
public void executeScriptFromCursor() {
InterpreterBuilder ib = FACADE.buildInterpreter();
// ib.inheritState(interpreterService.interpreterProperty().get());
/*LineMapping lm = new LineMapping(scriptArea.getText());
int line = lm.getLine(scriptArea.getCaretPosition());
int inLine = lm.getCharInLine(scriptArea.getCaretPosition());
ib.ignoreLinesUntil(scriptController.getSelectedScriptArea().getCaretPosition());
executeScript(ib, true);*/
}
@FXML
public void executeInDebugMode() {
executeScript(FACADE.buildInterpreter(), true);
}
//endregion
/** /**
* Execute the script that with using the interpreter that is build using teh interpreterbuilder * Execute the script that with using the interpreter that is build using teh interpreterbuilder
* *
...@@ -298,7 +321,10 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -298,7 +321,10 @@ public class DebuggerMainWindowController implements Initializable {
* @param debugMode * @param debugMode
*/ */
private void executeScript(InterpreterBuilder ib, boolean debugMode) { private void executeScript(InterpreterBuilder ib, boolean debugMode) {
Set<Breakpoint> breakpoints = scriptController.getBreakpoints();
if (proofTreeController.isAlreadyExecuted()) {
proofTreeController.saveGraphs();
}
this.debugMode.set(debugMode); this.debugMode.set(debugMode);
statusBar.publishMessage("Parse ..."); statusBar.publishMessage("Parse ...");
try { try {
...@@ -311,7 +337,7 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -311,7 +337,7 @@ public class DebuggerMainWindowController implements Initializable {
proofTreeController.setCurrentInterpreter(currentInterpreter); proofTreeController.setCurrentInterpreter(currentInterpreter);
proofTreeController.setMainScript(scripts.get(0)); proofTreeController.setMainScript(scripts.get(0));
statusBar.publishMessage("Executing script " + scripts.get(0).getName()); statusBar.publishMessage("Executing script " + scripts.get(0).getName());
proofTreeController.executeScript(this.debugMode.get(), statusBar); proofTreeController.executeScript(this.debugMode.get(), statusBar, breakpoints);
//highlight signature of main script //highlight signature of main script
//scriptController.setDebugMark(scripts.get(0).getStartPosition().getLineNumber()); //scriptController.setDebugMark(scripts.get(0).getStartPosition().getLineNumber());
} catch (RecognitionException e) { } catch (RecognitionException e) {
...@@ -319,6 +345,82 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -319,6 +345,82 @@ public class DebuggerMainWindowController implements Initializable {
} }
} }
public void openKeyFile(File keyFile) {
if (keyFile != null) {
setKeyFile(keyFile);
setInitialDirectory(keyFile.getParentFile());
Task<Void> task = FACADE.loadKeyFileTask(keyFile);
task.setOnSucceeded(event -> {
statusBar.publishMessage("Loaded key sourceName: %s", keyFile);
statusBar.stopProgress();
getInspectionViewsController().getActiveInspectionViewTab().getModel().getGoals().setAll(FACADE.getPseudoGoals());
});
task.setOnFailed(event -> {
statusBar.stopProgress();
event.getSource().exceptionProperty().get();
Utils.showExceptionDialog("Could not load sourceName", "Key sourceName loading error", "",
(Throwable) event.getSource().exceptionProperty().get()
);
});
ProgressBar bar = new ProgressBar();
bar.progressProperty().bind(task.progressProperty());
executorService.execute(task);
}
}
public void openJavaFile(File javaFile) {
if (javaFile != null) {
setJavaFile(javaFile);
initialDirectory.set(javaFile.getParentFile());
contractLoaderService.start();
}
}
public void setKeyFile(File keyFile) {
this.keyFile.set(keyFile);
}
@FXML
public void executeDiff() {
//save old PT
// Calculate top difference between current and last executed script
// Find last state of common ASTNode
// Use this state to build new interpreter in proof tree controller.
// execute residual script
}
//deprecated
@FXML
public void executeScriptFromCursor() {
InterpreterBuilder ib = FACADE.buildInterpreter();
//b.inheritState(interpreterService.interpreterProperty().get());
// Get State before cursor
// use goalnode to build new interpreter in proof tree controller.
//
//LineMapping lm = new LineMapping(scriptArea.getText());
//int line = lm.getLine(scriptArea.getCaretPosition());
//int inLine = lm.getCharInLine(scriptArea.getCaretPosition());
//ib.ignoreLinesUntil(scriptController.getSelectedScriptArea().getCaretPosition());
//executeScript(ib, true);
}
@FXML
public void executeInDebugMode() {
executeScript(FACADE.buildInterpreter(), true);
}
//endregion
//region Santa's Little Helper
//region Actions: Menu //region Actions: Menu
@FXML @FXML
...@@ -335,21 +437,47 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -335,21 +437,47 @@ public class DebuggerMainWindowController implements Initializable {
} }
} }
@FXML private File openFileChooserOpenDialog(String title, String description, String... fileEndings) {
public void saveScript() { FileChooser fileChooser = getFileChooser(title, description, fileEndings);
//File sourceName = fileChooser.showOpenDialog(inspectionViewsController.getInspectionViewTab().getGoalView().getScene().getWindow());
File file = fileChooser.showOpenDialog(statusBar.getScene().getWindow());
if (file != null) setInitialDirectory(file.getParentFile());
return file;
}
public void openScript(File scriptFile) {
assert scriptFile != null;
setInitialDirectory(scriptFile.getParentFile());
try { try {
scriptController.saveCurrentScript(); String code = FileUtils.readFileToString(scriptFile, Charset.defaultCharset());
ScriptArea area = scriptController.createNewTab(scriptFile);
} catch (IOException e) { } catch (IOException e) {
Utils.showExceptionDialog("Could not save file", "Saving File Error", "Could not save current script", e); Utils.showExceptionDialog("Exception occured", "",
"Could not load sourceName " + scriptFile, e);
} }
} }
private void saveScript(File scriptFile) { private FileChooser getFileChooser(String title, String description, String[] fileEndings) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(title);
fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter(description, fileEndings));
if (initialDirectory.get() == null)
setInitialDirectory(new File("src/test/resources/edu/kit/formal/interpreter/contraposition/"));
if (!initialDirectory.get().exists())
setInitialDirectory(new File("."));
fileChooser.setInitialDirectory(initialDirectory.get());
return fileChooser;
}
@FXML
public void saveScript() {
try { try {
scriptController.saveCurrentScriptAs(scriptFile); scriptController.saveCurrentScript();
} catch (IOException e) { } catch (IOException e) {
Utils.showExceptionDialog("Could not save file", "Saving File Error", "Could not save to file " + scriptFile.getName(), e); Utils.showExceptionDialog("Could not save file", "Saving File Error", "Could not save current script", e);
} }
} }
...@@ -364,15 +492,27 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -364,15 +492,27 @@ public class DebuggerMainWindowController implements Initializable {
} }
} }
public void openScript(File scriptFile) { /**
assert scriptFile != null; * Creates a filechooser dialog
setInitialDirectory(scriptFile.getParentFile()); *
* @param title of the dialog
* @param description of the files
* @param fileEndings sourceName that should be shown
* @return
*/
private File openFileChooserSaveDialog(String title, String description, String... fileEndings) {
FileChooser fileChooser = getFileChooser(title, description, fileEndings);
// File sourceName = fileChooser.showSaveDialog(inspectionViewsController.getInspectionViewTab().getGoalView().getScene().getWindow());
File file = fileChooser.showOpenDialog(statusBar.getScene().getWindow());
if (file != null) setInitialDirectory(file.getParentFile());
return file;
}
private void saveScript(File scriptFile) {
try { try {
String code = FileUtils.readFileToString(scriptFile, Charset.defaultCharset()); scriptController.saveCurrentScriptAs(scriptFile);
ScriptArea area = scriptController.createNewTab(scriptFile);
} catch (IOException e) { } catch (IOException e) {
Utils.showExceptionDialog("Exception occured", "", Utils.showExceptionDialog("Could not save file", "Saving File Error", "Could not save to file " + scriptFile.getName(), e);
"Could not load sourceName " + scriptFile, e);
} }
} }
...@@ -381,31 +521,7 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -381,31 +521,7 @@ public class DebuggerMainWindowController implements Initializable {
File keyFile = openFileChooserOpenDialog("Select KeY File", "KeY Files", "key", "kps"); File keyFile = openFileChooserOpenDialog("Select KeY File", "KeY Files", "key", "kps");
openKeyFile(keyFile); openKeyFile(keyFile);
} }
//endregion
public void openKeyFile(File keyFile) {
if (keyFile != null) {
setKeyFile(keyFile);
setInitialDirectory(keyFile.getParentFile());
Task<Void> task = FACADE.loadKeyFileTask(keyFile);
task.setOnSucceeded(event -> {
statusBar.publishMessage("Loaded key sourceName: %s", keyFile);
statusBar.stopProgress();
getInspectionViewsController().getActiveInspectionViewTab().getModel().getGoals().setAll(FACADE.getPseudoGoals());
});
task.setOnFailed(event -> {
statusBar.stopProgress();
event.getSource().exceptionProperty().get();
Utils.showExceptionDialog("Could not load sourceName", "Key sourceName loading error", "",
(Throwable) event.getSource().exceptionProperty().get()
);
});
ProgressBar bar = new ProgressBar();
bar.progressProperty().bind(task.progressProperty());
executorService.execute(task);
}
}
/** /**
* Save KeY proof as proof file * Save KeY proof as proof file
...@@ -417,67 +533,15 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -417,67 +533,15 @@ public class DebuggerMainWindowController implements Initializable {
LOGGER.error("saveProof not implemented!!!"); LOGGER.error("saveProof not implemented!!!");
} }
//endregion
//region Santa's Little Helper
@FXML
protected void loadJavaFile() {
File javaFile = openFileChooserOpenDialog("Select Java File", "Java Files", "java");
openJavaFile(javaFile);
}
public void openJavaFile(File javaFile) {
if (javaFile != null) {
setJavaFile(javaFile);
initialDirectory.set(javaFile.getParentFile());
contractLoaderService.start();
}
}
public void openJavaFile() { public void openJavaFile() {
loadJavaFile(); loadJavaFile();
showCodeDock(null); showCodeDock(null);
} }
/** @FXML
* Creates a filechooser dialog protected void loadJavaFile() {
* File javaFile = openFileChooserOpenDialog("Select Java File", "Java Files", "java");
* @param title of the dialog openJavaFile(javaFile);
* @param description of the files
* @param fileEndings sourceName that should be shown
* @return
*/
private File openFileChooserSaveDialog(String title, String description, String... fileEndings) {
FileChooser fileChooser = getFileChooser(title, description, fileEndings);
// File sourceName = fileChooser.showSaveDialog(inspectionViewsController.getInspectionViewTab().getGoalView().getScene().getWindow());
File file = fileChooser.showOpenDialog(statusBar.getScene().getWindow());
if (file != null) setInitialDirectory(file.getParentFile());
return file;
}
private File openFileChooserOpenDialog(String title, String description, String... fileEndings) {
FileChooser fileChooser = getFileChooser(title, description, fileEndings);
//File sourceName = fileChooser.showOpenDialog(inspectionViewsController.getInspectionViewTab().getGoalView().getScene().getWindow());
File file = fileChooser.showOpenDialog(statusBar.getScene().getWindow());
if (file != null) setInitialDirectory(file.getParentFile());
return file;
}
private FileChooser getFileChooser(String title, String description, String[] fileEndings) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(title);
fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter(description, fileEndings));
if (initialDirectory.get() == null)
setInitialDirectory(new File("src/test/resources/edu/kit/formal/interpreter/contraposition/"));
if (!initialDirectory.get().exists())
setInitialDirectory(new File("."));
fileChooser.setInitialDirectory(initialDirectory.get());
return fileChooser;
} }
public void stepOver(ActionEvent actionEvent) { public void stepOver(ActionEvent actionEvent) {
...@@ -490,16 +554,10 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -490,16 +554,10 @@ public class DebuggerMainWindowController implements Initializable {
PTreeNode newState = proofTreeController.stepBack(); PTreeNode newState = proofTreeController.stepBack();
} }
public KeYProofFacade getFacade() {
return FACADE;
}
//region Property //region Property
public boolean isDebugMode() { public boolean isDebugMode() {
return debugMode.get(); return debugMode.get();
} }
//endregion
public void setDebugMode(boolean debugMode) { public void setDebugMode(boolean debugMode) {
this.debugMode.set(debugMode); this.debugMode.set(debugMode);
...@@ -529,12 +587,6 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -529,12 +587,6 @@ public class DebuggerMainWindowController implements Initializable {
scriptController.newScript(); scriptController.newScript();
} }
public void showCodeDock(ActionEvent actionEvent) {
if (!javaAreaDock.isDocked()) {
javaAreaDock.dock(dockStation, DockPos.RIGHT);
}
}
public void showWelcomeDock(ActionEvent actionEvent) { public void showWelcomeDock(ActionEvent actionEvent) {
if (!welcomePaneDock.isDocked()) { if (!welcomePaneDock.isDocked()) {
welcomePaneDock.dock(dockStation, DockPos.CENTER); welcomePaneDock.dock(dockStation, DockPos.CENTER);
...@@ -580,10 +632,6 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -580,10 +632,6 @@ public class DebuggerMainWindowController implements Initializable {
return proofTreeController; return proofTreeController;
} }
public InspectionViewsController getInspectionViewsController() {
return inspectionViewsController;
}
public ExecutorService getExecutorService() { public ExecutorService getExecutorService() {
return executorService; return executorService;
} }
...@@ -608,26 +656,10 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -608,26 +656,10 @@ public class DebuggerMainWindowController implements Initializable {
return welcomePane; return welcomePane;
} }
public File getJavaFile() {
return javaFile.get();
}
public void setJavaFile(File javaFile) {
this.javaFile.set(javaFile);
}
public ObjectProperty<File> javaFileProperty() { public ObjectProperty<File> javaFileProperty() {
return javaFile; return javaFile;
} }
public File getKeyFile() {
return keyFile.get();
}
public void setKeyFile(File keyFile) {
this.keyFile.set(keyFile);
}
public ObjectProperty<File> keyFileProperty() { public ObjectProperty<File> keyFileProperty() {
return keyFile; return keyFile;
} }
...@@ -657,16 +689,6 @@ public class DebuggerMainWindowController implements Initializable { ...@@ -657,16 +689,6 @@ public class DebuggerMainWindowController implements Initializable {
} }