Skip to content

Commit

Permalink
Addresses #160 by providing a basic way to save tests as txt files
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Apr 30, 2024
1 parent 979206a commit 4a5f895
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
8 changes: 4 additions & 4 deletions gama.ui.shared/src/gama/ui/shared/parameters/FileEditor.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*******************************************************************************************************
*
* FileEditor.java, in gama.ui.shared.shared, is part of the source code of the GAMA modeling and simulation platform
* .
* FileEditor.java, in gama.ui.shared, is part of the source code of the GAMA modeling and simulation platform
* (v.2024-06).
*
* (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
* (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, ESPACE-DEV, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
Expand Down Expand Up @@ -160,7 +160,7 @@ public boolean select(final Viewer viewer, final Object parentElement,
dialog.setFilterPath(file != null ? file.getPath(getScope())
: GAMA.getModel() == null ? ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()
: GAMA.getModel().getFilePath());
dialog.setText("Choose a folder for parameter '" + param.getTitle() + "'");
dialog.setMessage("Choose a folder for parameter '" + param.getTitle() + "'");
final String path = dialog.open();
if (path != null) { file = Files.folderFile(getScope(), path, false); }
} else {
Expand Down
38 changes: 36 additions & 2 deletions gama.ui.shared/src/gama/ui/shared/views/TestView.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*******************************************************************************************************
*
* TestView.java, in gama.ui.shared, is part of the source code of the GAMA modeling and simulation platform (v.1.9.3).
* TestView.java, in gama.ui.shared, is part of the source code of the GAMA modeling and simulation platform
* (v.2024-06).
*
* (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
* (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, ESPACE-DEV, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
Expand All @@ -14,14 +15,19 @@
import static gama.ui.shared.resources.IGamaIcons.TEST_FILTER;
import static gama.ui.shared.resources.IGamaIcons.TEST_SORT;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.PartInitException;
Expand All @@ -32,6 +38,7 @@
import gama.core.common.interfaces.IGui;
import gama.core.common.interfaces.ItemList;
import gama.core.common.preferences.GamaPreferences;
import gama.core.common.util.FileUtils;
import gama.core.runtime.GAMA;
import gama.core.util.GamaColor;
import gama.gaml.statements.test.AbstractSummary;
Expand All @@ -44,6 +51,7 @@
import gama.ui.shared.resources.GamaColors;
import gama.ui.shared.resources.GamaColors.GamaUIColor;
import gama.ui.shared.resources.IGamaColors;
import gama.ui.shared.resources.IGamaIcons;
import gama.ui.shared.utils.ViewsHelper;
import gama.ui.shared.utils.WorkbenchHelper;
import gama.ui.shared.views.toolbar.GamaToolbar2;
Expand Down Expand Up @@ -238,6 +246,32 @@ public void createToolItems(final GamaToolbar2 tb) {
}, SWT.RIGHT);
t2.setSelection(FAILED_TESTS.getValue());
FAILED_TESTS.onChange(v -> t2.setSelection(v));
final ToolItem save =
tb.button(IGamaIcons.SAVE_AS, "Save tests", "Save the current tests as a text file", e -> {
this.saveTests();
}, SWT.RIGHT);
}

/**
* Save tests.
*/
public void saveTests() {
final DirectoryDialog dialog = new DirectoryDialog(WorkbenchHelper.getDisplay().getActiveShell(), SWT.NULL);
dialog.setFilterPath(GAMA.getModel() == null
? ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() : GAMA.getModel().getFilePath());
dialog.setText("Choose a folder for saving the tests");
final String path = dialog.open();
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
String file = path + "/" + "tests_" + timestamp.toString() + ".txt";
file = FileUtils.constructAbsoluteFilePath(GAMA.getRuntimeScope(), file, false);
try (PrintWriter out = new PrintWriter(file)) {
for (AbstractSummary summary : experiments) {
out.println(summary.toString());
out.flush();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}

}

Expand Down

0 comments on commit 4a5f895

Please sign in to comment.