Commit eae49bb3 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

add IScenarioChecker interface

parent 77d16c06
Pipeline #71357 passed with stages
in 64 minutes and 38 seconds
package org.vadere.gui.projectview.model;
import org.vadere.simulator.projects.Scenario;
public interface IScenarioChecker {
void checkScenario(final Scenario scenario);
}
......@@ -11,6 +11,7 @@ import org.vadere.gui.projectview.view.ScenarioNamePanel;
import org.vadere.gui.projectview.view.ScenarioPanel;
import org.vadere.gui.projectview.view.VDialogManager;
import org.vadere.gui.projectview.view.VTable;
import org.vadere.gui.topographycreator.model.IDrawPanelModel;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.VadereProject;
import org.vadere.simulator.projects.ProjectWriter;
......@@ -25,7 +26,7 @@ import java.util.concurrent.Executors;
import java.util.prefs.Preferences;
import java.util.stream.Collectors;
public class ProjectViewModel {
public class ProjectViewModel implements IScenarioChecker {
private static Logger logger = LogManager.getLogger(ProjectViewModel.class);
private VadereProject project;
......@@ -43,7 +44,8 @@ public class ProjectViewModel {
private final Collection<IOutputFileRefreshListener> outputRefreshListeners;
private final Collection<IProjectChangeListener> projectChangeListeners;
private ScenarioNamePanel scenarioNamePanel; // to add or remove the "*" to indicate unsaved changes
private List<IScenarioChecker> scenarioCheckerListeners;
private ScenarioNamePanel scenarioNamePanel; // to add or remove the "*" to indicate unsaved changes and ScenarioChecker indicator
private boolean showSimulationResultDialog;
public ProjectViewModel() {
......@@ -55,6 +57,7 @@ public class ProjectViewModel {
this.refreshOutputExecutor = Executors.newSingleThreadExecutor();
this.showSimulationResultDialog = Preferences.userNodeForPackage(VadereApplication.class)
.getBoolean("Project.simulationResult.show", true);
this.scenarioCheckerListeners = new ArrayList<>();
}
public void deleteOutputFiles(final int[] rows) throws IOException {
......@@ -424,4 +427,22 @@ public class ProjectViewModel {
public void setShowSimulationResultDialog(boolean showSimulationResultDialog) {
this.showSimulationResultDialog = showSimulationResultDialog;
}
public void scenarioCheckerStopObserve(){
scenarioNamePanel.stopObserver();
}
public void scenarioCheckerStartObserve(IDrawPanelModel model){
scenarioNamePanel.observerIDrawPanelModel(model);
}
public void scenarioCheckerCheck(final Scenario scenario){
scenarioNamePanel.check(scenario);
}
@Override
public void checkScenario(final Scenario scenario) {
scenarioNamePanel.check(scenario);
}
}
......@@ -12,6 +12,7 @@ import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rsyntaxtextarea.Theme;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.view.JComboCheckBox;
import org.vadere.gui.projectview.model.IScenarioChecker;
import org.vadere.gui.projectview.utils.SimpleDocumentListener;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager;
......@@ -63,6 +64,7 @@ class DataProcessingView extends JPanel implements IJsonView {
private Scenario currentScenario;
private boolean isEditable;
private IScenarioChecker scenarioChecker;
DataProcessingView() {
setLayout(new BorderLayout()); // force it to span across the whole available space
......@@ -88,6 +90,10 @@ class DataProcessingView extends JPanel implements IJsonView {
switchMode();
}
public void setScenarioChecker(IScenarioChecker scenarioChecker) {
this.scenarioChecker = scenarioChecker;
}
private void switchMode() {
String link = MessageFormat.format(Messages.getString("ProjectView.JSONSwitch.link"), (inGuiViewMode ? jsonViewMode : guiViewMode));
switchJsonViewModeLabel.setText("<html><span style='font-size:8px'><font color='blue'>" +
......@@ -99,11 +105,13 @@ class DataProcessingView extends JPanel implements IJsonView {
if (inGuiViewMode) {
logger.info("switch to gui view");
GuiView guiView = new GuiView();
guiView.setScenarioChecker(scenarioChecker);
activeJsonView = guiView;
viewPanel.add(guiView);
} else {
logger.info("switch to expert view");
TextView expertView = buildExpertView();
expertView.setScenarioChecker(scenarioChecker);
activeJsonView = expertView;
viewPanel.add(expertView);
}
......@@ -187,6 +195,7 @@ class DataProcessingView extends JPanel implements IJsonView {
private DataProcessor selectedDataProcessor;
private String latestJsonParsingError;
private Set<Integer> dataProcessIdsInUse = new HashSet<>();
private IScenarioChecker scenarioChecker;
GuiView() {
/* via www.oracle.com/technetwork/java/tablelayout-141489.html,
......@@ -323,9 +332,14 @@ class DataProcessingView extends JPanel implements IJsonView {
private void refreshGUI() {
currentScenario.updateCurrentStateSerialized();
scenarioChecker.checkScenario(currentScenario);
ProjectView.getMainWindow().refreshScenarioNames();
}
public void setScenarioChecker(IScenarioChecker scenarioChecker) {
this.scenarioChecker = scenarioChecker;
}
private String getDefaultFilename(){
String filename = "out.txt";
int count = 1;
......
......@@ -680,7 +680,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
scenarioNamePanel = new ScenarioNamePanel();
rightSidePanel.add(scenarioNamePanel, BorderLayout.NORTH);
scenarioJPanel = new ScenarioPanel(scenarioNamePanel, model);
scenarioJPanel = new ScenarioPanel(model);
model.setScenarioNamePanel(scenarioNamePanel); // TODO [priority=low] [task=refactoring] breaking mvc pattern (?) - but I need access to refresh the scenarioName
model.addProjectChangeListener(scenarioJPanel);
rightSidePanel.add(scenarioJPanel, BorderLayout.CENTER);
......
......@@ -33,7 +33,7 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
private static final long serialVersionUID = 0L;
private JTabbedPane tabbedPane;
private final ScenarioNamePanel scenarioNamePanel;
// private final ScenarioNamePanel scenarioNamePanel;
// tabs
private List<JMenu> menusInTabs = new ArrayList<>();
......@@ -58,8 +58,7 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
private static JEditorPane activeTopographyErrorMsg = null;
ScenarioPanel(ScenarioNamePanel scenarioNamePanel, ProjectViewModel model) {
this.scenarioNamePanel = scenarioNamePanel;
ScenarioPanel(ProjectViewModel model) {
this.onlineVisualization = new OnlineVisualization(true);
this.postVisualizationView = new PostvisualizationWindow(model.getCurrentProjectPath());
this.model = model;
......@@ -86,8 +85,7 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
tabbedPane.addChangeListener(e -> {
// remove ScenarioChecker listener if exists
scenarioNamePanel.stopObserver();
model.scenarioCheckerStopObserve();
int index = tabbedPane.getSelectedIndex();
if (index >= 0 && topographyFileView != null
......@@ -98,18 +96,23 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
&& index == tabbedPane.indexOfTab(Messages.getString("Tab.TopographyCreator.title"))
&& scenario != null) {
setTopography(scenario.getTopography());
scenarioNamePanel.observerIDrawPanelModel(topographyCreatorView.getPanelModel());
model.scenarioCheckerStartObserve(topographyCreatorView.getPanelModel());
return;
}
scenarioNamePanel.check(scenario);
// model.scenarioCheckerCheck(scenario);
});
//Tab
attributesSimulationView =
new TextView("/attributes", "default_directory_attributes", AttributeType.SIMULATION);
attributesSimulationView.setScenarioChecker(model);
tabbedPane.addTab(Messages.getString("Tab.Simulation.title"), attributesSimulationView);
//Tab
attributesModelView = new TextView("/attributes", "default_directory_attributes", AttributeType.MODEL);
attributesModelView.setScenarioChecker(model);
JMenuBar presetMenuBar = new JMenuBar();
......@@ -161,8 +164,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
mnModelNameMenu.add(submenuMainModels);
ModelHelper.instance().getSortedMainModel()
// ClassFinder.getMainModelNames().stream()
// .sorted()
.forEach(className -> submenuMainModels.add(new JMenuItem(new AbstractAction(className) {
@Override
public void actionPerformed(ActionEvent e) {
......@@ -171,8 +172,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
}
)));
// Map<String, List<String>> groupedPackages = ClassFinder.groupPackages(ClassFinder.getModelNames());
// Map<String, List<String>> groupedPackages = ModelHelper.instance().getModelsSortedByPackage();
ModelHelper.instance().getModelsSortedByPackageStream().forEach( entry -> {
JMenu currentSubMenu = new JMenu(entry.getKey());
......@@ -193,6 +192,8 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
tabbedPane.addTab(Messages.getString("Tab.Model.title"), attributesModelView);
topographyFileView = new TextView("/scenarios", "default_directory_scenarios", AttributeType.TOPOGRAPHY);
topographyFileView.setScenarioChecker(model);
tabbedPane.addTab(Messages.getString("Tab.Topography.title"), topographyFileView);
dataProcessingGUIview = new DataProcessingView();
tabbedPane.addTab(Messages.getString("Tab.OutputProcessors.title"), dataProcessingGUIview);
......@@ -228,7 +229,7 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
*/
public void setScenario(Scenario scenario, boolean isEditable) {
this.scenario = scenario;
this.scenarioNamePanel.setScenarioName(scenario.getDisplayName());
model.setScenarioNameLabelString(scenario.getDisplayName());
if (!initialized) {
initialize();
......@@ -297,7 +298,7 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
}
public void clearScenarioView() {
scenarioNamePanel.setScenarioName("");
model.setScenarioNameLabelString("");
initialized = false;
removeAll();
......
......@@ -29,6 +29,7 @@ import org.fife.ui.rsyntaxtextarea.Theme;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.projectview.VadereApplication;
import org.vadere.gui.projectview.model.IScenarioChecker;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager;
import org.vadere.simulator.projects.io.JsonConverter;
......@@ -64,7 +65,7 @@ public class TextView extends JPanel implements IJsonView {
private boolean isEditable;
private DocumentListener documentListener;
private IScenarioChecker scenarioChecker;
private JTextArea txtrTextfiletextarea;
private ActionListener saveToFileActionListener = new ActionListener() {
......@@ -193,6 +194,9 @@ public class TextView extends JPanel implements IJsonView {
ScenarioPanel.removeJsonParsingErrorMsg();
ProjectView.getMainWindow().refreshScenarioNames();
jsonValidIndicator.setValid();
if (scenarioChecker != null){
scenarioChecker.checkScenario(currentScenario);
}
} catch (Exception e) {
ScenarioPanel.setActiveJsonParsingErrorMsg(attributeType.name() + " tab:\n" + e.getMessage());
jsonValidIndicator.setInvalid();
......@@ -270,4 +274,8 @@ public class TextView extends JPanel implements IJsonView {
public void insertAtCursor(String text) {
txtrTextfiletextarea.insert(text, txtrTextfiletextarea.getCaretPosition());
}
public void setScenarioChecker(IScenarioChecker scenarioChecker) {
this.scenarioChecker = scenarioChecker;
}
}
......@@ -36,7 +36,7 @@ public enum ScenarioCheckerMessageType {
}
public boolean isWarnMsg(){
return type.equals("Warn");
return type.equals("Warning");
}
public String getType() {
......
......@@ -10,7 +10,7 @@ import java.util.PriorityQueue;
public class SimulationTimeStepLengthCheck extends AbstractScenarioCheck {
private final static double LOW_BOUND = 0.1;
private final static double LOW_BOUND = 0.01;
private final static double HIGH_BOUND = 1.0;
@Override
......@@ -19,7 +19,7 @@ public class SimulationTimeStepLengthCheck extends AbstractScenarioCheck {
AttributesSimulation simAttr = scenario.getAttributesSimulation();
double simTimeStep = simAttr.getSimTimeStepLength();
if(simTimeStep < LOW_BOUND || simTimeStep > HIGH_BOUND){
if(simTimeStep <= LOW_BOUND || simTimeStep >= HIGH_BOUND){
ret.add(msgBuilder.simulationAttrError()
.reason(ScenarioCheckerReason.SIM_TIME_STEP_WRONG,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment