Skip to content

Commit

Permalink
Add Wizard operator
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaillandier committed Apr 9, 2021
1 parent 8926448 commit 887441a
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 1 deletion.
4 changes: 4 additions & 0 deletions msi.gama.core/src/msi/gama/common/interfaces/IGui.java
Expand Up @@ -27,6 +27,8 @@
import msi.gama.runtime.exceptions.GamaRuntimeException;
import msi.gama.util.GamaFont;
import msi.gama.util.GamaMapFactory;
import msi.gama.util.IList;
import msi.gama.util.IMap;
import msi.gama.util.file.IFileMetaDataProvider;
import msi.gaml.architecture.user.UserPanelStatement;
import msi.gaml.statements.test.CompoundSummary;
Expand Down Expand Up @@ -99,6 +101,8 @@ public interface IGui {

Map<String, Object> openUserInputDialog(IScope scope, String title, List<IParameter> parameters, GamaFont font);

IList<IMap<String, Object>> openWizard(IScope scope, String title, IList<IMap<String, Object>> pages);

public Boolean openUserInputDialogConfirm(final IScope scope, final String title,final String message) ;


Expand Down
23 changes: 22 additions & 1 deletion msi.gama.core/src/msi/gama/runtime/HeadlessListener.java
Expand Up @@ -10,7 +10,6 @@
********************************************************************************************************/
package msi.gama.runtime;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand All @@ -23,6 +22,7 @@
import msi.gama.common.interfaces.IGamaView;
import msi.gama.common.interfaces.IGamlLabelProvider;
import msi.gama.common.interfaces.IGui;
import msi.gama.common.interfaces.IKeyword;
import msi.gama.common.interfaces.IStatusDisplayer;
import msi.gama.kernel.experiment.IExperimentPlan;
import msi.gama.kernel.experiment.IParameter;
Expand All @@ -39,7 +39,10 @@
import msi.gama.runtime.exceptions.GamaRuntimeException;
import msi.gama.util.GamaColor;
import msi.gama.util.GamaFont;
import msi.gama.util.GamaListFactory;
import msi.gama.util.GamaMapFactory;
import msi.gama.util.IList;
import msi.gama.util.IMap;
import msi.gama.util.file.IFileMetaDataProvider;
import msi.gama.util.file.IGamaFileMetaData;
import msi.gaml.architecture.user.UserPanelStatement;
Expand Down Expand Up @@ -81,6 +84,24 @@ public Map<String, Object> openUserInputDialog(final IScope scope, final String
});
return initialValues;
}
@Override
public IList<IMap<String, Object>> openWizard(IScope scope, String title, IList<IMap<String, Object>> pages) {
final IList<IMap<String, Object>> initialValues = GamaListFactory.create();
for (IMap l : pages) {
final IMap<String, Object> initialValuesPage = GamaMapFactory.create();
initialValues.add(initialValuesPage);
IList<IParameter> ps = (IList<IParameter>) l.get(IKeyword.PARAMETERS);
if (ps != null) {
ps.forEach(p -> {
initialValuesPage.put(p.getName(), p.getInitialValue(scope));
});
}

}

return initialValues;
}


@Override
public Boolean openUserInputDialogConfirm(final IScope scope, final String title,final String message) {
Expand Down
25 changes: 25 additions & 0 deletions msi.gama.core/src/msi/gaml/operators/System.java
Expand Up @@ -16,6 +16,7 @@
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.Platform;

Expand Down Expand Up @@ -307,6 +308,30 @@ public static IMap<String, Object> userInput(final IScope scope, final String ti
return GamaMapFactory.createWithoutCasting(Types.STRING, Types.NO_TYPE,
scope.getGui().openUserInputDialog(scope, title, parameters,font));
}

@operator (
value = IKeyword.WIZARD,
category = { IOperatorCategory.SYSTEM, IOperatorCategory.USER_CONTROL },
concept = {})
@no_test

public static IList<IMap<String, Object>> openWizard(final IScope scope, final String title, final IList<IMap<String, Object>> pages) {
return scope.getGui().openWizard(scope, title, pages);
}

@operator (
value = IKeyword.WIZARD_PAGE,
category = { IOperatorCategory.SYSTEM, IOperatorCategory.USER_CONTROL },
concept = {})
@no_test
public static IMap<String, Object> wizardPage(final String title, final String description,final IList parameters, final GamaFont font) {
IMap<String, Object> results = GamaMapFactory.create();
results.put(IKeyword.TITLE, title);
results.put(IKeyword.DESCRIPTION, description);
results.put(IKeyword.PARAMETERS, parameters);
results.put(IKeyword.FONT, font);
return results;
}

@operator (
value = IKeyword.USER_INPUT,
Expand Down
Expand Up @@ -414,6 +414,9 @@ public interface IKeyword {
String TIME_SERIES = "time_series"; // hqnghi facet for
// continuous Chart
String TABLE = "table";

String DESCRIPTION = "description";
String PARAMETERS = "parameters";
String TITLE = "title";
String TO = "to";
String TOPOLOGY = "topology";
Expand All @@ -432,6 +435,8 @@ public interface IKeyword {
String USER_COMMAND = "user_command";
String USER_INPUT = "user_input";
String USER_CONFIRM = "user_confirm";
String WIZARD = "wizard";
String WIZARD_PAGE = "wizard_page";
String USER_ONLY = "user_only";
String USER_FIRST = "user_first";
String USER_LAST = "user_last";
Expand Down
@@ -0,0 +1,51 @@
package ummisco.gama.ui.parameters;

import java.util.List;

import org.eclipse.jface.wizard.Wizard;

import msi.gama.util.GamaListFactory;
import msi.gama.util.IList;
import msi.gama.util.IMap;


public class GamaWizard extends Wizard{
protected List<GamaWizardPage> pages;
protected String title;

public GamaWizard(String title, List<GamaWizardPage> pages) {
super();
this.title = title;
this.pages = pages;
setNeedsProgressMonitor(true);
}

@Override
public String getWindowTitle() {
return title;
}

public IList<IMap<String, Object>> getValues() {
IList<IMap<String, Object>> values = GamaListFactory.create();
for(GamaWizardPage p : pages) {
System.out.println("page: " + p);
values.add(p.getValues());
}
return values;
}

@Override
public void addPages() {
for (GamaWizardPage p : pages) {
addPage(p);
}
}

@Override
public boolean performFinish() {
return true;
}



}
@@ -0,0 +1,33 @@
package ummisco.gama.ui.parameters;


import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;

import msi.gama.util.IList;
import msi.gama.util.IMap;

public class GamaWizardDialog extends WizardDialog{

GamaWizard wizard;
public GamaWizardDialog(Shell parentShell, GamaWizard newWizard) {
super(parentShell, newWizard);
this.wizard = newWizard;
}

/*@Override
protected Point getInitialSize() {
final var p = super.getInitialSize();
return new Point(p.x * 2, p.y);
}
@Override
protected boolean isResizable() {
return true;
}*/

public IList<IMap<String, Object>> getValues() {
return wizard.getValues();
}
}
@@ -0,0 +1,60 @@
package ummisco.gama.ui.parameters;

import java.util.List;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import msi.gama.kernel.experiment.IParameter;
import msi.gama.runtime.IScope;
import msi.gama.util.GamaFont;
import msi.gama.util.GamaMapFactory;
import msi.gama.util.IMap;
import ummisco.gama.ui.interfaces.EditorListener;

public class GamaWizardPage extends WizardPage{

private final IMap<String, Object> values = GamaMapFactory.createUnordered();
private final List<IParameter> parameters;
private final GamaFont font;
private final IScope scope;

public GamaWizardPage(final IScope scope, final List<IParameter> parameters,
final String title, final String description, final GamaFont font) {
super(title);
setTitle(title);
setDescription(description);
this.scope = scope;
this.font = font;
this.parameters = parameters;
parameters.forEach(p -> {
values.put(p.getName(), p.getInitialValue(scope));
});
}

@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
composite.setLayout(layout);
layout.numColumns = 2;
parameters.forEach(param -> {
final EditorListener<?> listener = newValue -> {
param.setValue(scope, newValue);
values.put(param.getName(), newValue);
};
EditorFactory.create(scope, composite, param, listener, false, false);
});
composite.layout();
setControl(composite);
}

public IMap<String, Object> getValues() {
return values;
}



}
47 changes: 47 additions & 0 deletions ummisco.gama.ui.shared/src/ummisco/gama/ui/utils/SwtGui.java
Expand Up @@ -41,6 +41,7 @@
import msi.gama.common.interfaces.IGamaView.User;
import msi.gama.common.interfaces.IGamlLabelProvider;
import msi.gama.common.interfaces.IGui;
import msi.gama.common.interfaces.IKeyword;
import msi.gama.common.interfaces.IRuntimeExceptionHandler;
import msi.gama.common.interfaces.IStatusDisplayer;
import msi.gama.common.preferences.GamaPreferences;
Expand All @@ -62,7 +63,9 @@
import msi.gama.runtime.ISimulationStateProvider;
import msi.gama.runtime.exceptions.GamaRuntimeException;
import msi.gama.util.GamaFont;
import msi.gama.util.GamaListFactory;
import msi.gama.util.GamaMapFactory;
import msi.gama.util.IList;
import msi.gama.util.IMap;
import msi.gama.util.file.IFileMetaDataProvider;
import msi.gaml.architecture.user.UserPanelStatement;
Expand All @@ -78,6 +81,9 @@
import ummisco.gama.ui.interfaces.ISpeedDisplayer;
import ummisco.gama.ui.interfaces.IUserDialogFactory;
import ummisco.gama.ui.parameters.EditorsDialog;
import ummisco.gama.ui.parameters.GamaWizard;
import ummisco.gama.ui.parameters.GamaWizardDialog;
import ummisco.gama.ui.parameters.GamaWizardPage;

/**
* Written by drogoul Modified on 6 mai 2011
Expand Down Expand Up @@ -280,6 +286,47 @@ public Map<String, Object> openUserInputDialog(final IScope scope, final String
return result;
}

@Override
public IList<IMap<String, Object>> openWizard(IScope scope, String title, IList<IMap<String, Object>> pages) {
final IList<IMap<String, Object>> result = GamaListFactory.create();
final IList<GamaWizardPage> wizardPages = GamaListFactory.create();
for (IMap<String, Object> l : pages) {
GamaFont f = (GamaFont) l.get(IKeyword.FONT);
String t = (String) l.get(IKeyword.TITLE);
String d = (String) l.get(IKeyword.DESCRIPTION);
List<IParameter> ps = (List<IParameter>) l.get(IKeyword.PARAMETERS);

wizardPages.add(new GamaWizardPage(scope, ps,t,d, f));

}


WorkbenchHelper.run(() -> {
final GamaWizard wizard = new GamaWizard(title, wizardPages);
GamaWizardDialog wizardDialog = new GamaWizardDialog(WorkbenchHelper.getShell(),wizard);
if (wizardDialog.open() == Window.OK) {
result.addAll(wizardDialog.getValues());
}
});
return result;
}

/*@Override
public Map<String, Object> openWizard(final IScope scope, final String title,
final List<IParameter> parameters, final GamaFont font) {
final IMap<String, Object> result = GamaMapFactory.createUnordered();
for (final IParameter p : parameters) {
result.put(p.getName(), p.getInitialValue(scope));
}
WorkbenchHelper.run(() -> {
final EditorsDialog dialog = new EditorsDialog(scope, WorkbenchHelper.getShell(), parameters, title, font);
if (dialog.open() == Window.OK) {
result.putAll(dialog.getValues());
}
});
return result;
}*/

@Override
public Boolean openUserInputDialogConfirm(final IScope scope, final String title,final String message) {
final List<Boolean> result = new ArrayList<>();
Expand Down

0 comments on commit 887441a

Please sign in to comment.